12 Replies Latest reply on Sep 16, 2003 9:50 AM by marks

    runtime requirements for JMS for use with servlet

    marks

      I wish to implement a servlet ( on Tomcat 4.1 ) that will put messages in a queue which is being serviced by a MDB ( in its OnMessage() method ) sitting on a JBoss server on another machine.

      1) Do I need to have JBoss installed on the Tomcat machine too? Or does JBoss come with a JMS service provider that I can use with my servlet?

      2) What JNDI service provider should I use?

        • 1. Re: runtime requirements for JMS for use with servlet

          1/ You don''t need JBoss installed on the machine of course ;-) JBoss comes with several invokers (HTTP, OIL, UIL, intra vm). To have a JBossMQ client implementation in your servlet, you need to add the needed jar to your classpath, that is:

          - J2EE interface
          - JBossMQ interfaces/ client implemtnation
          - JNDI access

          I would suggest jboss-j2ee.jar and jboss-allclient.jar which are located in the 'client' directory of the JBoss distribution.

          2/ Your jndi.properties should look like:

          java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
          java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
          java.naming.provider.url=YOUR_HOST

          Beware, however. Tomcat is bundled with its own naming service I think. You should overried it in some way

          Regards,

          Stephane



          • 2. Re: runtime requirements for JMS for use with servlet
            marks

            Thank you for the suggestions. I managed to compile a servlet at the Tomcat end, however on running it, it gives a NamingException. An excerpt of the relevant code is below:

            // Get set up with JNDI
            Hashtable env = new Hashtable();
            env.put(Context.PROVIDER_URL, "192.168.0.3:1099" );
            env.put( Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory" );
            env.put( Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces" );

            try
            {
            Context _context = new InitialContext( env );

            QueueConnectionFactory factory = (QueueConnectionFactory)_context.lookup("java:comp/env/jms/QCF");

            }
            catch( NamingException e )
            {
            }

            any pointers as to where the problem could be?

            ms

            • 3. Re: runtime requirements for JMS for use with servlet

              Yes.

              the java:/comp/env domain is accessible localy only. If you are querying a remote JNDI server (which is the case, even on the same machien as the JVM is different) you have to lookup for "ConnectionFactory" instead (for OIL/UIL)

              so

              _context.lookup("ConnectionFactory"); should work

              Regards,

              Stephane

              • 4. Re: runtime requirements for JMS for use with servlet
                marks

                I modified the code to what you suggested, and the same error persists.

                // Get set up with JNDI
                Hashtable env = new Hashtable();
                env.put(Context.PROVIDER_URL, "192.168.0.3:1099" );
                env.put( Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory" );
                env.put( Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");

                _context = new InitialContext( env );

                out.println("got the initial context\n");

                factory = ( QueueConnectionFactory) _context.lookup("ConnectionFactory");

                The exception I get is a java.rmi.ServerException: RemoteException. The first few lines of the stack trace are below:

                javax.naming.CommunicationException. Root exception is java.rmi.ServerException: RemoteException occurred in server thread; nested exception is: java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is: java.net.MalformedURLException: no protocol: Files/Apache at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:292) at sun.rmi.transport.Transport$1.run(Transport.java:148) at java.security.AccessController.doPrivileged(Native Method) at sun.rmi.transport.Transport.serviceCall(Transport.java:144) at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460) at
                ...
                ....

                I tried doing "rmi://192.168.0.3:1099" - that did not work.

                Who decides which invocation layer to use? The JMS provider? How do we force it to use a particular one?

                I also posted a related question earlier ( http://www.jboss.org/modules/bb/index.html?module=bb&op=viewtopic&t= ). I thought it had something to do with RMI.

                thanks,
                ms

                • 5. Re: runtime requirements for JMS for use with servlet

                  try,

                  // Get set up with JNDI
                  Hashtable env = new Hashtable();
                  env.put(Context.PROVIDER_URL, "192.168.0.3" );
                  env.put( Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory" );
                  env.put( Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces" );

                  Regards,

                  Stephane

                  • 6. Re: runtime requirements for JMS for use with servlet
                    marks

                    I did what you suggested, and I still get the same exception. Here are the first few lines of the stack trace:

                    javax.naming.CommunicationException. Root exception is java.rmi.ServerException: RemoteException occurred in server thread; nested exception is: java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is: java.net.MalformedURLException: no protocol: Files/Apache at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:292) at sun.rmi.transport.Transport$1.run(Transport.java:148) at java.security.AccessController.doPrivileged(Native Method) at sun.rmi.transport.Transport.serviceCall(Transport.java:144) at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460) at

                    What happens is that the firewall on the client prompts me to allow a connection to 192.168.0.3, port 1099. I allow that. Then the firewall on the client prompts me to allow a connection to 192.168.0.3, port 1177. I allow this, and then I get the exception. On the server side, doing a netstat reveals port 1099 and port 1177 in a TIME_WAIT state with the client machine ( the server dropped the connection - probably bcoz of the malformed URL ).

                    regards,
                    ms

                    • 7. Re: runtime requirements for JMS for use with servlet

                      mm if you want to use RMI accross firewalls it's not working that way. RMI needs the port 1099 and then choose randomly another port for the communication. You can change that by customizing the RMISocketFactory object.

                      Try to run the same code whitout the firewall to check that is the origin of the problem.

                      Regards,

                      Stephane

                      • 8. Re: runtime requirements for JMS for use with servlet
                        marks

                        I ran the code without the firewall, and I get the same error.

                        Somehow I dont think it is a firewall issue - the firewall is not blocking the connections, it prompts me to allow it and I do allow them.

                        Could this port 1177 on the server be the "randomly another port for the communication" that RMI uses. If so, I see connections being made to that port.

                        The server.log file at the JBoss server end does not report anything suspicious. Any other log files that I should look into at the JBoss end ?

                        regards,
                        ms

                        • 9. Re: runtime requirements for JMS for use with servlet

                          I don't think 1177 is this random port (normally RMI took higher value but it could be possible).

                          I don't really understand your problem actually. If it's not a network issue ... Have you tried google with the exception you got?

                          Regarding logs, put JBoss in debug mode (change the log4j.xml file in server/conf directory).

                          Regards,

                          Stephane

                          • 10. Re: runtime requirements for JMS for use with servlet
                            marks

                            I took your suggestion and hit the newsgroups, as well as looked closely at the stack trace:

                            javax.naming.CommunicationException. Root exception is java.rmi.ServerException: RemoteException occurred in server thread; nested exception is: java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is: java.net.MalformedURLException: no protocol: Files/Apache at
                            .....
                            ......

                            The phrase "Files/Apache", I thought, could be from the path "....Program Files/Apache Group..."

                            and then I found this link:

                            http://tinyurl.com/njbo

                            looks like the spaces in one of my paths might be causing problems...My directory structure for Apache and Tomcat look like this:

                            E:\
                            Program Files
                            Apache Group
                            Apache2
                            Tomcat-4.1
                            ......

                            does this give you something to work with?

                            • 11. Re: runtime requirements for JMS for use with servlet

                              as far as Jboss is concerned, no

                              Regards,

                              Stephane

                              • 12. Re: runtime requirements for JMS for use with servlet
                                marks

                                OK - that problem is now solved...

                                Spaces considered harmful:

                                The path to my servlet was E:/Program Files/Apache Group/Tomcat4-1/webapps/.....

                                I took it out from there and put it under the E:/ and modified the server.xml of Tomcat and restarted Tomcat and the problem was gone....