Search in sources :

Example 11 with SynapseXPath

use of org.apache.synapse.util.xpath.SynapseXPath in project wso2-synapse by wso2.

the class PropertyMediatorTest method testMediatorPropertiesExpression.

public void testMediatorPropertiesExpression() throws Exception {
    // 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')"));
    assertTrue("value".equals(medProp.getEvaluatedExpression(synCtx)));
}
Also used : SynapseXPath(org.apache.synapse.util.xpath.SynapseXPath) MediatorProperty(org.apache.synapse.mediators.MediatorProperty) MessageContext(org.apache.synapse.MessageContext) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext)

Example 12 with SynapseXPath

use of org.apache.synapse.util.xpath.SynapseXPath in project wso2-synapse by wso2.

the class FilterMediatorTest method testFilterConditionTrueXPath.

public void testFilterConditionTrueXPath() throws Exception {
    setFilterConditionPassed(false);
    // create a new filter mediator
    FilterMediator filter = new FilterMediator();
    // set xpath condition to IBM
    SynapseXPath xpath = new SynapseXPath("//*[wsx:symbol='IBM']");
    xpath.addNamespace("wsx", "http://www.webserviceX.NET/");
    filter.setXpath(xpath);
    // set dummy mediator to be called on success
    filter.addChild(testMediator);
    // test validate mediator, with static enveope
    filter.mediate(TestUtils.getTestContext(REQ));
    assertTrue(filterConditionPassed);
}
Also used : SynapseXPath(org.apache.synapse.util.xpath.SynapseXPath)

Example 13 with SynapseXPath

use of org.apache.synapse.util.xpath.SynapseXPath in project wso2-synapse by wso2.

the class FilterMediatorTest method testFilterConditionFalseXPath.

public void testFilterConditionFalseXPath() throws Exception {
    setFilterConditionPassed(false);
    // create a new filter mediator
    FilterMediator filter = new FilterMediator();
    // set xpath condition to MSFT
    SynapseXPath xpath = new SynapseXPath("//*[wsx:symbol='MSFT']");
    xpath.addNamespace("wsx", "http://www.webserviceX.NET/");
    filter.setXpath(xpath);
    // set dummy mediator to be called on success
    filter.addChild(testMediator);
    // test validate mediator, with static enveope
    filter.mediate(TestUtils.getTestContext(REQ));
    assertTrue(!filterConditionPassed);
}
Also used : SynapseXPath(org.apache.synapse.util.xpath.SynapseXPath)

Example 14 with SynapseXPath

use of org.apache.synapse.util.xpath.SynapseXPath 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 15 with SynapseXPath

use of org.apache.synapse.util.xpath.SynapseXPath in project wso2-synapse by wso2.

the class HeaderMediatorTest method testSimpleHeaderXPathSetAndRemove.

public void testSimpleHeaderXPathSetAndRemove() throws Exception {
    HeaderMediator headerMediator = new HeaderMediator();
    headerMediator.setQName(new QName(SynapseConstants.HEADER_TO));
    headerMediator.setExpression(new SynapseXPath("concat('http://','server','/path')"));
    // invoke transformation, with static enveope
    MessageContext synCtx = TestUtils.getTestContext("<empty/>");
    headerMediator.mediate(synCtx);
    assertTrue(TEST_HEADER.equals(synCtx.getTo().getAddress()));
    // set the header mediator as a remove-header
    headerMediator.setAction(HeaderMediator.ACTION_REMOVE);
    headerMediator.mediate(synCtx);
    assertTrue(synCtx.getTo() == null);
}
Also used : SynapseXPath(org.apache.synapse.util.xpath.SynapseXPath) QName(javax.xml.namespace.QName) MessageContext(org.apache.synapse.MessageContext) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext)

Aggregations

SynapseXPath (org.apache.synapse.util.xpath.SynapseXPath)68 MessageContext (org.apache.synapse.MessageContext)24 JaxenException (org.jaxen.JaxenException)20 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)15 OMElement (org.apache.axiom.om.OMElement)14 OMAttribute (org.apache.axiom.om.OMAttribute)11 Value (org.apache.synapse.mediators.Value)9 TestMessageContext (org.apache.synapse.TestMessageContext)8 Pattern (java.util.regex.Pattern)6 Iterator (java.util.Iterator)5 QName (javax.xml.namespace.QName)5 EndpointReference (org.apache.axis2.addressing.EndpointReference)4 SynapseException (org.apache.synapse.SynapseException)4 TestMessageContextBuilder (org.apache.synapse.TestMessageContextBuilder)4 SynapseJsonPath (org.apache.synapse.util.xpath.SynapseJsonPath)4 Method (java.lang.reflect.Method)3 Map (java.util.Map)3 MediatorProperty (org.apache.synapse.mediators.MediatorProperty)3 Field (java.lang.reflect.Field)2 List (java.util.List)2