MessageServer (pattern 2.b)

This Java thread shows how you can access the contents of the named queue by running specific operations in a query. In general, you use the Java Driver API to access the names queues in its own thread.

MessageServer starts it own independent Java application. This is a Tomcat web server as in RequestServer, that listens on http traffic from an external client such as a web browser.

In this sample code from MessageServer.java, processRequest():

  • Collects the browser user input regarding what type of operation is to be performed against what named queue, and so on.
  • Builds up a QueueQuery object with the user input.
  • Calls the executeQueueQuery() static method to run the operation on the queue.
  • Formats the response from the query and sends it back to the browser.
package com.infor.cloverleaf.javadriver.samples.messageserver;
...
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        // if we can't process the request, just toss out an exception
        // first, create a query from the request
        String indexString = request.getParameter("MSG_INDEX");
        Integer index = indexString.equals("") ? null : Integer.parseInt(indexString);
        QueueQuery query = new QueueQuery(request.getParameter("MSG_KEY"), request.getParameter("MSG_SUB_KEY"), request.getParameter("MSG_NAME"), index, QueueQuery.OperationEnum.valueOf(request.getParameter("MSG_OPERATION")));
        List<QueueQueryMessage> queryResponse;
        try {
            queryResponse = ToCloverleafLink.executeQueueQuery(query);
        } catch (Exception ex) {
            throw new ServletException(ex);
        }
        response.setContentType("text/html;charset=UTF-8");
        ...
    }
    public static String formatQueryResponse(QueueQuery queueQuery, List<QueueQueryMessage> response){
        String retS;
        retS = "+++++ Request Parameters  +++++<br/>";
        retS = retS + "    Request Key: " +
                printString(queueQuery.getKey()) +
                "    Request SubKey: " +
                printString(queueQuery.getSubKey()) +
                "    Request Name: " +
                printString(queueQuery.getName()) +
                "    Request Index: " +
                printString("" + queueQuery.getIndex()) +
                  "    Request Operation: " +
                printString(queueQuery.getOperation().name()) + "<br/>";
        // Process the return list of items that match request
        if (response.isEmpty()) {
            return retS + "<br/>Request returned zero length ArrayList.<br/>";
        }
        String itemS = (response.size() == 1) ? " item" : " items";
        retS = retS + "+++++ Request returned " + response.size() + itemS + ". +++++<br/>";
        for (QueueQueryMessage message : response){
            retS = retS + "  Message<br/>" +
                "    Message Key: " + printString(message.getKey()) +
                "    Message SubKey: " + printString(message.getSubKey()) +
                "    Message Name: " + printString(message.getName()) +
                "    Message Time: " + printString(message.getTime()) +
                "    Message Index: " + printString("" + message.getIndex()) +
                "    Message Length: " + printString("" + message.getLength()) +
                "    Message User Data: " + printString(message.getUserData()) +
                "    Message Driver Control: " + printString(message.getDriverControl()) +
                "    Message Type: " + printString(message.getType().name()) +
                "    Message: " + printString(message.getMessage()) +
                "<br/>";
        }  // End loop over input array list
        return retS;
    }
…