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));
}
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));
}
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());
}
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());
}
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);
}
Aggregations