How to find out what SerialContextProvider should use when performing a jndi search?

Today I was given 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 tried remotely accessing ejb, the violation code was

 Context c = new InitialContext(); 

I saw this exception before and fixed it, but I couldn’t remember exactly how I did it. I knew that I needed to set some environment variables for the source, contextual URL and the service provider or some similar materials.

In fact, I managed to find the code that I used to fix this problem the last time I had it, it looks like this.

 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, how can you find out which original factory context to use? I wrote an ejb module for our database that runs on Glassfish v3, by no means received any hint that, of course, I should use com.sun.enterprise.naming.SerialInitContextFactory , I mean that it so obvious. Who makes these contextual factories? Who decides which one I need to use and why? Why is there no list showing which one is required for different purposes? It seems that someone has gone astray to make the most impenetrable and mysterious way to access a resource that is humanly possible. Or I didn’t understand anything at all, or I lack a huge amount of knowledge.

I would very much like to receive some enlightenment on this issue.

Thanks to everyone.

+4
source share
3 answers

settings for glass fish for jndi.properties for reference:

 java.naming.factory.initial=com.sun.enterprise.naming.SerialInitContextFactory java.naming.factory.url.pkgs=com.sun.enterprise.naming java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl Context.SECURITY_PRINCIPAL=user1 Context.SECURITY_CREDENTIALS=pass123 org.omg.CORBA.ORBInitialHost=localhost org.omg.CORBA.ORBInitialPort=3700 

1.) The jndi.properties file jndi.properties loaded when the default InitialContext . In my opinion, this is preferable to hard coding these values, creating a Properties object, etc.

2.) These connection parameters work for me when Glassfish works locally. I gathered it together from various sources.

3.) I agree with the spirit in the question: where is it indicated in the thin manual? I saw some references to them in the manual, but they are not all in one place - at least for glass fish. It does not help that the manual for 4-dimensional glass fish is only available via PDF.

+3
source

Typically, JNDI looks for its configuration in the jndi.properties file in the class path.

Meybe has a rogue jndi.properties file that guides you incorrectly.

See https://glassfish.dev.java.net/javaee5/ejb/EJB_FAQ.html#StandaloneRemoteEJB for details

+1
source

Chk if jndiContext.lookup (???) is specified correctly.

0
source

All Articles