PROTOTYPE MESSAGE SERVER

5.1 Message Server

The Message Server is a Servlet that runs on a Tomcat 5.0 Server. Class MessageServlet is the main class that implements the message server. The Message Server continually listens for HTTP POST/GET Messages. The incoming HTTP POST and GET messages fire the doPost and doGet methods respectively.

 

The doPost method is fired when an http post is submitted to the Servlet. doPost() reads the post request and deposits the message to the destination queue specified.

 

The following line of code Gets the actual message text from the client (ie from the ActiveMQ examples the .net forms, a hyperlink etc)

 

String text = getPostedMessageBody(request);

 

This code sends the message text to the ActiveMQ queue:

 

Destination destination = getDestination(client, request);

 

log.info("Sending message to: " + ActiveMQDestination.inspect(destination) + " with text: " + text);

 

            TextMessage message = client.getSession().createTextMessage(text);

            appendParametersToMessage(request, message);

            client.send(destination, message);

 

 

doGet() reads the get request, retrieves a message from the specified queue and responds to the client with this message. The following code inside of the doGet() method reads from the queue:

 

 synchronized (consumer) {

                if (timeout == 0) {

                    message = consumer.receiveNoWait();

                }

                else {

                    message = consumer.receive(timeout);

                }

 }

  

The doGet method then calls sendMessageResponse to send the message retrieved from the queue to the client.