Search in sources :

Example 81 with MessageContext

use of org.apache.synapse.MessageContext in project wso2-synapse by wso2.

the class CloneMediatorTest method testClonningWithContinueParent.

public void testClonningWithContinueParent() throws Exception {
    Mediator clone = fac.createMediator(createOMElement("<clone continueParent=\"true\" " + "xmlns=\"http://ws.apache.org/ns/synapse\"><target soapAction=\"urn:clone\" " + "sequence=\"seqRef\"/><target to=\"http://test\"><sequence><sequence " + "key=\"seqRef\"/></sequence></target></clone>"), new Properties());
    assertTrue(clone.mediate(testCtx));
    while (helperMediator.getMediatedContext(1) == null) {
        Thread.sleep(100);
    }
    MessageContext mediatedCtx = helperMediator.getMediatedContext(0);
    assertTrue(mediatedCtx.getEnvelope().getBody().getFirstElement() == null);
    String formerSAction = mediatedCtx.getSoapAction();
    mediatedCtx = helperMediator.getMediatedContext(1);
    if ("urn:clone".equals(formerSAction)) {
        assertEquals(mediatedCtx.getSoapAction(), "urn:test");
        assertEquals(mediatedCtx.getTo().getAddress(), "http://test");
    } else {
        assertEquals(mediatedCtx.getSoapAction(), "urn:clone");
    }
    assertEquals(testCtx.getSoapAction(), "urn:test");
    assertEquals(testCtx.getTo(), null);
}
Also used : Mediator(org.apache.synapse.Mediator) PropertyMediator(org.apache.synapse.mediators.builtin.PropertyMediator) MessageContext(org.apache.synapse.MessageContext) Properties(java.util.Properties)

Example 82 with MessageContext

use of org.apache.synapse.MessageContext in project wso2-synapse by wso2.

the class CloneMediatorTest method testDeepClonedOMTypeProperty.

public void testDeepClonedOMTypeProperty() throws InterruptedException {
    String propName = "testProp";
    Mediator clone = fac.createMediator(createOMElement("<clone " + "xmlns=\"http://ws.apache.org/ns/synapse\"><target soapAction=\"urn:clone\" " + "sequence=\"seqRef\"/><target to=\"http://test\"><sequence><sequence " + "key=\"seqRef\"/></sequence></target></clone>"), new Properties());
    PropertyMediator propertyMediator = new PropertyMediator();
    propertyMediator.setName(propName);
    propertyMediator.setValueElement(TestUtils.createOMElement("<a><b>asdf</b></a>"));
    propertyMediator.setScope("default");
    propertyMediator.mediate(testCtx);
    clone.mediate(testCtx);
    while (helperMediator.getMediatedContext(1) == null) {
        Thread.sleep(100);
    }
    MessageContext mediatedCtx = helperMediator.getMediatedContext(0);
    Object obj = mediatedCtx.getProperty(propName);
    Assert.assertNotNull(obj);
    Assert.assertTrue(obj instanceof OMElement);
    OMElement omElement = (OMElement) obj;
    String cloneStr = omElement.getParent().toString();
    OMElement omElement1 = (OMElement) testCtx.getProperty(propName);
    String parentID = omElement1.getParent().toString();
    Assert.assertTrue(!cloneStr.equals(parentID));
}
Also used : PropertyMediator(org.apache.synapse.mediators.builtin.PropertyMediator) Mediator(org.apache.synapse.Mediator) PropertyMediator(org.apache.synapse.mediators.builtin.PropertyMediator) OMElement(org.apache.axiom.om.OMElement) MessageContext(org.apache.synapse.MessageContext) Properties(java.util.Properties)

Example 83 with MessageContext

use of org.apache.synapse.MessageContext in project wso2-synapse by wso2.

the class IterateMediatorTest method testIterationWithPreservePayload.

public void testIterationWithPreservePayload() throws Exception {
    Mediator iterate = fac.createMediator(createOMElement("<iterate " + "expression=\"//original/itr\" preservePayload=\"true\" attachPath=\"//original\" " + "xmlns=\"http://ws.apache.org/ns/synapse\"><target soapAction=\"urn:iterate\" " + "sequence=\"seqRef\"/></iterate>"), new Properties());
    iterate.mediate(testCtx);
    while (helperMediator.getMediatedContext(1) == null) {
        Thread.sleep(100);
    }
    MessageContext mediatedCtx = helperMediator.getMediatedContext(0);
    assertEquals(mediatedCtx.getSoapAction(), "urn:iterate");
    OMElement formerBody = mediatedCtx.getEnvelope().getBody().getFirstElement();
    mediatedCtx = helperMediator.getMediatedContext(1);
    assertEquals(mediatedCtx.getSoapAction(), "urn:iterate");
    if (formerBody == null) {
        assertEquals(mediatedCtx.getEnvelope().getBody().getFirstElement().getFirstElement().getText(), helperMediator.getCheckString());
    }
}
Also used : Mediator(org.apache.synapse.Mediator) OMElement(org.apache.axiom.om.OMElement) MessageContext(org.apache.synapse.MessageContext) Properties(java.util.Properties)

Example 84 with MessageContext

use of org.apache.synapse.MessageContext in project wso2-synapse by wso2.

the class AnnotatedCommandMediatorTest method testBasicExecute.

public void testBasicExecute() throws Exception {
    AnnotatedCommandMediator m = new AnnotatedCommandMediator();
    m.setCommand(AnnotatedCommand.class);
    Mediator pcm = MediatorFactoryFinder.getInstance().getMediator(createOMElement("<annotatedCommand name='org.apache.synapse.mediators.ext.AnnotatedCommand2' xmlns='http://ws.apache.org/ns/synapse'/>"), new Properties());
    MessageContext mc = TestUtils.getTestContext("<m:getQuote xmlns:m=\"http://services.samples/xsd\"><m:request><m:symbol>IBM</m:symbol></m:request></m:getQuote>");
    pcm.mediate(mc);
    assertEquals("IBM", AnnotatedCommand2.fieldResult);
    assertEquals("IBM", AnnotatedCommand2.methodResult);
}
Also used : Mediator(org.apache.synapse.Mediator) MessageContext(org.apache.synapse.MessageContext) Properties(java.util.Properties)

Example 85 with MessageContext

use of org.apache.synapse.MessageContext in project wso2-synapse by wso2.

the class Axis2MessageContextTest method testMessageContextGetStringValueEnvelope.

public void testMessageContextGetStringValueEnvelope() throws Exception {
    SynapseXPath axiomXpath = new SynapseXPath("/s11:Envelope/s11:Body/ns1:a/ns1:c");
    axiomXpath.addNamespace("s11", nsSoapEnv);
    axiomXpath.addNamespace("ns1", nsNamespace1);
    MessageContext synCtx = TestUtils.getTestContext(sampleBody);
    String result = axiomXpath.stringValueOf(synCtx);
    assertEquals("second", result);
}
Also used : SynapseXPath(org.apache.synapse.util.xpath.SynapseXPath) MessageContext(org.apache.synapse.MessageContext)

Aggregations

MessageContext (org.apache.synapse.MessageContext)220 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)86 SynapseConfiguration (org.apache.synapse.config.SynapseConfiguration)54 SynapseException (org.apache.synapse.SynapseException)29 TestMessageContextBuilder (org.apache.synapse.TestMessageContextBuilder)26 ArrayList (java.util.ArrayList)24 Axis2SynapseEnvironment (org.apache.synapse.core.axis2.Axis2SynapseEnvironment)24 SynapseXPath (org.apache.synapse.util.xpath.SynapseXPath)24 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)18 SynapseEnvironment (org.apache.synapse.core.SynapseEnvironment)18 OMElement (org.apache.axiom.om.OMElement)17 AxisConfiguration (org.apache.axis2.engine.AxisConfiguration)17 HashMap (java.util.HashMap)16 Mediator (org.apache.synapse.Mediator)16 TestMessageContext (org.apache.synapse.TestMessageContext)16 Map (java.util.Map)15 Properties (java.util.Properties)15 Test (org.junit.Test)15 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)14 QName (javax.xml.namespace.QName)13