7 Replies Latest reply on Oct 11, 2007 6:29 AM by Marc Lustig

    Context "java:comp/env/ejb" empty

    Marc Lustig Newbie


      We have an EAR deployed on AS 4.2.1
      In the webapp (war-archive), we need to access an SLSB (EJB3).

      MyBeanLocal bean = (MyBeanLocal) context.lookup("java:comp/env/ejb");

      But this context is not existing! How comes?

      We can access the Bean-proxy using JNDI-path "myapp/MyBean/local", but this object is not type-compatible with the local interface (MyBeanLocal).

      Any hint why "java:comp/env/ejb" is not existing, and how to obtain the type-compatile object?

      Marc

        • 1. Re: Context
          wayne baylor Apprentice

          you have to explicitly "put" stuff in the ejb context. this is usually done with web.xml and jboss-web.xml.

          • 2. Re: Context
            Marc Lustig Newbie

            I am still having trouble to resolve the SLSB on the web-client (running on the same VM inside the same EAR on AS 4.2.1):

            jboss-web.xml
            <jboss-web>
            <ejb-local-ref>
            <ejb-ref-name>ejb/ImportManagerBean</ejb-ref-name>
            <local-jndi-name>ImportManager</local-jndi-name>
            </ejb-local-ref>
            </jboss-web>

            web.xml
            <ejb-local-ref>
            <ejb-ref-name>ejb/ImportManagerBean</ejb-ref-name>
            <ejb-ref-type>Session</ejb-ref-type>
            <local-home>mypackage.ImportManager</local-home>
            mypackage.ImportManager
            <ejb-link>ImportManager</ejb-link>
            </ejb-local-ref>

            --> the Bean/local IF should now be available in JNDI-ctx "ImportManager"
            context.lookup("ImportManager");
            but it IS NOT !

            The ear is deployed successfully (not complaining about the config).
            I understand that this trouble is due to a "conflict" between JEE5 (EJB3) and JEE1.4 (Servlet 2.4). But there should be some solution to this.

            Any hint to solve this is appreciated.

            • 3. Re: Context
              Marc Lustig Newbie

              there was a typo in web.xml. It should look like this:

              <ejb-local-ref>
              <ejb-ref-name>ejb/ImportManagerBean</ejb-ref-name>
              <ejb-ref-type>Session</ejb-ref-type>
              <local-home>mypkg.ImportManager</local-home>
              mypkg.ImportManager
              <ejb-link>ImportManager</ejb-link>
              </ejb-local-ref>

              • 4. Re: Context
                jaikiran pai Master

                 

                <ejb-ref-name>ejb/ImportManagerBean</ejb-ref-name>




                context.lookup("ImportManager");
                but it IS NOT !


                Try this:

                context.lookup("java:comp/env/ejb/ImportManagerBean");


                • 5. Re: Context
                  Marc Lustig Newbie

                   

                  "jaikiran" wrote:

                  Try this:

                  context.lookup("java:comp/env/ejb/ImportManagerBean");


                  thanks for the hint. using the absolute JNDI-path "java:comp/env/ejb/ImportManager" I am getting the same proxy-instance like with "kportal/ImportManagerBean/local"

                  This proxy is not type-compatible!

                  java.lang.ClassCastException: $Proxy356


                  This is really interesting, because the JNDIView reports this:

                  kportal
                  | +- ImportManagerBean (class: org.jnp.interfaces.NamingContext)
                  | | +- local (proxy: $Proxy356 implements interface mypkg.ImportManager,interface org.jboss.ejb3.JBossProxy,interface javax.ejb.EJBLocalObject)



                  According to this JNDI-report the proxy is implementing the home-IF properly, but this obviously not the case.
                  Anymore idea on this matter?

                  • 6. Re: Context
                    jaikiran pai Master

                    Can you post the code where you are casting the object after the lookup? Additionally have a look at http://wiki.jboss.org/wiki/Wiki.jsp?page=ClassCastExceptions which will help you identify whether this is a classloader issue.

                    • 7. Re: Context
                      Marc Lustig Newbie

                      YES, it is a classical classloader problem.

                      I was putting the class mypgk.ImportManager not only in the ejb.jar, but also in mywar.war/WEB-INF/lib.
                      After removing the class from WEB-INF/lib, no ClassCastException anymore.

                      I am fully aware of the type-incompatibility when loaded from different class-loaders. But I don't understand one thing.
                      JBoss is based on a hierarchical class-loader, right?
                      classes in app.ear are also available in deployment-units inside of the EAR, but not in "sibling-deployment-units".

                      The scenario:
                      mypkg.ImportManager.class is available in ejb-package.jar ONLY.
                      How can this class be loaded in webapp.war deployment-unit without being deployed ??
                      I'd expect a ClassNotFoundException !