Example usage for javax.jms TextMessage getStringProperty

List of usage examples for javax.jms TextMessage getStringProperty

Introduction

In this page you can find the example usage for javax.jms TextMessage getStringProperty.

Prototype


String getStringProperty(String name) throws JMSException;

Source Link

Document

Returns the value of the String property with the specified name.

Usage

From source file:eu.learnpad.simulator.mon.manager.GlimpseManager.java

public void onMessage(Message messagePayload) {

    TextMessage msg = null;
    try {/*from ww w . j a  v  a 2 s .c o  m*/
        msg = (TextMessage) messagePayload;
        DebugMessages.line();
        DebugMessages.println(TimeStamp.getCurrentTime(), this.getClass().getSimpleName(),
                "receive " + msg.getText());
        DebugMessages.line();
        String xmlMessagePayload = msg.getText();
        String sender = msg.getStringProperty("SENDER");
        ComplexEventRuleActionListDocument ruleDoc;

        // check if the paylod of the message is a bpmn to be used for path
        // extraction and rules generation
        // or if the xml is already a rule to inject into the engine
        if (xmlMessagePayload.contains("http://www.omg.org/spec/BPMN/20100524/MODEL")) {
            DebugMessages.println(TimeStamp.getCurrentTime(), this.getClass().getSimpleName(),
                    "The message sent seems to contain a BPMN - Forwarding it to the LearnPAd Assessment Manager");

            @SuppressWarnings("unchecked")
            List<String> learnersIDs = (List<String>) msg.getObjectProperty("USERSINVOLVEDID");
            String bpmnID = msg.getObjectProperty("BPMNID").toString();
            String sessionID = msg.getObjectProperty("SESSIONID").toString();

            Vector<Learner> learnersInvolved = learnerAssessmentManager.getDBController()
                    .getOrSetLearners(learnersIDs);

            DebugMessages.print(TimeStamp.getCurrentTime(), this.getClass().getSimpleName(),
                    "Creating Session Score Buffer");
            sessionScoreBuffer = new ScoreTemporaryStorage(learnersInvolved, sessionID);
            if (sessionScoreBuffer != null)
                DebugMessages.ok();

            ruleDoc = learnerAssessmentManager.elaborateModel(xmlMessagePayload, learnersInvolved, sessionID,
                    bpmnID);

        } else {
            ruleDoc = ComplexEventRuleActionListDocument.Factory.parse(xmlMessagePayload);
        }
        ComplexEventRuleActionType rules = ruleDoc.getComplexEventRuleActionList();

        // the topic where the listener will give analysis results
        answerTopic = "answerTopic" + "#" + this.getName() + "#" + System.nanoTime();

        DebugMessages.print(TimeStamp.getCurrentTime(), this.getClass().getSimpleName(), "Create answerTopic");
        connectionTopic = publishSession.createTopic(answerTopic);
        // tPub = publishSession.createPublisher(connectionTopic);
        DebugMessages.ok();

        DebugMessages.println(TimeStamp.getCurrentTime(), this.getClass().getSimpleName(),
                "Setting up ComplexEventProcessor with new rule.");
        try {
            Object[] loadedKnowledgePackage = rulesManagerOne.loadRules(rules);

            //Object[] loadedKnowledgePackage = rulesManagerOne.vandaLoadRules(rules);

            // inserisco la coppia chiave valore dove la chiave  il KnowledgePackage
            // caricato, generato da DroolsRulesManager con la loadRules
            // e il valore  l'enabler che l'ha inviata
            // (il KnowledgePackage array dovrebbe avere sempre dimensione 1
            // essendo creato ad ogni loadrules)
            for (int i = 0; i < loadedKnowledgePackage.length; i++) {
                KnowledgePackageImp singleKnowlPack = (KnowledgePackageImp) loadedKnowledgePackage[i];
                Rule[] singleRuleContainer = new Rule[singleKnowlPack.getRules().size()];
                singleRuleContainer = singleKnowlPack.getRules().toArray(singleRuleContainer);

                for (int j = 0; j < singleRuleContainer.length; j++) {
                    requestMap.put(singleRuleContainer[j].getName(), new ConsumerProfile(sender, answerTopic));
                }
            }
            DebugMessages.println(TimeStamp.getCurrentTime(), this.getClass().getSimpleName(),
                    "KnowledgeBase packages loaded: " + rulesManagerOne.getLoadedKnowledgePackageCardinality());
            DebugMessages.print(TimeStamp.getCurrentTime(), this.getClass().getSimpleName(),
                    "Communicate the answerTopic to the requester");
            sendMessage(createMessage("AnswerTopic == " + answerTopic, sender));
            DebugMessages.ok();
        } catch (IncorrectRuleFormatException e) {
            sendMessage(createMessage("PROVIDED RULE CONTAINS ERRORS", sender));
        }

    } catch (NullPointerException asd) {
        try {
            sendMessage(createMessage("PROVIDED RULE IS NULL, PLEASE PROVIDE A VALID RULE",
                    msg.getStringProperty("SENDER")));
        } catch (JMSException e) {
            e.printStackTrace();
        }
    } catch (XmlException e) {
        try {
            sendMessage(createMessage("PROVIDED XML CONTAINS ERRORS", msg.getStringProperty("SENDER")));
        } catch (JMSException e1) {
            e1.printStackTrace();
        }
    } catch (JMSException ee) {
        ee.printStackTrace();
    }
    DebugMessages.line();
}

From source file:org.apache.stratos.cloud.controller.topic.instance.status.InstanceStatusEventMessageDelegator.java

@Override
public void run() {
    log.info("Instance status event message delegator started");

    while (true) {
        try {//from   ww  w. j a va  2 s . c om
            TextMessage message = InstanceStatusEventMessageQueue.getInstance().take();

            // retrieve the header
            String type = message.getStringProperty(Constants.EVENT_CLASS_NAME);
            log.info(String.format("Instance status event message received from queue: %s", type));

            if (InstanceStartedEvent.class.getName().equals(type)) {
                // retrieve the actual message
                String json = message.getText();
                TopologyBuilder.handleMemberStarted(
                        (InstanceStartedEvent) Util.jsonToObject(json, InstanceStartedEvent.class));
            } else if (InstanceActivatedEvent.class.getName().equals(type)) {
                // retrieve the actual message
                String json = message.getText();
                TopologyBuilder.handleMemberActivated(
                        (InstanceActivatedEvent) Util.jsonToObject(json, InstanceActivatedEvent.class));
            } else if (InstanceReadyToShutdownEvent.class.getName().equals(type)) {
                //retrieve the actual message
                String json = message.getText();
                TopologyBuilder.handleMemberReadyToShutdown((InstanceReadyToShutdownEvent) Util
                        .jsonToObject(json, InstanceReadyToShutdownEvent.class));
            } else if (InstanceMaintenanceModeEvent.class.getName().equals(type)) {
                //retrieve the actual message
                String json = message.getText();
                TopologyBuilder.handleMemberMaintenance((InstanceMaintenanceModeEvent) Util.jsonToObject(json,
                        InstanceMaintenanceModeEvent.class));
            } else {
                log.warn("Event message received is not InstanceStartedEvent or InstanceActivatedEvent");
            }
        } catch (Exception e) {
            String error = "Failed to retrieve the instance status event message";
            log.error(error, e);
            // Commenting throwing the error. Otherwise thread will not execute if an exception is thrown.
            //throw new RuntimeException(error, e);
        }
    }
}

From source file:org.apache.stratos.messaging.message.receiver.instance.notifier.InstanceNotifierEventMessageDelegator.java

@Override
public void run() {
    try {// w  ww .  j a  va 2s.co m
        if (log.isInfoEnabled()) {
            log.info("Instance notifier event message delegator started");
        }

        while (!terminated) {
            try {
                TextMessage message = messageQueue.take();

                // Retrieve the header
                String type = message.getStringProperty(Constants.EVENT_CLASS_NAME);

                // Retrieve the actual message
                String json = message.getText();
                if (log.isDebugEnabled()) {
                    log.debug(String.format("Instance notifier event message received from queue: %s", type));
                }

                // Delegate message to message processor chain
                if (log.isDebugEnabled()) {
                    log.debug(String.format("Delegating instance notifier event message: %s", type));
                }
                processorChain.process(type, json, null);
            } catch (Exception e) {
                log.error("Failed to retrieve instance notifier event message", e);
            }
        }
    } catch (Exception e) {
        if (log.isErrorEnabled()) {
            log.error("Instance notifier event message delegator failed", e);
        }
    }
}

From source file:org.apache.stratos.messaging.message.receiver.tenant.TenantEventMessageDelegator.java

@Override
public void run() {
    try {/*ww  w. jav a 2s. com*/
        if (log.isInfoEnabled()) {
            log.info("Tenant event message delegator started");
        }

        while (!terminated) {
            try {
                TextMessage message = messageQueue.take();

                // Retrieve the header
                String type = message.getStringProperty(Constants.EVENT_CLASS_NAME);

                // Retrieve the actual message
                String json = message.getText();
                if (log.isDebugEnabled()) {
                    log.debug(String.format("Tenant event message received from queue: %s", type));
                }

                // Delegate message to message processor chain
                if (log.isDebugEnabled()) {
                    log.debug(String.format("Delegating tenant event message: %s", type));
                }
                processorChain.process(type, json, null);
            } catch (Exception e) {
                log.error("Failed to retrieve tenant event message", e);
            }
        }
    } catch (Exception e) {
        if (log.isErrorEnabled()) {
            log.error("Tenant event message delegator failed", e);
        }
    }
}

From source file:org.apache.stratos.messaging.message.receiver.topology.TopologyEventMessageDelegator.java

@Override
public void run() {
    try {/*w ww.j a  va 2s. co  m*/
        if (log.isInfoEnabled()) {
            log.info("Topology event message delegator started");
        }

        while (!terminated) {
            try {
                TextMessage message = messageQueue.take();

                // Retrieve the header
                String type = message.getStringProperty(Constants.EVENT_CLASS_NAME);

                // Retrieve the actual message
                String json = message.getText();

                if (log.isDebugEnabled()) {
                    log.debug(String.format("Topology event message [%s] received from queue: %s", type,
                            messageQueue.getClass()));
                }

                try {
                    TopologyManager.acquireWriteLock();
                    if (log.isDebugEnabled()) {
                        log.debug(String.format("Delegating topology event message: %s", type));
                    }
                    processorChain.process(type, json, TopologyManager.getTopology());
                } finally {
                    TopologyManager.releaseWriteLock();
                }

            } catch (Exception e) {
                log.error("Failed to retrieve topology event message", e);
            }
        }
    } catch (Exception e) {
        if (log.isErrorEnabled()) {
            log.error("Topology event message delegator failed", e);
        }
    }
}

From source file:org.codehaus.stomp.StompTest.java

public void testSendMessageWithCustomHeadersAndSelector() throws Exception {

    MessageConsumer consumer = session.createConsumer(queue, "foo = 'abc'");

    String frame = "CONNECT\n" + "login: brianm\n" + "passcode: wombats\n\n" + Stomp.NULL;
    sendFrame(frame);/*from   w w  w .  j  a va 2s .co  m*/

    frame = receiveFrame(10000);
    Assert.assertTrue(frame.startsWith("CONNECTED"));

    frame = "SEND\n" + "foo:abc\n" + "bar:123\n" + "destination:/queue/" + getQueueName() + "\n\n"
            + "Hello World" + Stomp.NULL;

    sendFrame(frame);

    TextMessage message = (TextMessage) consumer.receive(1000);
    Assert.assertNotNull(message);
    Assert.assertEquals("Hello World", message.getText());
    Assert.assertEquals("foo", "abc", message.getStringProperty("foo"));
    Assert.assertEquals("bar", "123", message.getStringProperty("bar"));
}

From source file:org.codehaus.stomp.StompTest.java

public void testSendMessageWithStandardHeaders() throws Exception {

    MessageConsumer consumer = session.createConsumer(queue);

    String frame = "CONNECT\n" + "login: brianm\n" + "passcode: wombats\n\n" + Stomp.NULL;
    sendFrame(frame);//from   w  w w.j a v  a2  s .c  om

    frame = receiveFrame(10000);
    Assert.assertTrue(frame.startsWith("CONNECTED"));

    frame = "SEND\n" + "correlation-id:c123\n" + "priority:3\n" + "type:t345\n" + "JMSXGroupID:abc\n"
            + "foo:abc\n" + "bar:123\n" + "destination:/queue/" + getQueueName() + "\n\n" + "Hello World"
            + Stomp.NULL;

    sendFrame(frame);

    TextMessage message = (TextMessage) consumer.receive(1000);
    Assert.assertNotNull(message);
    Assert.assertEquals("Hello World", message.getText());
    Assert.assertEquals("JMSCorrelationID", "c123", message.getJMSCorrelationID());
    Assert.assertEquals("getJMSType", "t345", message.getJMSType());
    Assert.assertEquals("getJMSPriority", 3, message.getJMSPriority());
    Assert.assertEquals(DeliveryMode.PERSISTENT, message.getJMSDeliveryMode());
    Assert.assertEquals("foo", "abc", message.getStringProperty("foo"));
    Assert.assertEquals("bar", "123", message.getStringProperty("bar"));

    Assert.assertEquals("JMSXGroupID", "abc", message.getStringProperty("JMSXGroupID"));
    ActiveMQTextMessage amqMessage = (ActiveMQTextMessage) message;
    Assert.assertEquals("GroupID", "abc", amqMessage.getGroupID());
}

From source file:org.openanzo.combus.CombusConnection.java

/**
 * Send a request to a destination and wait for a response
 * //from  www  .j av a 2  s. c  o m
 * @param context
 *            context for this operational call
 * @param destinationName
 *            destination queue for this request
 * @param request
 *            request message
 * @param timeout
 *            timeout for waiting for a response
 * @return response message
 * @throws AnzoException
 *             if there was an exception sending request, or a timeout waiting for a response
 */
public TextMessage requestResponse(IOperationContext context, String destinationName, Message request,
        long timeout) throws AnzoException {
    Destination destination = null;

    if (context.getAttribute(OPTIONS.DATASOURCE) != null) {
        URI datasourceUri = (URI) context.getAttribute(OPTIONS.DATASOURCE);
        Queue defaultDestination = (Queue) destinations.get(destinationName);
        if (datasourceUri.toString().equals("http://openanzo.org/datasource/systemDatasource")) {
            destination = defaultDestination;
        } else {
            String queueNamePrefix = UriGenerator.generateEncapsulatedString("", datasourceUri.toString())
                    + "/";
            try {
                String[] parts = StringUtils.split(defaultDestination.getQueueName(), '/');
                String queue = "services/" + queueNamePrefix + parts[1];
                destination = destinations.get(queue);
                if (destination == null) {
                    destination = session.createQueue(queue);
                    destinations.put(queue, destination);
                }
            } catch (JMSException e) {
                throw new AnzoException(ExceptionConstants.COMBUS.NO_SUCH_DESTINATION, destinationName);
            }
        }
    } else {
        destination = destinations.get(destinationName);
        if (destination == null) {
            throw new AnzoException(ExceptionConstants.COMBUS.NO_SUCH_DESTINATION, destinationName);
        }
    }

    if (context.getAttribute(COMBUS.TIMEOUT) != null) {
        timeout = (Long) context.getAttribute(COMBUS.TIMEOUT);
    }

    String correlationId = context.getOperationId();
    if (correlationId == null) {
        correlationId = UUID.randomUUID().toString();
    }

    try {
        request.setJMSCorrelationID(correlationId);
        request.setJMSReplyTo(tempQueue);
        request.setIntProperty(SerializationConstants.protocolVersion, Constants.VERSION);
        if (context.getOperationPrincipal() != null
                && !context.getOperationPrincipal().getName().equals(this.userName)) {
            request.setStringProperty(SerializationConstants.runAsUser,
                    context.getOperationPrincipal().getName());
        }
        if (context.getAttribute(OPTIONS.PRIORITY) != null) {
            Integer priority = (Integer) context.getAttribute(OPTIONS.PRIORITY);
            request.setJMSPriority(priority);
            messageProducer.setPriority(priority);
        } else {
            messageProducer.setPriority(4);
        }
        if (context.getAttribute(OPTIONS.SKIPCACHE) != null) {
            request.setBooleanProperty(OPTIONS.SKIPCACHE,
                    context.getAttribute(OPTIONS.SKIPCACHE, Boolean.class));
        }
        if (log.isTraceEnabled()) {
            log.trace(LogUtils.COMBUS_MARKER,
                    MessageUtils.prettyPrint(request, "Sending Request: (destination=" + destination + ")"));
        }
        messageProducer.send(destination, request);
    } catch (JMSException jmsex) {
        performDisconnect(true);
        throw new AnzoException(ExceptionConstants.COMBUS.COULD_NOT_PUBLISH, jmsex);
    }
    lock.lock();
    try {
        Collection<TextMessage> messageSet = correlationIdToMessage.remove(correlationId);
        long start = System.currentTimeMillis();
        while (messageSet == null) {
            if (timeout <= 0) {
                try {
                    newMessage.await(2, TimeUnit.SECONDS);
                } catch (InterruptedException ie) {
                    throw new AnzoException(ExceptionConstants.COMBUS.INTERRUPTED, correlationId);
                }
                if (closed || closing) {
                    throw new AnzoException(ExceptionConstants.COMBUS.INTERRUPTED, correlationId);
                }
                messageSet = correlationIdToMessage.remove(correlationId);
            } else {
                try {
                    newMessage.await(timeout, TimeUnit.MILLISECONDS);
                } catch (InterruptedException ie) {
                    throw new AnzoException(ExceptionConstants.COMBUS.INTERRUPTED, correlationId);
                }
                if (closed || closing) {
                    throw new AnzoException(ExceptionConstants.COMBUS.INTERRUPTED, correlationId);
                }
                messageSet = correlationIdToMessage.remove(correlationId);
                if (!connected) {
                    log.error(LogUtils.COMBUS_MARKER, "Request Response failed because connection was closed");
                    throw new AnzoException(ExceptionConstants.COMBUS.JMS_NOT_CONNECTED, correlationId);
                }
                if (messageSet == null && ((timeout > 0) && ((System.currentTimeMillis() - start) > timeout))) {
                    throw new AnzoException(ExceptionConstants.COMBUS.NO_SERVER_RESPONSE, correlationId);
                }
            }
        }
        try {
            TextMessage message = messageSet.iterator().next();
            if (log.isTraceEnabled()) {
                log.trace(LogUtils.COMBUS_MARKER, MessageUtils.prettyPrint(message, "Received Response:"));
            }

            if (message.getBooleanProperty(SerializationConstants.operationFailed)) {
                long errorCodes = message.propertyExists(SerializationConstants.errorTags)
                        ? message.getLongProperty(SerializationConstants.errorCode)
                        : ExceptionConstants.COMBUS.JMS_SERVICE_EXCEPTION;

                // if available, use enumerated args, since these can be reconstruct an AnzoException correctly.
                List<String> args = new ArrayList<String>();
                for (int i = 0; true; i++) {
                    String errorArg = message.getStringProperty(SerializationConstants.errorMessageArg + i);
                    if (errorArg == null) {
                        break;
                    }
                    args.add(errorArg);
                }

                // NOTE: This doesn't really make any sense, but it was here before and it's better to be too verbose than not verbose enough
                // when it comes to error messages, so it stays.  For now at least. -jpbetz
                if (args.isEmpty()) {
                    args.add(message.getText());
                }
                throw new AnzoException(errorCodes, args.toArray(new String[0]));
            }
            /*Object prp = context.getAttribute("populateResponseProperties");
            if (prp != null && ((Boolean) prp)) {
            HashMap<String, Object> props = new HashMap<String, Object>();
            Enumeration<String> keys = message.getPropertyNames();
            while (keys.hasMoreElements()) {
                String key = keys.nextElement();
                props.put(key, message.getObjectProperty(key));
            }
            context.setAttribute("responseProperties", props);
            }*/
            return message;
        } catch (JMSException jmsex) {
            log.debug(LogUtils.COMBUS_MARKER, Messages.formatString(
                    ExceptionConstants.COMBUS.ERROR_PROCESSING_MESSGE, "request response"), jmsex);
        }
        return null;
    } finally {
        lock.unlock();
    }
}

From source file:org.openanzo.combus.CombusConnection.java

/**
 * Send a request to a destination and wait for a response
 * //w w  w. ja  v a 2s.co m
 * @param context
 *            context for this operational call
 * @param destinationName
 *            destination queue for this request
 * @param request
 *            request message
 * @param timeout
 *            timeout for waiting for a response
 * @param messageHandler
 *            the handler of multiple messages
 * @throws AnzoException
 *             if there was an exception sending request, or a timeout waiting for a response
 */
public void requestMultipleResponse(IOperationContext context, String destinationName, Message request,
        long timeout, IMessageHandler messageHandler) throws AnzoException {
    Destination destination = null;
    if (context.getAttribute(OPTIONS.DATASOURCE) != null) {
        URI datasourceUri = (URI) context.getAttribute(OPTIONS.DATASOURCE);
        Queue defaultDestination = (Queue) destinations.get(destinationName);
        if (datasourceUri.toString().equals("http://openanzo.org/datasource/systemDatasource")) {
            destination = defaultDestination;
        } else {
            String queueNamePrefix = UriGenerator.generateEncapsulatedString("", datasourceUri.toString())
                    + "/";
            try {
                String[] parts = StringUtils.split(defaultDestination.getQueueName(), '/');
                String queue = "services/" + queueNamePrefix + parts[1];
                destination = destinations.get(queue);
                if (destination == null) {
                    destination = session.createQueue(queue);
                    destinations.put(queue, destination);
                }
            } catch (JMSException e) {
                throw new AnzoException(ExceptionConstants.COMBUS.NO_SUCH_DESTINATION, destinationName);
            }
        }
    } else {
        destination = destinations.get(destinationName);
        if (destination == null) {
            throw new AnzoException(ExceptionConstants.COMBUS.NO_SUCH_DESTINATION, destinationName);
        }
    }
    String correlationId = context.getOperationId();
    if (correlationId == null) {
        correlationId = UUID.randomUUID().toString();
    }

    try {
        request.setJMSCorrelationID(correlationId);
        request.setJMSReplyTo(tempQueue);
        request.setIntProperty(SerializationConstants.protocolVersion, Constants.VERSION);
        if (context.getOperationPrincipal() != null
                && !context.getOperationPrincipal().getName().equals(this.userName)) {
            request.setStringProperty(SerializationConstants.runAsUser,
                    context.getOperationPrincipal().getName());
        }
        if (context.getAttribute(OPTIONS.PRIORITY) != null) {
            Integer priority = (Integer) context.getAttribute(OPTIONS.PRIORITY);
            request.setJMSPriority(priority);
            messageProducer.setPriority(priority);
        } else {
            messageProducer.setPriority(4);
        }
        if (context.getAttribute(OPTIONS.SKIPCACHE) != null) {
            request.setBooleanProperty(OPTIONS.SKIPCACHE,
                    context.getAttribute(OPTIONS.SKIPCACHE, Boolean.class));
        }
        if (context.getAttribute(OPTIONS.INCLUDEMETADATAGRAPHS) != null) {
            request.setBooleanProperty(OPTIONS.INCLUDEMETADATAGRAPHS,
                    context.getAttribute(OPTIONS.INCLUDEMETADATAGRAPHS, Boolean.class));
        }
        if (log.isTraceEnabled()) {
            log.trace(LogUtils.COMBUS_MARKER,
                    MessageUtils.prettyPrint(request, "Sending Request: (destination=" + destination + ")"));
        }
        messageProducer.send(destination, request);
    } catch (JMSException jmsex) {
        performDisconnect(true);
        throw new AnzoException(ExceptionConstants.COMBUS.COULD_NOT_PUBLISH, jmsex);
    }
    lock.lock();
    try {
        long start = System.currentTimeMillis();
        boolean done = false;
        int seq = 0;
        while (!done) {
            Collection<TextMessage> messageSet = correlationIdToMessage.remove(correlationId);
            while (messageSet == null) {
                if (timeout <= 0) {
                    try {
                        newMessage.await(2, TimeUnit.SECONDS);
                    } catch (InterruptedException ie) {
                        throw new AnzoException(ExceptionConstants.COMBUS.INTERRUPTED, correlationId);
                    }
                    if (closed || closing) {
                        throw new AnzoException(ExceptionConstants.COMBUS.INTERRUPTED, correlationId);
                    }
                    messageSet = correlationIdToMessage.remove(correlationId);
                } else {
                    try {
                        newMessage.await(timeout, TimeUnit.MILLISECONDS);
                    } catch (InterruptedException ie) {
                        throw new AnzoException(ExceptionConstants.COMBUS.INTERRUPTED, correlationId);
                    }
                    if (closed || closing) {
                        throw new AnzoException(ExceptionConstants.COMBUS.INTERRUPTED, correlationId);
                    }
                    messageSet = correlationIdToMessage.remove(correlationId);
                    if (!connected) {
                        log.error(LogUtils.COMBUS_MARKER, Messages.formatString(
                                ExceptionConstants.COMBUS.ERROR_PROCESSING_MESSGE, "connection closed"));
                        throw new AnzoException(ExceptionConstants.COMBUS.JMS_NOT_CONNECTED, correlationId);
                    }
                    if (messageSet == null
                            && ((timeout > -1) && ((System.currentTimeMillis() - start) > timeout))) {
                        throw new AnzoException(ExceptionConstants.COMBUS.NO_SERVER_RESPONSE, correlationId);
                    }
                }

            }
            try {
                for (TextMessage message : messageSet) {
                    if (log.isTraceEnabled()) {
                        log.trace(LogUtils.COMBUS_MARKER,
                                MessageUtils.prettyPrint(message, "Recieved Response:"));
                    }
                    if (message.propertyExists("done")) {
                        done = message.getBooleanProperty("done");
                    } else {
                        done = true;
                    }
                    if (message.propertyExists("sequence")) {
                        int sequence = message.getIntProperty("sequence");
                        if (sequence != seq) {
                            throw new AnzoException(ExceptionConstants.COMBUS.NO_SERVER_RESPONSE,
                                    correlationId);
                        } else {
                            seq++;
                        }
                    }

                    int totalSize = 0;
                    if (message.propertyExists(SerializationConstants.totalSolutions)) {
                        totalSize = message.getIntProperty(SerializationConstants.totalSolutions);
                    }
                    if (message.getBooleanProperty(SerializationConstants.operationFailed)) {
                        long errorCodes = message.propertyExists(SerializationConstants.errorTags)
                                ? message.getLongProperty(SerializationConstants.errorCode)
                                : ExceptionConstants.COMBUS.JMS_SERVICE_EXCEPTION;

                        // if available, use enumerated args, since these can be reconstruct an AnzoException correctly.
                        List<String> args = new ArrayList<String>();
                        for (int i = 0; true; i++) {
                            String errorArg = message
                                    .getStringProperty(SerializationConstants.errorMessageArg + i);
                            if (errorArg == null) {
                                break;
                            }
                            args.add(errorArg);
                        }

                        // NOTE: This doesn't really make any sense, but it was here before and it's better to be too verbose than not verbose enough
                        // when it comes to error messages, so it stays.  For now at least. -jpbetz
                        if (args.isEmpty()) {
                            args.add(message.getText());
                        }
                        throw new AnzoException(errorCodes, args.toArray(new String[0]));
                    } else {
                        messageHandler.handleMessage(message, seq, done, totalSize);
                    }
                }
            } catch (JMSException jmsex) {
                log.debug(LogUtils.COMBUS_MARKER, Messages.formatString(
                        ExceptionConstants.COMBUS.ERROR_PROCESSING_MESSGE, "request multiple response"), jmsex);
            }
        }
    } finally {
        lock.unlock();
    }
}

From source file:org.openanzo.combus.realtime.RealtimeUpdatePublisher.java

/**
 * Handler an update message from the model service
 * /*from  ww w .  j a va 2s.  c  o  m*/
 * @param context
 *            context of operation
 * @param session
 *            JMS session message came in over
 * @param message
 *            JMS Message containing update message stream
 * @throws AnzoException
 */
public void handleTransactionMessage(IOperationContext context, Session session, TextMessage message)
        throws AnzoException {
    try {
        // Get the XML data from the message and parse it with the updates parser
        String results = message.getText();
        String version = message.getStringProperty(SerializationConstants.version);
        if (version != null && currentServerId != null) {
            if (!version.equals(currentServerId)) {
                return;
            }
        }
        if (trackers.size() == 0)
            return;
        NotificationUpdateHandler handler = new NotificationUpdateHandler(session, version);
        synchronized (userDestinations) {
            JSONUpdatesReader.parseUpdateTransactions(results, handler);
        }
    } catch (JMSException jmsex) {
        log.error(LogUtils.COMBUS_MARKER, "Error handling transaction message", jmsex);
    }
}