Search in sources :

Example 81 with Axis2SynapseEnvironment

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;
}
Also used : AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) SynapseEnvironment(org.apache.synapse.core.SynapseEnvironment) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) OMDocument(org.apache.axiom.om.OMDocument) Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) MessageContext(org.apache.synapse.MessageContext) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext)

Example 82 with Axis2SynapseEnvironment

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()));
}
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

Axis2SynapseEnvironment (org.apache.synapse.core.axis2.Axis2SynapseEnvironment)81 SynapseConfiguration (org.apache.synapse.config.SynapseConfiguration)64 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)57 AxisConfiguration (org.apache.axis2.engine.AxisConfiguration)49 SynapseEnvironment (org.apache.synapse.core.SynapseEnvironment)43 Test (org.junit.Test)38 OMElement (org.apache.axiom.om.OMElement)30 Parameter (org.apache.axis2.description.Parameter)26 MessageContext (org.apache.synapse.MessageContext)23 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)21 Properties (java.util.Properties)14 TestMessageContext (org.apache.synapse.TestMessageContext)13 Mediator (org.apache.synapse.Mediator)12 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)10 ArrayList (java.util.ArrayList)8 AddressEndpoint (org.apache.synapse.endpoints.AddressEndpoint)7 Endpoint (org.apache.synapse.endpoints.Endpoint)7 HashMap (java.util.HashMap)5 OMDocument (org.apache.axiom.om.OMDocument)4 EndpointReference (org.apache.axis2.addressing.EndpointReference)4