How to access the JNDI namespace defined in the Websphere 7.0 from outside of the container?

Hitarthi picture Hitarthi · Mar 16, 2012 · Viewed 15.7k times · Source

I am tring to lookup the resource defined on the Websphere aplication server 7.0 from the out side of the Container with using the iiop protocol as below:

Java code for (RMI client)Test.jar:

public static void main(String[] args){
Hashtable<Object, Object> properties = new Hashtable<Object, Object>();
properties.put(Context.INITIAL_CONTEXT_FACTORY, 
        "com.ibm.websphere.naming.WsnInitialContextFactory"); 
           properties.put(Context.PROVIDER_URL, "iiop://localhost:2809"); 
InitialContext intCt;
try {
       InitialContext initCtx = new InitialContext(properties);
       Object obj = intCt.lookup(JNDI_NAME);
     }catch (NamingException namingE) {
            System.out.println("Naming Exception occurred :");
            namingE.printStackTrace();
        }   
}

Cmmand file to call the Test.jar:

set appClassPath=C:\WebSphere\AppServer7.0\deploytool\itp\plugins\com.ibm.websphere.v7_7.0.1.v20090422_1423\wasJars\naming.jar;C:\WebSphere\AppServer7.0\deploytool\itp\plugins\com.ibm.websphere.v7_7.0.1.v20090422_1423\wasJars\namingclient.jar;C:\WebSphere\AppServer7.0\properties;C:\Batch\CommandFiles\JobServer\Test.jar

C:\WebSphere\AppServer7.0\java\jre\bin\java -jar -cp "%appClassPath%" C:\Batch\CommandFiles\JobServer\Test.jar %Parameters%  

NOTE : Please not that I am runnig the client on my local machin and bootstrap host is : localhost and the port is 2809.

At the time of running the Test.jar code form the command file I am getting the following error:

javax.naming.NoInitialContextException: Failed to create InitialContext using factory specified in hashtable {java.naming.provider.url=iiop://localhost:2809, 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.(InitialContext.java:212)
    at com.uuic.ets.rmi.server.client.Client.main(Client.java:130)
Caused by: java.lang.NullPointerException
    at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:235)
    ... 5 more

I have no idea that why this code is not able to instantiat the InitialContext(Hashmap env). This same code is running in Websphere application server version 5.1 but having problem in Websphere application server version 7.0.

Answer

Brett Kail picture Brett Kail · Apr 18, 2012

Using JARs from WAS_HOME/deploytool for the classpath is not supported. Try using the documented EJB thinclient with WAS_HOME/runtimes/com.ibm.ws.ejb.thinclient_7.0.0.jar.