Java EE SSL Servlet Example

This example shows you how to configure and use servlet transport over SSL with HornetQ.

JBoss AS configuration

Please refer to HornetQ Quickstart guide to install it in JBoss AS 5

Example Configuration

The example leverages the JBoss Arquillian framework to run an AS 7 instance and deploy the MDB.

Example step-by-step

download AS 7.1.1.final from here and install.

set the JBOSS_HOME property to point to AS7 install directory

To run the example simply type mvn testfrom the example directory

  1. First we need to get an initial context so we can look-up the JMS connection factory and destination objects from JNDI. This initial context will get it's properties from the jndi.properties file in the directory config
  2.            initialContext = new InitialContext();
            
  3. We look up the JMS queue object from JNDI
  4.            Queue queue = (Queue) initialContext.lookup("/queue/testQueue");
            
  5. We look up the JMS connection factory object from JNDI
  6.            ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("/TestServletConnectionFactory");
            
  7. We create a JMS connection
  8.            connection = cf.createConnection();
            
  9. We create a JMS session. The session is created as non transacted and will auto acknowledge messages.
  10.            Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
            
  11. We create a JMS message producer on the session. This will be used to send the messages.
  12.           MessageProducer messageProducer = session.createProducer(queue);
           
  13. We create a JMS text messages that we are going to send.
  14.             TextMessage message = session.createTextMessage("This is a text message");
            
  15. We send messages to the queue
  16.            messageProducer.send(message);
            
  17. We create a JMS Message Consumer
  18.            MessageConsumer messageConsumer = session.createConsumer(queue);
            
  19. We start the connection
  20.             connection.start();
            
  21. We receive the message
  22.             TextMessage messageReceived = (TextMessage) messageConsumer.receive(5000);
            
  23. And finally, always remember to close your JMS connections and resources after use, in a finally block. Closing a JMS connection will automatically close all of its sessions, consumers, producer and browser objects
  24.            finally
               {
                  if (initialContext != null)
                  {
                    initialContext.close();
                  }
                  if (connection != null)
                  {
                     connection.close();
                  }
               }
            

  1. The stores were generating using the following commands :