2 Replies Latest reply on Jul 10, 2002 6:13 PM by Scott Taylor

    JNDI Lookup Confusion

    Scott Taylor Newbie

      Can somebody tell me what the difference is between the following techniques for referencing ejb's?...

      1) jndiContext.lookup("giftcert/Validate")
      2) jndiContext.lookup("java:comp/env/ejb/Validate")

      I have an EAR who's ejb is packaged up as "giftcert/Validate" in the jboss.xml file. Using #1 technique above I can connect to the ejb component with either an JSP or stand-alone java client... except that if I re-hot-deploy after making a successful jsp connection, then I can't connect upon a page refresh (however, I can reconnect w/ the fat java client).

      Using technique #2 works with JSP (it's the only technique that'll work w/ re-hot-deploy), but doesn't with the fat java client.

      So, can somebody explain when I would want to use the "java:comp..." convension and when I would want to use the other?

      Also, has anybody else ran into the "I can't hot-deploy w/ JSP after making an initial connection to an EJB" problem and found a solution?

        • 1. Re: JNDI Lookup Confusion
          Adrian Brock Master

          Each ejb has a global name "giftcert/Validate"
          this can be accessed from anywhere.

          You can also specify a local name "java:comp/env/ in your
          ejb-jar.xml or web.xml that can only be used from
          beans/servlets/jsp in the jar with that deployment
          descriptor (the xml)
          The idea is that you can code your jsp with the
          java:comp/env name without having to worry about where
          in jndi the bean is located. e.g. You could move it to
          a different name or even a different machine and you only
          have to change the deployment descriptor not the code.

          Which version of JBoss/JVM are you using?
          Is your jsp redeployed with the ejb?
          Are you holding onto the result of the first lookup
          inside the jsp after the redeploy?

          Regards,
          Adrian

          • 2. Re: JNDI Lookup Confusion
            Scott Taylor Newbie

            Actually, the more I poke into this, the more I think I'm having a Jetty problem rather than a jndi problem. The issue that I'm trying to track down is that when I redeploy an ear I run into a message like this...

            "java.lang.ClassCastException at com.sun.corba.se.internal.javax.rmi.PortableRemoteObject narrow", etc...

            The failure when doing a PortableRemoteObject call *only* happens when redeploying a JSP making a connection using the "giftcert/Validate" jndi lookup... it works fine after a redeploy if I use "java:comp/env/ejb/Validate".

            The reason I think it's a jetty problem is that I setup a test where I have JSP being served up by machine A, and the EJB running on machine B, so A talks to B. If I redeploy the ear on machine B the JSP still works fine. However, if I redeploy on machine A, then I get the error with the PortableRemoteObject call.

            And, I'm not sure how to answer the "am I holding the result in JSP" question. I've tried this w/ and w/o an object.remove call, and the API that I'm calling only returns a BOOL. Shouldn't any JSP cleanup any references past that, or do I need to explicitly clean something up I'm not?