use of org.apache.synapse.config.SynapseConfiguration in project wso2-synapse by wso2.
the class SynapseXMLConfigurationSerializerTest method testSerializeConfiguration8.
/**
* Test serializeConfigurationMethod with startUp added for SynapseConfiguration and assert OMElement returned
*/
@Test
public void testSerializeConfiguration8() {
SynapseXMLConfigurationSerializer serializer = new SynapseXMLConfigurationSerializer();
SynapseConfiguration synapseConfiguration = new SynapseConfiguration();
StartUpController startup = new StartUpController();
startup.setName("testStartup");
TaskDescription taskDescription = new TaskDescription();
taskDescription.setName("testTask");
startup.setTaskDescription(taskDescription);
synapseConfiguration.addStartup(startup);
OMElement element = serializer.serializeConfiguration(synapseConfiguration);
Assert.assertNotNull("OMElement is not returned", element);
Assert.assertEquals("definitions", element.getLocalName());
Assert.assertTrue("StartUp added is not serialized.", element.getChildren().next().toString().contains("name=\"testTask\""));
}
use of org.apache.synapse.config.SynapseConfiguration in project wso2-synapse by wso2.
the class SynapseXMLConfigurationSerializerTest method testSerializeConfiguration3.
/**
* Test serializeConfigurationMethod with taskManager set for SynapseConfiguration and assert OMElement returned
*/
@Test
public void testSerializeConfiguration3() {
SynapseXMLConfigurationSerializer serializer = new SynapseXMLConfigurationSerializer();
SynapseConfiguration synapseConfiguration = new SynapseConfiguration();
synapseConfiguration.setTaskManager(new QuartzTaskManager());
OMElement element = serializer.serializeConfiguration(synapseConfiguration);
Assert.assertNotNull("OMElement is not returned", element);
Assert.assertEquals("definitions", element.getLocalName());
Assert.assertTrue("TaskManager added is not serialized.", element.getChildren().next().toString().contains("taskManager"));
}
use of org.apache.synapse.config.SynapseConfiguration in project wso2-synapse by wso2.
the class ResolvingEndpoint method loadAndInitEndpoint.
public Endpoint loadAndInitEndpoint(ConfigurationContext cc, String key) {
Parameter parameter = cc.getAxisConfiguration().getParameter(SynapseConstants.SYNAPSE_CONFIG);
Parameter synEnvParameter = cc.getAxisConfiguration().getParameter(SynapseConstants.SYNAPSE_ENV);
if (parameter.getValue() instanceof SynapseConfiguration && synEnvParameter.getValue() instanceof SynapseEnvironment) {
SynapseConfiguration synCfg = (SynapseConfiguration) parameter.getValue();
SynapseEnvironment synapseEnvironment = (SynapseEnvironment) synEnvParameter.getValue();
if (log.isDebugEnabled()) {
log.debug("Loading real endpoint with key : " + key);
}
Endpoint ep = synCfg.getEndpoint(key);
if (ep != null && !ep.isInitialized()) {
synchronized (ep) {
if (!ep.isInitialized()) {
ep.init(synapseEnvironment);
}
}
}
return ep;
}
return null;
}
use of org.apache.synapse.config.SynapseConfiguration in project wso2-synapse by wso2.
the class ThrottleMediatorTest method testMediateWithXForwardedHeader.
/**
* Test the XForwarded header based throttling.
* @throws Exception
*/
public void testMediateWithXForwardedHeader() throws Exception {
ByteArrayInputStream in = null;
try {
in = new ByteArrayInputStream(NEW_POLICY.getBytes());
StAXOMBuilder build = new StAXOMBuilder(in);
ThrottleTestMediator throttleMediator = new ThrottleTestMediator();
throttleMediator.setInLinePolicy(build.getDocumentElement());
MessageContext synCtx = createLightweightSynapseMessageContext("<empty/>");
synCtx.setProperty(REMOTE_ADDR, "192.168.5.500");
Map<String, String> headers = new TreeMap<String, String>(new Comparator<String>() {
public int compare(String o1, String o2) {
return o1.compareToIgnoreCase(o2);
}
});
headers.put(NhttpConstants.HEADER_X_FORWARDED_FOR, "192.168..215");
SynapseConfiguration synCfg = new SynapseConfiguration();
synCtx.setConfiguration(synCfg);
for (int i = 0; i < 6; i++) {
try {
throttleMediator.mediate(synCtx);
Thread.sleep(1000);
} catch (Exception e) {
if (i == 3 || i == 4 || i == 5) {
assertTrue("X-forwarded header based throttling failed", e.getMessage().lastIndexOf("IP_BASE") > 0);
}
}
}
} finally {
if (in != null) {
in.close();
}
}
}
use of org.apache.synapse.config.SynapseConfiguration in project wso2-synapse by wso2.
the class ThrottleMediatorTest method createLightweightSynapseMessageContext.
public static MessageContext createLightweightSynapseMessageContext(String payload) throws Exception {
org.apache.axis2.context.MessageContext mc = new org.apache.axis2.context.MessageContext();
SynapseConfiguration config = new SynapseConfiguration();
SynapseEnvironment env = new Axis2SynapseEnvironment(config);
MessageContext synMc = new Axis2MessageContext(mc, config, env);
SOAPEnvelope envelope = OMAbstractFactory.getSOAP11Factory().getDefaultEnvelope();
OMDocument omDoc = OMAbstractFactory.getSOAP11Factory().createOMDocument();
omDoc.addChild(envelope);
envelope.getBody().addChild(createOMElement(payload));
synMc.setEnvelope(envelope);
return synMc;
}
Aggregations