2 Replies Latest reply on Apr 25, 2014 6:09 AM by Andy Gumbrecht

    How to connect to activeMQ queue using  arquillian with tomee

    Raymond titus Newbie

      HI  I am having this problem  trying to connect to a  jms queue using arquillian  it return a Null pointer exception because  my  getActiveMQConnection() method  return a null

      see below  I need to know how to setup jms queue properly to test.   Some help would be greatly appreciated  thanks in advance

       

      java.lang.NullPointerException

        at com.nttdata.imagn.business.delegate.lookup.CobolMessageProcessingService.doProcessing(CobolMessageProcessingService.java:28)

        at com.nttdata.imagn.business.delegate.BusinessLookupServiceTest.testCallingCobolMessageProcessingService(BusinessLookupServiceTest.java:83)

        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)

        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

        at java.lang.reflect.Method.invoke(Method.java:606)

        at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)

        at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)

        at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)

        at org.jboss.arquillian.junit.Arquillian$6$1.invoke(Arquillian.java:273)

        at org.jboss.arquillian.container.test.impl.execution.LocalTestExecuter.execute(LocalTestExecuter.java:60)

        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)

        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

        at java.lang.reflect.Method.invoke(Method.java:606)

        at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)

        at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:99)

        at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:81)

        at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:145)

        at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:116)

        at org.jboss.arquillian.core.impl.EventImpl.fire(EventImpl.java:67)

        at org.jboss.arquillian.container.test.impl.execution.ContainerTestExecuter.execute(ContainerTestExecuter.java:38)

        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)

        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

        at java.lang.reflect.Method.invoke(Method.java:606)

        at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)

        at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:99)

        at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:81)

        at org.jboss.arquillian.test.impl.TestContextHandler.createTestContext(TestContextHandler.java:102)

        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)

        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

        at java.lang.reflect.Method.invoke(Method.java:606)

        at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)

        at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)

        at org.jboss.arquillian.test.impl.TestContextHandler.createClassContext(TestContextHandler.java:84)

        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)

        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

        at java.lang.reflect.Method.invoke(Method.java:606)

        at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)

        at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)

        at org.jboss.arquillian.test.impl.TestContextHandler.createSuiteContext(TestContextHandler.java:65)

        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)

        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

        at java.lang.reflect.Method.invoke(Method.java:606)

        at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)

        at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)

        at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:145)

        at org.jboss.arquillian.test.impl.EventTestRunnerAdaptor.test(EventTestRunnerAdaptor.java:111)

        at org.jboss.arquillian.junit.Arquillian$6.evaluate(Arquillian.java:266)

        at org.jboss.arquillian.junit.Arquillian$4.evaluate(Arquillian.java:229)

        at org.jboss.arquillian.junit.Arquillian.multiExecute(Arquillian.java:317)

        at org.jboss.arquillian.junit.Arquillian.access$200(Arquillian.java:46)

        at org.jboss.arquillian.junit.Arquillian$5.evaluate(Arquillian.java:243)

        at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)

        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)

        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)

        at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)

        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)

        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)

        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)

        at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)

        at org.jboss.arquillian.junit.Arquillian$2.evaluate(Arquillian.java:188)

        at org.jboss.arquillian.junit.Arquillian.multiExecute(Arquillian.java:317)

        at org.jboss.arquillian.junit.Arquillian.access$200(Arquillian.java:46)

        at org.jboss.arquillian.junit.Arquillian$3.evaluate(Arquillian.java:202)

        at org.junit.runners.ParentRunner.run(ParentRunner.java:300)

        at org.jboss.arquillian.junit.Arquillian.run(Arquillian.java:150)

        at org.junit.runner.JUnitCore.run(JUnitCore.java:157)

        at org.junit.runner.JUnitCore.run(JUnitCore.java:136)

        at org.jboss.arquillian.junit.container.JUnitTestRunner.execute(JUnitTestRunner.java:64)

        at org.jboss.arquillian.protocol.servlet.runner.ServletTestRunner.executeTest(ServletTestRunner.java:159)

        at org.jboss.arquillian.protocol.servlet.runner.ServletTestRunner.execute(ServletTestRunner.java:125)

        at org.jboss.arquillian.protocol.servlet.runner.ServletTestRunner.doGet(ServletTestRunner.java:89)

        at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)

        at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)

        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)

        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)

        at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)

        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)

        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)

        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)

        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)

        at org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:45)

        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)

        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)

        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)

        at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)

        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)

        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)

        at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)

        at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)

        at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)

        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)

        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)

        at java.lang.Thread.run(Thread.java:744)

       

      my pom  is as follow

       

       

      <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

        <modelVersion>4.0.0</modelVersion>

       

       

        <groupId>com.nttdata.imagn.testing</groupId>

        <artifactId>PackagingFileServTest</artifactId>

        <version>0.0.1-SNAPSHOT</version>

        <packaging>jar</packaging>

       

       

        <name>PackagingFileServTest</name>

        <url>http://maven.apache.org</url>

       

       

        <properties>

        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

        </properties>

        <dependencyManagement>

        <dependencies>

        <dependency>

        <groupId>org.jboss.arquillian</groupId>

        <artifactId>arquillian-bom</artifactId>

        <version>1.1.4.Final</version>

        <scope>import</scope>

        <type>pom</type>

        </dependency>

        <dependency>

        <groupId>org.jboss.shrinkwrap.resolver</groupId>

        <artifactId>shrinkwrap-resolver-bom</artifactId>

        <version>2.1.0</version>

        <type>pom</type>

        <scope>import</scope>

        </dependency>

        </dependencies>

       

       

        </dependencyManagement>

        <build>

        <plugins>

        <plugin>

        <groupId>org.apache.maven.plugins</groupId>

        <artifactId>maven-compiler-plugin</artifactId>

        <version>2.3.2</version>

        <configuration>

        <source>1.6</source>

        <target>1.6</target>

        </configuration>

        </plugin>

        <plugin>

        <artifactId>maven-surefire-plugin</artifactId>

        <version>2.12</version>

        <configuration>

        <tomeeHttpPort>1234</tomeeHttpPort>

        <tomeeShutdownPort>5678</tomeeShutdownPort>

        </configuration>

       

       

        </plugin>

        </plugins>

        </build>

        <dependencies>

        <dependency>

        <groupId>junit</groupId>

        <artifactId>junit</artifactId>

        <version>4.8.1</version>

        <scope>test</scope>

        </dependency>

        <dependency>

        <groupId>org.jboss.arquillian.junit</groupId>

        <artifactId>arquillian-junit-container</artifactId>

        <scope>test</scope>

        </dependency>

        <dependency>

        <groupId>org.jboss.shrinkwrap.resolver</groupId>

        <artifactId>shrinkwrap-resolver-depchain</artifactId>

        <type>pom</type>

        <scope>test</scope>

        </dependency>

        <dependency> 

          <groupId>org.jboss.shrinkwrap.resolver</groupId> 

          <artifactId>shrinkwrap-resolver-impl-maven</artifactId> 

          <scope>test</scope> 

        </dependency>

        </dependencies>

        <profiles>

         <profile>

        <id>tomee-plus-remote</id>

        <activation>

        <activeByDefault>true</activeByDefault>

        </activation>

        <properties>

        <tomee.version>1.6.0</tomee.version>

        <tomee.classifier>plus</tomee.classifier>

        </properties>

        <build>

        <plugins>

        <plugin>

        <groupId>org.apache.openejb.maven</groupId>

        <artifactId>tomee-maven-plugin</artifactId>

        <version>1.6.0-SNAPSHOT</version>

        <configuration>

                                  <systemPropertyVariables>

                                      <tomee.httpPort>-1</tomee.httpPort>

                                      <tomee.stopPort>-1</tomee.stopPort>

                                      <tomee.ajpPort>-1</tomee.ajpPort>

                                      <tomee.classifier>${tomee.classifier}</tomee.classifier>

                                  </systemPropertyVariables>

        </configuration>

        </plugin>

        </plugins>

        </build>

        <dependencies>

        <dependency>

        <groupId>org.apache.openejb</groupId>

        <artifactId>arquillian-tomee-remote</artifactId>

        <version>${tomee.version}</version>

        </dependency>

        <dependency>

        <groupId>org.apache.openejb</groupId>

        <artifactId>apache-tomee</artifactId>

        <version>${tomee.version}</version>

        <classifier>${tomee.classifier}</classifier>

        <type>zip</type>

        </dependency>

        </dependencies>

        </profile>

        </profiles>

      </project>

       

      my resource file  is

      ====================================

         tomee.xml

      =====================================

       

      <tomee>

       

        <Resource id="MyJmsResourceAdapter" type="ActiveMQResourceAdapter">

        BrokerXmlConfig = broker:(tcp://localhost:61617)

        ServerUrl = tcp://localhost:61617

        </Resource>

       

       

        <Resource id="MyJmsConnectionFactory" type="javax.jms.ConnectionFactory">

        ResourceAdapter = MyJmsResourceAdapter

        </Resource>

       

      </tomee>

       

       

       

       

       

      ================================

      My CobolMessageProcessingService  class is as follow

      =================================

      package com.nttdata.imagn.business.delegate.lookup;

       

       

      import javax.jms.Connection;

      import javax.jms.Destination;

      import javax.jms.JMSException;

      import javax.jms.MessageProducer;

      import javax.jms.Session;

      import javax.jms.TextMessage;

       

       

      import org.apache.log4j.Logger;

       

       

      import static com.nttdata.imagn.common.service.ImagnConstants.*;

      import static com.nttdata.imagn.common.service.ImagnUtils.getActiveMQConnection;

      /*

      * This class actually send the message received by the client to ActiveMQ

      */

      public class CobolMessageProcessingService implements BusinessService {

        public static Logger logger = Logger

        .getLogger(CobolMessageProcessingService.class);

       

       

        private static String subject = AMGEN_QUEUE;

        private boolean isConnected = false;

        private Connection connection = null;

       

       

        public String doProcessing(String xmlMessage) throws JMSException {

        if (isValidRequest(xmlMessage)) {

        connectToActiveMQ();

        Session session = this.connection.createSession(false,

        Session.AUTO_ACKNOWLEDGE);

        Destination destination = session.createQueue(subject);

        MessageProducer producer = session.createProducer(destination);

        TextMessage message = session.createTextMessage(xmlMessage);

        producer.send(message); // see MessageReceiver.java for consumer of message

        logger.info("Sent message " + message.getText() + ",");

        return "OK_Cobol";

        } else {

        return "Fail";

        }

      //TODO: close connection and session

        }

       

      =================================================

      connectToActiveMQ method

      ================================================

        /**

        * this method connects to Active MQ

        */

        private void connectToActiveMQ() {

       

       

        if (!isConnected) {

               this.connection = getActiveMQConnection();

               if (this.connection != null) {

               try {

                       this.connection.start();

                       isConnected = true;

               } catch (JMSException e) {

                    e.printStackTrace();

               }

        }

        }

        }

       

       

       

      =====================================

        getActiveMQConnection() method

      ======================================

       

      public static  javax.jms.Connection  getActiveMQConnection(){
      InitialContext context = null;
      javax.jms.ConnectionFactory cf = null;
      javax.jms.Connection conn = null;
      try {
            context = new InitialContext();
          cf = (ConnectionFactory) context.lookup("openejb:Resource/MyJmsConnectionFactory");
          conn = cf.createConnection();
      } catch (NamingException e1) {
         e1.printStackTrace();

         }

       

       

      =====================================================

        test class

      =====================================================

       

      package com.nttdata.imagn.business.delegate;

      import java.io.File;

      import javax.jms.JMSException;

      import junit.framework.Assert;

      import org.jboss.arquillian.container.test.api.Deployment;

      import org.jboss.arquillian.junit.Arquillian;

      import org.jboss.shrinkwrap.api.ShrinkWrap;

      import org.jboss.shrinkwrap.api.asset.EmptyAsset;

      import org.jboss.shrinkwrap.api.spec.WebArchive;

      import org.jboss.shrinkwrap.resolver.api.maven.Maven;

      import org.junit.Test;

      import org.junit.runner.RunWith;

      import static com.nttdata.imagn.common.service.ImagnConstants.*;

      import com.nttdata.imagn.business.delegate.lookup.BusinessService;

      import com.nttdata.imagn.business.delegate.lookup.CobolMessageProcessingService;

      import com.nttdata.imagn.common.service.ImagnUtils;

      import com.nttdata.imagn.management.Command;

      import com.nttdata.imagn.management.Receiver;

      import com.nttdata.project.message.util.MessageUtil;

       

       

      @RunWith(Arquillian.class)

      public class BusinessLookupServiceTest {

      private static final String WEBAPP_SRC = "src/test/java";

        @Deployment

        public static WebArchive createDeployment() {

       

            File[] lib = Maven.resolver()

                    .resolve("log4j:log4j:1.2.17")

                    .withTransitivity().as(File.class);

           

        WebArchive warArchive = ShrinkWrap.create(WebArchive.class,"test.war")

        .addClasses(CobolMessageProcessingService.class)

        .addClasses(BusinessService.class)

        .addClasses(BusinessLookupService.class)

        .addClasses(Receiver.class,Command.class,MessageUtil.class,ImagnUtils.class)

        .addAsLibraries(lib)

       

        .addAsResource(new File("E:/Ray/ProjectWorkArea2/myWorkspace/PackagingFileServTest/src/test/java/tomee.xml"))

        .addAsLibrary(new File("E:/Ray/ProjectWorkArea2/GitRepository/Csat-Resources/ImagnProjectMessage/ImagnProjectMessage.jar"))

        .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");

       

        System.out.println(warArchive.toString(true));

       

        return warArchive;

        }

       

       

       

        @Test

        public void testCallingCobolMessageProcessingService() {

        BusinessLookupService businessLookupService = new BusinessLookupService();

        BusinessService bus = businessLookupService.getBusinessService(CALLCOBOLEJB);

        Assert.assertNotNull(bus);

        Assert.assertTrue(bus instanceof CobolMessageProcessingService);

       

        String argSearch=MessageUtil.createProjectXml("callCobolEJB"

                      , "cobol#1"

                      , "actionId"

                      , "COBOL/testFull.cob");

        Assert.assertNotNull(argSearch);

        System.out.println("argSearch ="+argSearch);

        try {

        String returnString = bus.doProcessing(argSearch);

        Assert.assertNotNull(returnString);

       

        } catch (JMSException e) {

        // TODO Auto-generated catch block

        e.printStackTrace();

        }

        }

       

       

      }

        • 1. Re: How to connect to activeMQ queue using  arquillian with tomee
          Justin Bertram Master

          I moved your question from the HornetQ forum to the Arquillian forum since it doesn't appear to be related to HornetQ.

          • 2. Re: How to connect to activeMQ queue using  arquillian with tomee
            Andy Gumbrecht Newbie

            Hi Raymond,

             

            You should be able to just add the ConnectionFactory as a resource to CobolMessageProcessingService

             

            @javax.annotation.Resource

            private ConnectionFactory connectionFactory;

             

            Also, you may want to try to define the AMQ resource in an arquillian.xml file rather than tomee.xml:

             

            <arquillian>

              <container qualifier="tomee-remote">

                <configuration>

                  <property name="httpPort">-1</property>

                  <property name="ajpPort">-1</property>

                  <property name="stopPort">-1</property>

                  <property name="dir">target/apache-tomee-remote</property>

                  <property name="appWorkingDir">target/arquillian-test-working-dir</property>

                  <property name="properties">

                    Default\ JMS\ Resource\ Adapter.BrokerXmlConfig = broker:(tcp://localhost:61617)?useJmx=false&amp;persistent=false

                    openejb.classloader.forced-load=com.nttdata.imagn.business.delegate

                  </property>

                </configuration>

              </container>

            </arquillian>

             

            Andy Gumbrecht

            http://www.tomitribe.com