开发者

javax.naming.NoInitialContextException: Failed to create InitialContext using factory specified in hashtable

I have small program which just creating intial context in unmanaged environment i.e. outside the container.I have been using Websphere 7.0. I have written following program to do the connection with application which is running on WAS 7 using corba url,

package snippet;

import java.util.Hashtable;

import javax.naming.Context;
import javax.naming.InitialContext;

public class test {
    public static void main(String[] args) {
        try {
            // create initial context
            Hashtable env = new Hashtable();
            env.put(Context.INITIAL_CONTEXT_FACTORY,
                    "com.ibm.websphere.naming.WsnInitialContextFactory");
            env
                    .put(Context.PROVIDER_URL,
                            "corbaloc:iiop:1.0@x1devapp63.dev.freightliner.com:2809/NameService");

            InitialContext ctx = new InitialContext(env);

            System.out.println(ctx);
        } catch (Exception ex) {
            ex.printStackTrace();
        }

    }
} 

I have created runnable jar and executing using shell script given below,

#!/bin/sh

WAS_ROOT_PATH=/application/WebSphere/AppServer
SCHEDULER_JAR=/application/apps/JobScheduler/testJNDI.jar
SCHEDULE_FILE=/application/apps/JobScheduler/schedule.xml
. "$WAS_ROOT_PATH"/bin/setupCmdLine.sh
CLASSPATH="$MQLIB":"$WAS_CLASSPATH"
"$JAVA_HOME"/bin/java -classpath "$CLASSPATH" -jar "$SCHEDULER_JAR"

Ater running i have been facing below exception,

$ testJNDI.sh
javax.naming.NoInitialContextException: Failed to create InitialContext using factory specified in hashtable {java.naming.provider.url=corbaloc:iiop:1.0@x1devapp63.dev.freightliner.com:2809/NameService, java.naming.factory.initial=com.ibm.websphere.naming.WsnInitialContextFactory} [Root exception is java.lang.NullPointerException]
        at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:243)
        at javax.naming.InitialContext.initializeDefaultInitCtx(InitialContext.java:327)
        at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:357)
        at javax.naming.InitialContext.internalInit(InitialContext.java:295)
        at javax.naming.InitialContext.<init>(InitialContext开发者_如何学C.java:212)
        at snippet.test.main(test.java:19)
Caused by: java.lang.NullPointerException
        at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:235)
        ... 5 more
$ 

I got stuck on above problem but i could not get why this is happening.

Please do the needful to get out me from above problem.


Don't forget to include the thinclient-jars to your buildpath. You will need them to do a jndi lookup from a standalone client.

%WAS_HOME%/runtimes is where they can be found.

http://publib.boulder.ibm.com/infocenter/wasinfo/v7r0/index.jsp?topic=/com.ibm.websphere.nd.multiplatform.doc/info/ae/ae/ccli_standaloneclient.html


The Provider URL helps you to identify the server and the root @ which you connect to the name space.

As an example, if you wanted to connect to the Cell Persisent root, you would specify the the Provider_URL as:

env.put(Context.PROVIDER_URL, "corbaloc:iiop:myhost.mycompany.com:2809/NameServiceCellPersistentRoot");

Server Root NameServiceServerRoot Cell Persistent Root NameServiceCellPersistentRoot Cell Root NameServiceCellRoot Node Root NameServiceNodeRoot

The default object key is:"NameService" so stating that in the URL is not required if you want to connect to the default location.

Also, is there anything else in the stack trace that states any other information?

Also from the client machine is the DNS name: x1devapp63.dev.freightliner.com resolvable?

Is this the name that is used by the WAS Server to identify itself? When WAS is installed you do specify a host name and does that match this name?

Can you also run the same from the same machine as the WAS Server and use localhost and see if the errors are the same.

I am just thinking about potential network related errors which are probably causing trouble.

Have a look at this for the various values that help you could connect to for the root context.

http://publib.boulder.ibm.com/infocenter/wasinfo/v7r0/index.jsp?topic=/com.ibm.websphere.nd.multiplatform.doc/info/ae/ae/rnam_example_prop5.html

HTH Manglu


Are you sure the provider URL is correct? According to various examples like this one (WAS Express 6) or this one (WAS 8) (couldn't find a reference for WAS 7 but it looks like things didn't change), the code to use a CORBA object URL with the WAS JNDI implementation is described as follows:

Using a CORBA object URL

This example shows a CORBA object URL.

...
import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.InitialContext;
...
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,
     "com.ibm.websphere.naming.WsnInitialContextFactory");
env.put(Context.PROVIDER_URL, "corbaloc:iiop:myhost.mycompany.com:2809");
Context initialContext = new InitialContext(env);
...

Don't know if this will help though.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜