Search in sources :

Example 26 with TemplateMediator

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

the class SynapseConfiguration method destroy.

public synchronized void destroy(boolean preserverState) {
    if (log.isDebugEnabled()) {
        log.debug("Destroying the Synapse Configuration");
    }
    // clear the timer tasks of Synapse
    synapseTimer.cancel();
    synapseTimer = null;
    // stop and shutdown all the proxy services
    for (ProxyService p : getProxyServices()) {
        if (p.getTargetInLineInSequence() != null) {
            p.getTargetInLineInSequence().destroy();
        }
        if (p.getTargetInLineOutSequence() != null) {
            p.getTargetInLineOutSequence().destroy();
        }
    }
    // destroy the managed mediators
    for (ManagedLifecycle seq : getDefinedSequences().values()) {
        seq.destroy();
    }
    // destroy sequence templates
    for (TemplateMediator seqTemplate : getSequenceTemplates().values()) {
        seqTemplate.destroy();
    }
    // destroy inbound endpoint
    for (InboundEndpoint endpoint : getInboundEndpoints()) {
        // This path trigger from server shutdown hook. So we don't want to remove scheduled inbound tasks
        // from registry. Only un-deployment should remove task from registry. Ref product-ei#1206
        endpoint.destroy(false);
    }
    // destroy the managed endpoints
    for (Endpoint endpoint : getDefinedEndpoints().values()) {
        endpoint.destroy();
    }
    // destroy the startups
    for (ManagedLifecycle stp : startups.values()) {
        stp.destroy();
    }
    // clear session information used for SA load balancing
    try {
        SALSessions.getInstance().reset();
        DataSourceRepositoryHolder.getInstance().getDataSourceRepositoryManager().clear();
    } catch (Throwable ignored) {
    }
    // destroy the priority executors.
    for (PriorityExecutor pe : executors.values()) {
        pe.destroy();
    }
    // destroy the Message Stores
    for (MessageStore ms : messageStores.values()) {
        if (ms instanceof AbstractMessageProcessor) {
            ((AbstractMessageProcessor) ms).destroy(preserverState);
        } else {
            ms.destroy();
        }
    }
    // destroy the Message processors
    for (MessageProcessor mp : messageProcessors.values()) {
        mp.destroy();
    }
    for (API api : apiTable.values()) {
        api.destroy();
    }
}
Also used : InboundEndpoint(org.apache.synapse.inbound.InboundEndpoint) MessageStore(org.apache.synapse.message.store.MessageStore) TemplateMediator(org.apache.synapse.mediators.template.TemplateMediator) InboundEndpoint(org.apache.synapse.inbound.InboundEndpoint) Endpoint(org.apache.synapse.endpoints.Endpoint) ProxyService(org.apache.synapse.core.axis2.ProxyService) AbstractMessageProcessor(org.apache.synapse.message.processor.impl.AbstractMessageProcessor) MessageProcessor(org.apache.synapse.message.processor.MessageProcessor) AbstractMessageProcessor(org.apache.synapse.message.processor.impl.AbstractMessageProcessor) API(org.apache.synapse.rest.API) PriorityExecutor(org.apache.synapse.commons.executors.PriorityExecutor) ManagedLifecycle(org.apache.synapse.ManagedLifecycle)

Example 27 with TemplateMediator

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

the class LibraryArtifact method loadComponentsInto.

public void loadComponentsInto(SynapseLibrary library) {
    for (String artifactName : subArtifacts.keySet()) {
        LibraryArtifact artifact = subArtifacts.get(artifactName);
        if (artifact.isLeafArtifact()) {
            delegateClassLoading(artifact, library);
            // this is where actual artifact is constructed to it's ture form
            Object template = artifact.file.build();
            if (artifact.file instanceof TemplateArtifactFile) {
                if (template instanceof TemplateMediator) {
                    TemplateMediator templateMediator = (TemplateMediator) template;
                    // make template dynamic as it is not directly available to synapse environment
                    templateMediator.setDynamic(true);
                    String templateName = templateMediator.getName();
                    library.addComponent(getQualifiedName(library.getPackage(), templateName, library.getQName().getLocalPart()), template);
                } else if (template instanceof Template) {
                    String templateName = ((Template) template).getName();
                    library.addComponent(getQualifiedName(library.getPackage(), templateName, library.getQName().getLocalPart()), template);
                } else if (template != null) {
                    library.addComponent(getQualifiedName(library.getPackage(), artifact.getName(), library.getQName().getLocalPart()), template);
                } else {
                    throw new SynapseArtifactDeploymentException("Cannot load components into " + "Synapse Library. Component " + "cannot be built for " + artifactName);
                }
            }
        } else {
            artifact.loadComponentsInto(library);
        }
    }
}
Also used : TemplateMediator(org.apache.synapse.mediators.template.TemplateMediator) SynapseArtifactDeploymentException(org.apache.synapse.deployers.SynapseArtifactDeploymentException) Template(org.apache.synapse.endpoints.Template)

Example 28 with TemplateMediator

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

the class DebugManagerTest method testDebugManagerProcessCommandClearBreakPointTemplate.

public void testDebugManagerProcessCommandClearBreakPointTemplate() throws Exception {
    TestMediator t1 = new TestMediator();
    TestMediator t2 = new TestMediator();
    TestMediator t3 = new TestMediator();
    TemplateMediator temp = new TemplateMediator();
    temp.addChild(t1);
    temp.addChild(t2);
    temp.addChild(t3);
    temp.setName("test_sequence_template_2");
    synConfig.addSequenceTemplate(temp.getName(), temp);
    String debug_command = "{\"command\":\"set\",\"command-argument\":\"breakpoint\"," + "\"mediation-component\":\"template\",\"template\":{\"template-key\":\"test_sequence_template_2\"," + "\"mediator-position\": \"0\"}}";
    dm.processDebugCommand(debug_command);
    debug_command = "{\"command\":\"clear\",\"command-argument\":\"breakpoint\"," + "\"mediation-component\":\"template\",\"template\":{\"template-key\":\"test_sequence_template_2\"," + "\"mediator-position\": \"0\"}}";
    dm.processDebugCommand(debug_command);
    assertTrue(!((AbstractMediator) temp.getChild(0)).isBreakPoint());
}
Also used : TemplateMediator(org.apache.synapse.mediators.template.TemplateMediator) TestMediator(org.apache.synapse.mediators.TestMediator) AbstractMediator(org.apache.synapse.mediators.AbstractMediator)

Example 29 with TemplateMediator

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

the class DebugManagerTest method testSkipTemplate.

public void testSkipTemplate() 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_5");
    temp.setParameters(new HashSet<String>());
    synConfig.addSequenceTemplate(temp.getName(), temp);
    String debug_command = "{\"command\":\"set\",\"command-argument\":\"skip\",\"mediation-component\":\"template\"," + "\"template\":{\"template-key\":\"test_sequence_template_5\",\"mediator-position\": \"0\"}}";
    dm.processDebugCommand(debug_command);
    debug_command = "{\"command\":\"set\",\"command-argument\":\"skip\",\"mediation-component\":\"template\"," + "\"template\":{\"template-key\":\"test_sequence_template_5\",\"mediator-position\": \"1\"}}";
    dm.processDebugCommand(debug_command);
    synEnv.setDebugEnabled(true);
    MessageContextCreatorForAxis2.setSynConfig(synConfig);
    MessageContextCreatorForAxis2.setSynEnv(synEnv);
    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());
    MessageContext synCtx = MessageContextCreatorForAxis2.getSynapseMessageContext(mc);
    temp.mediate(synCtx);
    assertTrue("T3".equals(result.toString()));
    synEnv.setDebugEnabled(false);
}
Also used : AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) TestMediator(org.apache.synapse.mediators.TestMediator) TemplateMediator(org.apache.synapse.mediators.template.TemplateMediator) TestMediateHandler(org.apache.synapse.mediators.TestMediateHandler) MessageContext(org.apache.synapse.MessageContext)

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