5 Replies Latest reply: Oct 7, 2011 9:15 AM by Robert.Patrick-Oracle RSS

    Is java:comp/env automatically prefixed ?

    870630
      I am developing some enterprise apps with EJB3 on WebLogic 10.3.5.
      An EJB in EAR A must call remote methods on an EJB in EAR B. Both EARs are deployed on the same server.
      I have arranged all XML descriptors according to specs and practices.

      The problem is looking up the remote EJB: if I use the standard jndi key,

      java:comp/env/ejb/MyBean

      I get a NameNotFoundException at runtime as soon as I call InitialContext()::lookup().

      On the other hand, I f I use the short key

      ejb/MyBean

      everything runs OK.

      To preserve application server portability (eg to Glassfish) I want to be able to query the JNDI tree with the full form "java:comp/env/ejb/MyBean".
      How can I configure Weblogic to stop setting the prefix atomatically ?

      Thanks
        • 1. Re: Is java:comp/env automatically prefixed ?
          Robert.Patrick-Oracle
          java:comp/env is the local, context-sensitive JNDI namespace for a particular Java EE component. I suspect the reason it works when you use "ejb/MyBean" is because the global JNDI name of the other EJB is set to ejb/MyBean.

          To use java:comp/env/ejb/MyBean to lookup another EJB in another application, you must map the other EJB into the local EJB's context-sensitive JNDI namespace. Using a deployment descriptor, you would add the following in the local EJB's ejb-jar.xml:

          <ejb-ref>
          <ejb-ref-name>ejb/MyBean</ejb-ref-name>
          <remote>com.foo.bar.MyBeanRemoteInterface</remote>
          </ejb-ref>

          and then add the following in local EJB's weblogic-ejb-jar.xml:

          <ejb-reference-description>
          <ejb-ref-name>ejb/MyBean</ejb-ref-name>
          <jndi-name>ejb/MyBean</jndi-name> <!-- Note that this must map to the global JNDI name specified by the other EJB -->
          </ejb-reference-description>

          Hope this helps,
          Robert
          • 2. Re: Is java:comp/env automatically prefixed ?
            870630
            Thanks for replying, but that's exactly how I had set things up in deployment descriptors...I checked them a thousand times and everything looks OK, that's why I thought about some specific WLS prepending and decided to post here.
            Still a mystery to me.

            In the meanwhile I worked around this by implementing a "two-phase" lookup, eg

            try {
            lookup("java:comp/env/ejb/MyBean") ;
            } catch (NameNotFoundException xc) {
            try {
            lookup("java:comp/env/ejb/MyBean") ;
            } catch (NameNotFoundException xc1) {
            throw fatal ;
            }
            }

            Running in Glassfish the first lookup is successful, running in WLS it falls back on the second.

            Pierangelo

            Edited by: user6780872 on 7-ott-2011 5.14
            • 3. Re: Is java:comp/env automatically prefixed ?
              Robert.Patrick-Oracle
              If you did what I recommended and it is still failing, please open an SR with Oracle Support and upload a test case. If you send me the SR number, I will take a look myself...
              • 4. Re: Is java:comp/env automatically prefixed ?
                870630
                Well, I do have a test case, but the WebLogic licensee is my Client, not me. I wonder if they are going to let me use their id.
                • 5. Re: Is java:comp/env automatically prefixed ?
                  Robert.Patrick-Oracle
                  If not, please send me the test case directly...just add @oracle.com to my forum ID. However, note that if a patch is required, an SR will be required so that is the preferred route.