JNDI Naming confusion
mikemil Jul 11, 2012 10:55 PMI am researching a migration from JBoss 4.2.3.GA to AS7.x and have been struggling with the new JNDI processing. I read both of the following links
- http://https://docs.jboss.org/author/display/AS71/Remote+EJB+invocations+via+JNDI+-+EJB+client+API+or+remote-naming+project
- https://docs.jboss.org/author/display/AS71/EJB+invocations+from+a+remote+client+using+JNDI
along with many others because we the migration would also include moving from EJB 2.1 up to EJB 3.x. Tonight, after re-reading the first link from above, I think part of my confusion has been resolved.
My initial research was with the "ejb-remote" project from the quick starts, specifically for the stateless beans. One of the things adding to my confusion was the log statement that logs all of the bindings created for this session bean. I was under the impression that I should be able to lookup the session bean using each of the jndi names listed below.
19:56:13,406 INFO [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-4) JNDI bindings for session bean named CalculatorBean in deployment unit deployment "jboss-as-ejb-remote-app.jar" are as follows:
java:global/jboss-as-ejb-remote-app/CalculatorBean!org.jboss.as.quickstarts.ejb.remote.stateless.RemoteCalculator
java:app/jboss-as-ejb-remote-app/CalculatorBean!org.jboss.as.quickstarts.ejb.remote.stateless.RemoteCalculator
java:module/CalculatorBean!org.jboss.as.quickstarts.ejb.remote.stateless.RemoteCalculator
java:jboss/exported/jboss-as-ejb-remote-app/CalculatorBean!org.jboss.as.quickstarts.ejb.remote.stateless.RemoteCalculator
java:global/jboss-as-ejb-remote-app/CalculatorBean
java:app/jboss-as-ejb-remote-app/CalculatorBean
java:module/CalculatorBean
So I decided to write an EJBClient program that attempted to do a jndi lookup for each of these jndi names and do it without any magic files like the jboss-ejb-client.properties file. I added all the jndi properties explicitly before creating the InitialContext. Exactly NONE of these strings worked, but I knew that the quick start client worked, so after reviewing that code, I added an additional entry to the array of jndi names
"ejb:/jboss-as-ejb-remote-app/CalculatorBean!org.jboss.as.quickstarts.ejb.remote.stateless.RemoteCalculator"
Re-running the program, now I got 1 success - better but not really what I was expecting. So after re-reading the first link AGAIN, I came across two very important points:
- Note: Since the JNDI name that you use on the client side is always relative to java:jboss/exported namespace, you shouldn't be prefixing the java:jboss/exported/ string to the JNDI name.
- Note that only the java:jboss/exported/ namespace is available to remote clients.
So back to my test program - I took each of the names from the log statement, repeated them and removed the first part of each string on the newly repeated line, so java:app/, java:module/ and java:global/, java:jboss/exported/ and ran again. Now I got a couple more successful lookups - mostly because by removing the namespace (is that the correct term?), some of the strings were basically resolving to the same string.
Is it safe to say that we can ignore all but the java:jboss/exported/ naming bindings, at least for remote clients, since that is the only name space available to remote clients? If so, why are all those other bindings included in the log?
I have attached my sample program in case there were any questions about how I created my test.
-
EJBClient.java.zip 1.1 KB