Example usage for javax.jms TextMessage getObjectProperty

List of usage examples for javax.jms TextMessage getObjectProperty

Introduction

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

Prototype


Object getObjectProperty(String name) throws JMSException;

Source Link

Document

Returns the value of the Java object 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 {//  w  w  w  .  ja v a2s.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.mule.transport.jms.JmsMuleMessageFactoryTestCase.java

@Override
protected Object getValidTransportMessage() throws Exception {
    TextMessage textMessage = mock(TextMessage.class);
    when(textMessage.getText()).thenReturn(MESSAGE_TEXT);
    when(textMessage.getJMSCorrelationID()).thenReturn(null);
    when(textMessage.getJMSDeliveryMode()).thenReturn(Integer.valueOf(1));
    when(textMessage.getJMSDestination()).thenReturn(null);
    when(textMessage.getJMSExpiration()).thenReturn(Long.valueOf(0));
    when(textMessage.getJMSMessageID()).thenReturn("1234567890");
    when(textMessage.getJMSPriority()).thenReturn(Integer.valueOf(4));
    when(textMessage.getJMSRedelivered()).thenReturn(Boolean.FALSE);
    when(textMessage.getJMSReplyTo()).thenReturn(null);
    when(textMessage.getJMSTimestamp()).thenReturn(Long.valueOf(0));
    when(textMessage.getJMSType()).thenReturn(null);
    when(textMessage.getPropertyNames())
            .thenReturn(IteratorUtils.asEnumeration(IteratorUtils.arrayIterator(new Object[] { "foo" })));
    when(textMessage.getObjectProperty("foo")).thenReturn("bar");
    return textMessage;
}