Search in sources :

Example 26 with Mediator

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

the class POJOCommandMediatorTest method testPojoWithStaticPropertiesCommandImpl.

public void testPojoWithStaticPropertiesCommandImpl() throws Exception {
    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\"/></pojoCommand>"), new Properties());
    POJOCommandTestHelper.reset();
    TestMessageContext msgContext = new TestMessageContext();
    msgContext.setEnvironment(new Axis2SynapseEnvironment(new SynapseConfiguration()));
    pcm.mediate(msgContext);
    assertEquals("Test Property", POJOCommandTestHelper.getInstance().getChangedProperty());
    assertTrue(POJOCommandTestHelper.getInstance().isExecuted());
}
Also used : Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) TestMessageContext(org.apache.synapse.TestMessageContext) Mediator(org.apache.synapse.Mediator) Properties(java.util.Properties) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration)

Example 27 with Mediator

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

the class SwitchMediatorTest method setUp.

public void setUp() throws Exception {
    ibmMediator = new TestMediator();
    ibmMediator.setHandler(new TestMediateHandler() {

        public void handle(MessageContext synCtx) {
            setExecutedCase("IBM");
        }
    });
    msftMediator = new TestMediator();
    msftMediator.setHandler(new TestMediateHandler() {

        public void handle(MessageContext synCtx) {
            setExecutedCase("MSFT");
        }
    });
    defaultMediator = new TestMediator();
    defaultMediator.setHandler(new TestMediateHandler() {

        public void handle(MessageContext synCtx) {
            setExecutedCase("DEFAULT");
        }
    });
    // create a new switch mediator
    switchMediator = new SwitchMediator();
    // set xpath condition to select symbol
    SynapseXPath xpath = new SynapseXPath("//wsx:symbol");
    xpath.addNamespace("wsx", "http://www.webserviceX.NET/");
    switchMediator.setSource(xpath);
    SwitchCase caseOne = new SwitchCase();
    caseOne.setRegex(Pattern.compile("IBM"));
    AnonymousListMediator mediatorOne = new AnonymousListMediator();
    mediatorOne.addAll(Arrays.asList(new Mediator[] { ibmMediator }));
    caseOne.setCaseMediator(mediatorOne);
    SwitchCase caseTwo = new SwitchCase();
    caseTwo.setRegex(Pattern.compile("MSFT"));
    AnonymousListMediator mediatorTwo = new AnonymousListMediator();
    mediatorTwo.addAll(Arrays.asList(new Mediator[] { msftMediator }));
    caseTwo.setCaseMediator(mediatorTwo);
    SwitchCase caseDefault = new SwitchCase();
    AnonymousListMediator mediatorDefault = new AnonymousListMediator();
    mediatorDefault.addAll(Arrays.asList(new Mediator[] { defaultMediator }));
    caseDefault.setCaseMediator(mediatorDefault);
    // set ibm mediator to be called for IBM, msft for MSFT and default for others..
    switchMediator.addCase(caseOne);
    switchMediator.addCase(caseTwo);
    switchMediator.setDefaultCase(caseDefault);
}
Also used : SynapseXPath(org.apache.synapse.util.xpath.SynapseXPath) SwitchCase(org.apache.synapse.config.xml.SwitchCase) TestMediateHandler(org.apache.synapse.mediators.TestMediateHandler) AnonymousListMediator(org.apache.synapse.config.xml.AnonymousListMediator) TestMediator(org.apache.synapse.mediators.TestMediator) Mediator(org.apache.synapse.Mediator) AnonymousListMediator(org.apache.synapse.config.xml.AnonymousListMediator) TestMediator(org.apache.synapse.mediators.TestMediator) MessageContext(org.apache.synapse.MessageContext)

Example 28 with Mediator

use of org.apache.synapse.Mediator 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 29 with Mediator

use of org.apache.synapse.Mediator 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 30 with Mediator

use of org.apache.synapse.Mediator 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)

Aggregations

Mediator (org.apache.synapse.Mediator)108 Properties (java.util.Properties)30 SequenceMediator (org.apache.synapse.mediators.base.SequenceMediator)24 OMElement (org.apache.axiom.om.OMElement)22 AbstractMediator (org.apache.synapse.mediators.AbstractMediator)22 MessageContext (org.apache.synapse.MessageContext)16 SynapseLog (org.apache.synapse.SynapseLog)16 FlowContinuableMediator (org.apache.synapse.mediators.FlowContinuableMediator)13 SynapseException (org.apache.synapse.SynapseException)12 TestMessageContext (org.apache.synapse.TestMessageContext)12 SynapseConfiguration (org.apache.synapse.config.SynapseConfiguration)12 Axis2SynapseEnvironment (org.apache.synapse.core.axis2.Axis2SynapseEnvironment)12 TemplateMediator (org.apache.synapse.mediators.template.TemplateMediator)12 Test (org.junit.Test)10 AbstractListMediator (org.apache.synapse.mediators.AbstractListMediator)9 SynapseSequenceType (org.apache.synapse.debug.constructs.SynapseSequenceType)8 SequenceMediationFlowPoint (org.apache.synapse.debug.constructs.SequenceMediationFlowPoint)6 ForEachMediatorFactory (org.apache.synapse.config.xml.ForEachMediatorFactory)5 MediatorFactory (org.apache.synapse.config.xml.MediatorFactory)5 MediatorFaultHandler (org.apache.synapse.mediators.MediatorFaultHandler)5