4 Replies Latest reply on Sep 29, 2011 4:23 PM by nwhite

    SFSB injection

    iapazmino

      Hello,

       

      I've got an SFSB I'm testing and it just won't be injected by means of @EJB. I have to inject it with @Inject.

       

      This happens  only with Stateful beans. Stateless beans have no problem.

       

      Caused by: javax.naming.NamingException: No EJB found in JNDI, tried the following names: java:global/test.ear/test/StatefulBeanBean, java:global/test.ear/test/StatefulBean, java:global/test/StatefulBean, java:global/test/StatefulBeanBean, java:global/test/StatefulBean/no-interface, test/StatefulBeanBean/local, test/StatefulBeanBean/remote, test/StatefulBean/no-interface, StatefulBeanBean/local, StatefulBeanBean/remote, StatefulBean/no-interface

       

      Maybe a bug or am I not considering an important difference between SF and SL or @EJB anf @Inject?

        • 1. Re: SFSB injection
          iapazmino

          Injecting the reference with @Inject isn't a solution either, because injected reference is null. I supposed because a beans.xml was missing so I added it to the deployment

           

          jar.addAsManifestResource(new ByteArrayAsset(new byte[0]), ArchivePaths.create("beans.xml"));
          

           

          but it just leads to the previous error, the SFSB is not found so a naming exception is thrown

           

          Caused by: java.lang.RuntimeException: Error retreiving EJB from JNDI StatefulBean (SFSB); BeanClass: class package.ejb.StatefulBean; Local Business Interfaces: [Business interface: class package.ejb.StatefulBean]
              at org.jboss.weld.integration.ejb.JBossEjbServices.resolveEjb(JBossEjbServices.java:69)
              at org.jboss.weld.bean.SessionBean.createReference(SessionBean.java:476)
              at org.jboss.weld.bean.proxy.EnterpriseBeanProxyMethodHandler.<init>(EnterpriseBeanProxyMethodHandler.java:75)
              at org.jboss.weld.bean.SessionBean.create(SessionBean.java:331)
              ... 90 more
          Caused by: javax.naming.NamingException: Could not dereference object
              at org.jnp.interfaces.NamingContext.getObjectInstanceWrapFailure(NamingContext.java:1508)
              at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:824)
              at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:688)
              at javax.naming.InitialContext.lookup(InitialContext.java:392)
              at org.jboss.weld.integration.ejb.JBossSessionObjectReference.<init>(JBossSessionObjectReference.java:44)
              at org.jboss.weld.integration.ejb.JBossEjbServices.resolveEjb(JBossEjbServices.java:65)
              ... 93 more
          

           

          How should I inject a @LocalBean @Stateful bean in my test class?

          • 2. Re: SFSB injection
            aslak

            have you tried @EJB.mappedName ?

            • 3. Re: SFSB injection
              nwhite

              I was just about to post about a similar problem and have been down a similar route. I have SLSB which I am trying to inject into the Arquillian test class. I am using the GF 3.1 embedded container and these are No Interface local 3.1 EJBs.

               

              I am shrink wrapping my EJBs into a jar, foo.jar, and I added a persistence.xml manifest resource. The test class injects them like so:

               

               

              @EJB

              FooBean fooBean;

               

              The no-interface SSB simply looks like so:

               

              @Stateless

              public class FooBean {

              ...

              }

               

              The first time I got the same EJBInjectionEnricher lookup failure where it tries the default static JDNI names. I went looking at the EJBInjectionEnricher code and noticed that it also will check the mappedName annotation and use this to override the default lookups. I tried various permutations of the mappedName, eg:

               

              mappedName = "java:global/FooBean"

              mappedName = "java:global/foo/FooBean"

               

              No joy.  Based on the EJB FAQ [1]:

               

              If FooBean is packaged in fooejb.jar and deployed as a stand-alone module, its resulting JNDI name entry is :

               

                  java:global/fooejb/FooBean

               

              [1] - http://glassfish.java.net/javaee5/ejb/EJB_FAQ.html#SessionBeanGlobalJNDINameAssignment

              • 4. Re: SFSB injection
                nwhite

                Right after I posted this I realized I could see the JNDI names for these beans at deploy time being emitted by the embedded container (buried in all the other noise).

                 

                It reports:

                 

                INFO: Portable JNDI names for EJB FooBean : [java:global/test/FooBean, java:global/test/FooBean!com.acme.controller.FooBean]

                 

                Where is test coming from? Is this something the Arquillian deployment infrastructure is setting up for a default module name? The FAQ seems to indicate this is supposed to be based on:

                 

                <module-name> defaults to the unqualified name of the ejb-jar file or .war file in which the EJB component is defined, minus the file extension.

                 

                Based on my ShrinkWrap JavaArchive foo.jar I would expect my module name to have been foo.

                 

                -Noah