Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JNDI - Location Transparency ?

 
Malli Raman
Ranch Hand
Posts: 312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

Location Transparency can by achieved by using JNDI object. How is it possible?

Context ctx = null;
java.util.Hashtable ht = new java.util.Hashtable();
ht.put(-- Initial Context Factory --);
ht.put(-- Provider URL --);
ctx =new InitialContext(ht);

If we give the provider url details then how will it become location transparency?

I think in using ejb-ref we can achieve the location transparency for the server side clients (servlets/bean client). But what about standalone application uses datasources/beans etc?

If we put Context ctx = new InitialContext(); then how can achieve the location transparency?

Regards,
M.S.Raman
 
Valentin Tanase
Ranch Hand
Posts: 704
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One way is to use application resource files. Having a file named jndi.properties that defines all properties required to build the initial context will help achieving the location transparency. This file must be located in the application's classpath or it might be located under the $JAVA_HOME/lib folder. Another way is to use an IoC container like PicoContainer or Spring framework that does that job for you.
Regards.
 
Malli Raman
Ranch Hand
Posts: 312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Valentin Tanase:
One way is to use application resource files. Having a file named jndi.properties that defines all properties required to build the initial context will help achieving the location transparency. This file must be located in the application's classpath or it might be located under the $JAVA_HOME/lib folder. Another way is to use an IoC container like PicoContainer or Spring framework that does that job for you.
Regards.


Hi,
I tried this and it is working fine. By doing this way I can say that the client don't require to hardcode the "provider_url" in the code to get the initial context.

Now it brings me another question. In the jndi.properties file you are mentioning the Provider URL to locate the context. Fine, If that is the case how will you say that it is location transparent to the client since the client knows the Provider URL in his $java_home/lib folder. Also whether the client can able to speak with two different context at the same time?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic