File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB and other Java EE Technologies and the fly likes fundamental question about j2ee/jndi Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "fundamental question about j2ee/jndi" Watch "fundamental question about j2ee/jndi" New topic
Author

fundamental question about j2ee/jndi

Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1873
Hi all,
Okay. So far so good. I've written first Hello World session bean and read much about theory.
I have a very fundamental question about how jndi works with/for j2ee ejb references.
- I know that there are two ways of getting Home object for any bean in a client,
1. if the client is local then, we can use empty arg constructor for InitialContext() and then use JNDIName as java:comp/env/ejb/Hello for example..
2. if the client is not local then we have to specify the InitialContext parameters like PROVIDER_URL etc, right?
Now, here are my questions,
1. Does the deployer (or whoever) really go to some Directory Server and register the ejb so that one can lookup? If so how is that done (In general. No specific app server I am looking at so it would suffice if you just tell me that there is a configuration in the app server for this and what is specified in that configuration)?
2. Once that Directory server binding is done the client have to know the PROVIDER_URL, right? Now, I have just used JNDI to connect to ldap so far for other applications so I am not sure what protocol the client has to use to connect to the Directory server to specify InitialContext?
e.g. If my appserver is publicly visible at,
http://myappserver.com/ then do I just write,
env.put(Context.PROVIDER_URL,"??://myappserver.com/o=apps,ou=myapp");
(Well, this 'o' and 'ou' are specific to LDAP but thats what I have dealt with so far)
I guess you get the idea what I am looking for.
Just for you to know about my experience so far, I have done little RMI and CORBA once so I know that client code has to know the server url and the object they are trying to connect to by some means of lookups or something...
Regards
Maulin
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1873
and btw,
I am working on sun one app server and drilling down the Admin interface to controll applications so I might get some magical knowledge about JNDI while doing that but it would be helpful to have your insights to make my bootup with j2ee faster...
Regards
Maulin
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1873
Hi all,
Okay. Finally yesterday I think I understood how this works.
1. To connect from the client thats outside the container we have to know,
- a protocol used by the appserver for communication e.g. iiop, jrmp etc
- port no on which there is a protocol listener on app server. e.g. ORB-port etc
- JNDI name which is specified in app server specific way. e.g. ejb/MyBean
- the client must be able to download stubs on the fly which means the client might have to deal with specifying policy file entry to allow socket connects etc from url its going to download stubs...OR...client need the generated stub class files from the server in a jar already and then go from there...(of course client would need classes for home/local/remote interfaces etc)...
total example: url = iiop://localhost:1064/, jndiname = ejb/MyBean
2. Every app server has its own internal directory server where it registers the things. If we wanted to use external JNDI then we have to configure references to map to the external JNDI resource. Again, I guess ways to achieve are app server specific as far as they follow required parameters equally..

Regards
Maulin
sever oon
Ranch Hand

Joined: Feb 08, 2004
Posts: 268
You might want to check out the Service Locator pattern from Core J2EE Patterns. I used it at my last company (well, a stripped down version of it) to great effect.
sev
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: fundamental question about j2ee/jndi