Search in sources :

Example 1 with Mediator

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

the class EnqueueMediator method mediate.

public boolean mediate(MessageContext synCtx) {
    if (synCtx.getEnvironment().isDebuggerEnabled()) {
        if (super.divertMediationRoute(synCtx)) {
            return true;
        }
    }
    SynapseLog log = getLog(synCtx);
    if (log.isTraceOrDebugEnabled()) {
        log.traceOrDebug("Start: enqueue mediator");
    }
    assert executorName != null : "executor name shouldn't be null";
    PriorityExecutor executor = synCtx.getConfiguration().getPriorityExecutors().get(executorName);
    if (executor == null) {
        log.auditWarn("Cannot find executor " + executorName + ". Using existing thread for mediation");
        Mediator m = synCtx.getSequence(sequenceName);
        if (m != null && m instanceof SequenceMediator) {
            return m.mediate(synCtx);
        } else {
            handleException("Sequence cannot be found : " + sequenceName, synCtx);
            return false;
        }
    }
    Mediator m = synCtx.getSequence(sequenceName);
    if (m != null && m instanceof SequenceMediator) {
        MediatorWorker worker = new MediatorWorker(m, synCtx);
        try {
            // execute with the given priority
            executor.execute(worker, priority);
        } catch (RejectedExecutionException ex) {
            // if RejectedExecutionException, jump to fault handler
            handleException("Unable to process message in priority executor " + executorName + " with priority " + priority + ". Thread pool exhausted.", synCtx);
        }
        // with the nio transport, this causes the listener not to write a 202
        // Accepted response, as this implies that Synapse does not yet know if
        // a 202 or 200 response would be written back.
        ((Axis2MessageContext) synCtx).getAxis2MessageContext().getOperationContext().setProperty(org.apache.axis2.Constants.RESPONSE_WRITTEN, "SKIP");
        if (log.isTraceOrDebugEnabled()) {
            log.traceOrDebug("End: enqueue mediator");
        }
        return true;
    } else {
        handleException("Sequence cannot be found : " + sequenceName, synCtx);
        return false;
    }
}
Also used : SynapseLog(org.apache.synapse.SynapseLog) 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) PriorityExecutor(org.apache.synapse.commons.executors.PriorityExecutor) MediatorWorker(org.apache.synapse.mediators.MediatorWorker) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext)

Example 2 with Mediator

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

the class ValidateMediator method mediate.

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

Example 3 with Mediator

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

the class FilterMediator method mediate.

public boolean mediate(MessageContext synCtx, ContinuationState continuationState) {
    SynapseLog synLog = getLog(synCtx);
    if (synLog.isTraceOrDebugEnabled()) {
        synLog.traceOrDebug("Filter mediator : Mediating from ContinuationState");
    }
    boolean result;
    int subBranch = ((ReliantContinuationState) continuationState).getSubBranch();
    boolean isStatisticsEnabled = RuntimeStatisticCollector.isStatisticsEnabled();
    if (subBranch == 0) {
        if (!continuationState.hasChild()) {
            result = super.mediate(synCtx, continuationState.getPosition() + 1);
        } else {
            FlowContinuableMediator mediator = (FlowContinuableMediator) getChild(continuationState.getPosition());
            result = mediator.mediate(synCtx, continuationState.getChildContState());
            if (isStatisticsEnabled) {
                ((Mediator) mediator).reportCloseStatistics(synCtx, null);
            }
        }
    } else {
        if (!continuationState.hasChild()) {
            result = elseMediator.mediate(synCtx, continuationState.getPosition() + 1);
        } else {
            FlowContinuableMediator mediator = (FlowContinuableMediator) elseMediator.getChild(continuationState.getPosition());
            result = mediator.mediate(synCtx, continuationState.getChildContState());
            if (isStatisticsEnabled) {
                ((Mediator) mediator).reportCloseStatistics(synCtx, null);
            }
        }
        if (isStatisticsEnabled) {
            elseMediator.reportCloseStatistics(synCtx, null);
        }
    }
    return result;
}
Also used : ReliantContinuationState(org.apache.synapse.continuation.ReliantContinuationState) SynapseLog(org.apache.synapse.SynapseLog) FlowContinuableMediator(org.apache.synapse.mediators.FlowContinuableMediator) 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)

Example 4 with Mediator

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

the class FailoverForwardingService method sendThroughFaultSeq.

/**
 * Sending the out message through the fault sequence.
 *
 * @param msgCtx Synapse {@link MessageContext} to be sent through the fault
 *               sequence.
 */
public void sendThroughFaultSeq(MessageContext msgCtx) {
    if (faultSeq == null) {
        log.warn("Failed to send the message through the fault sequence. Sequence name does not Exist.");
        return;
    }
    Mediator mediator = msgCtx.getSequence(faultSeq);
    if (mediator == null) {
        log.warn("Failed to send the message through the fault sequence. Sequence [" + faultSeq + "] does not Exist.");
        return;
    }
    mediator.mediate(msgCtx);
}
Also used : Mediator(org.apache.synapse.Mediator)

Example 5 with Mediator

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

the class FailoverForwardingService method sendThroughDeactivateSeq.

/**
 * Sending the out message through the deactivate sequence.
 *
 * @param msgCtx Synapse {@link MessageContext} to be sent through the deactivate
 *               sequence.
 */
public void sendThroughDeactivateSeq(MessageContext msgCtx) {
    if (deactivateSeq == null) {
        log.warn("Failed to send the message through the deactivate sequence. Sequence name does not Exist.");
        return;
    }
    Mediator mediator = msgCtx.getSequence(deactivateSeq);
    if (mediator == null) {
        log.warn("Failed to send the message through the deactivate sequence. Sequence [" + deactivateSeq + "] does not Exist.");
        return;
    }
    mediator.mediate(msgCtx);
}
Also used : Mediator(org.apache.synapse.Mediator)

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