JNDI and NotSerializableException
astrien Apr 27, 2004 10:20 AMHere's the thing:
I've got a very nicely coded WAR file that starts life with a bootstrap class (extending ServletContextListener). Within that class, one of the first things I try to do is to bind() some tidbits to the InitialContext. This is where the fun starts.
In the interest of not pissing off Adrian (God of the Boards), I have done much research into this and have found the following by compiling bits from the Resin boards, Google, the forums here, and rips in the space-time continuum.
What I've found is that (I think), in the jndi.properties file, I have the following:
# DO NOT EDIT THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING # java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces java.naming.provider.url=localhost:1099
This causes all of the calls to JNDI, be it bind()s or lookup()s, to be forced through on port 1099, which requires anything you are trying to bind() or lookup() to be Serializable.
All I'm trying to do here is to get the nice, normal, local JNDI context from within classes running in my WAR and use them internally. I am not trying to access JNDI externally (yet).
What is stumping me is how to get the normal JNDI context that I know and love, with local memory hashes and all, that does not require me to implement Serializable on everything I want to pass through it.
The code I am using is as follows:
To get the InitialContext
this.vInitCtx = new InitialContext();
To bind something to the context where name=String and target=Object
try { this.vInitCtx.bind(name,target); } catch(NamingException nEx) { String msg = "JNDIHelper could not bind target object to name '"+name+"'"; this.logger.severe(msg); this.logger.severe("-- "+nEx.getExplanation()); this.logger.severe("-- "+nEx.getMessage()); throw new Exception(msg,nEx); }
As far as I can tell, when the thread hits the bind() method, I am getting a NamingException, which is wrapped around a CommunicationException, and that has as it's root a NotSerializableException.
So who's the first to tell me that I missed a period somewhere?