use of org.apache.synapse.config.SynapseConfiguration in project wso2-synapse by wso2.
the class URLMappingBasedDispatcherTest method testMultipleResourceDispatch.
public void testMultipleResourceDispatch() throws Exception {
API api = new API("TestAPI", "/test");
Resource resource1 = new Resource();
resource1.setDispatcherHelper(new URLMappingHelper("/foo/*"));
resource1.setInSequence(getTestSequence(PROP_NAME, "resource1"));
Resource resource2 = new Resource();
resource2.setDispatcherHelper(new URLMappingHelper("/foo/bar/*"));
resource2.setInSequence(getTestSequence(PROP_NAME, "resource2"));
Resource resource3 = new Resource();
resource3.setDispatcherHelper(new URLMappingHelper("*.jsp"));
resource3.setInSequence(getTestSequence(PROP_NAME, "resource3"));
api.addResource(resource1);
api.addResource(resource2);
api.addResource(resource3);
SynapseConfiguration synapseConfig = new SynapseConfiguration();
synapseConfig.addAPI(api.getName(), api);
RESTRequestHandler handler = new RESTRequestHandler();
MessageContext synCtx = getMessageContext(synapseConfig, false, "/test/foo/", "GET");
handler.process(synCtx);
assertEquals("resource1", synCtx.getProperty(PROP_NAME));
synCtx = getMessageContext(synapseConfig, false, "/test/foo/index.html?a=5", "GET");
handler.process(synCtx);
assertEquals("resource1", synCtx.getProperty(PROP_NAME));
synCtx = getMessageContext(synapseConfig, false, "/test/foo/bars", "GET");
handler.process(synCtx);
assertEquals("resource1", synCtx.getProperty(PROP_NAME));
synCtx = getMessageContext(synapseConfig, false, "/test/foo/index.jsp", "GET");
handler.process(synCtx);
assertEquals("resource1", synCtx.getProperty(PROP_NAME));
synCtx = getMessageContext(synapseConfig, false, "/test/foo/bar/", "GET");
handler.process(synCtx);
assertEquals("resource2", synCtx.getProperty(PROP_NAME));
synCtx = getMessageContext(synapseConfig, false, "/test/foo/bar/index.html?a=5", "GET");
handler.process(synCtx);
assertEquals("resource2", synCtx.getProperty(PROP_NAME));
synCtx = getMessageContext(synapseConfig, false, "/test/foo/bar/hello", "GET");
handler.process(synCtx);
assertEquals("resource2", synCtx.getProperty(PROP_NAME));
synCtx = getMessageContext(synapseConfig, false, "/test/foo/bar/index.jsp", "GET");
handler.process(synCtx);
assertEquals("resource2", synCtx.getProperty(PROP_NAME));
synCtx = getMessageContext(synapseConfig, false, "/test/index.jsp", "GET");
handler.process(synCtx);
assertEquals("resource3", synCtx.getProperty(PROP_NAME));
synCtx = getMessageContext(synapseConfig, false, "/test/hello/index.jsp?a=5", "GET");
handler.process(synCtx);
assertEquals("resource3", synCtx.getProperty(PROP_NAME));
synCtx = getMessageContext(synapseConfig, false, "/test/foolish/bars/index.jsp", "GET");
handler.process(synCtx);
assertEquals("resource3", synCtx.getProperty(PROP_NAME));
synCtx = getMessageContext(synapseConfig, false, "/test/foolish/index.html", "GET");
handler.process(synCtx);
assertNull(synCtx.getProperty(PROP_NAME));
}
use of org.apache.synapse.config.SynapseConfiguration in project wso2-synapse by wso2.
the class URLMappingBasedDispatcherTest method testResponseDispatch.
public void testResponseDispatch() throws Exception {
API api = new API("TestAPI", "/test");
Resource resource = new Resource();
resource.setDispatcherHelper(new URLMappingHelper("/foo/bar/*"));
resource.setOutSequence(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");
synCtx.setProperty(RESTConstants.SYNAPSE_REST_API, api.getName());
synCtx.setResponse(true);
handler.process(synCtx);
assertNull(synCtx.getProperty(PROP_NAME));
synCtx.setProperty(RESTConstants.SYNAPSE_RESOURCE, resource.getName());
handler.process(synCtx);
assertEquals(PROP_VALUE, synCtx.getProperty(PROP_NAME));
}
use of org.apache.synapse.config.SynapseConfiguration in project wso2-synapse by wso2.
the class TestMessageContextBuilder method build.
/**
* Build the test message context.
* This method returns a new (and independent) instance on every invocation.
*
* @return
* @throws Exception
*/
public MessageContext build() throws Exception {
SynapseConfiguration testConfig = new SynapseConfiguration();
// TODO: check whether we need a SynapseEnvironment in all cases
SynapseEnvironment synEnv = new Axis2SynapseEnvironment(new ConfigurationContext(new AxisConfiguration()), testConfig);
MessageContext synCtx;
if (requireAxis2MessageContext) {
synCtx = new Axis2MessageContext(new org.apache.axis2.context.MessageContext(), testConfig, synEnv);
} else {
synCtx = new TestMessageContext();
synCtx.setEnvironment(synEnv);
synCtx.setConfiguration(testConfig);
}
for (Map.Entry<String, Entry> mapEntry : entries.entrySet()) {
testConfig.addEntry(mapEntry.getKey(), mapEntry.getValue());
}
XMLStreamReader parser = null;
if (contentString != null) {
parser = StAXUtils.createXMLStreamReader(new StringReader(contentString));
} else if (contentFile != null) {
parser = StAXUtils.createXMLStreamReader(new FileInputStream(contentFile));
} else if (contentStringJson != null) {
// synCtx = new Axis2MessageContext(null, testConfig, synEnv);
SOAPEnvelope envelope = OMAbstractFactory.getSOAP11Factory().getDefaultEnvelope();
synCtx.setEnvelope(envelope);
JsonUtil.getNewJsonPayload(((Axis2MessageContext) synCtx).getAxis2MessageContext(), contentStringJson, true, true);
return synCtx;
}
SOAPEnvelope envelope;
if (parser != null) {
if (contentIsEnvelope) {
envelope = new StAXSOAPModelBuilder(parser).getSOAPEnvelope();
} else {
envelope = OMAbstractFactory.getSOAP11Factory().getDefaultEnvelope();
// TODO: don't know why this is here, but without it some unit tests fail...
OMDocument omDoc = OMAbstractFactory.getSOAP11Factory().createOMDocument();
omDoc.addChild(envelope);
SOAPBody body = envelope.getBody();
StAXOMBuilder builder = new StAXOMBuilder(parser);
OMElement bodyElement = builder.getDocumentElement();
if (addTextAroundBody) {
OMFactory fac = OMAbstractFactory.getOMFactory();
body.addChild(fac.createOMText("\n"));
body.addChild(bodyElement);
body.addChild(fac.createOMText("\n"));
} else {
body.addChild(bodyElement);
}
}
} else {
envelope = OMAbstractFactory.getSOAP11Factory().getDefaultEnvelope();
}
synCtx.setEnvelope(envelope);
return synCtx;
}
use of org.apache.synapse.config.SynapseConfiguration in project wso2-synapse by wso2.
the class StatisticIdentityGeneratorTest method init.
@BeforeClass
public static void init() {
synapseConfiguration = new SynapseConfiguration();
StatisticIdentityGenerator.setSynapseConfiguration(synapseConfiguration);
artifactHolder = new ArtifactHolder();
ArrayList<StructuringElement> structuringElementList = new ArrayList<>();
structuringElement = new StructuringElement(COMPONENT_ID, ComponentType.ENDPOINT);
structuringElementList.add(structuringElement);
artifactHolder.setList(structuringElementList);
artifactHolder.setParent(PARENT);
artifactHolder.setHashCode(HASH_CODE);
Stack<StructuringElement> structuringElementStack = new Stack<>();
structuringElementStack.add(structuringElement);
artifactHolder.setStack(structuringElementStack);
artifactHolder.setId(0);
}
use of org.apache.synapse.config.SynapseConfiguration in project wso2-synapse by wso2.
the class MultiXMLConfigurationBuilderTest method testConfigurationBuilder.
public void testConfigurationBuilder() throws Exception {
URL u = this.getClass().getClassLoader().getResource("synapse-config");
String root = new File(u.toURI()).getAbsolutePath();
System.out.println("Using SYNAPSE_CONFIG_HOME=" + root);
SynapseConfiguration synapseConfig = MultiXMLConfigurationBuilder.getConfiguration(root, new Properties());
assertNotNull(synapseConfig.getDefinedSequences().get("main"));
assertNotNull(synapseConfig.getDefinedSequences().get("fault"));
SequenceMediator foo = synapseConfig.getDefinedSequences().get("foo");
SequenceMediator seq1 = synapseConfig.getDefinedSequences().get("synapse_xml_seq1");
assertNotNull(foo);
assertNotNull(seq1);
assertEquals("foo.xml", foo.getFileName());
assertNull(seq1.getFileName());
assertNull(synapseConfig.getDefinedSequences().get("bar"));
assertNotNull(synapseConfig.getDefinedEndpoints().get("epr1"));
assertNotNull(synapseConfig.getDefinedEndpoints().get("synapse_xml_epr1"));
assertNotNull(synapseConfig.getProxyService("proxy1"));
assertNotNull(synapseConfig.getStartup("task1"));
assertNotNull(synapseConfig.getRegistry());
assertTrue(JavaUtils.isTrueExplicitly(synapseConfig.getProperty(MultiXMLConfigurationBuilder.SEPARATE_REGISTRY_DEFINITION)));
}
Aggregations