3 Replies Latest reply on Jul 16, 2007 4:34 PM by Frank Langelage

    Lookup ejb by its COMP_NAME

    Umakanth Srinivasan Newbie


      I have given the code that I used to lookup a bean by its COMP_NAME, after googling for several hours, posting this here to get some clues atleast.

      Code:

      Context initial = new InitialContext();
      Object objref = initial.lookup("java:comp/env/ejb/LicenseVerifier");
      LicenseVerifierLocalHome home = (LicenseVerifierLocalHome) objref;
      LicenseVerifierLocal license = home.create();


      Exception:
      javax.naming.NameNotFoundException: env not bound

      JNDI View
      java:comp namespace of the LicenseVerifier bean:
      +- env (class: org.jnp.interfaces.NamingContext)
      | +- ejb (class: org.jnp.interfaces.NamingContext)
      | | +- LicenseVerifier[link -> LicenseVerifierLocalHome] (class: javax.naming.LinkRef)
      | +- security (class: org.jnp.interfaces.NamingContext)
      | | +- subject[link -> java:/jaas/SecurityPolicy/subject] (class: javax.naming.LinkRef)
      | | +- security-domain[link -> java:/jaas/SecurityPolicy] (class: javax.naming.LinkRef)


        • 1. Re: Lookup ejb by its COMP_NAME
          Umakanth Srinivasan Newbie

          ejb-jar.xml


          <![CDATA[LicenseVerifier]]>

          <ejb-name>LicenseVerifier</ejb-name>

          com.dhyan.nms.server.common.license.interfaces.LicenseVerifierHome
          com.dhyan.nms.server.common.license.interfaces.LicenseVerifier
          <local-home>com.dhyan.nms.server.common.license.interfaces.LicenseVerifierLocalHome</local-home>
          com.dhyan.nms.server.common.license.interfaces.LicenseVerifierLocal
          <ejb-class>com.dhyan.nms.server.common.license.ejb.LicenseVerifierBean</ejb-class>
          <session-type>Stateful</session-type>
          <transaction-type>Container</transaction-type>

          <ejb-local-ref >
          <ejb-ref-name>ejb/LicenseVerifier</ejb-ref-name>
          <ejb-ref-type>Session</ejb-ref-type>
          <local-home>com.dhyan.nms.server.common.license.interfaces.LicenseVerifierLocalHome</local-home>
          com.dhyan.nms.server.common.license.interfaces.LicenseVerifierLocal
          <ejb-link>LicenseVerifier</ejb-link>
          </ejb-local-ref>



          jboss.xml


          <ejb-name>LicenseVerifier</ejb-name>
          <jndi-name>LicenseVerifier</jndi-name>
          <local-jndi-name>LicenseVerifierLocalHome</local-jndi-name>
          <ejb-local-ref>
          <ejb-ref-name>ejb/LicenseVerifier</ejb-ref-name>
          <local-jndi-name>LicenseVerifier</local-jndi-name>
          </ejb-local-ref>
          <method-attributes>
          </method-attributes>


          • 2. Re: Lookup ejb by its COMP_NAME
            Umakanth Srinivasan Newbie

            same exception even when I tried

            InitialContext iniCtx = new InitialContext();
            Context ejbCtx = (Context) iniCtx.lookup("java:comp/env/ejb");


            • 3. Re: Lookup ejb by its COMP_NAME
              Frank Langelage Master

              I think you misunderstood something.
              You'll have to add the ejb-local-ref to the bean where you want to lookup LicenseVerfifierFrom from by COMP_NAME.

              Just one example from my code base.
              In SalesOrderImportMDB I have this for XDoclet to generate the deployment descriptor entries:

               * @ejb.ejb-external-ref view-type="local" type="Session"
               * ref-name="ejb/MailServiceLocal"
               * home="ejb.session.core.MailServiceLocalHome"
               * business="ejb.session.core.MailServiceLocal"
               * jndi-name="test/MailServiceLocal"
              


              ejb-jar.xml:
              <message-driven>
               <display-name>SalesOrderImportMDB</display-name>
              ...
               <ejb-local-ref >
               <ejb-ref-name>ejb/MailServiceLocal</ejb-ref-name>
               <ejb-ref-type>Session</ejb-ref-type>
               <local-home>ejb.session.core.MailServiceLocalHome</local-home>
               <local>ejb.session.core.MailServiceLocal</local>
               </ejb-local-ref>
              ...
              </message-driven >
              

              jboss.xml:
              <message-driven>
               <ejb-name>SalesOrderImportMDB</ejb-name>
              ...
               <ejb-local-ref>
               <ejb-ref-name>ejb/MailServiceLocal</ejb-ref-name>
               <local-jndi-name>test/MailServiceLocal</local-jndi-name>
               </ejb-local-ref>
              ...
              </message-driven>
              

              jmx-console, JNDI-view:
              java:comp namespace of the SalesOrderImportMDB bean:
               +- env (class: org.jnp.interfaces.NamingContext)
               | +- ejb (class: org.jnp.interfaces.NamingContext)
               | | +- MailServiceLocal[link -> test/MailServiceLocal] (class: javax.naming.LinkRef)