use of org.apache.synapse.mediators.base.SequenceMediator in project wso2-synapse by wso2.
the class SequenceDeployer method updateSynapseArtifact.
@Override
public String updateSynapseArtifact(OMElement artifactConfig, String fileName, String existingArtifactName, Properties properties) {
Mediator m = MediatorFactoryFinder.getInstance().getMediator(artifactConfig, properties);
CustomLogSetter.getInstance().setLogAppender((m != null) ? ((SequenceMediator) m).getArtifactContainerName() : "");
if (log.isDebugEnabled()) {
log.debug("Sequence update from file : " + fileName + " has started");
}
try {
if (m == null || !(m instanceof SequenceMediator)) {
handleSynapseArtifactDeploymentError("Sequence update failed. The artifact " + "defined in the file: " + fileName + " is not a valid sequence.");
return null;
}
SequenceMediator seq = (SequenceMediator) m;
seq.setFileName(new File(fileName).getName());
if ((SynapseConstants.MAIN_SEQUENCE_KEY.equals(existingArtifactName) || SynapseConstants.FAULT_SEQUENCE_KEY.equals(existingArtifactName)) && !existingArtifactName.equals(seq.getName())) {
handleSynapseArtifactDeploymentError(existingArtifactName + " sequence cannot be renamed");
}
if (log.isDebugEnabled()) {
log.debug("Sequence: " + seq.getName() + " has been built from the file: " + fileName);
}
seq.init(getSynapseEnvironment());
SequenceMediator existingSeq = getSynapseConfiguration().getDefinedSequences().get(existingArtifactName);
if (existingArtifactName.equals(seq.getName())) {
getSynapseConfiguration().updateSequence(existingArtifactName, seq);
} else {
getSynapseConfiguration().addSequence(seq.getName(), seq);
getSynapseConfiguration().removeSequence(existingArtifactName);
log.info("Sequence: " + existingArtifactName + " has been undeployed");
}
log.info("Sequence: " + seq.getName() + " has been updated from the file: " + fileName);
// Give some time for worker threads to release the old sequence
waitForCompletion();
existingSeq.destroy();
return seq.getName();
} catch (DeploymentException e) {
handleSynapseArtifactDeploymentError("Error while updating the sequence from the " + "file: " + fileName);
}
return null;
}
use of org.apache.synapse.mediators.base.SequenceMediator in project wso2-synapse by wso2.
the class SequenceDeployer method restoreSynapseArtifact.
@Override
public void restoreSynapseArtifact(String artifactName) {
if (log.isDebugEnabled()) {
log.debug("Restoring the Sequence with name : " + artifactName + " : Started");
}
try {
SequenceMediator seq = getSynapseConfiguration().getDefinedSequences().get(artifactName);
CustomLogSetter.getInstance().setLogAppender((seq != null) ? seq.getArtifactContainerName() : "");
OMElement seqElem = MediatorSerializerFinder.getInstance().getSerializer(seq).serializeMediator(null, seq);
if (seq.getFileName() != null) {
String fileName = getServerConfigurationInformation().getSynapseXMLLocation() + File.separator + MultiXMLConfigurationBuilder.SEQUENCES_DIR + File.separator + seq.getFileName();
writeToFile(seqElem, fileName);
if (log.isDebugEnabled()) {
log.debug("Restoring the Sequence with name : " + artifactName + " : Completed");
}
log.info("Sequence named '" + artifactName + "' has been restored");
} else {
handleSynapseArtifactDeploymentError("Couldn't restore the sequence named '" + artifactName + "', filename cannot be found");
}
} catch (Exception e) {
handleSynapseArtifactDeploymentError("Restoring of the sequence named '" + artifactName + "' has failed", e);
}
}
use of org.apache.synapse.mediators.base.SequenceMediator in project wso2-synapse by wso2.
the class RESTMediationTestCase method getTestSequence.
protected SequenceMediator getTestSequence(String name, String value) {
SequenceMediator seq = new SequenceMediator();
PropertyMediator prop = new PropertyMediator();
prop.setName(name);
prop.setValue(value);
seq.addChild(prop);
return seq;
}
use of org.apache.synapse.mediators.base.SequenceMediator in project wso2-synapse by wso2.
the class ProxyServiceTest method testRegisterFaultHandler.
/**
* Tests if the correct fault handler is set when a fault handler is not explicitly set, and when set by using
* targetFaultSequence and targetInlineFaultSequence properties of the proxy.
*/
public void testRegisterFaultHandler() {
ProxyService proxyService = new ProxyService("TestRegisterFaultHandlerProxy");
MessageContext messageContext = new TestMessageContext();
SynapseConfiguration synCfg = new SynapseConfiguration();
messageContext.setConfiguration(synCfg);
SequenceMediator faultMediator = new SequenceMediator();
synCfg.addSequence("fault", faultMediator);
// test if the default fault proxy set in the message context is returned when a fault sequence is not
// explicitly set
faultMediator.setName("defaultFault");
proxyService.registerFaultHandler(messageContext);
String faultMediatorName = ((SequenceMediator) ((MediatorFaultHandler) messageContext.getFaultStack().pop()).getFaultMediator()).getName();
Assert.assertEquals("Incorrect fault handler set: " + faultMediatorName, "defaultFault", faultMediatorName);
// tests the functionality when the fault sequence is set in line in the target
faultMediator.setName("targetInLineFaultSequenceMediator");
proxyService.setTargetInLineFaultSequence(faultMediator);
proxyService.registerFaultHandler(messageContext);
faultMediatorName = ((SequenceMediator) ((MediatorFaultHandler) messageContext.getFaultStack().pop()).getFaultMediator()).getName();
Assert.assertEquals("Incorrect fault handler set: " + faultMediatorName, "targetInLineFaultSequenceMediator", faultMediatorName);
// tests the functionality when the fault sequence is set separately in the target
AxisConfiguration axisCfg = new AxisConfiguration();
SynapseEnvironment synEnv = new Axis2SynapseEnvironment(new ConfigurationContext(axisCfg), synCfg);
messageContext.setEnvironment(synEnv);
proxyService.setTargetFaultSequence("targetFaultSequence");
// when the message context does not have the correct fault sequence specified as the target fault sequence
faultMediator.setName("defaultFaultMediator");
proxyService.registerFaultHandler(messageContext);
faultMediatorName = ((SequenceMediator) ((MediatorFaultHandler) messageContext.getFaultStack().pop()).getFaultMediator()).getName();
Assert.assertEquals("Incorrect fault handler set: " + faultMediatorName, "defaultFaultMediator", faultMediatorName);
// when the message context has the correct fault sequence specified as the target fault sequence
faultMediator.setName("targetFaultSequenceMediator");
synCfg.addSequence("targetFaultSequence", faultMediator);
proxyService.registerFaultHandler(messageContext);
faultMediatorName = ((SequenceMediator) ((MediatorFaultHandler) messageContext.getFaultStack().pop()).getFaultMediator()).getName();
Assert.assertEquals("Incorrect fault handler set: " + faultMediatorName, "targetFaultSequenceMediator", faultMediatorName);
}
use of org.apache.synapse.mediators.base.SequenceMediator in project wso2-synapse by wso2.
the class DebugManagerTest method testDebugManagerProcessCommandSetSkipInboundErrorSequence.
public void testDebugManagerProcessCommandSetSkipInboundErrorSequence() throws Exception {
InboundEndpoint inboundEndpoint = new InboundEndpoint();
inboundEndpoint.setName("test_inbound_4");
TestMediator in1 = new TestMediator();
TestMediator in2 = new TestMediator();
TestMediator in3 = new TestMediator();
SequenceMediator dispatchSeq = new SequenceMediator();
dispatchSeq.addChild(in1);
dispatchSeq.addChild(in2);
dispatchSeq.addChild(in3);
TestMediator out1 = new TestMediator();
TestMediator out2 = new TestMediator();
TestMediator out3 = new TestMediator();
SequenceMediator errorSeq = new SequenceMediator();
errorSeq.addChild(out1);
errorSeq.addChild(out2);
errorSeq.addChild(out3);
synConfig.addSequence("dispatch_4", dispatchSeq);
inboundEndpoint.setInjectingSeq("dispatch_4");
synConfig.addSequence("error_4", errorSeq);
inboundEndpoint.setOnErrorSeq("error_4");
synConfig.addInboundEndpoint(inboundEndpoint.getName(), inboundEndpoint);
String debug_command = "{\"command\":\"set\",\"command-argument\":\"skip\",\"mediation-component\":\"sequence\"," + "\"sequence\":{\"inbound\":{\"inbound-key\":\"test_inbound_4\",\"sequence-type\":\"inbound_faultseq\",\"mediator-position\":\"0\"}}}";
dm.processDebugCommand(debug_command);
assertTrue(((AbstractMediator) errorSeq.getChild(0)).isSkipEnabled());
}
Aggregations