Package org.apache.synapse

Examples of org.apache.synapse.MessageContext


        assertTrue(node instanceof OMElement);
        assertEquals(message, ((OMElement)node).getText());
    }

    public void testHeaderRelativeXPath() throws Exception {
        MessageContext ctx =  TestUtils.getTestContext("<test>" + message + "</test>");
        OMFactory fac = ctx.getEnvelope().getOMFactory();
        OMNamespace ns = fac.createOMNamespace("http://test", "t");
        ctx.getEnvelope().getHeader().addHeaderBlock("test", ns).setText(message);
        ctx.getEnvelope().getHeader().addHeaderBlock("test2", ns);
       
        SynapseXPath xpath = new SynapseXPath("$header/t:test");
        xpath.addNamespace(ns);
        assertEquals(message, xpath.stringValueOf(ctx));
       
View Full Code Here


        assertEquals(2, xpath.selectNodes(ctx).size());
    }

    public void testContextProperties() throws Exception {
        SynapseXPath xpath = new SynapseXPath("$ctx:test");
        MessageContext synCtx = new TestMessageContext();
        synCtx.setProperty("test", message);
        assertEquals(xpath.evaluate(synCtx), message);
    }
View Full Code Here

        assertEquals(1234, new SynapseXPath("$axis2:test2").numberValueOf(synCtx).intValue());
        assertTrue(new SynapseXPath("$axis2:test2 = 1234").booleanValueOf(synCtx));
    }
   
    public void testStandardXPathFunctions() throws Exception {
        MessageContext ctx = TestUtils.getTestContext("<test>123456</test>");
        assertEquals(6, new SynapseXPath("string-length(//test)").numberValueOf(ctx).intValue());
    }
View Full Code Here

    public void testInlineScriptMediatorFactory() throws XMLStreamException {
        ScriptMediatorFactory mf = new ScriptMediatorFactory();
        Mediator mediator = mf.createMediator(INLINE_MEDIATOR_CONFIG, new Properties());
        try{
            MessageContext mc = TestUtils.getTestContext("<foo/>",null);
            assertTrue(mediator.mediate(mc));
        }catch(Exception e){
            e.printStackTrace();
        }
    }
View Full Code Here

        Entry prop = new Entry();
        prop.setKey("MyMediator");
        prop.setValue(MY_MEDIATOR);
        Map<String,Entry> props = new HashMap<String,Entry>();
        props.put("MyMediator", prop);
        MessageContext mc = TestUtils.getTestContext("<foo/>", props);

        ScriptMediatorFactory mf = new ScriptMediatorFactory();
        Mediator mediator = mf.createMediator(REG_PROP_MEDIATOR_CONFIG, new Properties());
        assertTrue(mediator.mediate(mc));
    }
View Full Code Here

    public void testRegPropWithFunctionMediatorFactory() throws Exception {
        Entry prop = new Entry();
        prop.setValue(MY_MEDIATOR_FOO_FUNC);
        Map<String,Entry> props = new HashMap<String,Entry>();
        props.put("MyFooMediator", prop);
        MessageContext mc = TestUtils.getTestContext("<foo/>", props);

        ScriptMediatorFactory mf = new ScriptMediatorFactory();
        Mediator mediator = mf.createMediator(REG_PROP_FOO_FUNC_MEDIATOR_CONFIG, new Properties());
        assertTrue(mediator.mediate(mc));
    }
View Full Code Here

     * @see SynapseXPathVariableContext#getVariableValue(String, String, String)
     */
    @Override
    protected Context getContext(Object obj) {
        if (obj instanceof MessageContext) {
            MessageContext synCtx = (MessageContext)obj;
            ContextSupport baseContextSupport = getContextSupport();
            ContextSupport contextSupport =
                new ContextSupport(baseContextSupport.getNamespaceContext(),
                                   new SynapseXPathFunctionContext(baseContextSupport.getFunctionContext(), synCtx),
                                   new SynapseXPathVariableContext(baseContextSupport.getVariableContext(), synCtx),
                                   baseContextSupport.getNavigator());
            Context context = new Context(contextSupport);
            context.setNodeSet(new SingletonList(synCtx.getEnvelope()));
            return context;
        } else if (obj instanceof SOAPEnvelope) {
            SOAPEnvelope env = (SOAPEnvelope)obj;
            ContextSupport baseContextSupport = getContextSupport();
            ContextSupport contextSupport =
View Full Code Here

        // set regex to MSFT
        Pattern regex = Pattern.compile("MSFT");
        filter.setRegex(regex);

        MessageContext msgCtx = TestUtils.getTestContext(REQ);

        SequenceMediator seq = new SequenceMediator();
        seq.setName("refSeq");
        seq.addChild(testMediator);

        msgCtx.getConfiguration().addSequence("refSeq", testMediator);

        filter.setElseKey("refSeq");
        // test validate mediator, with static enveope
        filter.mediate(msgCtx);
View Full Code Here

     */
    private MessageContext getIteratedMessage(MessageContext synCtx, int msgNumber, int msgCount,
        SOAPEnvelope envelope, OMNode o) throws AxisFault, JaxenException {
       
        // clone the message for the mediation in iteration
        MessageContext newCtx = MessageHelper.cloneMessageContext(synCtx);

        // set the messageSequence property for possibal aggreagtions
        newCtx.setProperty(
            EIPConstants.MESSAGE_SEQUENCE,
            msgNumber + EIPConstants.MESSAGE_SEQUENCE_DELEMITER + msgCount);

        // get a clone of the envelope to be attached
        SOAPEnvelope newEnvelope = MessageHelper.cloneSOAPEnvelope(envelope);

        // if payload should be preserved then attach the iteration element to the
        // node specified by the attachPath
        if (preservePayload) {

            Object attachElem = attachPath.evaluate(newEnvelope);
            if (attachElem != null &&
                attachElem instanceof List && !((List) attachElem).isEmpty()) {
                attachElem = ((List) attachElem).get(0);
            }

            // for the moment attaching element should be an OMElement
            if (attachElem != null && attachElem instanceof OMElement) {
                ((OMElement) attachElem).addChild(o);
            } else {
                handleException("Error in attaching the splitted elements :: " +
                    "Unable to get the attach path specified by the expression " +
                    attachPath, synCtx);
            }

        } else if (newEnvelope.getBody() != null) {
            // if not preserve payload then attach the iteration element to the body
            newEnvelope.getBody().addChild(o);
        }

        // set the envelope and mediate as specified in the target
        newCtx.setEnvelope(newEnvelope);

        return newCtx;
    }
View Full Code Here

        public void run() {
            if (log.isDebugEnabled()) {
                log.debug("Started running the message processor");
            }
            for (int i = 0; i < samplingRate && !messageQueue.isEmpty(); i++) {
                MessageContext synCtx = messageQueue.get();
                if (log.isDebugEnabled()) {
                    log.debug("Mediating the message on the message queue with message id : "
                            + synCtx.getMessageID());
                }
                target.mediate(synCtx);
            }
            if (log.isDebugEnabled()) {
                log.debug("Message processing completed for the given sampling rate");
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.