4 Replies Latest reply on Jan 5, 2014 7:39 AM by CHRISTIAN CONTRERAS

    Integration Jboss 7 -- Tomcat 7 with Jms




           I have a problem and would like to help me fix it. I develop an application with the server hosted on Jboss 7 and client on a Tomcat 7.
      On the client and server, I set the context as follows:

      String, Hashtable = new Hashtable Object> jndiProperties Object> Of String ();
      jndiProperties.put (Context.URL_PKG_PREFIXES,

      context = new InitialContext (jndiProperties);

      and work with the EJB smoothly.

      However, I can not work with JMS. The server creates messages without problem, but when I run the client:

      QueueConnectionFactory QueueConnectionFactory = (QueueConnectionFactory) jndiContext.lookup (Global.NOMBRE_CONECTION_FACTORY_JMS);

      NullPointerException excpecion one is launched. In the context of the cliente i don´t found the QueueConnectionFactory.

      Can anyone help me? I'm desperate.

        • 1. Re: Integration Jboss 7 -- Tomcat 7 with Jms
          Wolf-Dieter Fink Master

          I suppose you use a wrong InitialContext. It will be different for EJB and other JNDI stuff.


          Have a look to jboss-eap-quickstarts/helloworld-jms

          • 2. Re: Re: Integration Jboss 7 -- Tomcat 7 with Jms
            CHRISTIAN CONTRERAS Newbie

            Hello Wolf-Dieter. Thank you for the response.


              I watched this example and i haven´t problem to send the event. The problem is that my client is in a Tomcat, out of the Jboss. Can i have diferent InitialContext in the same aplication? Can be the problem that i haven´t configuration QHornet in Tomcat? What do you think?


            Thank you very much.

            • 3. Re: Integration Jboss 7 -- Tomcat 7 with Jms
              Wolf-Dieter Fink Master

              For one InitialContext you can set the "org.jboss.ejb.client.naming" to support EJB.

              The other InitialContext include the remote-naming approach (there is no *ejb* property) as it's shown in the JMS quickstart.

              You should not mix the properties in the same InitialContext, but you can use multiple IC's in the same JVM

              1 of 1 people found this helpful
              • 4. Re: Integration Jboss 7 -- Tomcat 7 with Jms
                CHRISTIAN CONTRERAS Newbie

                Hello wfink

                    Thank you very much for the answer. Finally, i found the problem. The problem was that I put in the System.properties the property "java.naming.provider.url" before to create the InitialContext for the JMS connection. Now,  I´m writing the InitialContext for the JMS before put this property and now works.

                   But now, i have other problem. I need create a MessageListener that catch the event. My program´s code is:


                =====                      SERVER                  ======


                Context jndiContext = oLocator.getContexto();


                QueueConnectionFactory queueConnectionFactory = (QueueConnectionFactory) jndiContext



                QueueConnection queueConnection = queueConnectionFactory

                                .createQueueConnection("cam", "cam");


                QueueSession qsession = queueConnection.createQueueSession(false,



                Queue q = (Queue) jndiContext.lookup(Global.NOMBRE_COLA_JMS);


                QueueSender qsender = qsession.createSender(q);



                ObjectMessage message = qsession.createObjectMessage();

                HashMap<String, Object> map = new HashMap<String, Object>();



                map.put("usuario", usuario);




                qsender.send(message, DeliveryMode.PERSISTENT,

                                Message.DEFAULT_PRIORITY, 7 * 24 * 3600 * 1000L);







                =====                      CLIENT                     ======


                public void crearJms() {

                        try {

                            // Set up the context for the JNDI lookup

                            final Properties env = new Properties();

                            env.put(Context.INITIAL_CONTEXT_FACTORY, INITIAL_CONTEXT_FACTORY);


                                    System.getProperty(Context.PROVIDER_URL, PROVIDER_URL));


                                    System.getProperty("username", "cam"));


                                    System.getProperty("password", "cam"));

                            InitialContext context = new InitialContext(env);


                            // Perform the JNDI lookups

                            String connectionFactoryString = System.getProperty(

                                    "connection.factory", DEFAULT_CONNECTION_FACTORY);

                            QueueConnectionFactory queueConnectionFactory = (QueueConnectionFactory) context



                            String destinationString = System.getProperty("destination",


                            Destination destination = (Destination) context



                            // Create the JMS connection, session, producer, and consumer

                            connection = queueConnectionFactory.createQueueConnection(

                                    System.getProperty("username", DEFAULT_USERNAME),

                                    System.getProperty("password", DEFAULT_PASSWORD));


                            QueueSession session = connection.createQueueSession(false,



                            MessageConsumer consumer = session.createConsumer(destination);



                            consumer.setMessageListener(new UserQueueReceiverAdapter());



                        } catch (Exception ex) {

                            System.out.println("Error " + ex);

                        } finally {

                            if (connection != null) {

                                try {


                                } catch (Exception ex) {

                                    System.out.println("Error cerrando " + ex);







                =====                      LISTENER IN THE CLIENT                 =====


                public class UserQueueReceiverAdapter implements MessageListener {



                     * Recibe los mensajes enviados al cliente


                     * @param message

                     *            Message


                    public void onMessage(Message oMensaje) {


                        try {

                            String JMSType = oMensaje.getJMSType();


                            if (JMSType.equals("alta.intercambio")) {


                                ObjectMessage objectMessage = (ObjectMessage) oMensaje;

                                Map args = (Map) objectMessage.getObject();



                        } catch (JMSException ex) {

                            Mensajes.mostrarMensajeError("Error al recibir el mensaje." + ex,







                But the class UserQueueReceiverAdapter don´t catch nothing.

                Have you any idea? Can you help me?


                Thank you very much!