We are having difficulties looking up remote EJB's in JNDI. We are using Websphere 5.0. We created the following test scenario to demonstrate our problem:
We are using Websphere Studio Application Develor(WSAD). In WSAD, we setup up two different EARs and deployed them to two different servers. We changed the ports on both servers so that they don't conflict. Each EAR has a different EJB deployed to it.
We wrote the following standalone app to access the JNDI InitialContext on both servers and dump the initial context: (note: DumpNameSpace is a class in naming.jar)
///////////////////////////////////////////////////////
/// Lookup JNDI context for Server A
DumpNameSpace dumpNizzle = new DumpNameSpace();
Hashtable proj1 = new Hashtable();
proj1.put( Context.INITIAL_CONTEXT_FACTORY,
"com.ibm.websphere.naming.WsnInitialContextFactory");
proj1.put(Context.PROVIDER_URL, "iiop://localhost:9809");
InitialContext proje1Context = new InitialContext(proj1);
dumpNizzle.generateDump(proje1Context);
/// Lookup JNDI context for Server B
Hashtable sheet = new Hashtable();
sheet.put( Context.INITIAL_CONTEXT_FACTORY,
"com.ibm.websphere.naming.WsnInitialContextFactory");
sheet.put(Context.PROVIDER_URL, "iiop://localhost:5809");
InitialContext sheetContext = new InitialContext(sheet);
dumpNizzle.generateDump(sheetContext);
///////////////////////////////////////////////////////
When we run this code in a standalone client, it works as expected. We get two different JNDI contexts and they hold the EJB's from their respective servers.
However, when we run the same exact code from a servlet running in a separate Websphere web application, we do not get the same results. Instead of getting the JNDI context from the specified server and port, we get the JNDI context for the Web application that the servlet is running in. We get this same context for both of the above lookups. We are therefore unable to access these EJBs from our web app, because we can't look them up.
1) What is going on here?
2) How can we access remote EJBs from a web application running in a different server?
Thanks for any help.
-Mike