5 Replies Latest reply on Feb 17, 2008 3:08 PM by Tim Fox

    Tomcat and JBoss messaging

    Jaya Srinivasan Newbie

      Hi

      I have a tomcat app that needs to send and receive JMS messages from JBoss App server (4.2.2) with JBOSS messaging. Both the tomcat service and the JBoss App Server are on the same machine.

      I made the following changes on the Tomcat side

      1) Added the following to {catalina-home}/conf/context.xml
      <Resource
      name="/ConnectionFactory"
      auth="Container" type="org.jboss.jms.server.connectionfactory.ConnectionFactory" factory="org.jboss.jms.server.bridge.JNDIConnectionFactoryFactory" description="JBOSS JMS Connection Factory for sending recieving messages"
      /Resource>

      2) Added the following to web-inf/web.xml

      <resource-env-ref>
      <resource-env-ref-name>/ConnectionFactory</resource-env-ref-name>
      <resource-env-ref-type>org.jboss.jms.server.connectionfactory.ConnectionFactory</resource-env-ref-type>
      </resource-env-ref>

      3) In my java code I do the following

      mLog.info("creeating InitialContext");
      Properties jndiProps = new Properties();
      jndiProps.setProperty(Context.INITIAL_CONTEXT_FACTORY,
      "org.jnp.interfaces.NamingContextFactory");
      jndiProps.setProperty(Context.URL_PKG_PREFIXES,
      "org.jboss.naming:org.jnp.interface");
      jndiProps.setProperty(Context.PROVIDER_URL, "jnp://10.195.4.123:1099");
      ic = new InitialContext(jndiProps);

      mLog.info("Looking up environment context");
      Context envCtx = (Context) ic.lookup("java:comp/env");

      mLog.info("Looking up Connection factory");
      ConnectionFactory cf = (ConnectionFactory)envCtx.lookup("/ConnectionFactory");


      When I run the above on Tomcat I get the following error

      javax.naming.NameNotFoundException: comp not bound

      I verified JBOSS app server was running on port 1099. Can someone help?

      thanks!
      Jaya



        • 1. Re: Tomcat and JBoss messaging
          Andy Taylor Master

          Instead of doing this:

           mLog.info("Looking up environment context");
          Context envCtx = (Context) ic.lookup("java:comp/env");
          
          mLog.info("Looking up Connection factory");
          ConnectionFactory cf = (ConnectionFactory)envCtx.lookup("/ConnectionFactory");
          


          Can you not just look up the connection factory directly i.e.
          mLog.info("Looking up Connection factory");
          ConnectionFactory cf = (ConnectionFactory)iclookup("/ConnectionFactory");
          


          • 2. Re: Tomcat and JBoss messaging
            Jaya Srinivasan Newbie

            Thanks for the reply, Andy!

            I tried that as well but then I get a ServletException when it's trying to look up teh conenction factory

            2008-02-13 14:42:16,046 [http-8000-1] ERROR org.apache.catalina.core.ContainerBase.[Standalone].[localhost].[/allocationmessaging].[AllocationMessaging] - Servlet.service() for servlet AllocationMessaging threw exception
            javax.servlet.ServletException: Servlet execution threw an exception
            at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:313)
            at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
            at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:228)
            at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
            at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
            at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
            at com.disney.tomcat.GreenCookieValve.invoke(Unknown Source)
            at com.disney.tomcat.RequestThrottleValve.invoke(Unknown Source)
            at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
            at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:216)
            at org.apache.coyote.http11.Http11NioProcessor.process(Http11NioProcessor.java:888)
            at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:624)
            at org.apache.tomcat.util.net.NioEndpoint$Worker.run(NioEndpoint.java:1465)
            at java.lang.Thread.run(Thread.java:619)

            Couple of questions...

            1) Does tomcat support external JNDI calls? My tomcat app and the JBOSS App server are on the same machine but they are separate services.

            2) If it does then just modifying the initial context to point to JBOSS JNDI should be sufficient, correct (the way I am doing in the code posted earlier)? I should need to modify the server.xml or web.xml on the tomcat side, right?

            I am sorry if the questions are too trivial :(. I am a newbie with JBoss messaging.

            Any input/ideas appreciated!

            thank you
            jaya

            • 3. Re: Tomcat and JBoss messaging
              Jaya Srinivasan Newbie

              Sorry...I meant to ask in my earlier post do I need to modify the server.xml and web.xml to get tomcat to refer to JBoss JNDI resource? I thought the resources specified in those files apply to Tomcat's local JNDI and for any external JNDI access, just modifying the InitialContext should be sufficient.

              Please correct me if the above is not true.

              jaya

              • 4. Re: Tomcat and JBoss messaging
                Tim Fox Master

                Just use the standard JCA JMS resource adaptor - this is available in the same VM:

                http://wiki.jboss.org/wiki/Wiki.jsp?page=JBossJMSRA

                • 5. Re: Tomcat and JBoss messaging
                  Tim Fox Master

                  I'm assuming you're trying to access JBM from a Servlet being running with the version of JBoss Web that comes bundled with JBoss AS.

                  If you're not using that, I'd ask why you don't just use that!