Search in sources :

Example 81 with SequenceMediator

use of org.apache.synapse.mediators.base.SequenceMediator in project wso2-synapse by wso2.

the class FilterMediatorTest method testFilterConditionWithThenElseKey.

public void testFilterConditionWithThenElseKey() throws Exception {
    setFilterConditionPassed(false);
    // create a new filter mediator
    FilterMediator filter = new FilterMediator();
    // set source xpath condition to //symbol
    SynapseXPath source = new SynapseXPath("//wsx:symbol");
    source.addNamespace("wsx", "http://www.webserviceX.NET/");
    filter.setSource(source);
    // set regex to MSFT
    Pattern regex = Pattern.compile("MSFT");
    filter.setRegex(regex);
    MessageContext msgCtx = TestUtils.getTestContext(REQ);
    SequenceMediator seq = new SequenceMediator();
    seq.setName("refSeq");
    seq.addChild(testMediator);
    msgCtx.getConfiguration().addSequence("refSeq", testMediator);
    filter.setElseKey("refSeq");
    // test validate mediator, with static enveope
    filter.mediate(msgCtx);
    assertTrue(filterConditionPassed);
}
Also used : SynapseXPath(org.apache.synapse.util.xpath.SynapseXPath) Pattern(java.util.regex.Pattern) MessageContext(org.apache.synapse.MessageContext) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator)

Example 82 with SequenceMediator

use of org.apache.synapse.mediators.base.SequenceMediator in project wso2-synapse by wso2.

the class ForEachMediatorTest method setUp.

protected void setUp() throws Exception {
    super.setUp();
    SynapseConfiguration synCfg = new SynapseConfiguration();
    AxisConfiguration config = new AxisConfiguration();
    testCtx = new Axis2MessageContext(new org.apache.axis2.context.MessageContext(), synCfg, new Axis2SynapseEnvironment(new ConfigurationContext(config), synCfg));
    ((Axis2MessageContext) testCtx).getAxis2MessageContext().setConfigurationContext(new ConfigurationContext(config));
    SOAPEnvelope envelope = OMAbstractFactory.getSOAP11Factory().getDefaultEnvelope();
    testCtx.setEnvelope(envelope);
    testCtx.setSoapAction("urn:test");
    SequenceMediator seqMed = new SequenceMediator();
    helperMediator = new ForEachHelperMediator();
    helperMediator.init(testCtx.getEnvironment());
    seqMed.addChild(helperMediator);
    SequenceMediator seqMedInvalid = new SequenceMediator();
    SendMediator sendMediator = new SendMediator();
    sendMediator.init(testCtx.getEnvironment());
    seqMedInvalid.addChild(sendMediator);
    testCtx.getConfiguration().addSequence("seqRef", seqMed);
    testCtx.getConfiguration().addSequence("seqRefInvalid", seqMedInvalid);
    testCtx.getConfiguration().addSequence("main", new SequenceMediator());
    testCtx.getConfiguration().addSequence("fault", new SequenceMediator());
    testCtx.setEnvelope(envelope);
}
Also used : AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) MessageContext(org.apache.synapse.MessageContext) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext)

Example 83 with SequenceMediator

use of org.apache.synapse.mediators.base.SequenceMediator in project wso2-synapse by wso2.

the class DynamicResourceTest method testDynamicSequenceLookup.

public void testDynamicSequenceLookup() throws Exception {
    System.out.println("Testing dynamic sequence lookup...");
    // Phase 1
    System.out.println("Testing basic registry lookup functionality...");
    MessageContext synCtx = TestUtils.createLightweightSynapseMessageContext("<empty/>", config);
    Mediator seq1 = synCtx.getSequence(KEY_DYNAMIC_SEQUENCE_1);
    assertNotNull(seq1);
    assertTrue(((SequenceMediator) seq1).isInitialized());
    assertEquals(1, registry.getHitCount());
    seq1.mediate(synCtx);
    assertEquals("bar", synCtx.getProperty("foo"));
    // Phase 2
    System.out.println("Testing basic sequence caching...");
    synCtx = TestUtils.createLightweightSynapseMessageContext("<empty/>", config);
    Mediator seq2 = synCtx.getSequence(KEY_DYNAMIC_SEQUENCE_1);
    assertNotNull(seq2);
    assertTrue(((SequenceMediator) seq2).isInitialized());
    assertEquals(1, registry.getHitCount());
    seq2.mediate(synCtx);
    assertEquals("bar", synCtx.getProperty("foo"));
    assertTrue(seq1 == seq2);
    // Phase 3
    System.out.println("Testing advanced sequence caching...");
    synCtx = TestUtils.createLightweightSynapseMessageContext("<empty/>", config);
    System.out.println("Waiting for the cache to expire...");
    Thread.sleep(8500L);
    Mediator seq3 = synCtx.getSequence(KEY_DYNAMIC_SEQUENCE_1);
    assertNotNull(seq3);
    assertTrue(((SequenceMediator) seq3).isInitialized());
    assertEquals(1, registry.getHitCount());
    seq3.mediate(synCtx);
    assertEquals("bar", synCtx.getProperty("foo"));
    assertTrue(seq1 == seq3);
    // Phase 4
    System.out.println("Testing sequence reloading...");
    registry.updateResource(KEY_DYNAMIC_SEQUENCE_1, TestUtils.createOMElement(DYNAMIC_SEQUENCE_2));
    System.out.println("Waiting for the cache to expire...");
    Thread.sleep(8500L);
    synCtx = TestUtils.createLightweightSynapseMessageContext("<empty/>", config);
    Mediator seq4 = synCtx.getSequence(KEY_DYNAMIC_SEQUENCE_1);
    assertNotNull(seq4);
    assertTrue(((SequenceMediator) seq4).isInitialized());
    assertEquals(2, registry.getHitCount());
    seq4.mediate(synCtx);
    assertEquals("baz", synCtx.getProperty("foo"));
    assertTrue(seq1 != seq4);
    assertTrue(!((SequenceMediator) seq1).isInitialized());
    // Phase 5
    System.out.println("Testing for non-existing sequences...");
    synCtx = TestUtils.createSynapseMessageContext("<empty/>", config);
    Mediator seq5 = synCtx.getSequence("non-existing-sequence");
    assertNull(seq5);
    System.out.println("Dynamic sequence lookup tests were successful...");
}
Also used : Mediator(org.apache.synapse.Mediator) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator) MessageContext(org.apache.synapse.MessageContext) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator)

Example 84 with SequenceMediator

use of org.apache.synapse.mediators.base.SequenceMediator in project wso2-synapse by wso2.

the class AbstractSplitMediatorTestCase method setUp.

protected void setUp() throws Exception {
    super.setUp();
    SynapseConfiguration synCfg = new SynapseConfiguration();
    AxisConfiguration config = new AxisConfiguration();
    testCtx = new Axis2MessageContext(new org.apache.axis2.context.MessageContext(), synCfg, new Axis2SynapseEnvironment(new ConfigurationContext(config), synCfg));
    ((Axis2MessageContext) testCtx).getAxis2MessageContext().setConfigurationContext(new ConfigurationContext(config));
    SOAPEnvelope envelope = OMAbstractFactory.getSOAP11Factory().getDefaultEnvelope();
    envelope.getBody().addChild(createOMElement("<original>test-split-context</original>"));
    testCtx.setEnvelope(envelope);
    testCtx.setSoapAction("urn:test");
    SequenceMediator seqMed = new SequenceMediator();
    helperMediator = new SplitTestHelperMediator();
    helperMediator.init(testCtx.getEnvironment());
    seqMed.addChild(helperMediator);
    testCtx.getConfiguration().addSequence("seqRef", seqMed);
    testCtx.getConfiguration().addSequence("main", new SequenceMediator());
    testCtx.getConfiguration().addSequence("fault", new SequenceMediator());
}
Also used : AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) MessageContext(org.apache.synapse.MessageContext) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext)

Aggregations

SequenceMediator (org.apache.synapse.mediators.base.SequenceMediator)84 Mediator (org.apache.synapse.Mediator)24 MessageContext (org.apache.synapse.MessageContext)21 SynapseConfiguration (org.apache.synapse.config.SynapseConfiguration)19 TestMediator (org.apache.synapse.mediators.TestMediator)18 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)16 Test (org.junit.Test)14 Map (java.util.Map)13 ProxyService (org.apache.synapse.core.axis2.ProxyService)13 OMElement (org.apache.axiom.om.OMElement)12 Endpoint (org.apache.synapse.endpoints.Endpoint)12 EndpointReference (org.apache.axis2.addressing.EndpointReference)11 AbstractMediator (org.apache.synapse.mediators.AbstractMediator)11 Options (org.apache.axis2.client.Options)9 InboundEndpoint (org.apache.synapse.inbound.InboundEndpoint)8 TemplateMediator (org.apache.synapse.mediators.template.TemplateMediator)8 OMAttribute (org.apache.axiom.om.OMAttribute)6 AxisConfiguration (org.apache.axis2.engine.AxisConfiguration)6 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)5 File (java.io.File)4