Search in sources :

Example 46 with API

use of org.apache.synapse.api.API in project wso2-synapse by wso2.

the class BasicAPIMediationTest method testRestURLPostfix1.

public void testRestURLPostfix1() throws Exception {
    API api = new API(TEST_API, "/test");
    SynapseConfiguration synapseConfig = new SynapseConfiguration();
    synapseConfig.addAPI(TEST_API, api);
    RESTRequestHandler handler = new RESTRequestHandler();
    MessageContext synCtx = getMessageContext(synapseConfig, false, "/test", "GET");
    handler.process(synCtx);
    checkRestURLPostfix(synCtx, "");
    synCtx = getMessageContext(synapseConfig, false, "/test/me/now", "GET");
    handler.process(synCtx);
    checkRestURLPostfix(synCtx, "/me/now");
    synCtx = getMessageContext(synapseConfig, false, "/test?a=5", "GET");
    handler.process(synCtx);
    checkRestURLPostfix(synCtx, "?a=5");
    api.setVersionStrategy(new URLBasedVersionStrategy(api, "1.0.0", null));
    synCtx = getMessageContext(synapseConfig, false, "/test/1.0.0?a=5", "GET");
    handler.process(synCtx);
    checkRestURLPostfix(synCtx, "?a=5");
    synCtx = getMessageContext(synapseConfig, false, "/test/1.0.0/foo?a=5", "GET");
    handler.process(synCtx);
    checkRestURLPostfix(synCtx, "/foo?a=5");
}
Also used : API(org.apache.synapse.api.API) MessageContext(org.apache.synapse.MessageContext) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration) URLBasedVersionStrategy(org.apache.synapse.api.version.URLBasedVersionStrategy)

Example 47 with API

use of org.apache.synapse.api.API in project wso2-synapse by wso2.

the class BasicAPIMediationTest method testRestURLPostfix3.

public void testRestURLPostfix3() throws Exception {
    API api = new API(TEST_API, "/services/Foo");
    SynapseConfiguration synapseConfig = new SynapseConfiguration();
    synapseConfig.addAPI(TEST_API, api);
    RESTRequestHandler handler = new RESTRequestHandler();
    MessageContext synCtx = getMessageContext(synapseConfig, false, "/services/Foo/test", "GET");
    // When the service path is in the URL, NHTTP transport removes that portion
    // from the postfix
    ((Axis2MessageContext) synCtx).getAxis2MessageContext().setProperty(NhttpConstants.REST_URL_POSTFIX, "/test");
    handler.process(synCtx);
    checkRestURLPostfix(synCtx, "/test");
}
Also used : API(org.apache.synapse.api.API) MessageContext(org.apache.synapse.MessageContext) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration)

Example 48 with API

use of org.apache.synapse.api.API in project wso2-synapse by wso2.

the class ResourceTest method testFaultSequence.

public void testFaultSequence() throws Exception {
    API api = new API("TestAPI", "/test");
    Resource resource = new Resource();
    resource.setDispatcherHelper(new URITemplateHelper("/~{user}"));
    SequenceMediator inSequence = getTestSequence("seq.in", "seq.in.value");
    ((PropertyMediator) inSequence.getChild(0)).setScope("axis2");
    XSLTMediator xsltMediator = new XSLTMediator();
    xsltMediator.setXsltKey(new Value("/bogus/key"));
    inSequence.addChild(xsltMediator);
    resource.setInSequence(inSequence);
    SequenceMediator faultSequence = getTestSequence("seq.fault", "seq.fault.value");
    ((PropertyMediator) faultSequence.getChild(0)).setScope("axis2");
    resource.setFaultSequence(faultSequence);
    api.addResource(resource);
    SynapseConfiguration synapseConfig = new SynapseConfiguration();
    synapseConfig.addAPI(api.getName(), api);
    synapseConfig.addSequence("main", getTestSequence("main.in", "main.value"));
    MessageContext synCtx = getMessageContext(synapseConfig, false, "/test/~foo", "GET");
    MessageContextCreatorForAxis2.setSynConfig(synapseConfig);
    MessageContextCreatorForAxis2.setSynEnv(synCtx.getEnvironment());
    org.apache.axis2.context.MessageContext mc = ((Axis2MessageContext) synCtx).getAxis2MessageContext();
    mc.setConfigurationContext(((Axis2SynapseEnvironment) synCtx.getEnvironment()).getAxis2ConfigurationContext());
    new SynapseMessageReceiver().receive(mc);
    assertEquals("seq.in.value", mc.getProperty("seq.in"));
    assertEquals("seq.fault.value", mc.getProperty("seq.fault"));
}
Also used : Resource(org.apache.synapse.api.Resource) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration) URITemplateHelper(org.apache.synapse.api.dispatch.URITemplateHelper) XSLTMediator(org.apache.synapse.mediators.transform.XSLTMediator) PropertyMediator(org.apache.synapse.mediators.builtin.PropertyMediator) Value(org.apache.synapse.mediators.Value) API(org.apache.synapse.api.API) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator) MessageContext(org.apache.synapse.MessageContext) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext) SynapseMessageReceiver(org.apache.synapse.core.axis2.SynapseMessageReceiver) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext)

Example 49 with API

use of org.apache.synapse.api.API in project wso2-synapse by wso2.

the class ResourceTest method testQueryParams.

public void testQueryParams() throws Exception {
    API api = new API("TestAPI", "/test");
    Resource resource = new Resource();
    api.addResource(resource);
    SynapseConfiguration synapseConfig = new SynapseConfiguration();
    synapseConfig.addAPI(api.getName(), api);
    RESTRequestHandler handler = new RESTRequestHandler();
    MessageContext synCtx = getMessageContext(synapseConfig, false, "/test/admin?a=5&b=10&user=bar", "GET");
    handler.process(synCtx);
    assertEquals("5", synCtx.getProperty(RESTConstants.REST_QUERY_PARAM_PREFIX + "a"));
    assertEquals("10", synCtx.getProperty(RESTConstants.REST_QUERY_PARAM_PREFIX + "b"));
    assertEquals("bar", synCtx.getProperty(RESTConstants.REST_QUERY_PARAM_PREFIX + "user"));
    synCtx = getMessageContext(synapseConfig, false, "/test/admin?a=5", "GET");
    handler.process(synCtx);
    assertEquals("5", synCtx.getProperty(RESTConstants.REST_QUERY_PARAM_PREFIX + "a"));
    synCtx = getMessageContext(synapseConfig, false, "/test/admin?a=Hello%20World&b=10&c=/foo/bar", "GET");
    handler.process(synCtx);
    assertEquals("Hello World", synCtx.getProperty(RESTConstants.REST_QUERY_PARAM_PREFIX + "a"));
    assertEquals("10", synCtx.getProperty(RESTConstants.REST_QUERY_PARAM_PREFIX + "b"));
    assertEquals("/foo/bar", synCtx.getProperty(RESTConstants.REST_QUERY_PARAM_PREFIX + "c"));
}
Also used : Resource(org.apache.synapse.api.Resource) API(org.apache.synapse.api.API) MessageContext(org.apache.synapse.MessageContext) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration)

Example 50 with API

use of org.apache.synapse.api.API in project wso2-synapse by wso2.

the class ResourceTest method testQueryParamWithURL.

public void testQueryParamWithURL() throws Exception {
    API api = new API("TestAPI", "/test");
    Resource resource = new Resource();
    api.addResource(resource);
    SynapseConfiguration synapseConfig = new SynapseConfiguration();
    synapseConfig.addAPI(api.getName(), api);
    RESTRequestHandler handler = new RESTRequestHandler();
    MessageContext synCtx = getMessageContext(synapseConfig, false, "/test/admin?a=http://test.com", "GET");
    handler.process(synCtx);
    // verify query parameters with URLs as values
    assertEquals("http://test.com", synCtx.getProperty(RESTConstants.REST_QUERY_PARAM_PREFIX + "a"));
    synCtx = getMessageContext(synapseConfig, false, "/test/admin?a=http://test.com&b=10&c=/foo/bar", "GET");
    handler.process(synCtx);
    // verify query parameters with URLs as values
    assertEquals("http://test.com", synCtx.getProperty(RESTConstants.REST_QUERY_PARAM_PREFIX + "a"));
    assertEquals("10", synCtx.getProperty(RESTConstants.REST_QUERY_PARAM_PREFIX + "b"));
    assertEquals("/foo/bar", synCtx.getProperty(RESTConstants.REST_QUERY_PARAM_PREFIX + "c"));
}
Also used : Resource(org.apache.synapse.api.Resource) API(org.apache.synapse.api.API) MessageContext(org.apache.synapse.MessageContext) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration)

Aggregations

API (org.apache.synapse.api.API)64 MessageContext (org.apache.synapse.MessageContext)33 SynapseConfiguration (org.apache.synapse.config.SynapseConfiguration)33 Resource (org.apache.synapse.api.Resource)23 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)14 OMElement (org.apache.axiom.om.OMElement)10 URLMappingHelper (org.apache.synapse.api.dispatch.URLMappingHelper)7 Test (org.junit.Test)6 URITemplateHelper (org.apache.synapse.api.dispatch.URITemplateHelper)5 Cache (javax.cache.Cache)4 DeploymentException (org.apache.axis2.deployment.DeploymentException)4 SynapseException (org.apache.synapse.SynapseException)4 ContextVersionStrategy (org.apache.synapse.api.version.ContextVersionStrategy)4 ProxyService (org.apache.synapse.core.axis2.ProxyService)4 InboundEndpoint (org.apache.synapse.inbound.InboundEndpoint)4 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4 APIManagerConfiguration (org.wso2.carbon.apimgt.impl.APIManagerConfiguration)4 APIManagerConfigurationService (org.wso2.carbon.apimgt.impl.APIManagerConfigurationService)4 CacheProvider (org.wso2.carbon.apimgt.impl.caching.CacheProvider)4 ArrayList (java.util.ArrayList)3