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);
}
}
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;
}
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());
}
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());
}
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());
}
Aggregations