4 Replies Latest reply on Sep 22, 2011 11:52 AM by gunterze

    ejb-jar.xml ignored by jbossas-remote-6?

    gunterze

      I want to specifiy injections of resources in the EJB deployment descriptor to avoid putting resource mapping names in the EJB source, e.g.

       

      @Stateful

      @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)

      public class CompositeQueryBean implements CompositeQuery {

       

          // avoid @Resource(mappedName="java:/DefaultDS")

          private DataSource dataSource;

       

      META-INF/ejb-jar.xml:

       

      <ejb-jar xmlns="http://java.sun.com/xml/ns/javaee"

        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd"

        version="3.1">

      :

        <enterprise-beans>

      :

          <session>

            <ejb-name>CompositeQueryBean</ejb-name>

            <ejb-class>org.dcm4chee.archive.ejb.query.CompositeQueryBean</ejb-class>

            <resource-ref>

              <res-ref-name>jdbc/dataSource</res-ref-name>

              <res-type>javax.sql.DataSource</res-type>

              <mapped-name>java:/DefaultDS</mapped-name>

              <injection-target>

                <injection-target-class>org.dcm4chee.archive.ejb.query.CompositeQueryBean</injection-target-class>

                <injection-target-name>dataSource</injection-target-name>

              </injection-target>

            </resource-ref>

          </session>

      :

        </enterprise-beans>

      :

      </ejb-jar>

       

      which actually works in regular deployment to JBoss 6.1.0 final, but not when deploying it

      by Arquillian-1.0.0.Alpha-5:

       

      @RunWith(Arquillian.class)

      public class PatientQueryTest {

       

          @Deployment

          public static JavaArchive createDeployment() {

              return ShrinkWrap.create(JavaArchive.class, "test.jar")

                      .addClasses(

                              CompositeQuery.class,

                              CompositeQueryBean.class)

                      .addAsResource("META-INF/ejb-jar.xml");

          }

       

          @EJB

          private CompositeQuery query;

       

          @Test

          public testFoo() {

             :

             query.foo(..);

             :

          }

       

      :

       

      => The test fails because CompositeQueryBean.dataSource does not get injected.

       

      I did not evaluate, if the deployment descriptor is just ignored, or if just the specified injection is not performed.

        • 1. Re: ejb-jar.xml ignored by jbossas-remote-6?
          jaikiran

          Try changing this

          .addAsResource("META-INF/ejb-jar.xml");

          to:

           

          .addAsManifestResource("META-INF/ejb-jar.xml", "ejb-jar.xml");

           

          You can also dump the jar contents by doing a

           

          JavaArchive jar = Shrinkwrap.create(...)

          jar.toString(true);

           

          That'll show you the actual contents of the jar.


          • 2. Re: ejb-jar.xml ignored by jbossas-remote-6?
            aslak

            The problem is... Arquillian has to somehow communicate with the TestClass to do inconainer testing. In JBossAS6, the defualt is to use the "Servlet 3.0" Protocol for communication, which implies that a Servlet has to be included in the deployment somehow. The DeploymentPackager that comes with the Servlet 3.0 protocol will 'rewrite' your defined @Deployment so it can communicate with it.

             

            In this case where you define a JavaArchive, The Servlet 3.0 Protocol will rewrite that as a WebArchive and place your JavaArchive in WEB-INF/lib (pluss adding some other libs to WEB-INF/lib that registeres a web-fragment and so on)

             

            The EJB 3.1 spec states:

                 "A .war may contain an ejb-jar.xml file. If present, the ejb-jar.xml is packaged as WEB-INF/ejb-jar.xml."

             

            Since your JavaArchive is placed under WEB-INF/lib, from the container view ejb-jar.xml is now located in WEB-INF/lib/test.jar/META-INF/ejb-jar.xml which is ignored.

             

            So you have two options, either create a WebArchive with the EJBs in WEB-INF/classes:

             

             

            ShrinkWrap.create(WebArchive.class, "test.war")
                 .addClasses(CompositeQuery.class, CompositeQueryBean.class)
                 .addAsWebInfResource("META-INF/ejb-jar.xml", "ejb-jar.xml")
            
            

             

            or create a WebArchive with EJBs in a library in WEB-INF/lib and ejb-jar.xml in WEB-INF/

             

             

            ShrinkWrap.create(WebArchive.class, "test.war")
                 .addAsLibrary(
                    ShrinkWrap.ctreate(JavaArchive.class, "test.jar")
                      .addClasses(CompositeQuery.class, CompositeQueryBean.class)
                  )
                 .addAsWebInfResource("META-INF/ejb-jar.xml", "ejb-jar.xml")
            
            
            • 3. Re: ejb-jar.xml ignored by jbossas-remote-6?
              aslak
              • 4. Re: ejb-jar.xml ignored by jbossas-remote-6?
                gunterze

                It works! Thanks!