10 Replies Latest reply on Jan 13, 2012 9:14 PM by Justin Bertram

    How to embed REST in a stand-alone server?

    Yair Ogen Expert

      Hi,

       

      I've been using a stand-alone hornet server using JMS interface.

       

      I now want to add to the same server some REST capabilities. I assume that is not possible as the REST API needs a HTTP container for running.

       

      The explanations on how to create such a server are not clear.

       

      Is it possible to run Tomcat, for example, so that both JMS and REST interfaces are exposed in the same server process?

       

      I would like for users to send messages via HTTP REST and receive using JMS subscription.

       

      Any exmaples out there?

       

      Thanks,

       

      Yair

        • 1. Re: How to embed REST in a stand-alone server?
          Yong Hao Gao Master

          Please have a look at "HornetQ Rest Guide" for details.

           

          Howard

          • 4. Re: How to embed REST in a stand-alone server?
            Yair Ogen Expert

            If you are refering to:

             

            http://docs.jboss.org/resteasy/hornetq-rest/1.0-beta-1/userguide/html_single/index.html#d0e49

             

            This is exactly the point. Couldn't make it to work.

             

            Isn't there anywhere a ready-to-use war I can just drop in Tomcat?

             

            Also, it is not clear if such a war can also serve as the jms server for a regular client connecting to it with a connection factory.

             

            Any clarifications are welcome.

             

            Yair

            • 5. Re: How to embed REST in a stand-alone server?
              Andy Taylor Master

              This is exactly the point. Couldn't make it to work.

              Maybe you should be asking us for help with why you couldnt get it to work.

              • 6. Re: How to embed REST in a stand-alone server?
                Yair Ogen Expert

                Looks like it cannot connect, but trying to start it on localhost...

                 

                In catalina out I see:

                 

                Sep 15, 2011 2:08:56 PM org.hornetq.core.logging.impl.JULLogDelegate info
                INFO: Server is now live
                Sep 15, 2011 2:08:56 PM org.hornetq.core.logging.impl.JULLogDelegate info
                INFO: HornetQ Server version 2.2.5.Final (HQ_2_2_5_FINAL_AS7, 121) [e6ad4978-df87-11e0-a8b6-000c29c10eab] started
                Sep 15, 2011 2:08:56 PM org.hornetq.core.logging.impl.JULLogDelegate warn
                WARNING: Tried 1 times to connect. Now giving up on reconnecting it.
                Sep 15, 2011 2:08:56 PM org.apache.catalina.core.StandardContext listenerStart
                SEVERE: 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)
                at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4206)
                at org.apache.catalina.core.StandardContext.start(StandardContext.java:4705)
                at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:799)
                at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:779)
                at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:601)
                at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1079)
                at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:1002)
                at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:506)
                at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1317)
                at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:324)
                at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:142)
                at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1065)
                at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
                at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
                at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
                at org.apache.catalina.core.StandardService.start(StandardService.java:525)
                at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
                at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                at java.lang.reflect.Method.invoke(Method.java:597)
                at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
                at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
                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)
                at org.hornetq.rest.MessageServiceManager.start(MessageServiceManager.java:154)
                at org.hornetq.rest.integration.RestMessagingBootstrapListener.contextInitialized(RestMessagingBootstrapListener.java:36)
                ... 24 more
                Sep 15, 2011 2:08:56 PM org.apache.catalina.core.StandardContext start
                SEVERE: Error listenerStart
                Sep 15, 2011 2:08:56 PM org.apache.catalina.core.StandardContext start
                SEVERE: Context [/hornetq-rest] startup failed due to previous errors

                 

                 

                in the hornet log:

                 

                <message>Exception sending context initialized event to listener instance of class org.hornetq.rest.integration.RestMessagingBootstrapListener</message>
                  <exception>
                    <message>java.lang.RuntimeException: HornetQException[errorCode=2 message=Cannot connect to server(s). Tried with all available servers.]</message>

                 

                • 7. Re: How to embed REST in a stand-alone server?
                  Scott O'Brien Newbie

                  If perhaps I could put my $0.02 in here.

                   

                  I think it would be great to have some better examples on getting REST to work.  I find myself in the same boat as Yair but I think the problem here is assumed knowledge in the documentation.  It looks great on how to consume and use the REST services.  Just not set up.

                   

                  For instance, one of the biggest advantages of starting out with HornetQ over ActiveMQ was that you don't need a book to help you along the way, you unarchive it, run the run.sh/bat script and away you go... this is great for people like myself that arn't experienced with Maven and the like either yet to start creating and consuming JMS.

                   

                  The problem is there's no 'from scratch' about how to enable REST, a great deal on how to consume and use REST but not much getting started.  Even if it was a simple "At the time of writing you won't be able to simply use the existing run.sh script for REST support because...  You'll need to set up an application server for REST support, a simple application server you might like to try is...."

                   

                  If someone wouldn't mind filling in the gaps here too that would be awesome

                  • 8. Re: How to embed REST in a stand-alone server?
                    Gurvinderpal Narula Newbie

                    Having the same problem here. I'm trying to get RESTEasy setup with HornetQ on jboss-as 5.1.0 and I get exactly the same exception as Yair Ogen :

                     

                    Here's what posted in the logs of jboss-as :

                     

                     

                    14:11:38,267 ERROR [0-SNAPSHOT]] 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)

                              at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3910)

                              at org.apache.catalina.core.StandardContext.start(StandardContext.java:4389)

                              at org.jboss.web.tomcat.service.deployers.TomcatDeployment.performDeployInternal(TomcatDeployment.java:321)

                              at org.jboss.web.tomcat.service.deployers.TomcatDeployment.performDeploy(TomcatDeployment.java:145)

                              at org.jboss.web.deployers.AbstractWarDeployment.start(AbstractWarDeployment.java:461)

                              at org.jboss.web.deployers.WebModule.startModule(WebModule.java:118)

                              at org.jboss.web.deployers.WebModule.start(WebModule.java:97)

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

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

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

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

                              at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:157)

                              at org.jboss.mx.server.Invocation.dispatch(Invocation.java:96)

                              at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)

                              at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)

                              at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:668)

                              at org.jboss.system.microcontainer.ServiceProxy.invoke(ServiceProxy.java:206)

                              at $Proxy38.start(Unknown Source)

                              at org.jboss.system.microcontainer.StartStopLifecycleAction.installAction(StartStopLifecycleAction.java:42)

                              at org.jboss.system.microcontainer.StartStopLifecycleAction.installAction(StartStopLifecycleAction.java:37)

                              at org.jboss.dependency.plugins.action.SimpleControllerContextAction.simpleInstallAction(SimpleControllerContextAction.java:62)

                              at org.jboss.dependency.plugins.action.AccessControllerContextAction.install(AccessControllerContextAction.java:71)

                              at org.jboss.dependency.plugins.AbstractControllerContextActions.install(AbstractControllerContextActions.java:51)

                              at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:348)

                              at org.jboss.system.microcontainer.ServiceControllerContext.install(ServiceControllerContext.java:297)

                              at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:1652)

                              at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:938)

                              at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1082)

                              at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:988)

                              at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:826)

                              at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:556)

                              at org.jboss.system.ServiceController.doChange(ServiceController.java:688)

                              at org.jboss.system.ServiceController.start(ServiceController.java:460)

                              at org.jboss.system.deployers.ServiceDeployer.start(ServiceDeployer.java:163)

                              at org.jboss.system.deployers.ServiceDeployer.deploy(ServiceDeployer.java:99)

                              at org.jboss.system.deployers.ServiceDeployer.deploy(ServiceDeployer.java:46)

                              at org.jboss.deployers.spi.deployer.helpers.AbstractSimpleRealDeployer.internalDeploy(AbstractSimpleRealDeployer.java:62)

                              at org.jboss.deployers.spi.deployer.helpers.AbstractRealDeployer.deploy(AbstractRealDeployer.java:55)

                              at org.jboss.deployers.plugins.deployers.DeployerWrapper.deploy(DeployerWrapper.java:179)

                              at org.jboss.deployers.plugins.deployers.DeployersImpl.doDeploy(DeployersImpl.java:1454)

                              at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFirst(DeployersImpl.java:1172)

                              at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFirst(DeployersImpl.java:1193)

                              at org.jboss.deployers.plugins.deployers.DeployersImpl.install(DeployersImpl.java:1113)

                              at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:348)

                              at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:1652)

                              at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:938)

                              at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1082)

                              at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:988)

                              at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:826)

                              at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:556)

                              at org.jboss.deployers.plugins.deployers.DeployersImpl.process(DeployersImpl.java:789)

                              at org.jboss.deployers.plugins.main.MainDeployerImpl.process(MainDeployerImpl.java:699)

                              at org.jboss.system.server.profileservice.repository.MainDeployerAdapter.process(MainDeployerAdapter.java:117)

                              at org.jboss.system.server.profileservice.repository.ProfileDeployAction.install(ProfileDeployAction.java:70)

                              at org.jboss.system.server.profileservice.repository.AbstractProfileAction.install(AbstractProfileAction.java:53)

                              at org.jboss.system.server.profileservice.repository.AbstractProfileService.install(AbstractProfileService.java:403)

                              at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:348)

                              at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:1652)

                              at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:938)

                              at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1082)

                              at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:988)

                              at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:778)

                              at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:543)

                              at org.jboss.system.server.profileservice.repository.AbstractProfileService.registerProfile(AbstractProfileService.java:308)

                              at org.jboss.system.server.profileservice.ProfileServiceBootstrap.start(ProfileServiceBootstrap.java:256)

                              at org.jboss.bootstrap.AbstractServerImpl.start(AbstractServerImpl.java:461)

                              at org.jboss.Main.boot(Main.java:221)

                              at org.jboss.Main$1.run(Main.java:556)

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

                    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)

                              at org.hornetq.rest.MessageServiceManager.start(MessageServiceManager.java:154)

                              at org.hornetq.rest.integration.RestMessagingBootstrapListener.contextInitialized(RestMessagingBootstrapListener.java:36)

                              ... 69 more

                     

                     

                    Any help on this will be appreciated.

                    • 9. Re: How to embed REST in a stand-alone server?
                      Justin Bertram Master

                      I'm going to try to respond to a number of questions and points raised on this thread...

                      I've been using a stand-alone hornet server using JMS interface.

                       

                      I now want to add to the same server some REST capabilities. I assume that is not possible as the REST API needs a HTTP container for running.

                      Your assumption is correct.  You cannot add REST support to a stand-alone HornetQ server.  REST functionality requires an HTTP server.

                      The explanations on how to create such a server are not clear.

                      As the HornetQ REST documentation indicates, you can do this with JBoss AS or ostensibly with a different container. 

                       

                      To do this, for example, in JBoss AS7 (which is what I would recommend at this point in terms of JBoss AS versions) which comes with HornetQ pre-configured you just need to create a WAR file with the web.xml specified in the documentation and the hornetq-rest.jar in WEB-INF/lib. Since AS7 classloading semantics are a bit different than in previous versions you'll also nee the MANIFEST.MF in the WAR file to include this:

                       

                        Dependencies: org.hornetq, org.jboss.netty

                      Is it possible to run Tomcat, for example, so that both JMS and REST interfaces are exposed in the same server process?

                      I have tried this out and have not been able to make HornetQ REST work within Tomcat yet.

                      I would like for users to send messages via HTTP REST and receive using JMS subscription.

                       

                      Any exmaples out there?

                      Check this out.

                      Isn't there anywhere a ready-to-use war I can just drop in Tomcat?

                      There is no ready-made WAR you can just drop-in to any container.  However, it should be fairly simple to construct using the example pom.xml files in the documentation.

                      Also, it is not clear if such a war can also serve as the jms server for a regular client connecting to it with a connection factory.

                      If configured properly, JBoss AS7 will have HornetQ running which will expose all the normal JMS resources (e.g. connection factories, destinations, etc.).  Deploying HornetQ REST will add the REST interface to that.  Since I haven't been able to make HornetQ REST work in Tomcat I can't comment on whether or not all the normal JMS resources would be exposed.  My guess is that they wouldn't.

                      The problem is there's no 'from scratch' about how to enable REST

                      The documentation does cover this point, although it's not perfect.  I can vouch that it works in AS7 given you add the proper dependency entry to the WAR's MANIFEST.MF.  I'll see if I can't clean it up a bit and make things more clear for AS7 (HORNETQ-823). 

                       

                      I'll also try to track down the Tomcat issue as well (HORNETQ-824).

                      • 10. Re: How to embed REST in a stand-alone server?
                        Justin Bertram Master

                        I was able to get HornetQ REST (including the embedded HornetQ server) working on Tomcat by paying closer attention to the documentation.  Once I added the org.hornetq.rest.integration.HornetqBootstrapListener to my web.xml along with hornetq-configuration.xml, hornetq-jms.xml, and hornetq-users.xml in WEB-INF/classes everything worked appropriately.