-
1. Re: Remote Tomcat EJB Reference
jamesstrachan Aug 11, 2003 7:19 AM (in response to jm2hall)The behaviour that you describe is correct, surely, for accessing a remote service.
You should be looking up a JNDI name "ejb/xxx" without the "java:comp/env" prefix.
Your problem may be that you want to deploy exactly the same code in both the local and remote instances of Tomcat.
My solution is to use a Name Factory that translates logical to physical EJB names, and then to add the prefix if the Tomcat service is embedded within the J2EE server.
As below :-
String result = nameLookup( logicalName );
// Add the environment prefix if the application is deployed in an embedded server.
if ( ClientProperties.deploymentIsEmbeddedServer() ) {
result = "java:/comp/env/ejb/" + result;
}
The ClientProperties class just reads a Properties file which has a property that flags whether the deployment is embedded - ANT will build that for you.
There is a separate bug where JBoss will not resolve a prefixed name without an equivalent entry in jboss-web.xml - but you may have fought your way past that.
James Strachan -
2. Re: Remote Tomcat EJB Reference
jm2hall Aug 11, 2003 9:41 PM (in response to jm2hall)Ahh... Thanks for your reply.
What you have suggested is actually what I am doing now...
But I thought there was some way by specifying the EJB classes in either the server.xml or web.xml of the remote Tomcat instance, that would resister the EJB in the 'java:com/env' name space? Thus allowing me to a lookup on that namespace?...
So really my question, I think, boils down to: how do you specify a level of indirection of the JNDI name of a remote InitialContext to something different? So that when you do a ctx.lookup("xxx") you are looking up your name specified in one of the .xml files?
Or am i just way off?
Thanks,
Jules -
3. Re: Remote Tomcat EJB Reference
jamesstrachan Aug 12, 2003 4:41 AM (in response to jm2hall)Jules,
I don't think that you can do what you want using the descriptors.
The JNDI names that are visible on the remote J2EE server will always be the "plain vanilla" names. Only an instance of an EJB on the remote server will be able to access the "java:comp/env" namespace of that instance.
If you really need the indirection, you could write a Facade EJB for the remote instance whose sole function is to receive a method call, look up another JNDI name in its "java:comp/env" namespace, pass on the method call and then return the response.
So the bare bones of a sample method would look like :-
getTaxRate( String taxCode ) {
TaxHome home = (TaxHome) ctx.lookup( "java:comp/env/ejb/taxserver" );
return home.create().getTaxRate( taxCode );
}
This EJB would, of course, be a stateless session bean.
The Facade EJB can then be declared as the public facade for the service, whilst you have the ability to redirect to an internal implementation by setting up EJB links in ejb-jar.xml.
I haven't tried this, but it should work. Putting a Facade in place would also free you to change the coding of the internal implementation if necessary.
James -
4. Re: Remote Tomcat EJB Reference
jm2hall Aug 12, 2003 10:10 PM (in response to jm2hall)Gotcha. Thanks James.... I'll just have to stick with the 'plain vanilla' ,as you put it, jndi name.
I was actually trying to look up a session facade bean!
Jules