-
1. Re: How to look up a bean in another JBoss' JNDI ?
sudsy Dec 31, 2003 10:25 AM (in response to ftg314159)Everything derives from the InitialContext which you use to perform lookups. Check out this code:
Hashtable env = new Hashtable();
env.put("java.naming.factory.initial",
"org.jnp.interfaces.NamingContextFactory");
env.put("java.naming.provider.url",
"somehost:1099");
Context ctx = new InitialContext( env );
This assumes that you're running the default JBoss naming service on a host known as somehost at the default port (1099). Now you can just use ctx in the usual manner, i.e.:
Object obj = ctx.lookup( "someclass" );
Be sure to use PortableRemoteObject.narrow() rather than just a simple cast as you're dealing with a remote reference here. -
2. Re: How to look up a bean in another JBoss' JNDI ?
ftg314159 Jan 2, 2004 7:38 AM (in response to ftg314159)Thanks for the reply.
I know the actual JNDI mechanics of doing this, but I was looking for a way to do it outside of the code, e.g. in the deployment descriptor or in the JBoss configuration files. I don't want the code to have to particpate in JNDI management.
Section 19.7 of the spec states that the container must take care of linking an <ejb-ref> to the InitialContext of the owning server, but doesn't say where to specify the server. I'm assuming that the way to do it is container-specific, so basically what I'm asking is how to tell JBoss to do it... -
3. Re: How to look up a bean in another JBoss' JNDI ?
jonlee Jan 2, 2004 8:53 AM (in response to ftg314159)For your ejb-ref tag set in jboss.xml, try:
<ejb-ref-name>ejb/SomeBean</ejb-ref-name> <jndi-name>jnp://remoteserver:1099/some/RemoteBean</jndi-name>
I haven't tried it in a while but it should work. You then use the ejb-ref in your lookup.... ctx.lookup("java:comp/env/ejb/SomeBean");
You'll need to create the appropriate ejb-ref tags in ejb-jar.xml to complete the mapping.
This, as with the original suggestion, only works with communication using the same JBoss version servers - due to the requirements of Java class versioning imposed by the client-server communication.
Refer to http://amitysolutions.com.au/documents/JBossTomcatJNDI-technote.pdffor more information on reference mappings.
Hope that helps. -
4. Re: How to look up a bean in another JBoss' JNDI ?
ftg314159 Jan 2, 2004 10:13 AM (in response to ftg314159)Sounds promising; I'll try it. Thanks for the post.