Search in sources :

Example 21 with SynapseXPath

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

the class SynapseXPathTest method testHeaderRelativeXPath.

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));
    xpath = new SynapseXPath("$header/*");
    assertEquals(2, xpath.selectNodes(ctx).size());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) SynapseXPath(org.apache.synapse.util.xpath.SynapseXPath) OMNamespace(org.apache.axiom.om.OMNamespace) TestMessageContext(org.apache.synapse.TestMessageContext) MessageContext(org.apache.synapse.MessageContext) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext)

Example 22 with SynapseXPath

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

the class SynapseXPathTest method testContextProperties.

public void testContextProperties() throws Exception {
    SynapseXPath xpath = new SynapseXPath("$ctx:test");
    MessageContext synCtx = new TestMessageContext();
    synCtx.setProperty("test", message);
    assertEquals(xpath.evaluate(synCtx), message);
}
Also used : SynapseXPath(org.apache.synapse.util.xpath.SynapseXPath) TestMessageContext(org.apache.synapse.TestMessageContext) TestMessageContext(org.apache.synapse.TestMessageContext) MessageContext(org.apache.synapse.MessageContext) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext)

Example 23 with SynapseXPath

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

Example 24 with SynapseXPath

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

the class EventFilterTest method testTopicBasedEventFilter.

public void testTopicBasedEventFilter() {
    String status = "snow";
    try {
        MessageContext msgCtx = TestUtils.getAxis2MessageContext("<weatherCondition>" + status + "</weatherCondition>", null).getAxis2MessageContext();
        Event<MessageContext> event = new Event<MessageContext>();
        event.setMessage(msgCtx);
        TopicBasedEventFilter filter = new TopicBasedEventFilter();
        filter.setResultValue(status);
        filter.setSourceXpath(new SynapseXPath("//weatherCondition"));
        assertTrue(filter.match(event));
        filter.setResultValue("rain");
        assertFalse(filter.match(event));
    } catch (Exception e) {
        fail("Error while constructing the test message context: " + e.getMessage());
    }
}
Also used : SynapseXPath(org.apache.synapse.util.xpath.SynapseXPath) Event(org.wso2.eventing.Event) MessageContext(org.apache.axis2.context.MessageContext)

Example 25 with SynapseXPath

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

the class EventFilterTest method testXPathBasedEventFilter.

public void testXPathBasedEventFilter() {
    String status = "snow";
    try {
        org.apache.synapse.MessageContext msgCtx = TestUtils.createLightweightSynapseMessageContext("<weatherCondition>" + status + "</weatherCondition>");
        XPathBasedEventFilter filter = new XPathBasedEventFilter();
        filter.setResultValue(status);
        filter.setSourceXpath(new SynapseXPath("//weatherCondition"));
        assertTrue(filter.isSatisfied(msgCtx));
        filter.setResultValue("rain");
        assertFalse(filter.isSatisfied(msgCtx));
    } catch (Exception e) {
        e.printStackTrace();
        fail("Error while constructing the test message context: " + e.getMessage());
    }
}
Also used : SynapseXPath(org.apache.synapse.util.xpath.SynapseXPath)

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