use of org.apache.synapse.rest.dispatch.URLMappingHelper in project wso2-synapse by wso2.
the class URLMappingBasedDispatcherTest method testPathBasedDispatch.
public void testPathBasedDispatch() throws Exception {
API api = new API("TestAPI", "/test");
Resource resource = new Resource();
resource.setDispatcherHelper(new URLMappingHelper("/foo/bar/*"));
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", "GET");
handler.process(synCtx);
assertEquals(PROP_VALUE, synCtx.getProperty(PROP_NAME));
synCtx = getMessageContext(synapseConfig, false, "/test/foo/bar/", "GET");
handler.process(synCtx);
assertEquals(PROP_VALUE, synCtx.getProperty(PROP_NAME));
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/foo/bar?a=b", "GET");
handler.process(synCtx);
assertEquals(PROP_VALUE, synCtx.getProperty(PROP_NAME));
synCtx = getMessageContext(synapseConfig, false, "/test/foo/bar/baz?a=b", "GET");
handler.process(synCtx);
assertEquals(PROP_VALUE, synCtx.getProperty(PROP_NAME));
synCtx = getMessageContext(synapseConfig, false, "/test/foo/bar/?a=b", "GET");
handler.process(synCtx);
assertEquals(PROP_VALUE, synCtx.getProperty(PROP_NAME));
synCtx = getMessageContext(synapseConfig, false, "/test/foo/bars?a=b", "GET");
handler.process(synCtx);
assertNull(synCtx.getProperty(PROP_NAME));
synCtx = getMessageContext(synapseConfig, false, "/test/foo/", "GET");
handler.process(synCtx);
assertNull(synCtx.getProperty(PROP_NAME));
}
use of org.apache.synapse.rest.dispatch.URLMappingHelper in project wso2-synapse by wso2.
the class URLMappingBasedDispatcherTest method testDefaultResourceDispatch.
public void testDefaultResourceDispatch() throws Exception {
API api = new API("TestAPI", "/test");
Resource resource = new Resource();
resource.setDispatcherHelper(new URLMappingHelper("/"));
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", "GET");
handler.process(synCtx);
assertEquals(PROP_VALUE, synCtx.getProperty(PROP_NAME));
}
use of org.apache.synapse.rest.dispatch.URLMappingHelper 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.rest.dispatch.URLMappingHelper in project wso2-synapse by wso2.
the class ResourceFactory method configureURLMappings.
private static void configureURLMappings(Resource resource, OMElement resourceElt) {
OMAttribute urlMappingAtt = resourceElt.getAttribute(new QName("url-mapping"));
OMAttribute uriTemplateAtt = resourceElt.getAttribute(new QName("uri-template"));
if (urlMappingAtt != null && !"".equals(urlMappingAtt.getAttributeValue())) {
resource.setDispatcherHelper(new URLMappingHelper(urlMappingAtt.getAttributeValue()));
} else if (uriTemplateAtt != null && !"".equals(uriTemplateAtt.getAttributeValue())) {
resource.setDispatcherHelper(new URITemplateHelper(uriTemplateAtt.getAttributeValue()));
}
}
use of org.apache.synapse.rest.dispatch.URLMappingHelper in project wso2-synapse by wso2.
the class URLMappingBasedDispatcherTest method testExactMatchBasedDispatch.
public void testExactMatchBasedDispatch() throws Exception {
API api = new API("TestAPI", "/test");
Resource resource = new Resource();
resource.setDispatcherHelper(new URLMappingHelper("/foo/bar"));
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", "GET");
handler.process(synCtx);
assertEquals(PROP_VALUE, synCtx.getProperty(PROP_NAME));
synCtx = getMessageContext(synapseConfig, false, "/test/foo/bar/", "GET");
handler.process(synCtx);
assertEquals(PROP_VALUE, synCtx.getProperty(PROP_NAME));
synCtx = getMessageContext(synapseConfig, false, "/test/foo/bar?a=5", "GET");
handler.process(synCtx);
assertEquals(PROP_VALUE, synCtx.getProperty(PROP_NAME));
synCtx = getMessageContext(synapseConfig, false, "/test/foo/bar?a=5&name=test", "GET");
handler.process(synCtx);
assertEquals(PROP_VALUE, synCtx.getProperty(PROP_NAME));
synCtx = getMessageContext(synapseConfig, false, "/test/foo", "GET");
handler.process(synCtx);
assertNull(synCtx.getProperty(PROP_NAME));
synCtx = getMessageContext(synapseConfig, false, "/test/foo/bar/index.html", "GET");
handler.process(synCtx);
assertNull(synCtx.getProperty(PROP_NAME));
}
Aggregations