use of org.apache.synapse.MessageContext in project wso2-synapse by wso2.
the class APIDispatcherTest method testAPIContextVersionBasedDispatchWithNoVersion.
public void testAPIContextVersionBasedDispatchWithNoVersion() throws Exception {
API api = new API(TEST_API, "/test");
api.setVersionStrategy(new ContextVersionStrategy(api, TEST_API_VERSION, null));
SynapseConfiguration synapseConfig = new SynapseConfiguration();
synapseConfig.addAPI(api.getName(), api);
RESTRequestHandler handler = new RESTRequestHandler();
MessageContext synCtx = getMessageContext(synapseConfig, false, "/test", "GET");
handler.process(synCtx);
assertEquals(api.getName(), synCtx.getProperty(RESTConstants.SYNAPSE_REST_API));
assertEquals(TEST_API_VERSION, synCtx.getProperty(RESTConstants.SYNAPSE_REST_API_VERSION));
synCtx = getMessageContext(synapseConfig, false, "/test/", "GET");
handler.process(synCtx);
assertEquals(api.getName(), synCtx.getProperty(RESTConstants.SYNAPSE_REST_API));
assertEquals(TEST_API_VERSION, synCtx.getProperty(RESTConstants.SYNAPSE_REST_API_VERSION));
synCtx = getMessageContext(synapseConfig, false, "/test/foo/bar?a=5", "GET");
handler.process(synCtx);
assertEquals(api.getName(), synCtx.getProperty(RESTConstants.SYNAPSE_REST_API));
assertEquals(TEST_API_VERSION, synCtx.getProperty(RESTConstants.SYNAPSE_REST_API_VERSION));
synCtx = getMessageContext(synapseConfig, false, "/test?a=5", "GET");
handler.process(synCtx);
assertEquals(api.getName(), synCtx.getProperty(RESTConstants.SYNAPSE_REST_API));
assertEquals(TEST_API_VERSION, synCtx.getProperty(RESTConstants.SYNAPSE_REST_API_VERSION));
// Message with '/test' context & URL as a Query Parameter should be dispatched
synCtx = getMessageContext(synapseConfig, false, "/test?a=http://localhost.com", "GET");
handler.process(synCtx);
assertEquals(api.getName(), synCtx.getProperty(RESTConstants.SYNAPSE_REST_API));
assertEquals(TEST_API_VERSION, synCtx.getProperty(RESTConstants.SYNAPSE_REST_API_VERSION));
}
use of org.apache.synapse.MessageContext in project wso2-synapse by wso2.
the class BasicAPIMediationTest method testRestURLPostfix2.
public void testRestURLPostfix2() throws Exception {
API api = new API(TEST_API, "/");
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, "/test");
synCtx = getMessageContext(synapseConfig, false, "/test/me/now", "GET");
handler.process(synCtx);
checkRestURLPostfix(synCtx, "/test/me/now");
synCtx = getMessageContext(synapseConfig, false, "/test?a=5", "GET");
handler.process(synCtx);
checkRestURLPostfix(synCtx, "/test?a=5");
}
use of org.apache.synapse.MessageContext in project wso2-synapse by wso2.
the class RESTMediationTestCase method getMessageContext.
protected MessageContext getMessageContext(SynapseConfiguration synapseConfig, boolean https, String url, String method) throws Exception {
MessageContext synCtx = TestUtils.createSynapseMessageContext("<foo/>", synapseConfig);
org.apache.axis2.context.MessageContext msgCtx = ((Axis2MessageContext) synCtx).getAxis2MessageContext();
if (https) {
msgCtx.setIncomingTransportName("https");
} else {
msgCtx.setIncomingTransportName("http");
}
msgCtx.setProperty(Constants.Configuration.HTTP_METHOD, method);
msgCtx.setProperty(Constants.Configuration.TRANSPORT_IN_URL, url);
msgCtx.setProperty(NhttpConstants.REST_URL_POSTFIX, url.substring(1));
return synCtx;
}
use of org.apache.synapse.MessageContext in project wso2-synapse by wso2.
the class RestUtilsTest method testGetFullRequestPath.
public void testGetFullRequestPath() throws Exception {
SynapseConfiguration synapseConfig = new SynapseConfiguration();
MessageContext msgCtx = getMessageContext(synapseConfig, false, "http://localhos:9443/test/admin?PARAM1=1&PARAM2=2", "GET");
String url = RESTUtils.getFullRequestPath(msgCtx);
Assert.assertTrue(url.contains("PARAM1=1&PARAM2=2"));
}
use of org.apache.synapse.MessageContext in project wso2-synapse by wso2.
the class URITemplateBasedDispatcherTest method testMultipleResourceDispatch.
public void testMultipleResourceDispatch() throws Exception {
API api = new API("TestAPI", "/");
Resource resource1 = new Resource();
resource1.setDispatcherHelper(new URITemplateHelper("/dictionary/{char}/{word}"));
resource1.setInSequence(getTestSequence(PROP_NAME, "r1"));
api.addResource(resource1);
Resource resource2 = new Resource();
resource2.setDispatcherHelper(new URITemplateHelper("/dictionary/{char}"));
resource2.setInSequence(getTestSequence(PROP_NAME, "r2"));
api.addResource(resource2);
Resource resource3 = new Resource();
resource3.setDispatcherHelper(new URITemplateHelper("/dictionary/{char}{#ref}"));
resource3.setInSequence(getTestSequence(PROP_NAME, "r3"));
api.addResource(resource3);
SynapseConfiguration synapseConfig = new SynapseConfiguration();
synapseConfig.addAPI(api.getName(), api);
RESTRequestHandler handler = new RESTRequestHandler();
MessageContext synCtx = getMessageContext(synapseConfig, false, "/dictionary/c/cat", "GET");
handler.process(synCtx);
assertEquals("r1", synCtx.getProperty(PROP_NAME));
assertEquals("c", synCtx.getProperty(RESTConstants.REST_URI_VARIABLE_PREFIX + "char"));
assertEquals("cat", synCtx.getProperty(RESTConstants.REST_URI_VARIABLE_PREFIX + "word"));
synCtx = getMessageContext(synapseConfig, false, "/dictionary/d", "GET");
handler.process(synCtx);
assertEquals("r2", synCtx.getProperty(PROP_NAME));
assertEquals("d", synCtx.getProperty(RESTConstants.REST_URI_VARIABLE_PREFIX + "char"));
synCtx = getMessageContext(synapseConfig, false, "/dictionary/e#test", "GET");
handler.process(synCtx);
assertEquals("r3", synCtx.getProperty(PROP_NAME));
assertEquals("e", synCtx.getProperty(RESTConstants.REST_URI_VARIABLE_PREFIX + "char"));
assertEquals("test", synCtx.getProperty(RESTConstants.REST_URI_VARIABLE_PREFIX + "ref"));
synCtx = getMessageContext(synapseConfig, false, "/dictionary/c/cat/test", "GET");
handler.process(synCtx);
assertNull(synCtx.getProperty(PROP_NAME));
synCtx = getMessageContext(synapseConfig, false, "/dictionary/c/cat#ref", "GET");
handler.process(synCtx);
assertNull(synCtx.getProperty(PROP_NAME));
/* With ESBJAVA-4260 we now support optional query parameters for URITemplates */
synCtx = getMessageContext(synapseConfig, false, "/dictionary/c/cat?a=5", "GET");
handler.process(synCtx);
assertEquals("r1", synCtx.getProperty(PROP_NAME));
assertEquals("c", synCtx.getProperty(RESTConstants.REST_URI_VARIABLE_PREFIX + "char"));
assertEquals("cat", synCtx.getProperty(RESTConstants.REST_URI_VARIABLE_PREFIX + "word"));
}
Aggregations