Package org.apache.synapse

Examples of org.apache.synapse.MessageContext


      log.error("to address not set");
      return;

    }

        MessageContext mc = synapseEnvironment.createMessageContext();
//        AspectHelper.setGlobalAudit(mc);    TODO
        mc.pushFaultHandler(new MediatorFaultHandler(mc.getFaultSequence()));
        mc.setTo(new EndpointReference(to));
        if (format == null) {
            PayloadHelper.setXMLPayload(mc, message.cloneOMElement());
        } else {
            try {
                if (SOAP11_FORMAT.equalsIgnoreCase(format)) {
                    mc.setEnvelope(OMAbstractFactory.getSOAP11Factory().createSOAPEnvelope());
                } else if (SOAP12_FORMAT.equalsIgnoreCase(format)) {
                    mc.setEnvelope(OMAbstractFactory.getSOAP12Factory().createSOAPEnvelope());
                } else if (POX_FORMAT.equalsIgnoreCase(format)) {
                    mc.setDoingPOX(true);
                } else if (GET_FORMAT.equalsIgnoreCase(format)) {
                    mc.setDoingGET(true);
                }
                PayloadHelper.setXMLPayload(mc, message.cloneOMElement());
            } catch (AxisFault axisFault) {
                String msg = "Error in setting the message payload : " + message;
                log.error(msg, axisFault);
                throw new SynapseException(msg, axisFault);
            }
        }
        if (soapAction != null) {
            mc.setSoapAction(soapAction);
        }
        synapseEnvironment.injectMessage(mc);

  }
View Full Code Here


            String payload) throws Exception {
        org.apache.axis2.context.MessageContext mc =
                new org.apache.axis2.context.MessageContext();
        SynapseConfiguration config = new SynapseConfiguration();
        SynapseEnvironment env = new Axis2SynapseEnvironment(config);
        MessageContext synMc = new Axis2MessageContext(mc, config, env);
        SOAPEnvelope envelope =
                OMAbstractFactory.getSOAP11Factory().getDefaultEnvelope();
        OMDocument omDoc =
                OMAbstractFactory.getSOAP11Factory().createOMDocument();
        omDoc.addChild(envelope);

        envelope.getBody().addChild(createOMElement(payload));

        synMc.setEnvelope(envelope);
        return synMc;
    }
View Full Code Here

    public void testMediate() throws Exception {
        ByteArrayInputStream in = new ByteArrayInputStream(POLICY.getBytes());
        StAXOMBuilder builde = new StAXOMBuilder(in);
        ThrottleTestMediator throttleMediator = new ThrottleTestMediator();
        throttleMediator.setPolicyKey("throttlepolicy");
        MessageContext synCtx = createLightweightSynapseMessageContext("<empty/>");
        synCtx.setProperty(REMOTE_ADDR, "192.168.8.212");
        SynapseConfiguration synCfg = new SynapseConfiguration();
        Entry prop = new Entry();
        prop.setKey("throttlepolicy");
        prop.setType(Entry.INLINE_XML);
        prop.setValue(builde.getDocumentElement());
        synCfg.addEntry("throttlepolicy", prop);
        synCtx.setConfiguration(synCfg);
        for (int i = 0; i < 6; i++) {
            try {
                throttleMediator.mediate(synCtx);
                Thread.sleep(1000);
            }
View Full Code Here

    public void testMediateWithInLineXML() throws Exception {
        ByteArrayInputStream in = new ByteArrayInputStream(NEW_POLICY.getBytes());
        StAXOMBuilder build = new StAXOMBuilder(in);
        ThrottleTestMediator throttleMediator = new ThrottleTestMediator();
        throttleMediator.setInLinePolicy(build.getDocumentElement());
        MessageContext synCtx = createLightweightSynapseMessageContext("<empty/>");
        synCtx.setProperty(REMOTE_ADDR, "192.168.8.212");
        SynapseConfiguration synCfg = new SynapseConfiguration();
        synCtx.setConfiguration(synCfg);
        for (int i = 0; i < 6; i++) {
            try {
                throttleMediator.mediate(synCtx);
                Thread.sleep(1000);
            }
View Full Code Here

*/
public class SpringMediatorTest extends TestCase {

    public void testSpringBean() throws Exception {

        MessageContext msgCtx = TestUtils.getTestContext("<dummy/>");
        msgCtx.setConfiguration(
            SynapseConfigurationBuilder.getConfiguration("./../../repository/conf/sample/resources/spring/synapse_spring_unittest.xml", new Properties()));
        msgCtx.getMainSequence().mediate(msgCtx);

        assertEquals(TestMediateHandlerImpl.invokeCount, 202);
    }
View Full Code Here

    public void setAppContext(ApplicationContext appContext) {
        this.appContext = appContext;
    }

    public void init(SynapseEnvironment se) {
        MessageContext synCtx = se.createMessageContext();
        buildAppContext(synCtx, getLog(synCtx));
    }
View Full Code Here

    String message = "This is XPath test";   

    public void testStringXPath() throws Exception {
        SynapseXPath xpath = SynapseXPath.parseXPathString("$body//{http://somens}test");
        MessageContext ctx =  TestUtils.getTestContext("<m0:test xmlns:m0=\"http://somens\">" + message + "</m0:test>");
        assertEquals(message, xpath.stringValueOf(ctx));
    }
View Full Code Here

        assertEquals(message, xpath.stringValueOf(ctx));
    }

    public void testStringXPath2() throws Exception {
        SynapseXPath xpath = SynapseXPath.parseXPathString("$body//{http://somens}test/{http://someother}another");
        MessageContext ctx =  TestUtils.getTestContext("<m0:test xmlns:m0=\"http://somens\"><m1:another xmlns:m1=\"http://someother\">" + message + "</m1:another></m0:test>");
        assertEquals(message, xpath.stringValueOf(ctx));
    }
View Full Code Here

        assertEquals(message, xpath.stringValueOf(ctx));
    }

    public void testAbsoluteXPath() throws Exception {
        SynapseXPath xpath = new SynapseXPath("//test");
        MessageContext ctx =  TestUtils.getTestContext("<test>" + message + "</test>");
        assertEquals(message, xpath.stringValueOf(ctx));
    }
View Full Code Here

        assertEquals(message, xpath.stringValueOf(ctx));
    }

    public void testBodyRelativeXPath() throws Exception {
        SynapseXPath xpath = new SynapseXPath("$body/test");
        MessageContext ctx =  TestUtils.getTestContext("<test>" + message + "</test>");
        assertEquals(message, xpath.stringValueOf(ctx));
        Object node = xpath.selectSingleNode(ctx);
        assertTrue(node instanceof OMElement);
        assertEquals(message, ((OMElement)node).getText());
    }
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.