By olaf.heimburger on September 26, 2007 12:15 AM
The JNDI context
In Java EE you have to use the JNDI context to lookup objects. This works quite well in many cases. To start with you have to obtain an InitialContext which uses some configuration information on how to connect to the real host. This information is provided either directly through a Properties collection or a jndi.properties file from the class path.
Default Constructor InitialContext within the Container
If you use the InitialContext within the Container you can usually use the InitialContext default constructor. This creates the context for the surrounding container.
Default Constructor InitialContext in a Client
If your using the default constructor for the InitialContext, you can provide a jndi.properties file in your class path to hint the constructor to the real host. This is quite easy to use and highly configurable.
Choke Point
As long as you stay in one environment everything works smooth and fine. But things get difficult if you want to connect to a different Java EE container from within a container. How? Simply consider a helper method getting information from the JNDI context through InitialContext() and an explicit connection with InitialContext(props). While the your application/facade connects to the correct container, the helper method takes the information from the container it is located in... If both contexts are supposed to connect to the same container this doesn't work correctly anymore. Not convinced? Give it some thoughts...