2 Replies Latest reply on Aug 31, 2015 4:58 AM by rm0han

    Arquillian JMS configuration

    rm0han

      There are no straightforward examples that show how JMS queues and template configuration files are loaded when using 'ShrinkWrap'. It may be easy for those who use ActiveMQ or Artemis or HornetQ. But we don't. We use it only for testing. Ours is MQ.

       

      EnterpriseArchive ear = ShrinkWrap.create( ZipImporter.class,

                                           "Ear.ear")

                                           .importFrom(new File("Ear.ear"))

                                            .as(EnterpriseArchive.class) ;

       

          //now add the testClass and any test util classes that are not in the archive

              JavaArchive testLibraryHelper = ShrinkWrap.create(JavaArchive.class)

                                  .addClass("com.test.ExampleListener").addClass("com.test.UnitTest");

              ear.addAsLibrary(testLibraryHelper);

              File xbean = Maven.

              resolver().

              resolve("org.apache.xbean:xbean-spring:4.3")

              .withoutTransitivity().asSingle(File.class);

            

              File activemq = Maven.

              resolver().

              resolve("org.apache.activemq:activemq-spring:5.8.0")

              .withoutTransitivity().asSingle(File.class);

       

       

              File artemisjmsserver = Maven.

        resolver().

        resolve("org.apache.activemq:artemis-jms-server:1.0.0")

        .withoutTransitivity().asSingle(File.class);

       

       

              File activemqqall = Maven.

        resolver().

        resolve("org.apache.activemq:activemq-all:5.11.1")

        .withoutTransitivity().asSingle(File.class);

       

       

              File artemisserver = Maven.

        resolver().

        resolve("org.apache.activemq:artemis-server:1.0.0")

        .withoutTransitivity().asSingle(File.class);

       

       

          WebArchive war = ear.getAsType(WebArchive.class, "/Web.war");

          war.addAsWebInfResource("applicationContext-Business.xml");

          war.addAsWebInfResource("applicationContext-listener.xml");

          war.addAsWebInfResource("applicationContext.xml");

          war.addAsWebInfResource("artemis-roles.properties");

          war.addAsWebInfResource("artemis-users.properties");

          war.addAsWebInfResource("broker.xml");

          war.addAsWebInfResource("spring-jms-beans.xml");

          war.addAsWebInfResource("spring-beans-embedded.xml");

          war.delete("/WEB-INF/applicationContext-sender.xml");

              war.addAsLibraries(xbean);

              war.addAsLibraries(artemisserver);

      I have 5 files from an example I found.

      1. artemis-roles.properties

      2.artemis-users.properties

      3.broker.xml

      4.spring-beans-embedded.xml

      5.spring-jms-beans.xml

       

      I am loading all these into WEB-INF/lib. Is that correct ?

       

      My broker.xml is

       

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

                     xmlns="urn:activemq"

                     xsi:schemaLocation="urn:activemq /schema/artemis-server.xsd">

         <jms xmlns="urn:activemq:jms">

            <!--the queue used by the example-->

            <queue name="exampleQueue"/>

         </jms>

         <core xmlns="urn:activemq:core">

            <persistence-enabled>false</persistence-enabled>

            <acceptors>

               <acceptor name="in-vm">vm://0</acceptor>

            </acceptors>

            <!-- Other config -->

            <security-settings>

               <!--security for example queue-->

               <security-setting match="#">

                  <permission type="createDurableQueue" roles="guest"/>

                  <permission type="deleteDurableQueue" roles="guest"/>

                  <permission type="createNonDurableQueue" roles="guest"/>

                  <permission type="deleteNonDurableQueue" roles="guest"/>

                  <permission type="consume" roles="guest"/>

                  <permission type="send" roles="guest"/>

               </security-setting>

            </security-settings>

         </core>

      </configuration>

       

      But I get this when JBoss WildFly tries to deploy the EAR. The EAR exists.

       

      org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Failed to import bean definitions from relative location [broker.xml]

      Offending resource: ServletContext resource [/WEB-INF/applicationContext.xml]; nested exception is org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 23 in XML document from ServletContext resource [/WEB-INF/broker.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 23; columnNumber: 77; cvc-elt.1.a: Cannot find the declaration of element 'configuration'.

        at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:70)

        at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:85)

        at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:76)

        at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.importBeanDefinitionResource(DefaultBeanDefinitionDocumentReader.java:274)

        at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseDefaultElement(DefaultBeanDefinitionDocumentReader.java:199)

        at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:184)

        at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.doRegisterBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:141)

        • 1. Re: Arquillian JMS configuration
          raneves

          Hi, Mohan. how are you? fine?

           

          In my application I don't need configuration ShrinkWrap for libs(war.addAsLibraries(xbean);)... I just configuration context by .xml files like that:

           

          ShrinkWrap.create(WebArchive.class, "app.war")

                          .addAsWebInfResource("applicationContext-arquillian-test.xml", "applicationContext.xml" )

                          .addAsWebInfResource("database-arquillian-test.xml", "databaseTest.xml")

                        ... more webInfResources here like servlets...

                          .addAsResource("conf/app.testProperties", "app.properties")

                          .addAsManifestResource("arquillian.xml")

                          .setWebXML("in-container-web.xml");

           

          This works very well for me, I using spring MVC 3.1 and other dependencies.

           

          PS: see the tag xsi:schemaLocation="urn:activemq /schema/artemis-server.xsd maybe you need inform this file in addAsWebInfResource too.

          • 2. Re: Arquillian JMS configuration
            rm0han

            Hi,

             

               I am fine but my tests are not. How are you ?

            It seems that just this file is enough for my Artemis JMS tests. Is it not ? Is it Artemis or just ActiveMQ ?

            I don't know why the others are needed.

             

            1. artemis-roles.properties

            2.artemis-users.properties

            3.broker.xml

            4.spring-beans-embedded.xml( copied below )

            5.spring-jms-beans.xml

             

            <beans

              xmlns="http://www.springframework.org/schema/beans"

              xmlns:amq="http://activemq.apache.org/schema/core"

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

              xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd

              http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd">

             

              <!--  lets create an embedded ActiveMQ Broker -->

              <amq:broker useJmx="false" persistent="false">

                <amq:transportConnectors>

                  <amq:transportConnector uri="tcp://localhost:0" />

                </amq:transportConnectors>

              </amq:broker>

             

             

               <!--  ActiveMQ destinations to use  -->

              <amq:queue id="destination"  physicalName="org.apache.activemq.spring.Test.spring.embedded"/>

             

             

              <!-- JMS ConnectionFactory to use, configuring the embedded broker using XML -->

              <amq:connectionFactory id="jmsFactory" brokerURL="vm://localhost"/>

             

             

             

              <!-- Spring JMS Template -->

              <bean id="myJmsTemplate" class="org.springframework.jms.core.JmsTemplate">

                <property name="connectionFactory">

                  <!-- lets wrap in a pool to avoid creating a connection per send -->

                  <bean class="org.springframework.jms.connection.SingleConnectionFactory">

                    <property name="targetConnectionFactory">

                      <ref local="jmsFactory" />

                    </property>

                  </bean>

                </property>

              </bean>

             

             

              <bean id="consumerJmsTemplate" class="org.springframework.jms.core.JmsTemplate">

                <property name="connectionFactory" ref="jmsFactory"/>

              </bean>

             

             

              <!-- JMS Queue Template -->

              <bean id="regResponseJmsTemplate" class="org.springframework.jms.core.JmsTemplate">

                <property name="connectionFactory" ref="jmsFactory"></property>

                <property name="destinationResolver">

                  <ref bean="regResponseJmsDestinationResolver"/>

                </property>

                 <property name="pubSubDomain">

                  <value>false</value>

                </property>

                <property name="receiveTimeout">

                  <value>20000</value>

                </property>       

              </bean>

             

              <bean id="regResponseJmsDestinationResolver" class=" org.springframework.jms.support.destination.DynamicDestinationResolver"/>

             

             

             

              <!-- a sample POJO which uses a Spring JmsTemplate -->

              <bean id="producer" class="scos.hrg.e2e.SpringProducer">

                <property name="template">

                  <ref bean="myJmsTemplate"></ref>

                </property>

             

             

                <property name="destination">

                  <ref bean="destination" />

                </property>

             

             

                <property name="messageCount">

                  <value>10</value>

                </property>

              </bean>

             

             

              <!-- a sample POJO consumer -->

              <bean id="consumer" class="scos.hrg.e2e.SpringConsumer">

                <property name="template" ref="consumerJmsTemplate"/>

                <property name="destination" ref="destination"/>

              </bean>

             

             

                <bean id="listener" class="scos.hrg.e2e.ExampleListener">

                 <property name="regResponseJmsTemplate">

                   <ref bean="regResponseJmsTemplate"></ref>

                 </property>

              </bean>

             

             

            </beans>

             

            Why do you put 'arquillian.xml' into the ShrinkWrap ? I am able to deploy it into Wildfly without that.

            Could you attach your conf. files ? Hope you don't mind.

             

            I am trying to autowire 'regResponseJmsTemplate' into 'ExampleListener' and for some reason it fails.

             

            Thanks,

            Mohan