Search in sources :

Example 1 with TemplateMediator

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

the class TemplateDeployer method restoreSynapseArtifact.

@Override
public void restoreSynapseArtifact(String artifactName) {
    if (log.isDebugEnabled()) {
        log.debug("Restoring the Template with name : " + artifactName + " : Started");
    }
    try {
        Template st = getSynapseConfiguration().getEndpointTemplate(artifactName);
        if (st != null) {
            TemplateSerializer ts = new TemplateSerializer();
            OMElement stElem = ts.serializeEndpointTemplate(st, null);
            if (st.getFileName() != null) {
                String fileName = getServerConfigurationInformation().getSynapseXMLLocation() + File.separator + MultiXMLConfigurationBuilder.TEMPLATES_DIR + File.separator + st.getFileName();
                writeToFile(stElem, fileName);
                if (log.isDebugEnabled()) {
                    log.debug("Restoring the Endpoint Template with name : " + artifactName + " : Completed");
                }
                log.info("Template named '" + artifactName + "' has been restored");
            }
        } else {
            TemplateMediator mt = getSynapseConfiguration().getSequenceTemplate(artifactName);
            if (mt != null) {
                TemplateMediatorSerializer ts = new TemplateMediatorSerializer();
                OMElement stElem = ts.serializeMediator(null, mt);
                if (mt.getFileName() != null) {
                    String fileName = getServerConfigurationInformation().getSynapseXMLLocation() + File.separator + MultiXMLConfigurationBuilder.TEMPLATES_DIR + File.separator + st.getFileName();
                    writeToFile(stElem, fileName);
                    if (log.isDebugEnabled()) {
                        log.debug("Restoring the Sequence Template with name : " + artifactName + " : Completed");
                    }
                    log.info("Template named '" + artifactName + "' has been restored");
                }
            } else {
                handleSynapseArtifactDeploymentError("Couldn't restore the Template named '" + artifactName + "', filename cannot be found");
            }
        }
    } catch (Exception e) {
        handleSynapseArtifactDeploymentError("Restoring of the Template named '" + artifactName + "' has failed", e);
    }
}
Also used : TemplateMediator(org.apache.synapse.mediators.template.TemplateMediator) TemplateMediatorSerializer(org.apache.synapse.config.xml.TemplateMediatorSerializer) TemplateSerializer(org.apache.synapse.config.xml.endpoints.TemplateSerializer) OMElement(org.apache.axiom.om.OMElement) SynapseException(org.apache.synapse.SynapseException) DeploymentException(org.apache.axis2.deployment.DeploymentException) Template(org.apache.synapse.endpoints.Template)

Example 2 with TemplateMediator

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

the class TemplateDeployer method updateSynapseArtifact.

@Override
public String updateSynapseArtifact(OMElement artifactConfig, String fileName, String existingArtifactName, Properties properties) {
    if (log.isDebugEnabled()) {
        log.debug("Template update from file : " + fileName + " has started");
    }
    try {
        OMElement element = artifactConfig.getFirstChildWithName(new QName(SynapseConstants.SYNAPSE_NAMESPACE, "endpoint"));
        if (element != null) {
            org.apache.synapse.config.xml.endpoints.TemplateFactory templateFactory = new org.apache.synapse.config.xml.endpoints.TemplateFactory();
            Template tm = templateFactory.createEndpointTemplate(artifactConfig, properties);
            tm.setFileName(new File(fileName).getName());
            if (log.isDebugEnabled()) {
                log.debug("Endpoint Template named '" + tm.getName() + "' has been built from the file " + fileName);
            }
            Template existingSt = getSynapseConfiguration().getEndpointTemplate(existingArtifactName);
            if (existingArtifactName.equals(tm.getName())) {
                getSynapseConfiguration().updateEndpointTemplate(tm.getName(), tm);
            } else {
                getSynapseConfiguration().addEndpointTemplate(tm.getName(), tm);
                getSynapseConfiguration().removeEndpointTemplate(existingSt.getName());
                log.info("Template: " + existingArtifactName + " has been undeployed");
            }
            log.info("Template: " + tm.getName() + " has been updated from the file: " + fileName);
            return tm.getName();
        } else {
            element = artifactConfig.getFirstChildWithName(new QName(SynapseConstants.SYNAPSE_NAMESPACE, "sequence"));
            if (element != null) {
                Mediator mediator = MediatorFactoryFinder.getInstance().getMediator(artifactConfig, properties);
                if (mediator instanceof TemplateMediator) {
                    TemplateMediator tm = (TemplateMediator) mediator;
                    tm.setFileName((new File(fileName)).getName());
                    if (log.isDebugEnabled()) {
                        log.debug("Sequence Template named '" + tm.getName() + "' has been built from the file " + fileName);
                    }
                    tm.init(getSynapseEnvironment());
                    if (log.isDebugEnabled()) {
                        log.debug("Initialized the Template : " + tm.getName());
                    }
                    TemplateMediator existingSt = getSynapseConfiguration().getSequenceTemplate(existingArtifactName);
                    if (existingArtifactName.equals(tm.getName())) {
                        getSynapseConfiguration().updateSequenceTemplate(tm.getName(), tm);
                    } else {
                        getSynapseConfiguration().addSequenceTemplate(tm.getName(), tm);
                        getSynapseConfiguration().removeSequenceTemplate(existingSt.getName());
                        log.info("Template: " + existingArtifactName + " has been undeployed");
                    }
                    existingSt.destroy();
                    log.info("Template: " + tm.getName() + " has been updated from the file: " + fileName);
                    return tm.getName();
                }
            }
        }
    } catch (DeploymentException e) {
        handleSynapseArtifactDeploymentError("Error while updating the Template from the " + "file: " + fileName);
    }
    return null;
}
Also used : QName(javax.xml.namespace.QName) OMElement(org.apache.axiom.om.OMElement) Template(org.apache.synapse.endpoints.Template) TemplateMediator(org.apache.synapse.mediators.template.TemplateMediator) TemplateMediator(org.apache.synapse.mediators.template.TemplateMediator) Mediator(org.apache.synapse.Mediator) DeploymentException(org.apache.axis2.deployment.DeploymentException) File(java.io.File)

Example 3 with TemplateMediator

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

the class DebugManagerTest method testDebugManagerProcessCommandClearSkipTemplate.

public void testDebugManagerProcessCommandClearSkipTemplate() 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_4");
    synConfig.addSequenceTemplate(temp.getName(), temp);
    String debug_command = "{\"command\":\"set\",\"command-argument\":\"skip\"," + "\"mediation-component\":\"template\",\"template\":{\"template-key\":\"test_sequence_template_4\"," + "\"mediator-position\": \"0\"}}";
    dm.processDebugCommand(debug_command);
    debug_command = "{\"command\":\"clear\",\"command-argument\":\"skip\",\"mediation-component\":\"template\"," + "\"template\":{\"template-key\":\"test_sequence_template_4\",\"mediator-position\": \"0\"}}";
    dm.processDebugCommand(debug_command);
    assertTrue(!((AbstractMediator) temp.getChild(0)).isSkipEnabled());
}
Also used : TemplateMediator(org.apache.synapse.mediators.template.TemplateMediator) TestMediator(org.apache.synapse.mediators.TestMediator) AbstractMediator(org.apache.synapse.mediators.AbstractMediator)

Example 4 with TemplateMediator

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

the class DebugManagerTest method testDebugManagerProcessCommandSetSkipTemplate.

public void testDebugManagerProcessCommandSetSkipTemplate() 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_3");
    synConfig.addSequenceTemplate(temp.getName(), temp);
    String debug_command = "{\"command\":\"set\",\"command-argument\":\"skip\"," + "\"mediation-component\":\"template\",\"template\":{\"template-key\":\"test_sequence_template_3\"," + "\"mediator-position\": \"0\"}}";
    dm.processDebugCommand(debug_command);
    assertTrue(((AbstractMediator) temp.getChild(0)).isSkipEnabled());
}
Also used : TemplateMediator(org.apache.synapse.mediators.template.TemplateMediator) TestMediator(org.apache.synapse.mediators.TestMediator)

Example 5 with TemplateMediator

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

the class DebugManagerTest method testDebugManagerProcessCommandSetBreakPointTemplate.

public void testDebugManagerProcessCommandSetBreakPointTemplate() 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_1");
    synConfig.addSequenceTemplate(temp.getName(), temp);
    String debug_command = "{\"command\":\"set\",\"command-argument\":\"breakpoint\"," + "\"mediation-component\":\"template\",\"template\":{\"template-key\":\"test_sequence_template_1\"," + "\"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)

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