How to extract stateful session handle without using jndi.properties
Hello,
Is there a way I can extract a stateful session bean handle and use it to obtain its EJBObject without using a jndi.properties file?
I have several servlets running on a web server (Tomcat) and I would like to use different
providers for some of them. How can I accomplish this? Without the file, I get a NoInitialContextException().
Thanks.
[393 byte] By [
misterph] at [2007-9-26 1:48:48]

You will need to create an environment property object for the InitialContext constructor to use to initialise a context.
Something like this:
Properties env = new Properties();
env.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
env.put(javax.naming.Context.PROVIDER_URL, "jnp://localhost:3001");
env.put(javax.naming.Context.URL_PKG_PREFIXES, "org.jboss.naming");
This is specific to the JBoss naming service, so you must find out which initial context factory class you need to use for your servers naming service, aswell as the provider url you should use.
You can then call your initialcontext() method like so...
javax.naming.Context context = new javax.naming.InitialContext(env);
and your initial context will have been created using the naming service specified in the env properties object.
Hope this helps.
Andy
I'm still a bit confused. How does this link to "handle.getEJBObject()"?
In the first client connection, I store the handle in the user session:
session.setAttribute ("handle", sb.getHandle());
When retrieving the handle, I call:
Handle handle = (Handle) session.getAttribute ("handle");
SB sb = (SB) handle.getEJBObject();
The getEJBObject() call according to the call stack in an exception calls InitialContext() with no parameters, using information in jndi.properties. If jndi.properties doesn't exist, I get a NoInitialContextException. I was under the assumption that the handle is supposed to be the network address of where the basket is located, so why do I need to create a new InitialContext? I need to find a way around this. Otherwise, all of my servlets are forced to use the configuration in jndi.properties.
Thanks.