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

40,254

Solution 1

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

Solution 2

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

Share:
40,254
Sharad Ahire
Author by

Sharad Ahire

Updated on July 09, 2022

Comments

  • Sharad Ahire
    Sharad Ahire almost 2 years

    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:[email protected]: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:[email protected]: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.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.