Search in sources :

Example 31 with Mediator

use of org.apache.synapse.Mediator in project wso2-synapse by wso2.

the class AnnotatedCommandMediatorTest method testBasicExecute.

public void testBasicExecute() throws Exception {
    AnnotatedCommandMediator m = new AnnotatedCommandMediator();
    m.setCommand(AnnotatedCommand.class);
    Mediator pcm = MediatorFactoryFinder.getInstance().getMediator(createOMElement("<annotatedCommand name='org.apache.synapse.mediators.ext.AnnotatedCommand2' xmlns='http://ws.apache.org/ns/synapse'/>"), new Properties());
    MessageContext mc = TestUtils.getTestContext("<m:getQuote xmlns:m=\"http://services.samples/xsd\"><m:request><m:symbol>IBM</m:symbol></m:request></m:getQuote>");
    pcm.mediate(mc);
    assertEquals("IBM", AnnotatedCommand2.fieldResult);
    assertEquals("IBM", AnnotatedCommand2.methodResult);
}
Also used : Mediator(org.apache.synapse.Mediator) MessageContext(org.apache.synapse.MessageContext) Properties(java.util.Properties)

Example 32 with Mediator

use of org.apache.synapse.Mediator in project wso2-synapse by wso2.

the class ClassMediatorTest method testInitializationAndMedition.

public void testInitializationAndMedition() throws Exception {
    Mediator cm = MediatorFactoryFinder.getInstance().getMediator(createOMElement("<class name='org.apache.synapse.mediators.ext.ClassMediatorTestMediator' " + "xmlns='http://ws.apache.org/ns/synapse'/>"), new Properties());
    ((ManagedLifecycle) cm).init(new Axis2SynapseEnvironment(new SynapseConfiguration()));
    assertTrue(ClassMediatorTestMediator.initialized);
    TestMessageContext msgContext = new TestMessageContext();
    msgContext.setEnvironment(new Axis2SynapseEnvironment(new SynapseConfiguration()));
    cm.mediate(msgContext);
    assertTrue(ClassMediatorTestMediator.invoked);
}
Also used : Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) TestMessageContext(org.apache.synapse.TestMessageContext) Mediator(org.apache.synapse.Mediator) Properties(java.util.Properties) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration) ManagedLifecycle(org.apache.synapse.ManagedLifecycle)

Example 33 with Mediator

use of org.apache.synapse.Mediator in project wso2-synapse by wso2.

the class ClassMediatorTest method testMediationWithLiteralProperties.

public void testMediationWithLiteralProperties() throws Exception {
    Mediator cm = MediatorFactoryFinder.getInstance().getMediator(createOMElement("<class name='org.apache.synapse.mediators.ext.ClassMediatorTestMediator' " + "xmlns='http://ws.apache.org/ns/synapse'><property name='testProp' value='testValue'/></class>"), new Properties());
    TestMessageContext msgContext = new TestMessageContext();
    msgContext.setEnvironment(new Axis2SynapseEnvironment(new SynapseConfiguration()));
    cm.mediate(msgContext);
    assertTrue(ClassMediatorTestMediator.invoked);
    assertTrue(ClassMediatorTestMediator.testProp.equals("testValue"));
}
Also used : Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) TestMessageContext(org.apache.synapse.TestMessageContext) Mediator(org.apache.synapse.Mediator) Properties(java.util.Properties) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration)

Example 34 with Mediator

use of org.apache.synapse.Mediator in project wso2-synapse by wso2.

the class SEDAMediator method init.

public void init(SynapseEnvironment se) {
    Mediator mediator = se.getSynapseConfiguration().getSequence(consumer);
    sedaQueue = new SEDAQueue(sedaQueuePolicy, new SEDAQueueConsumerWorkerFactory(sedaQueueConsumerPolicy, new DefaultConsumer(mediator)));
    sedaQueueProducer = new SEDAQueueProducer(sedaQueueProducerPolicy, sedaQueue);
    sedaQueue.init();
    initialized = true;
}
Also used : AbstractMediator(org.apache.synapse.mediators.AbstractMediator) Mediator(org.apache.synapse.Mediator)

Example 35 with Mediator

use of org.apache.synapse.Mediator in project wso2-synapse by wso2.

the class AbstractTestCase method serialization.

protected boolean serialization(String inputXml, MediatorFactory mediatorFactory, MediatorSerializer mediatorSerializer) {
    OMElement inputOM = createOMElement(inputXml);
    Mediator mediator = mediatorFactory.createMediator(inputOM, new Properties());
    OMElement resultOM = mediatorSerializer.serializeMediator(null, mediator);
    try {
        assertXMLEqual(resultOM.toString(), inputXml);
        return true;
    } catch (SAXException e) {
        log.error(e);
    } catch (IOException e) {
        log.error(e);
    }
    return false;
}
Also used : OMElement(org.apache.axiom.om.OMElement) Mediator(org.apache.synapse.Mediator) IOException(java.io.IOException) Properties(java.util.Properties) SAXException(org.xml.sax.SAXException)

Aggregations

Mediator (org.apache.synapse.Mediator)108 Properties (java.util.Properties)30 SequenceMediator (org.apache.synapse.mediators.base.SequenceMediator)24 OMElement (org.apache.axiom.om.OMElement)22 AbstractMediator (org.apache.synapse.mediators.AbstractMediator)22 MessageContext (org.apache.synapse.MessageContext)16 SynapseLog (org.apache.synapse.SynapseLog)16 FlowContinuableMediator (org.apache.synapse.mediators.FlowContinuableMediator)13 SynapseException (org.apache.synapse.SynapseException)12 TestMessageContext (org.apache.synapse.TestMessageContext)12 SynapseConfiguration (org.apache.synapse.config.SynapseConfiguration)12 Axis2SynapseEnvironment (org.apache.synapse.core.axis2.Axis2SynapseEnvironment)12 TemplateMediator (org.apache.synapse.mediators.template.TemplateMediator)12 Test (org.junit.Test)10 AbstractListMediator (org.apache.synapse.mediators.AbstractListMediator)9 SynapseSequenceType (org.apache.synapse.debug.constructs.SynapseSequenceType)8 SequenceMediationFlowPoint (org.apache.synapse.debug.constructs.SequenceMediationFlowPoint)6 ForEachMediatorFactory (org.apache.synapse.config.xml.ForEachMediatorFactory)5 MediatorFactory (org.apache.synapse.config.xml.MediatorFactory)5 MediatorFaultHandler (org.apache.synapse.mediators.MediatorFaultHandler)5