Search in sources :

Example 11 with SynapseLog

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

the class OutMediator 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 : Out mediator");
        if (synLog.isTraceTraceEnabled()) {
            synLog.traceTrace("Message : " + synCtx.getEnvelope());
        }
    }
    boolean result = true;
    if (test(synCtx)) {
        synLog.traceOrDebug("Current message is outgoing - executing child mediators");
        ContinuationStackManager.addReliantContinuationState(synCtx, 0, getMediatorPosition());
        result = super.mediate(synCtx);
        if (result) {
            ContinuationStackManager.removeReliantContinuationState(synCtx);
        }
    } else {
        synLog.traceOrDebug("Current message is a request - skipping child mediators");
    }
    synLog.traceOrDebug("End : Out mediator");
    return result;
}
Also used : SynapseLog(org.apache.synapse.SynapseLog)

Example 12 with SynapseLog

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

the class OutMediator method mediate.

public boolean mediate(MessageContext synCtx, ContinuationState continuationState) {
    SynapseLog synLog = getLog(synCtx);
    if (synLog.isTraceOrDebugEnabled()) {
        synLog.traceOrDebug("Out 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 13 with SynapseLog

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

the class SwitchMediator method mediate.

/**
 * Iterate over switch cases and find match and execute selected sequence
 *
 * @param synCtx current context
 * @return as per standard 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 : Switch mediator");
        if (synLog.isTraceTraceEnabled()) {
            synLog.traceTrace("Message : " + synCtx.getEnvelope());
        }
    }
    int parentsEffectiveTraceState = synCtx.getTracingState();
    // if I have been explicitly asked to enable or disable tracing, set it to the message
    // to pass it on; else, do nothing -> i.e. let the parents state flow
    setEffectiveTraceState(synCtx);
    String sourceText = source.stringValueOf(synCtx);
    if (synLog.isTraceOrDebugEnabled()) {
        synLog.traceOrDebug("XPath : " + source + " evaluates to : " + sourceText);
    }
    try {
        if ((sourceText == null || cases.isEmpty()) && defaultCase != null) {
            synLog.traceOrDebug("Source XPath evaluated to : null or no switch " + "cases found. Executing the default case");
            ContinuationStackManager.addReliantContinuationState(synCtx, 0, getMediatorPosition());
            boolean result = defaultCase.mediate(synCtx);
            if (result) {
                ContinuationStackManager.removeReliantContinuationState(synCtx);
            }
            return result;
        } else {
            for (int i = 0; i < cases.size(); i++) {
                SwitchCase swCase = cases.get(i);
                if (swCase != null) {
                    if (swCase.matches(sourceText)) {
                        if (synLog.isTraceOrDebugEnabled()) {
                            synLog.traceOrDebug("Matching case found : " + swCase.getRegex());
                        }
                        ContinuationStackManager.addReliantContinuationState(synCtx, i + 1, getMediatorPosition());
                        boolean result = swCase.mediate(synCtx);
                        if (result) {
                            ContinuationStackManager.removeReliantContinuationState(synCtx);
                        }
                        return result;
                    }
                }
            }
            if (defaultCase != null) {
                // if any of the switch cases did not match
                synLog.traceOrDebug("None of the switch cases matched - executing default");
                ContinuationStackManager.addReliantContinuationState(synCtx, 0, getMediatorPosition());
                boolean result = defaultCase.mediate(synCtx);
                if (result) {
                    ContinuationStackManager.removeReliantContinuationState(synCtx);
                }
                return result;
            } else {
                synLog.traceOrDebug("None of the switch cases matched - no default case");
            }
        }
    } finally {
        synCtx.setTracingState(parentsEffectiveTraceState);
    }
    synLog.traceOrDebug("End : Switch mediator");
    return true;
}
Also used : SwitchCase(org.apache.synapse.config.xml.SwitchCase) SynapseLog(org.apache.synapse.SynapseLog)

Example 14 with SynapseLog

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

the class SwitchMediator method mediate.

public boolean mediate(MessageContext synCtx, ContinuationState continuationState) {
    SynapseLog synLog = getLog(synCtx);
    if (synLog.isTraceOrDebugEnabled()) {
        synLog.traceOrDebug("Switch mediator : Mediating from ContinuationState");
    }
    boolean result;
    int subBranch = ((ReliantContinuationState) continuationState).getSubBranch();
    if (subBranch == 0) {
        if (!continuationState.hasChild()) {
            result = defaultCase.getCaseMediator().mediate(synCtx, continuationState.getPosition() + 1);
        } else {
            FlowContinuableMediator mediator = (FlowContinuableMediator) defaultCase.getCaseMediator().getChild(continuationState.getPosition());
            result = mediator.mediate(synCtx, continuationState.getChildContState());
            if (RuntimeStatisticCollector.isStatisticsEnabled()) {
                ((Mediator) mediator).reportCloseStatistics(synCtx, null);
            }
        }
    } else {
        if (!continuationState.hasChild()) {
            result = cases.get(subBranch - 1).getCaseMediator().mediate(synCtx, continuationState.getPosition() + 1);
        } else {
            FlowContinuableMediator mediator = (FlowContinuableMediator) cases.get(subBranch - 1).getCaseMediator().getChild(continuationState.getPosition());
            result = mediator.mediate(synCtx, continuationState.getChildContState());
            if (RuntimeStatisticCollector.isStatisticsEnabled()) {
                ((Mediator) mediator).reportCloseStatistics(synCtx, null);
            }
        }
    }
    return result;
}
Also used : ReliantContinuationState(org.apache.synapse.continuation.ReliantContinuationState) SynapseLog(org.apache.synapse.SynapseLog) FlowContinuableMediator(org.apache.synapse.mediators.FlowContinuableMediator) AbstractMediator(org.apache.synapse.mediators.AbstractMediator) FlowContinuableMediator(org.apache.synapse.mediators.FlowContinuableMediator) Mediator(org.apache.synapse.Mediator)

Example 15 with SynapseLog

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

the class InvokeMediator method mediate.

public boolean mediate(MessageContext synCtx, ContinuationState continuationState) {
    SynapseLog synLog = getLog(synCtx);
    if (synLog.isTraceOrDebugEnabled()) {
        synLog.traceOrDebug("Invoke mediator : Mediating from ContinuationState");
    }
    boolean result;
    int subBranch = ((ReliantContinuationState) continuationState).getSubBranch();
    boolean isStatisticsEnabled = RuntimeStatisticCollector.isStatisticsEnabled();
    if (subBranch == 0) {
        // Default flow
        TemplateMediator templateMediator = (TemplateMediator) synCtx.getSequenceTemplate(targetTemplate);
        if (!continuationState.hasChild()) {
            result = templateMediator.mediate(synCtx, continuationState.getPosition() + 1);
            if (result) {
                templateMediator.popFuncContextFrom(synCtx);
            }
        } else {
            FlowContinuableMediator mediator = (FlowContinuableMediator) templateMediator.getChild(continuationState.getPosition());
            result = mediator.mediate(synCtx, continuationState.getChildContState());
            if (isStatisticsEnabled) {
                ((Mediator) mediator).reportCloseStatistics(synCtx, null);
            }
        }
        if (isStatisticsEnabled) {
            templateMediator.reportCloseStatistics(synCtx, null);
        }
    } else {
        // Pre fetching invoke mediator flow
        String prefetchInvokeKey = key.evaluateValue(synCtx);
        InvokeMediator prefetchInvoke = (InvokeMediator) synCtx.getDefaultConfiguration(prefetchInvokeKey);
        ContinuationState childContinuationState = continuationState.getChildContState();
        result = prefetchInvoke.mediate(synCtx, childContinuationState);
        if (result && !childContinuationState.hasChild()) {
            // Pre fetching invoke mediator flow completed.
            // Remove ContinuationState represent the prefetchInvoke mediator and
            // flip the subbranch to default flow
            continuationState.removeLeafChild();
            ((ReliantContinuationState) continuationState).setSubBranch(0);
            // after prefetch invoke mediator flow, execute default flow
            result = mediate(synCtx, false);
        }
        if (isStatisticsEnabled) {
            prefetchInvoke.reportCloseStatistics(synCtx, null);
        }
    }
    return result;
}
Also used : ReliantContinuationState(org.apache.synapse.continuation.ReliantContinuationState) SynapseLog(org.apache.synapse.SynapseLog) FlowContinuableMediator(org.apache.synapse.mediators.FlowContinuableMediator) AbstractMediator(org.apache.synapse.mediators.AbstractMediator) FlowContinuableMediator(org.apache.synapse.mediators.FlowContinuableMediator) Mediator(org.apache.synapse.Mediator) ContinuationState(org.apache.synapse.ContinuationState) ReliantContinuationState(org.apache.synapse.continuation.ReliantContinuationState)

Aggregations

SynapseLog (org.apache.synapse.SynapseLog)53 Mediator (org.apache.synapse.Mediator)16 FlowContinuableMediator (org.apache.synapse.mediators.FlowContinuableMediator)13 SynapseException (org.apache.synapse.SynapseException)10 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)9 MessageContext (org.apache.synapse.MessageContext)8 AbstractMediator (org.apache.synapse.mediators.AbstractMediator)8 OMNode (org.apache.axiom.om.OMNode)7 AbstractListMediator (org.apache.synapse.mediators.AbstractListMediator)6 SequenceMediator (org.apache.synapse.mediators.base.SequenceMediator)6 JaxenException (org.jaxen.JaxenException)5 PreparedStatement (java.sql.PreparedStatement)4 Set (java.util.Set)4 AxisFault (org.apache.axis2.AxisFault)4 OperationContext (org.apache.axis2.context.OperationContext)4 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)3 ReliantContinuationState (org.apache.synapse.continuation.ReliantContinuationState)3 Endpoint (org.apache.synapse.endpoints.Endpoint)3 IOException (java.io.IOException)2 Method (java.lang.reflect.Method)2