Package org.apache.synapse

Examples of org.apache.synapse.MessageContext


     * @return MessageContext the cloned message context
     */
    private MessageContext getClonedMessageContext(MessageContext synCtx, int messageSequence,
        int messageCount) {

        MessageContext newCtx = null;
        try {
            newCtx = MessageHelper.cloneMessageContext(synCtx);

            // set the property MESSAGE_SEQUENCE to the MC for aggregation purposes
            newCtx.setProperty(EIPConstants.MESSAGE_SEQUENCE,
                String.valueOf(messageSequence) + EIPConstants.MESSAGE_SEQUENCE_DELEMITER +
                messageCount);           
        } catch (AxisFault axisFault) {
            handleException("Error cloning the message context", axisFault, synCtx);
        }
View Full Code Here


        if (!markedCompletedNow) {
            return;
        }
       
        MessageContext newSynCtx = getAggregatedMessage(aggregate);
        if (newSynCtx == null) {
            log.warn("An aggregation of messages timed out with no aggregated messages", null);
            return;
        }

        activeAggregates.remove(aggregate.getCorrelation());

        if ((correlateExpression != null &&
            !correlateExpression.toString().equals(aggregate.getCorrelation())) ||
            correlateExpression == null) {

            if (onCompleteSequence != null) {
                onCompleteSequence.mediate(newSynCtx);

            } else if (onCompleteSequenceRef != null
                && newSynCtx.getSequence(onCompleteSequenceRef) != null) {
                newSynCtx.getSequence(onCompleteSequenceRef).mediate(newSynCtx);

            } else {
                handleException("Unable to find the sequence for the mediation " +
                    "of the aggregated message", newSynCtx);
            }
View Full Code Here

     * aggregation
     * @return the aggregated message context
     */
    private MessageContext getAggregatedMessage(Aggregate aggregate) {

        MessageContext newCtx = null;

        for (MessageContext synCtx : aggregate.getMessages()) {
           
            if (newCtx == null) {
                newCtx = synCtx;

                if (log.isDebugEnabled()) {
                    log.debug("Generating Aggregated message from : " + newCtx.getEnvelope());
                }

            } else {
                try {
                    if (log.isDebugEnabled()) {
                        log.debug("Merging message : " + synCtx.getEnvelope() + " using XPath : " +
                                aggregationExpression);
                    }

                    EIPUtils.enrichEnvelope(
                            newCtx.getEnvelope(), synCtx.getEnvelope(), aggregationExpression);

                    if (log.isDebugEnabled()) {
                        log.debug("Merged result : " + newCtx.getEnvelope());
                    }

                } catch (JaxenException e) {
                    handleException("Error merging aggregation results using XPath : " +
                            aggregationExpression.toString(), e, synCtx);
View Full Code Here

            // if any messages have been collected, check if the completion criteria is met
            if (!messages.isEmpty()) {

                // get total messages for this group, from the first message we have collected
                MessageContext mc = messages.get(0);
                Object prop = mc.getProperty(EIPConstants.MESSAGE_SEQUENCE);
           
                if (prop != null && prop instanceof String) {
                    String[] msgSequence = prop.toString().split(
                            EIPConstants.MESSAGE_SEQUENCE_DELEMITER);
                    int total = Integer.parseInt(msgSequence[1]);
View Full Code Here

         // set a local property to the synapse context
        PropertyMediator propMediatorTwo = new PropertyMediator();
        propMediatorTwo.setName("nameTwo");
        propMediatorTwo.setValue("valueTwo");

        MessageContext synCtx = TestUtils.getTestContext("<empty/>");
        propMediator.mediate(synCtx);
        propMediatorTwo.mediate(synCtx);
        assertTrue(
            "value".equals((new SynapseXPath(
                "synapse:get-property('name')")).stringValueOf(synCtx)));
View Full Code Here

        PropertyMediator propMediatorSeven = new PropertyMediator();
        propMediatorSeven.setName("nameSeven");
        propMediatorSeven.setValue("123.456", XMLConfigConstants.DATA_TYPES.FLOAT.name());

        MessageContext synCtx = TestUtils.createLightweightSynapseMessageContext("<empty/>");
        propMediatorOne.mediate(synCtx);
        propMediatorTwo.mediate(synCtx);
        propMediatorThree.mediate(synCtx);
        propMediatorFour.mediate(synCtx);
        propMediatorFive.mediate(synCtx);
        propMediatorSix.mediate(synCtx);
        propMediatorSeven.mediate(synCtx);

        org.apache.axis2.context.MessageContext axisCtx = ((Axis2MessageContext) synCtx).getAxis2MessageContext();
        Map transportHeaders = (Map) axisCtx.getProperty(
                org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS);

        Object valueOne = synCtx.getProperty("nameOne");
        Object valueTwo = axisCtx.getProperty("nameTwo");
        Object valueThree = transportHeaders.get("nameThree");
        Object valueFour = synCtx.getProperty("nameFour");
        Object valueFive = axisCtx.getProperty("nameFive");
        Object valueSix = transportHeaders.get("nameSix");
        Object valueSeven = synCtx.getProperty("nameSeven");

        assertEquals("valueOne", valueOne);
        assertEquals(new Integer(25000), valueTwo);
        assertEquals(new Double(123.456), valueThree);
        assertEquals(Boolean.TRUE, valueFour);
View Full Code Here

        String xml = "<Project><name>Synapse</name></Project>";
        OMElement valueOne = TestUtils.createOMElement(xml);
        propMediatorOne.setValueElement(valueOne);

        // Test setting XML properties
        MessageContext synCtx = TestUtils.getTestContext("<getQuote><symbol>IBM</symbol></getQuote>");
        propMediatorOne.mediate(synCtx);
        Object prop = synCtx.getProperty("nameOne");
        assertEquals(valueOne, prop);

        // Test XML property retreival
        String exprValue = new SynapseXPath("synapse:get-property('nameOne')").stringValueOf(synCtx);
        assertEquals(xml, exprValue);

        // Test property removal
        propMediatorOne.setAction(PropertyMediator.ACTION_REMOVE);
        propMediatorOne.mediate(synCtx);
        assertNull(synCtx.getProperty("nameOne"));

        // Setting XML properties using expressions
        synCtx.setProperty("nameOne", xml);
        PropertyMediator propertyMediatorTwo = new PropertyMediator();
        propertyMediatorTwo.setName("nameTwo");
        propertyMediatorTwo.setExpression(new SynapseXPath("synapse:get-property('nameOne')"),
                XMLConfigConstants.DATA_TYPES.OM.name());
        propertyMediatorTwo.mediate(synCtx);
        Object exprProp = synCtx.getProperty("nameTwo");
        assertTrue(exprProp != null && exprProp instanceof OMElement);
    }
View Full Code Here

        // set a local property to the synapse context
        PropertyMediator propMediator = new PropertyMediator();
        propMediator.setName("name");
        propMediator.setValue("value");

        MessageContext synCtx = TestUtils.getTestContext("<empty/>");
        propMediator.mediate(synCtx);

        // read property through a mediator property
        MediatorProperty medProp = new MediatorProperty();
        medProp.setExpression(new SynapseXPath("synapse:get-property('name')"));
View Full Code Here

        Mediator pcm = MediatorFactoryFinder.getInstance().getMediator(createOMElement(
                "<pojoCommand name='org.apache.synapse.mediators.ext.POJOCommandTestImplementedMediator' " +
                        "xmlns='http://ws.apache.org/ns/synapse'><property name=\"testProp\" " +
                        "value=\"Test Property\" context-name=\"testPropInMC\"/></pojoCommand>"), new Properties());
        POJOCommandTestHelper.reset();
        MessageContext ctx = new TestMessageContext();
        pcm.mediate(ctx);
        assertEquals("Test Property", POJOCommandTestHelper.getInstance().getChangedProperty());
        assertEquals("Test Property", ctx.getProperty("testPropInMC"));
        assertTrue(POJOCommandTestHelper.getInstance().isExecuted());
    }
View Full Code Here

        Mediator pcm = MediatorFactoryFinder.getInstance().getMediator(createOMElement(
                "<pojoCommand name='org.apache.synapse.mediators.ext.POJOCommandTestImplementedMediator' " +
                        "xmlns='http://ws.apache.org/ns/synapse'><property name=\"testProp\" " +
                        "value=\"TestProperty\" expression=\"//testNode\"/></pojoCommand>"), new Properties());
        POJOCommandTestHelper.reset();
        MessageContext ctx = new TestMessageContext();
        SOAPEnvelope envelope = OMAbstractFactory.getSOAP11Factory().getDefaultEnvelope();
        envelope.getBody().addChild(createOMElement("<original><testNode/></original>"));
        ctx.setEnvelope(envelope);
        pcm.mediate(ctx);
        assertEquals("TestProperty", POJOCommandTestHelper.getInstance().getChangedProperty());
        assertEquals("<original>TestProperty</original>", ctx.getEnvelope().getBody().getFirstOMChild().toString());
        assertTrue(POJOCommandTestHelper.getInstance().isExecuted());
    }
View Full Code Here

TOP

Related Classes of org.apache.synapse.MessageContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.