Search in sources :

Example 6 with SequenceMediator

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;
}
Also used : Mediator(org.apache.synapse.Mediator) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator) DeploymentException(org.apache.axis2.deployment.DeploymentException) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator) File(java.io.File)

Example 7 with SequenceMediator

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);
    }
}
Also used : OMElement(org.apache.axiom.om.OMElement) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator) DeploymentException(org.apache.axis2.deployment.DeploymentException)

Example 8 with SequenceMediator

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;
}
Also used : PropertyMediator(org.apache.synapse.mediators.builtin.PropertyMediator) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator)

Example 9 with SequenceMediator

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);
}
Also used : AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) MediatorFaultHandler(org.apache.synapse.mediators.MediatorFaultHandler) TestMessageContext(org.apache.synapse.TestMessageContext) SynapseEnvironment(org.apache.synapse.core.SynapseEnvironment) MessageContext(org.apache.synapse.MessageContext) TestMessageContext(org.apache.synapse.TestMessageContext) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration)

Example 10 with SequenceMediator

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());
}
Also used : InboundEndpoint(org.apache.synapse.inbound.InboundEndpoint) TestMediator(org.apache.synapse.mediators.TestMediator) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator)

Aggregations

SequenceMediator (org.apache.synapse.mediators.base.SequenceMediator)70 TestMediator (org.apache.synapse.mediators.TestMediator)18 OMElement (org.apache.axiom.om.OMElement)12 ProxyService (org.apache.synapse.core.axis2.ProxyService)12 Endpoint (org.apache.synapse.endpoints.Endpoint)12 Mediator (org.apache.synapse.Mediator)11 AbstractMediator (org.apache.synapse.mediators.AbstractMediator)11 MessageContext (org.apache.synapse.MessageContext)9 TemplateMediator (org.apache.synapse.mediators.template.TemplateMediator)8 SynapseConfiguration (org.apache.synapse.config.SynapseConfiguration)7 InboundEndpoint (org.apache.synapse.inbound.InboundEndpoint)7 OMAttribute (org.apache.axiom.om.OMAttribute)6 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)6 AxisConfiguration (org.apache.axis2.engine.AxisConfiguration)6 File (java.io.File)4 ManagedLifecycle (org.apache.synapse.ManagedLifecycle)4 SynapseException (org.apache.synapse.SynapseException)4 SynapseLog (org.apache.synapse.SynapseLog)4 QName (javax.xml.namespace.QName)3 OMNode (org.apache.axiom.om.OMNode)3