Search in sources :

Example 1 with SynapseMessageReceiver

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"));
}
Also used : SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration) URITemplateHelper(org.apache.synapse.rest.dispatch.URITemplateHelper) XSLTMediator(org.apache.synapse.mediators.transform.XSLTMediator) PropertyMediator(org.apache.synapse.mediators.builtin.PropertyMediator) Value(org.apache.synapse.mediators.Value) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator) MessageContext(org.apache.synapse.MessageContext) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext) SynapseMessageReceiver(org.apache.synapse.core.axis2.SynapseMessageReceiver) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext)

Example 2 with SynapseMessageReceiver

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()));
}
Also used : AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) SynapseException(org.apache.synapse.SynapseException) TestMediator(org.apache.synapse.mediators.TestMediator) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration) Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) TestMediateHandler(org.apache.synapse.mediators.TestMediateHandler) MessageContext(org.apache.synapse.MessageContext) SynapseMessageReceiver(org.apache.synapse.core.axis2.SynapseMessageReceiver)

Aggregations

MessageContext (org.apache.synapse.MessageContext)2 SynapseConfiguration (org.apache.synapse.config.SynapseConfiguration)2 SynapseMessageReceiver (org.apache.synapse.core.axis2.SynapseMessageReceiver)2 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)1 AxisConfiguration (org.apache.axis2.engine.AxisConfiguration)1 SynapseException (org.apache.synapse.SynapseException)1 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)1 Axis2SynapseEnvironment (org.apache.synapse.core.axis2.Axis2SynapseEnvironment)1 TestMediateHandler (org.apache.synapse.mediators.TestMediateHandler)1 TestMediator (org.apache.synapse.mediators.TestMediator)1 Value (org.apache.synapse.mediators.Value)1 SequenceMediator (org.apache.synapse.mediators.base.SequenceMediator)1 PropertyMediator (org.apache.synapse.mediators.builtin.PropertyMediator)1 XSLTMediator (org.apache.synapse.mediators.transform.XSLTMediator)1 URITemplateHelper (org.apache.synapse.rest.dispatch.URITemplateHelper)1