use of org.apache.synapse.core.axis2.Axis2SynapseEnvironment in project wso2-synapse by wso2.
the class TestUtils method createSynapseMessageContext.
public static MessageContext createSynapseMessageContext(String payload, SynapseConfiguration config) throws Exception {
org.apache.axis2.context.MessageContext mc = new org.apache.axis2.context.MessageContext();
AxisConfiguration axisConfig = config.getAxisConfiguration();
if (axisConfig == null) {
axisConfig = new AxisConfiguration();
config.setAxisConfiguration(axisConfig);
}
ConfigurationContext cfgCtx = new ConfigurationContext(axisConfig);
SynapseEnvironment env = new Axis2SynapseEnvironment(cfgCtx, 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;
}
use of org.apache.synapse.core.axis2.Axis2SynapseEnvironment in project wso2-synapse by wso2.
the class SequenceMediatorTest method testErrorHandling.
public void testErrorHandling() throws Exception {
TestMediator t1 = new TestMediator();
t1.setHandler(new TestMediateHandler() {
public void handle(MessageContext synCtx) {
result.append("T1.");
}
});
TestMediator t2 = new TestMediator();
t2.setHandler(new TestMediateHandler() {
public void handle(MessageContext synCtx) {
result.append("T2.");
throw new SynapseException("test");
}
});
TestMediator t3 = new TestMediator();
t3.setHandler(new TestMediateHandler() {
public void handle(MessageContext synCtx) {
result.append("T3.");
}
});
TestMediator t4 = new TestMediator();
t4.setHandler(new TestMediateHandler() {
public void handle(MessageContext synCtx) {
result.append("T4");
assertEquals("test", synCtx.getProperty(SynapseConstants.ERROR_MESSAGE));
}
});
SequenceMediator seq = new SequenceMediator();
seq.addChild(t1);
seq.addChild(t2);
seq.addChild(t3);
seq.setErrorHandler("myErrorHandler");
SequenceMediator seqErr = new SequenceMediator();
seqErr.setName("myErrorHandler");
seqErr.addChild(t4);
// invoke transformation, with static enveope
SynapseConfiguration synConfig = new SynapseConfiguration();
synConfig.addSequence("myErrorHandler", seqErr);
synConfig.addSequence(SynapseConstants.MAIN_SEQUENCE_KEY, seq);
MessageContextCreatorForAxis2.setSynConfig(synConfig);
MessageContextCreatorForAxis2.setSynEnv(new Axis2SynapseEnvironment(synConfig));
org.apache.axis2.context.MessageContext mc = new org.apache.axis2.context.MessageContext();
AxisConfiguration axisConfig = synConfig.getAxisConfiguration();
if (axisConfig == null) {
axisConfig = new AxisConfiguration();
synConfig.setAxisConfiguration(axisConfig);
}
ConfigurationContext cfgCtx = new ConfigurationContext(axisConfig);
mc.setConfigurationContext(cfgCtx);
mc.setEnvelope(TestUtils.getTestContext("<empty/>").getEnvelope());
new SynapseMessageReceiver().receive(mc);
assertTrue("T1.T2.T4".equals(result.toString()));
}
Aggregations