Search in sources :

Example 6 with TemplateMediator

use of org.apache.synapse.mediators.template.TemplateMediator in project wso2-synapse by wso2.

the class DebugManagerTest method testBreakPointTemplate.

public void testBreakPointTemplate() 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.");
        }
    });
    TestMediator t3 = new TestMediator();
    t3.setHandler(new TestMediateHandler() {

        public void handle(MessageContext synCtx) {
            result.append("T3");
        }
    });
    TemplateMediator temp = new TemplateMediator();
    temp.addChild(t1);
    temp.addChild(t2);
    temp.addChild(t3);
    temp.setName("test_sequence_template_6");
    temp.setParameters(new HashSet<String>());
    synConfig.addSequenceTemplate(temp.getName(), temp);
    String debug_command = "{\"command\":\"set\",\"command-argument\":\"breakpoint\",\"mediation-component\":" + "\"template\",\"template\":{\"template-key\":\"test_sequence_template_6\",\"mediator-position\": \"0\"}}";
    dm.processDebugCommand(debug_command);
    debug_command = "{\"command\":\"set\",\"command-argument\":\"breakpoint\",\"mediation-component\":\"template\"," + "\"template\":{\"template-key\":\"test_sequence_template_6\",\"mediator-position\": \"1\"}}";
    dm.processDebugCommand(debug_command);
    MessageContext synCtx = TestUtils.getTestContext("<empty/>");
    synEnv.setDebugEnabled(false);
    temp.mediate(synCtx);
    assertTrue("T1.T2.T3".equals(result.toString()));
}
Also used : TemplateMediator(org.apache.synapse.mediators.template.TemplateMediator) TestMediateHandler(org.apache.synapse.mediators.TestMediateHandler) TestMediator(org.apache.synapse.mediators.TestMediator) MessageContext(org.apache.synapse.MessageContext)

Example 7 with TemplateMediator

use of org.apache.synapse.mediators.template.TemplateMediator in project wso2-synapse by wso2.

the class SynapseXMLConfigurationSerializerTest method testSerializeConfiguration5.

/**
 * Test serializeConfigurationMethod with TemplateMediator added for SynapseConfiguration
 * and assert OMElement returned
 */
@Test
public void testSerializeConfiguration5() {
    SynapseXMLConfigurationSerializer serializer = new SynapseXMLConfigurationSerializer();
    SynapseConfiguration synapseConfiguration = new SynapseConfiguration();
    org.apache.synapse.mediators.TestMediator t1 = new org.apache.synapse.mediators.TestMediator();
    org.apache.synapse.mediators.TestMediator t2 = new org.apache.synapse.mediators.TestMediator();
    org.apache.synapse.mediators.TestMediator t3 = new org.apache.synapse.mediators.TestMediator();
    TemplateMediator templateMediator = new TemplateMediator();
    templateMediator.addChild(t1);
    templateMediator.addChild(t2);
    templateMediator.addChild(t3);
    synapseConfiguration.addSequence("testSequence", templateMediator);
    OMElement element = serializer.serializeConfiguration(synapseConfiguration);
    Assert.assertNotNull("OMElement is not returned", element);
    Assert.assertEquals("definitions", element.getLocalName());
    Assert.assertTrue("Template added is not serialized.", element.getChildren().next().toString().contains("template"));
}
Also used : TemplateMediator(org.apache.synapse.mediators.template.TemplateMediator) OMElement(org.apache.axiom.om.OMElement) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration) Test(org.junit.Test)

Example 8 with TemplateMediator

use of org.apache.synapse.mediators.template.TemplateMediator in project wso2-synapse by wso2.

the class XMLToTemplateMapperTest method testGetObjectFromOMNodeSequence.

/**
 * Test getObjectFromOMNode by parsing a XML with sequence tag.
 *
 * @throws XMLStreamException
 */
@Test
public void testGetObjectFromOMNodeSequence() throws XMLStreamException {
    String input = "<template xmlns=\"http://ws.apache.org/ns/synapse\" name=\"" + NAME + "\">\n" + "   <sequence>\n" + "      <log level=\"full\">\n" + "         <property xmlns:ns2=\"http://org.apache.synapse/xsd\" name=\"message\" " + "expression=\"$func:message\"></property>\n" + "      </log>\n" + "   </sequence>\n" + "</template>";
    OMElement element = AXIOMUtil.stringToOM(input);
    TemplateMediator templateMediator = (TemplateMediator) mapper.getObjectFromOMNode(element, properties);
    Assert.assertEquals("name should be parsed into the element", NAME, templateMediator.getName());
}
Also used : TemplateMediator(org.apache.synapse.mediators.template.TemplateMediator) OMElement(org.apache.axiom.om.OMElement) Test(org.junit.Test)

Example 9 with TemplateMediator

use of org.apache.synapse.mediators.template.TemplateMediator in project wso2-synapse by wso2.

the class SynapseObserverTest method testSimpleObserver.

public void testSimpleObserver() {
    SynapseConfiguration synapseConfig = new SynapseConfiguration();
    synapseConfig.setAxisConfiguration(new AxisConfiguration());
    synapseConfig.registerObserver(observer);
    Endpoint epr = new AddressEndpoint();
    epr.setName("endpoint1");
    synapseConfig.addEndpoint(epr.getName(), epr);
    assertItemAdded(epr.getName(), ENDPOINT);
    synapseConfig.removeEndpoint(epr.getName());
    assertItemRemoved(epr.getName(), ENDPOINT);
    SequenceMediator seq = new SequenceMediator();
    seq.setName("sequence1");
    synapseConfig.addSequence(seq.getName(), seq);
    assertItemAdded(seq.getName(), SEQUENCE);
    synapseConfig.removeSequence(seq.getName());
    assertItemRemoved(seq.getName(), SEQUENCE);
    TemplateMediator template = new TemplateMediator();
    template.setName("template1");
    synapseConfig.addSequenceTemplate(template.getName(), template);
    assertItemAdded(template.getName(), SEQUENCE_TEMPLATE);
    synapseConfig.removeSequenceTemplate(template.getName());
    assertItemRemoved(template.getName(), SEQUENCE_TEMPLATE);
    Entry entry = new Entry();
    entry.setKey("entry1");
    synapseConfig.addEntry(entry.getKey(), entry);
    assertItemAdded(entry.getKey(), ENTRY);
    synapseConfig.removeEntry(entry.getKey());
    assertItemRemoved(entry.getKey(), ENTRY);
    ProxyService proxy = new ProxyService("proxy1");
    synapseConfig.addProxyService(proxy.getName(), proxy);
    assertItemAdded(proxy.getName(), PROXY);
    synapseConfig.removeProxyService(proxy.getName());
    assertItemRemoved(proxy.getName(), PROXY);
    Startup startup = new StartUpController();
    startup.setName("startup1");
    synapseConfig.addStartup(startup);
    assertItemAdded(startup.getName(), STARTUP);
    synapseConfig.removeStartup(startup.getName());
    assertItemRemoved(startup.getName(), STARTUP);
    SynapseEventSource eventSrc = new SynapseEventSource("eventSrc1");
    synapseConfig.addEventSource(eventSrc.getName(), eventSrc);
    assertItemAdded(eventSrc.getName(), EVENT_SRC);
    synapseConfig.removeEventSource(eventSrc.getName());
    assertItemRemoved(eventSrc.getName(), EVENT_SRC);
    PriorityExecutor exec = new PriorityExecutor();
    exec.setName("exec1");
    synapseConfig.addPriorityExecutor(exec.getName(), exec);
    assertItemAdded(exec.getName(), EXECUTOR);
    synapseConfig.removeExecutor(exec.getName());
    assertItemRemoved(exec.getName(), EXECUTOR);
}
Also used : AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) StartUpController(org.apache.synapse.startup.quartz.StartUpController) AddressEndpoint(org.apache.synapse.endpoints.AddressEndpoint) AddressEndpoint(org.apache.synapse.endpoints.AddressEndpoint) Endpoint(org.apache.synapse.endpoints.Endpoint) InboundEndpoint(org.apache.synapse.inbound.InboundEndpoint) TemplateMediator(org.apache.synapse.mediators.template.TemplateMediator) SynapseEventSource(org.apache.synapse.eventing.SynapseEventSource) ProxyService(org.apache.synapse.core.axis2.ProxyService) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator) PriorityExecutor(org.apache.synapse.commons.executors.PriorityExecutor) Startup(org.apache.synapse.Startup)

Example 10 with TemplateMediator

use of org.apache.synapse.mediators.template.TemplateMediator in project wso2-synapse by wso2.

the class TestMessageContext method getSequenceTemplate.

public Mediator getSequenceTemplate(String key) {
    Object o = localEntries.get(key);
    if (o != null && o instanceof Mediator) {
        return (Mediator) o;
    } else {
        Mediator m = getConfiguration().getSequence(key);
        if (m instanceof TemplateMediator) {
            TemplateMediator templateMediator = (TemplateMediator) m;
            synchronized (m) {
                if (!templateMediator.isInitialized()) {
                    templateMediator.init(synEnv);
                }
            }
        }
        localEntries.put(key, m);
        return m;
    }
}
Also used : TemplateMediator(org.apache.synapse.mediators.template.TemplateMediator) TemplateMediator(org.apache.synapse.mediators.template.TemplateMediator) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator)

Aggregations

TemplateMediator (org.apache.synapse.mediators.template.TemplateMediator)29 OMElement (org.apache.axiom.om.OMElement)10 Template (org.apache.synapse.endpoints.Template)9 SynapseException (org.apache.synapse.SynapseException)7 SequenceMediator (org.apache.synapse.mediators.base.SequenceMediator)7 Endpoint (org.apache.synapse.endpoints.Endpoint)6 InboundEndpoint (org.apache.synapse.inbound.InboundEndpoint)6 TestMediator (org.apache.synapse.mediators.TestMediator)6 ProxyService (org.apache.synapse.core.axis2.ProxyService)5 QName (javax.xml.namespace.QName)4 DeploymentException (org.apache.axis2.deployment.DeploymentException)4 Mediator (org.apache.synapse.Mediator)4 PriorityExecutor (org.apache.synapse.commons.executors.PriorityExecutor)4 File (java.io.File)3 Entry (org.apache.synapse.config.Entry)3 SynapseEventSource (org.apache.synapse.eventing.SynapseEventSource)3 MessageProcessor (org.apache.synapse.message.processor.MessageProcessor)3 MessageStore (org.apache.synapse.message.store.MessageStore)3 API (org.apache.synapse.rest.API)3 Test (org.junit.Test)3