4 Replies Latest reply on Aug 22, 2016 3:18 AM by emag

    tomcat cannot connect to server Jms ActiveMQ Wildfly 10

    ehsanlinux

      hi all

      when i want connect jms ActiveMQ  inside servlet tomcat to the my queue in wildfly 10  i got this error :

       

      org.jboss.naming.remote.protocol.NamingIOException: Failed to lookup [Root exception is java.io.IOException: java.lang.ClassNotFoundException: org.apache.activemq.artemis.jms.client.ActiveMQJMSConnectionFactory]   at org.jboss.naming.remote.client.ClientUtil.namingException(ClientUtil.java:49)   at org.jboss.naming.remote.protocol.v1.Protocol$1.execute(Protocol.java:104)   at org.jboss.naming.remote.protocol.v1.RemoteNamingStoreV1.lookup(RemoteNamingStoreV1.java:95)   at org.jboss.naming.remote.client.HaRemoteNamingStore$1.operation(HaRemoteNamingStore.java:276)   at org.jboss.naming.remote.client.HaRemoteNamingStore.namingOperation(HaRemoteNamingStore.java:137)   at org.jboss.naming.remote.client.HaRemoteNamingStore.lookup(HaRemoteNamingStore.java:272)   at org.jboss.naming.remote.client.RemoteContext.lookup(RemoteContext.java:87)   at org.jboss.naming.remote.client.RemoteContext.lookup(RemoteContext.java:129)   at javax.naming.InitialContext.lookup(InitialContext.java:417)   at com.almasprocess.model.bl.JndiJmsDbServer.getSession(JndiJmsDbServer.java:90)   at micro.MailService.callsendMessageToDB(MailService.java:218)   at micro.MailService.callSendMail(MailService.java:176)   at micro.MailService.sendMail(MailService.java:83)   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)   at java.lang.reflect.Method.invoke(Method.java:483)   at org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory$1.invoke(ResourceMethodInvocationHandlerFactory.java:81)   at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:125)   at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$ResponseOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:152)   at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:91)   at org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:346)   at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:341)   at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:101)   at org.glassfish.jersey.server.ServerRuntime$1.run(ServerRuntime.java:224)   at org.glassfish.jersey.internal.Errors$1.call(Errors.java:271)   at org.glassfish.jersey.internal.Errors$1.call(Errors.java:267)   at org.glassfish.jersey.internal.Errors.process(Errors.java:315)   at org.glassfish.jersey.internal.Errors.process(Errors.java:297)   at org.glassfish.jersey.internal.Errors.process(Errors.java:267)   at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:317)   at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:198)   at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:946)   at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:323)   at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:372)   at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:335)   at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:218)   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)   at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)   at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:506)   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)   at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:537)   at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1081)   at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:658)   at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222)   at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1566)   at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1523)   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)   at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)   at java.lang.Thread.run(Thread.java:745) Caused by: java.io.IOException: java.lang.ClassNotFoundException: org.apache.activemq.artemis.jms.client.ActiveMQJMSConnectionFactory   at org.jboss.naming.remote.protocol.v1.Protocol$1$3.read(Protocol.java:159)   at org.jboss.naming.remote.protocol.v1.Protocol$1$3.read(Protocol.java:149)   at org.jboss.naming.remote.protocol.v1.BaseProtocolCommand.readResult(BaseProtocolCommand.java:59)   at org.jboss.naming.remote.protocol.v1.Protocol$1.handleClientMessage(Protocol.java:149)   at org.jboss.naming.remote.protocol.v1.RemoteNamingStoreV1$MessageReceiver$1.run(RemoteNamingStoreV1.java:232)   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)   ... 1 more Caused by: java.lang.ClassNotFoundException: org.apache.activemq.artemis.jms.client.ActiveMQJMSConnectionFactory   at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1293)   at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1145)   at java.lang.Class.forName0(Native Method)   at java.lang.Class.forName(Class.java:340)   at org.jboss.marshalling.AbstractClassResolver.loadClass(AbstractClassResolver.java:131)   at org.jboss.marshalling.AbstractClassResolver.resolveClass(AbstractClassResolver.java:112)   at org.jboss.marshalling.river.RiverUnmarshaller.doReadClassDescriptor(RiverUnmarshaller.java:1002)   at org.jboss.marshalling.river.RiverUnmarshaller.doReadNewObject(RiverUnmarshaller.java:1256)   at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:276)   at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:209)   at org.jboss.marshalling.AbstractObjectInput.readObject(AbstractObjectInput.java:41)   at org.jboss.naming.remote.protocol.v1.Protocol$1$3.read(Protocol.java:156)   ... 7 more

       

      and my code is :

      private static final String DEFAULT_CONNECTION_FACTORY = "jms/RemoteConnectionFactory";
      private static final String DEFAULT_DESTINATION = "java:/jms/queue/EmailSend";
      private static final String DEFAULT_MESSAGE_COUNT = "1";
      private static final String DEFAULT_USERNAME = "user";
      private static final String DEFAULT_PASSWORD = "pass";
      private static final String INITIAL_CONTEXT_FACTORY = "org.jboss.naming.remote.client.InitialContextFactory";
      private static final String PROVIDER_URL = "http-remoting://138.241.163.76:8080";
      .
      .
      .
      Context context = null;
        final Properties props = new Properties();
      
        props.setProperty(Context.INITIAL_CONTEXT_FACTORY,INITIAL_CONTEXT_FACTORY);
        props.put(Context.PROVIDER_URL, PROVIDER_URL);  // NOTICE: "http-remoting" and port "8080"
        props.put(Context.SECURITY_PRINCIPAL, DEFAULT_USERNAME);
        props.put(Context.SECURITY_CREDENTIALS, DEFAULT_PASSWORD);
        props.put("java.naming.factory.url.pkgs","org.jboss.ejb.client.naming");
        context = new InitialContext(props);
      
      
      
      
      
      
      
      
      

      is org.jboss.ejb.client.naming correct parameter for this properties (java.naming.factory.url.pkgs) in wildfly 10???

      and i was change parameter

      java.naming.factory.url.pkgs

      with this (org.jboss.naming:org.jnp.interfaces) or this (org.jboss.naming.remote.client.InitialContextFactory) but i'v got the error in above


      when i dont use this line :props.put("java.naming.factory.url.pkgs","org.jboss.ejb.client.naming");

      tomcat automatic add to context parameter java.naming.factory.url.pkgs with value org.apache.naming

      notice:

      in wildfly 8 im use props.put("java.naming.factory.url.pkgs","org.jboss.ejb.client.naming") and worked correct but in wildfly 10 iv got error above???


      Can help me about this error ???

        • 1. Re: tomcat cannot connect to server Jms ActiveMQ Wildfly 10
          jbertram

          This looks like a fairly basic classloading issue.  The exception here is:

          java.lang.ClassNotFoundException: org.apache.activemq.artemis.jms.client.ActiveMQJMSConnectionFactory

          Which really doesn't have anything to do with your JNDI lookup properties.

           

          The JMS implementation changed from HornetQ in Wildfly 8 to Apache ActiveMQ Artemis is Wildfly 10 so my guess is that you haven't updated your client application with the most recent client jars.

          • 2. Re: tomcat cannot connect to server Jms ActiveMQ Wildfly 10
            ehsanlinux

            Justin Bertram wrote:

             

            This looks like a fairly basic classloading issue.  The exception here is:

            java.lang.ClassNotFoundException: org.apache.activemq.artemis.jms.client.ActiveMQJMSConnectionFactory

            Which really doesn't have anything to do with your JNDI lookup properties.

             

            The JMS implementation changed from HornetQ in Wildfly 8 to Apache ActiveMQ Artemis is Wildfly 10 so my guess is that you haven't updated your client application with the most recent client jars.

            Im copied last client jars from [wildfl10y_home]\bin\client into my project too.

            and i connected jms queue from client project but i want connect jms queue from servlet i got error because tomcat when make context add properties  java.naming.factory.url.pkgs with value org.apache.naming and i can't connect jms queue from servlet

            • 3. Re: tomcat cannot connect to server Jms ActiveMQ Wildfly 10
              mnovak

              Hi,

               

              Justin is correct. There is just problem with your classpath on Servlet/Tomcat side. Adding jboss-client.jar from WF10 to classpath will solve it.

               

              Further your JNDI properties should look like:

               

              final Properties env = new Properties();

              env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");

              env.put(Context.PROVIDER_URL, "http-remoting://127.0.0.1:8080");

              context = new InitialContext(env);

               

              If you have configured security then you must add:

              env.put(Context.SECURITY_PRINCIPAL, "user");

              env.put(Context.SECURITY_CREDENTIALS, "password");

               

              Remember that you can look up only JNDI objects which have java:jboss/exported/... prefix and you look up them by relative JNDI name. So for example if you want to look up queue with full JNDI name java:jboss/exported/jms/queue/testQueue then use relative JNDI name is jms/queue/testQueue:

               

              Queue queue = (Queue) context.lookup("jms/queue/testQueue");

               

              Cheers,

              Mirek

              • 4. Re: tomcat cannot connect to server Jms ActiveMQ Wildfly 10
                emag

                In addition to Justin and Miroslav, wildfly-quickstart/helloworld-jms 's pom.xml might help you if you use Maven. Though the sample is standalone java app, the dependecy setting should be available with Tomcat.

                 

                quickstart/pom.xml at 10.x · wildfly/quickstart · GitHub