Search in sources :

Example 1 with URLMappingHelper

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));
}
Also used : URLMappingHelper(org.apache.synapse.rest.dispatch.URLMappingHelper) MessageContext(org.apache.synapse.MessageContext) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration)

Example 2 with URLMappingHelper

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));
}
Also used : URLMappingHelper(org.apache.synapse.rest.dispatch.URLMappingHelper) MessageContext(org.apache.synapse.MessageContext) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration)

Example 3 with URLMappingHelper

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));
}
Also used : URLMappingHelper(org.apache.synapse.rest.dispatch.URLMappingHelper) MessageContext(org.apache.synapse.MessageContext) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration)

Example 4 with URLMappingHelper

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()));
    }
}
Also used : URITemplateHelper(org.apache.synapse.rest.dispatch.URITemplateHelper) QName(javax.xml.namespace.QName) URLMappingHelper(org.apache.synapse.rest.dispatch.URLMappingHelper) OMAttribute(org.apache.axiom.om.OMAttribute)

Example 5 with URLMappingHelper

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));
}
Also used : URLMappingHelper(org.apache.synapse.rest.dispatch.URLMappingHelper) MessageContext(org.apache.synapse.MessageContext) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration)

Aggregations

URLMappingHelper (org.apache.synapse.rest.dispatch.URLMappingHelper)8 MessageContext (org.apache.synapse.MessageContext)6 SynapseConfiguration (org.apache.synapse.config.SynapseConfiguration)6 URITemplateHelper (org.apache.synapse.rest.dispatch.URITemplateHelper)2 QName (javax.xml.namespace.QName)1 OMAttribute (org.apache.axiom.om.OMAttribute)1 OMElement (org.apache.axiom.om.OMElement)1 SequenceMediatorSerializer (org.apache.synapse.config.xml.SequenceMediatorSerializer)1 DispatcherHelper (org.apache.synapse.rest.dispatch.DispatcherHelper)1