5 Replies Latest reply on Sep 30, 2011 1:48 PM by Michael Musgrove

    REST API on JBoss 7

    vlari Newbie

      Hello, I'm trying to deploy the HornetQ REST API on jboss 7, following the instructions found

      [here|http://docs.jboss.org/hornetq/2.2.2.Final/rest-interface-manual/html_single/index.html#d0e57]

       

      Here is the content of my war file:

       

       

      {code}

      0 Mon Jul 11 18:40:20 PDT 2011 META-INF/

         126 Mon Jul 11 18:40:18 PDT 2011 META-INF/MANIFEST.MF

           0 Mon Jul 11 18:40:18 PDT 2011 WEB-INF/

           0 Mon Jul 11 18:40:18 PDT 2011 WEB-INF/classes/

           0 Mon Jul 11 18:40:18 PDT 2011 WEB-INF/lib/

      110716 Thu Jul 07 17:17:26 PDT 2011 WEB-INF/lib/hornetq-rest-2.2.2.Final.jar

      2257 Mon Jul 11 17:34:44 PDT 2011 WEB-INF/web.xml


      {code}

      (note that I upgraded hornetq-rest-2.2.0 (as indicated in the documentation but no longer available) to 2.2.2.Final.

       

      Here is ny web.xml:

       

      {code}

      <web-app  xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

               xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"

               version="2.4">

       

          <listener>

              <listener-class>org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap</listener-class>

          </listener>

       

          <listener>

              <listener-class>org.hornetq.rest.integration.RestMessagingBootstrapListener</listener-class>

          </listener>

       

          <filter>

              <filter-name>Rest-Messaging</filter-name>

              <filter-class>

                  org.jboss.resteasy.plugins.server.servlet.FilterDispatcher

              </filter-class>

          </filter>

       

          <filter-mapping>

              <filter-name>Rest-Messaging</filter-name>

              <url-pattern>/*</url-pattern>

          </filter-mapping>

      </web-app>

      {code}

       

       

      I'm starting  AS7 with the following command (to make sure hornet is deployed at boot-time):

       

       

      {code}

      ./bin/standalone.sh -server-config standalone-preview.xml

      {code}

       

      Now, when I deployed this war I get the following error:

       

       

      {code}
      [...]

      18:32:26,365 INFO  [org.hornetq.core.remoting.impl.netty.NettyAcceptor] (MSC service thread 1-4) Started Netty Acceptor version 3.2.3.Final-r${buildNumber} localhost:5445 for CORE protocol

      18:32:26,371 INFO  [org.hornetq.core.server.impl.HornetQServerImpl] (MSC service thread 1-4) Server is now live

      18:32:26,372 INFO  [org.hornetq.core.server.impl.HornetQServerImpl] (MSC service thread 1-4) HornetQ Server version 2.2.6.Final (HQ_2_2_6_FINAL_AS7, 121) [977a50d5-ac0e-11e0-a395-005056c00008] started

      18:32:26,411 INFO  [org.hornetq.core.server.impl.HornetQServerImpl] (MSC service thread 1-4) trying to deploy queue jms.queue.testQueue

      18:32:26,530 INFO  [org.hornetq.core.server.impl.HornetQServerImpl] (MSC service thread 1-1) trying to deploy queue jms.topic.testTopic

      [...]

      18:32:26,821 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-3) Starting deployment of "hq-test.war"

      18:32:27,366 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/hq-test]] (MSC service thread 1-3) Exception sending context initialized event to listener instance of class org.hornetq.rest.integration.RestMessagingBootstrapListener: java.lang.NoClassDefFoundError: org/hornetq/api/core/client/ServerLocator

          at org.hornetq.rest.integration.RestMessagingBootstrapListener.contextInitialized(RestMessagingBootstrapListener.java:28) [hornetq-rest-2.2.2.Final.jar:]

          at org.apache.catalina.core.StandardContext.contextListenerStart(StandardContext.java:3368) [jbossweb-7.0.0.CR4.jar:7.0.0.CR1]

      [...]
      {code}

       

       

      Okay, for some mysterious reason, the Bootstrap Listener does not find org.hornetq.api.core.client.ServerLocator, which is in $JBOSS_HOME/modules/org/hornetq/main/hornetq-core-2.2.6.Final.jar.

       

      So, I add this jar to the archive:

       

      {code}

      0 Mon Jul 11 18:40:20 PDT 2011 META-INF/

         126 Mon Jul 11 18:40:18 PDT 2011 META-INF/MANIFEST.MF

           0 Mon Jul 11 18:40:18 PDT 2011 WEB-INF/

           0 Mon Jul 11 18:40:18 PDT 2011 WEB-INF/classes/

           0 Mon Jul 11 18:40:18 PDT 2011 WEB-INF/lib/

      1377085 Mon Jul 11 18:40:08 PDT 2011 WEB-INF/lib/hornetq-core-2.2.6.Final.jar

      110716 Thu Jul 07 17:17:26 PDT 2011 WEB-INF/lib/hornetq-rest-2.2.2.Final.jar

      2257 Mon Jul 11 17:34:44 PDT 2011 WEB-INF/web.xml

      {code}

       

       

      But when I deploy this war, I get this error:

       

       

      {code}

      18:40:45,350 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-4) Starting deployment of "hq-test.war"

      18:40:46,146 WARNING [org.hornetq.core.client.impl.ClientSessionFactoryImpl] (MSC service thread 1-4) Tried 1 times to connect. Now giving up on reconnecting it.

      18:40:46,147 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/hq-test]] (MSC service thread 1-4) Exception sending context initialized event to listener instance of class org.hornetq.rest.integration.RestMessagingBootstrapListener: java.lang.RuntimeException: HornetQException[errorCode=2 message=Cannot connect to server(s). Tried with all available servers.]

          at org.hornetq.rest.integration.RestMessagingBootstrapListener.contextInitialized(RestMessagingBootstrapListener.java:42) [hornetq-rest-2.2.2.Final.jar:]

          at org.apache.catalina.core.StandardContext.contextListenerStart(StandardContext.java:3368) [jbossweb-7.0.0.CR4.jar:7.0.0.CR1]

          at org.apache.catalina.core.StandardContext.start(StandardContext.java:3821) [jbossweb-7.0.0.CR4.jar:7.0.0.CR1]

          at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:70) [jboss-as-web-7.0.0.CR1.jar:7.0.0.CR1]

          at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1765)

          at org.jboss.msc.service.ServiceControllerImpl$ClearTCCLTask.run(ServiceControllerImpl.java:2291)

          at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [:1.6.0_24]

          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [:1.6.0_24]

          at java.lang.Thread.run(Thread.java:680) [:1.6.0_24]

      Caused by: HornetQException[errorCode=2 message=Cannot connect to server(s). Tried with all available servers.]

          at org.hornetq.core.client.impl.ServerLocatorImpl.createSessionFactory(ServerLocatorImpl.java:619) [hornetq-core-2.2.5.Final.jar:]

          at org.hornetq.rest.MessageServiceManager.start(MessageServiceManager.java:154) [hornetq-rest-2.2.2.Final.jar:]

          at org.hornetq.rest.integration.RestMessagingBootstrapListener.contextInitialized(RestMessagingBootstrapListener.java:36) [hornetq-rest-2.2.2.Final.jar:]

          ... 8 more

      {code}

       

       

      Any idea of what I'm doing wrong?

      Is AS7 + HornetQ-REST documented somewhere?

      Actually, I switched to AS7 because I was having the same kind of problems with AS 6, so updated instructions for AS 6 would do too.

       

      Thanks,

       

      VL.

        • 1. Re: REST API on JBoss 7
          vlari Newbie

          I tried on Jboss AS 7 Final. AS7 Final does not have a profile that includes messaging, so I'm bootstrapping Hornetq with the REST webapp.

          Here is the war file:

           

          {code}

             0 Tue Jul 12 11:44:14 PDT 2011 META-INF/

             126 Tue Jul 12 11:44:12 PDT 2011 META-INF/MANIFEST.MF

               0 Tue Jul 12 11:44:12 PDT 2011 WEB-INF/

               0 Tue Jul 12 11:44:12 PDT 2011 WEB-INF/classes/

               0 Tue Jul 12 11:44:12 PDT 2011 WEB-INF/lib/

            2894 Tue Jul 12 11:44:12 PDT 2011 WEB-INF/classes/hornetq-configuration.xml

            1481 Tue Jul 12 11:44:12 PDT 2011 WEB-INF/classes/hornetq-jms.xml

             335 Tue Jul 12 11:44:12 PDT 2011 WEB-INF/classes/hornetq-users.xml

          1377085 Mon Jul 11 18:40:08 PDT 2011 WEB-INF/lib/hornetq-core-2.2.5.Final.jar

          229904 Tue Jul 12 10:57:56 PDT 2011 WEB-INF/lib/hornetq-jms-2.2.5.Final.jar

          110716 Thu Jul 07 17:17:26 PDT 2011 WEB-INF/lib/hornetq-rest-2.2.2.Final.jar

          27597 Sat Jul 17 12:41:38 PDT 2010 WEB-INF/lib/jboss-jms-api_1.1_spec-1.0.0.Beta1.jar

          112249 Tue Mar 09 13:35:40 PST 2010 WEB-INF/lib/junit-4.1.jar

          790250 Tue Jul 05 17:05:56 PDT 2011 WEB-INF/lib/netty-3.2.4.Final.jar

            2385 Tue Jul 12 10:40:12 PDT 2011 WEB-INF/web.xml

          {code}

           

          And here is web.xml:

           

           

          {code}

          <web-app  xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

                   xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"

                   version="2.4">

           

              <listener>

                  <listener-class>org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap</listener-class>

              </listener>

           

              <listener>

                  <listener-class>org.hornetq.rest.integration.HornetqBootstrapListener</listener-class>

              </listener>

           

              <listener>

                  <listener-class>org.hornetq.rest.integration.RestMessagingBootstrapListener</listener-class>

              </listener>

           

              <filter>

                  <filter-name>Rest-Messaging</filter-name>

                  <filter-class>

                      org.jboss.resteasy.plugins.server.servlet.FilterDispatcher

                  </filter-class>

              </filter>

           

              <filter-mapping>

                  <filter-name>Rest-Messaging</filter-name>

                  <url-pattern>/*</url-pattern>

              </filter-mapping>

          </web-app>

          {code}

           

           

          The HornetQ server is launched without problems:

           

           

          {code}

          17:50:59,371 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-4) Starting deployment of "hq-test.war"

          17:51:01,791 WARNING [org.hornetq.core.deployers.impl.FileConfigurationParser] (MSC service thread 1-3) AIO wasn't located on this platform, it will fall back to using pure Java NIO. If your platform is Linux, install LibAIO to enable the AIO journal

          17:51:01,854 INFO  [org.hornetq.core.server.impl.HornetQServerImpl] (MSC service thread 1-3) live server is starting with configuration HornetQ Configuration (clustered=false,backup=false,sharedStore=true,journalDirectory=../data/journal,bindingsDirectory=../data/bindings,largeMessagesDirectory=../data/large-messages,pagingDirectory=../data/paging)

          17:51:01,854 INFO  [org.hornetq.core.server.impl.HornetQServerImpl] (MSC service thread 1-3) Waiting to obtain live lock

          17:51:01,878 INFO  [org.hornetq.core.persistence.impl.journal.JournalStorageManager] (MSC service thread 1-3) Using NIO Journal

          17:51:01,887 WARNING [org.hornetq.core.server.impl.HornetQServerImpl] (MSC service thread 1-3) Security risk! It has been detected that the cluster admin user and password have not been changed from the installation default. Please see the HornetQ user guide, cluster chapter, for instructions on how to do this.

          17:51:02,096 INFO  [org.hornetq.core.server.impl.FileLockNodeManager] (MSC service thread 1-3) Waiting to obtain live lock

          17:51:02,096 INFO  [org.hornetq.core.server.impl.FileLockNodeManager] (MSC service thread 1-3) Live Server Obtained live lock

          17:51:05,272 INFO  [org.hornetq.core.server.impl.HornetQServerImpl] (MSC service thread 1-3) trying to deploy queue jms.queue.DLQ

          17:51:05,282 INFO  [org.hornetq.core.server.impl.HornetQServerImpl] (MSC service thread 1-3) trying to deploy queue jms.queue.ExpiryQueue

          17:51:05,348 INFO  [org.hornetq.core.remoting.impl.netty.NettyAcceptor] (MSC service thread 1-3) Started Netty Acceptor version 3.2.3.Final-r${buildNumber} localhost:5446 for CORE protocol

          17:51:05,352 INFO  [org.hornetq.core.remoting.impl.netty.NettyAcceptor] (MSC service thread 1-3) Started Netty Acceptor version 3.2.3.Final-r${buildNumber} localhost:5455 for CORE protocol

          17:51:05,353 INFO  [org.hornetq.core.server.impl.HornetQServerImpl] (MSC service thread 1-3) Server is now live

          17:51:05,353 INFO  [org.hornetq.core.server.impl.HornetQServerImpl] (MSC service thread 1-3) HornetQ Server version 2.2.5.Final (HQ_2_2_5_FINAL_AS7, 121) [7cd4b54f-a8fa-11e0-9c70-005056c00008] started

          {code}

           

           

          But I'm still getting an error when the RestMessagingBootstrapListener attempts to connect to HQ:

           

          {code}

          17:51:05,368 WARNING [org.hornetq.core.client.impl.ClientSessionFactoryImpl] (MSC service thread 1-3) Tried 1 times to connect. Now giving up on reconnecting it.

          17:51:05,369 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/hq-test]] (MSC service thread 1-3) Exception sending context initialized event to listener instance of class org.hornetq.rest.integration.RestMessagingBootstrapListener: java.lang.RuntimeException: HornetQException[errorCode=2 message=Cannot connect to server(s). Tried with all available servers.]

              at org.hornetq.rest.integration.RestMessagingBootstrapListener.contextInitialized(RestMessagingBootstrapListener.java:42) [hornetq-rest-2.2.2.Final.jar:]

              at org.apache.catalina.core.StandardContext.contextListenerStart(StandardContext.java:3368) [jbossweb-7.0.0.CR4.jar:7.0.0.Final]

          {code}

           

           

          I don't understand where the rest listener gets its list of servers from;

          I imagine it tries to connect to the Netty acceptor, but where does it get the url ? It's not configurable via the REST config file (MessageServiceConfiguration), and ClientSessionFactoryImpl does not read hornetq-configuration.xml; I tried to follow the code, but could not find the place where it's configured.

           

          Has anybody managed to run a recent version (2.2.2+) of the REST API webapp?

           

          Thanks,

           

          VL.

          • 2. Re: REST API on JBoss 7
            vlari Newbie

            Okay, I figured it out. What the documentation does not tell you is that you have to configure an in-VM connector for the rest api to be able to talk to HQ.

            • 3. Re: REST API on JBoss 7
              Rakesh Shukla Newbie

              Hello Vlari,

                            i have followed same steps and having same issue. Could you please let me know what changes do I need to make HornetQ REST working without bootstraping ( ....preconfigured environment ).

               

               

              Thanks.

              • 4. Re: REST API on JBoss 7
                vlari Newbie

                Hi Rakesh,

                 

                Just add this acceptor to your hornetq config file:

                 

                <acceptor name="in-vm">

                    <factory-class>org.hornetq.core.remoting.impl.invm.InVMAcceptorFactory</factory-class>

                </acceptor>

                 

                 

                vlari

                • 5. Re: REST API on JBoss 7
                  Michael Musgrove Master
                  i have followed same steps and having same issue. Could you please let me know what changes do I need to make HornetQ REST working without bootstraping ( ....preconfigured environment ).

                   

                  AS7 is modules based so when deploying the hornetq rest war you need to express a dependency on hornetq (see https://docs.jboss.org/author/display/AS7/Class+Loading+in+AS7 for details). Do this by putting a file called src/main/resources/META-INF/MANIFEST.MF into you project directory with contents:

                   

                       Dependencies: org.hornetq