4 Replies Latest reply on Aug 12, 2003 10:10 PM by jm2hall

    Remote Tomcat EJB Reference

    jm2hall Newbie

      Hi Guys,
      I've got jboss3.2-tomcat4.1.24 bundle running just fine. And when I want to lookup an ejb in the java:comp/env/ namespace its fine!

      But I've got a thin client running tomcat 4.1.24 on a seperate machine that also needs to look up the ejb remotely. I've added:
      to my web xml of the correct web app... but I still can't seem to look it up on the java:comp/env/ name space!

      If i just do a look up on the JNDI name 'ejb/xxx' that works fine.. but I would like to look it up on the java:comp/env namespace....

      Any suggestions?

      I'v also added this context to my server.xml on the remote instance of tomcat:

      java.naming.factory.initial org.jnp.interfaces.NamingContextFactory



      Any help would be great!! Thanks,


        • 1. Re: Remote Tomcat EJB Reference
          jamesstrachan Newbie

          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 Newbie

            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?



            • 3. Re: Remote Tomcat EJB Reference
              jamesstrachan Newbie


              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.


              • 4. Re: Remote Tomcat EJB Reference
                jm2hall Newbie

                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!