Search in sources :

Example 21 with SynapseConfiguration

use of org.apache.synapse.config.SynapseConfiguration 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 22 with SynapseConfiguration

use of org.apache.synapse.config.SynapseConfiguration 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 23 with SynapseConfiguration

use of org.apache.synapse.config.SynapseConfiguration 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 24 with SynapseConfiguration

use of org.apache.synapse.config.SynapseConfiguration in project wso2-synapse by wso2.

the class ClassMediatorTest method testInitializationAndMedition.

public void testInitializationAndMedition() throws Exception {
    Mediator cm = MediatorFactoryFinder.getInstance().getMediator(createOMElement("<class name='org.apache.synapse.mediators.ext.ClassMediatorTestMediator' " + "xmlns='http://ws.apache.org/ns/synapse'/>"), new Properties());
    ((ManagedLifecycle) cm).init(new Axis2SynapseEnvironment(new SynapseConfiguration()));
    assertTrue(ClassMediatorTestMediator.initialized);
    TestMessageContext msgContext = new TestMessageContext();
    msgContext.setEnvironment(new Axis2SynapseEnvironment(new SynapseConfiguration()));
    cm.mediate(msgContext);
    assertTrue(ClassMediatorTestMediator.invoked);
}
Also used : Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) TestMessageContext(org.apache.synapse.TestMessageContext) Mediator(org.apache.synapse.Mediator) Properties(java.util.Properties) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration) ManagedLifecycle(org.apache.synapse.ManagedLifecycle)

Example 25 with SynapseConfiguration

use of org.apache.synapse.config.SynapseConfiguration in project wso2-synapse by wso2.

the class ClassMediatorTest method testMediationWithLiteralProperties.

public void testMediationWithLiteralProperties() throws Exception {
    Mediator cm = MediatorFactoryFinder.getInstance().getMediator(createOMElement("<class name='org.apache.synapse.mediators.ext.ClassMediatorTestMediator' " + "xmlns='http://ws.apache.org/ns/synapse'><property name='testProp' value='testValue'/></class>"), new Properties());
    TestMessageContext msgContext = new TestMessageContext();
    msgContext.setEnvironment(new Axis2SynapseEnvironment(new SynapseConfiguration()));
    cm.mediate(msgContext);
    assertTrue(ClassMediatorTestMediator.invoked);
    assertTrue(ClassMediatorTestMediator.testProp.equals("testValue"));
}
Also used : Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) TestMessageContext(org.apache.synapse.TestMessageContext) Mediator(org.apache.synapse.Mediator) Properties(java.util.Properties) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration)

Aggregations

SynapseConfiguration (org.apache.synapse.config.SynapseConfiguration)145 Axis2SynapseEnvironment (org.apache.synapse.core.axis2.Axis2SynapseEnvironment)64 AxisConfiguration (org.apache.axis2.engine.AxisConfiguration)59 MessageContext (org.apache.synapse.MessageContext)56 Test (org.junit.Test)56 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)50 SynapseEnvironment (org.apache.synapse.core.SynapseEnvironment)49 OMElement (org.apache.axiom.om.OMElement)41 Parameter (org.apache.axis2.description.Parameter)29 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)27 TestMessageContext (org.apache.synapse.TestMessageContext)16 Properties (java.util.Properties)15 SynapseException (org.apache.synapse.SynapseException)13 Mediator (org.apache.synapse.Mediator)12 AddressEndpoint (org.apache.synapse.endpoints.AddressEndpoint)11 File (java.io.File)10 ArrayList (java.util.ArrayList)10 HashMap (java.util.HashMap)9 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)7 Endpoint (org.apache.synapse.endpoints.Endpoint)7