Today I was presented with this exception
Caused by: javax.naming.NamingException: Unable to acquire SerialContextProvider for SerialContext [Root exception is java.lang.NullPointerException]
at com.sun.enterprise.naming.impl.SerialContext.getProvider(SerialContext.java:276)
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:430)
... 23 more
I was trying to remotely access an ejb, the offending code was
Context c = new InitialContext();
Ive seen this exception before and fixed it but couldn't remember exactly how I did it. I knew that I had to set some environment variables for the initial ,context url and service provider or some such stuff.
In fact I managed to find the code I used to fix this issue last time i had it, it is as follows.
Hashtable<String, String> env = new Hashtable<String, String>();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.enterprise.naming.SerialInitContextFactory");
env.put(Context.PROVIDER_URL, "localhost:1099");
Context c = new InitialContext(env);
My question is this how can you find out what initial context factory to use? I've written an ejb module for our database that runs on glassfish v3, at no point did I get any hint that of course I should use the com.sun.enterprise.naming.SerialInitContextFactory
, I mean like its so obvious. Who makes these context factories? Who decides which one I have to use and why? Why isn't there a list showing which one is required for different purposes? It seems like someone's gone out of their way to make the most impenetrable and cryptic method of accessing a resource that is humanly possible. Or I have completely misunderstood something here or am lacking a huge chunk of knowledge.
I would very much appreciate some enlightenment on this subject.
Thank you all.