Search in sources :

Example 61 with Mediator

use of org.apache.synapse.Mediator in project wso2-synapse by wso2.

the class RespondMediatorFactory method createSpecificMediator.

@Override
protected Mediator createSpecificMediator(OMElement elem, Properties properties) {
    Mediator responseMediator = new RespondMediator();
    processAuditStatus(responseMediator, elem);
    return responseMediator;
}
Also used : RespondMediator(org.apache.synapse.mediators.builtin.RespondMediator) RespondMediator(org.apache.synapse.mediators.builtin.RespondMediator) Mediator(org.apache.synapse.Mediator)

Example 62 with Mediator

use of org.apache.synapse.Mediator in project wso2-synapse by wso2.

the class DropMediatorFactory method createSpecificMediator.

public Mediator createSpecificMediator(OMElement el, Properties properties) {
    Mediator dropMediator = new DropMediator();
    // after successfully creating the mediator
    // set its common attributes such as tracing etc
    processAuditStatus(dropMediator, el);
    return dropMediator;
}
Also used : DropMediator(org.apache.synapse.mediators.builtin.DropMediator) Mediator(org.apache.synapse.Mediator) DropMediator(org.apache.synapse.mediators.builtin.DropMediator)

Example 63 with Mediator

use of org.apache.synapse.Mediator in project wso2-synapse by wso2.

the class CloneMediator method mediate.

public boolean mediate(MessageContext synCtx, ContinuationState continuationState) {
    SynapseLog synLog = getLog(synCtx);
    if (synLog.isTraceOrDebugEnabled()) {
        synLog.traceOrDebug("Clone mediator : Mediating from ContinuationState");
    }
    boolean result;
    int subBranch = ((ReliantContinuationState) continuationState).getSubBranch();
    SequenceMediator branchSequence = targets.get(subBranch).getSequence();
    boolean isStatisticsEnabled = RuntimeStatisticCollector.isStatisticsEnabled();
    if (!continuationState.hasChild()) {
        result = branchSequence.mediate(synCtx, continuationState.getPosition() + 1);
    } else {
        FlowContinuableMediator mediator = (FlowContinuableMediator) branchSequence.getChild(continuationState.getPosition());
        result = mediator.mediate(synCtx, continuationState.getChildContState());
        if (isStatisticsEnabled) {
            ((Mediator) mediator).reportCloseStatistics(synCtx, null);
        }
    }
    if (isStatisticsEnabled) {
        branchSequence.reportCloseStatistics(synCtx, null);
    }
    return result;
}
Also used : ReliantContinuationState(org.apache.synapse.continuation.ReliantContinuationState) SynapseLog(org.apache.synapse.SynapseLog) FlowContinuableMediator(org.apache.synapse.mediators.FlowContinuableMediator) FlowContinuableMediator(org.apache.synapse.mediators.FlowContinuableMediator) AbstractMediator(org.apache.synapse.mediators.AbstractMediator) Mediator(org.apache.synapse.Mediator) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator) Endpoint(org.apache.synapse.endpoints.Endpoint)

Example 64 with Mediator

use of org.apache.synapse.Mediator in project wso2-synapse by wso2.

the class IterateMediator method mediate.

public boolean mediate(MessageContext synCtx, ContinuationState continuationState) {
    SynapseLog synLog = getLog(synCtx);
    if (synLog.isTraceOrDebugEnabled()) {
        synLog.traceOrDebug("Iterate mediator : Mediating from ContinuationState");
    }
    boolean result;
    SequenceMediator branchSequence = target.getSequence();
    boolean isStatisticsEnabled = RuntimeStatisticCollector.isStatisticsEnabled();
    if (!continuationState.hasChild()) {
        result = branchSequence.mediate(synCtx, continuationState.getPosition() + 1);
    } else {
        FlowContinuableMediator mediator = (FlowContinuableMediator) branchSequence.getChild(continuationState.getPosition());
        result = mediator.mediate(synCtx, continuationState.getChildContState());
        if (isStatisticsEnabled) {
            ((Mediator) mediator).reportCloseStatistics(synCtx, null);
        }
    }
    if (isStatisticsEnabled) {
        branchSequence.reportCloseStatistics(synCtx, null);
    }
    return result;
}
Also used : SynapseLog(org.apache.synapse.SynapseLog) FlowContinuableMediator(org.apache.synapse.mediators.FlowContinuableMediator) FlowContinuableMediator(org.apache.synapse.mediators.FlowContinuableMediator) AbstractMediator(org.apache.synapse.mediators.AbstractMediator) Mediator(org.apache.synapse.Mediator) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator)

Example 65 with Mediator

use of org.apache.synapse.Mediator in project wso2-synapse by wso2.

the class FilterMediator method mediate.

/**
 * Executes the list of sub/child mediators, if the filter condition is satisfied
 *
 * @param synCtx the current message
 * @return true if filter condition fails. else returns as per List mediator semantics
 */
public boolean mediate(MessageContext synCtx) {
    if (synCtx.getEnvironment().isDebuggerEnabled()) {
        if (super.divertMediationRoute(synCtx)) {
            return true;
        }
    }
    SynapseLog synLog = getLog(synCtx);
    if (synLog.isTraceOrDebugEnabled()) {
        synLog.traceOrDebug("Start : Filter mediator");
        if (synLog.isTraceTraceEnabled()) {
            synLog.traceTrace("Message : " + synCtx.getEnvelope());
        }
    }
    boolean result = false;
    if (test(synCtx)) {
        if (thenKey != null) {
            if (synLog.isTraceOrDebugEnabled()) {
                synLog.traceOrDebug((xpath == null ? "Source : " + source + " against : " + regex.pattern() + " matches" : "XPath expression : " + xpath + " evaluates to true") + " - executing then sequence with key : " + thenKey);
            }
            ContinuationStackManager.updateSeqContinuationState(synCtx, getMediatorPosition());
            Mediator seq = synCtx.getSequence(thenKey);
            if (seq != null) {
                result = seq.mediate(synCtx);
            } else {
                handleException("Couldn't find the referred then sequence with key : " + thenKey, synCtx);
            }
        } else {
            if (synLog.isTraceOrDebugEnabled()) {
                synLog.traceOrDebug((xpath == null ? "Source : " + source + " against : " + regex.pattern() + " matches" : "XPath expression : " + xpath + " evaluates to true") + " - executing child mediators");
            }
            ContinuationStackManager.addReliantContinuationState(synCtx, 0, getMediatorPosition());
            result = super.mediate(synCtx);
            if (result) {
                ContinuationStackManager.removeReliantContinuationState(synCtx);
            }
        }
    } else {
        if (elseKey != null) {
            if (synLog.isTraceOrDebugEnabled()) {
                synLog.traceOrDebug((xpath == null ? "Source : " + source + " against : " + regex.pattern() + " does not match" : "XPath expression : " + xpath + " evaluates to false") + " - executing the else sequence with key : " + elseKey);
            }
            ContinuationStackManager.updateSeqContinuationState(synCtx, getMediatorPosition());
            Mediator elseSeq = synCtx.getSequence(elseKey);
            if (elseSeq != null) {
                result = elseSeq.mediate(synCtx);
            } else {
                handleException("Couldn't find the referred else sequence with key : " + elseKey, synCtx);
            }
        } else if (elseMediator != null) {
            if (synLog.isTraceOrDebugEnabled()) {
                synLog.traceOrDebug((xpath == null ? "Source : " + source + " against : " + regex.pattern() + " does not match" : "XPath expression : " + xpath + " evaluates to false") + " - executing the else path child mediators");
            }
            ContinuationStackManager.addReliantContinuationState(synCtx, 1, getMediatorPosition());
            result = elseMediator.mediate(synCtx);
            if (result) {
                ContinuationStackManager.removeReliantContinuationState(synCtx);
            }
        } else {
            if (synLog.isTraceOrDebugEnabled()) {
                synLog.traceOrDebug((xpath == null ? "Source : " + source + " against : " + regex.pattern() + " does not match" : "XPath expression : " + xpath + " evaluates to false and no else path") + " - skipping child mediators");
            }
            result = true;
        }
    }
    synLog.traceOrDebug("End : Filter mediator ");
    return result;
}
Also used : SynapseLog(org.apache.synapse.SynapseLog) ListMediator(org.apache.synapse.mediators.ListMediator) AnonymousListMediator(org.apache.synapse.config.xml.AnonymousListMediator) FlowContinuableMediator(org.apache.synapse.mediators.FlowContinuableMediator) Mediator(org.apache.synapse.Mediator) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator) AbstractListMediator(org.apache.synapse.mediators.AbstractListMediator)

Aggregations

Mediator (org.apache.synapse.Mediator)108 Properties (java.util.Properties)30 SequenceMediator (org.apache.synapse.mediators.base.SequenceMediator)24 OMElement (org.apache.axiom.om.OMElement)22 AbstractMediator (org.apache.synapse.mediators.AbstractMediator)22 MessageContext (org.apache.synapse.MessageContext)16 SynapseLog (org.apache.synapse.SynapseLog)16 FlowContinuableMediator (org.apache.synapse.mediators.FlowContinuableMediator)13 SynapseException (org.apache.synapse.SynapseException)12 TestMessageContext (org.apache.synapse.TestMessageContext)12 SynapseConfiguration (org.apache.synapse.config.SynapseConfiguration)12 Axis2SynapseEnvironment (org.apache.synapse.core.axis2.Axis2SynapseEnvironment)12 TemplateMediator (org.apache.synapse.mediators.template.TemplateMediator)12 Test (org.junit.Test)10 AbstractListMediator (org.apache.synapse.mediators.AbstractListMediator)9 SynapseSequenceType (org.apache.synapse.debug.constructs.SynapseSequenceType)8 SequenceMediationFlowPoint (org.apache.synapse.debug.constructs.SequenceMediationFlowPoint)6 ForEachMediatorFactory (org.apache.synapse.config.xml.ForEachMediatorFactory)5 MediatorFactory (org.apache.synapse.config.xml.MediatorFactory)5 MediatorFaultHandler (org.apache.synapse.mediators.MediatorFaultHandler)5