Search in sources :

Example 76 with MessageContext

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

the class URLMappingBasedDispatcherTest method testExtensionBasedDispatch.

public void testExtensionBasedDispatch() throws Exception {
    API api = new API("TestAPI", "/test");
    Resource resource = new Resource();
    resource.setDispatcherHelper(new URLMappingHelper("*.jsp"));
    resource.setInSequence(getTestSequence(PROP_NAME, PROP_VALUE));
    api.addResource(resource);
    SynapseConfiguration synapseConfig = new SynapseConfiguration();
    synapseConfig.addAPI(api.getName(), api);
    RESTRequestHandler handler = new RESTRequestHandler();
    MessageContext synCtx = getMessageContext(synapseConfig, false, "/test/foo/bar/index.jsp", "GET");
    handler.process(synCtx);
    assertEquals(PROP_VALUE, synCtx.getProperty(PROP_NAME));
    synCtx = getMessageContext(synapseConfig, false, "/test/welcome.jsp", "GET");
    handler.process(synCtx);
    assertEquals(PROP_VALUE, synCtx.getProperty(PROP_NAME));
    synCtx = getMessageContext(synapseConfig, false, "/test/index.jsp?a=5&b=10", "GET");
    handler.process(synCtx);
    assertEquals(PROP_VALUE, synCtx.getProperty(PROP_NAME));
    synCtx = getMessageContext(synapseConfig, false, "/test/foo/index.html", "GET");
    handler.process(synCtx);
    assertNull(synCtx.getProperty(PROP_NAME));
}
Also used : URLMappingHelper(org.apache.synapse.rest.dispatch.URLMappingHelper) MessageContext(org.apache.synapse.MessageContext) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration)

Example 77 with MessageContext

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

the class SynapseXPathTest method testStringXPath2.

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));
}
Also used : SynapseXPath(org.apache.synapse.util.xpath.SynapseXPath) TestMessageContext(org.apache.synapse.TestMessageContext) MessageContext(org.apache.synapse.MessageContext) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext)

Example 78 with MessageContext

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

the class SynapseXPathTest method testBodyRelativeXPath.

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());
}
Also used : SynapseXPath(org.apache.synapse.util.xpath.SynapseXPath) OMElement(org.apache.axiom.om.OMElement) TestMessageContext(org.apache.synapse.TestMessageContext) MessageContext(org.apache.synapse.MessageContext) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext)

Example 79 with MessageContext

use of org.apache.synapse.MessageContext 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 80 with MessageContext

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

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