use of org.apache.synapse.core.axis2.SynapseMessageReceiver in project wso2-synapse by wso2.
the class ResourceTest method testFaultSequence.
public void testFaultSequence() throws Exception {
API api = new API("TestAPI", "/test");
Resource resource = new Resource();
resource.setDispatcherHelper(new URITemplateHelper("/~{user}"));
SequenceMediator inSequence = getTestSequence("seq.in", "seq.in.value");
((PropertyMediator) inSequence.getChild(0)).setScope("axis2");
XSLTMediator xsltMediator = new XSLTMediator();
xsltMediator.setXsltKey(new Value("/bogus/key"));
inSequence.addChild(xsltMediator);
resource.setInSequence(inSequence);
SequenceMediator faultSequence = getTestSequence("seq.fault", "seq.fault.value");
((PropertyMediator) faultSequence.getChild(0)).setScope("axis2");
resource.setFaultSequence(faultSequence);
api.addResource(resource);
SynapseConfiguration synapseConfig = new SynapseConfiguration();
synapseConfig.addAPI(api.getName(), api);
synapseConfig.addSequence("main", getTestSequence("main.in", "main.value"));
MessageContext synCtx = getMessageContext(synapseConfig, false, "/test/~foo", "GET");
MessageContextCreatorForAxis2.setSynConfig(synapseConfig);
MessageContextCreatorForAxis2.setSynEnv(synCtx.getEnvironment());
org.apache.axis2.context.MessageContext mc = ((Axis2MessageContext) synCtx).getAxis2MessageContext();
mc.setConfigurationContext(((Axis2SynapseEnvironment) synCtx.getEnvironment()).getAxis2ConfigurationContext());
new SynapseMessageReceiver().receive(mc);
assertEquals("seq.in.value", mc.getProperty("seq.in"));
assertEquals("seq.fault.value", mc.getProperty("seq.fault"));
}
use of org.apache.synapse.core.axis2.SynapseMessageReceiver 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