Search in sources :

Example 41 with SynapseLog

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

the class DetachMediator method mediate.

public boolean mediate(MessageContext synCtx) {
    SynapseLog synLog = getLog(synCtx);
    OMNode node = source.selectOMNode(synCtx, synLog);
    node.detach();
    synCtx.setProperty(property, node);
    return true;
}
Also used : OMNode(org.apache.axiom.om.OMNode) SynapseLog(org.apache.synapse.SynapseLog)

Example 42 with SynapseLog

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

the class ReplaceMediator method mediate.

public boolean mediate(MessageContext synCtx) {
    SynapseLog synLog = getLog(synCtx);
    OMNode replacement = (OMNode) synCtx.getProperty(property);
    OMNode node = target.selectOMNode(synCtx, synLog);
    node.insertSiblingAfter(replacement);
    node.detach();
    synCtx.setProperty(property, null);
    return true;
}
Also used : OMNode(org.apache.axiom.om.OMNode) SynapseLog(org.apache.synapse.SynapseLog)

Example 43 with SynapseLog

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

the class ForEachMediator method mediate.

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 : Foreach mediator");
    }
    if (expression == null) {
        handleException("ForEach: expression is null", synCtx);
    }
    if (synLog.isTraceOrDebugEnabled()) {
        synLog.traceOrDebug("ForEach expression : " + expression.toString());
    }
    String idPrefix = (getId() == null) ? "" : getId() + "_";
    // Set original message property
    String originalMsgPropName = idPrefix + FOREACH_ORIGINAL_MESSAGE;
    SOAPEnvelope originalEnvelope = MessageHelper.cloneSOAPEnvelope(synCtx.getEnvelope());
    synCtx.setProperty(originalMsgPropName, originalEnvelope);
    // Set counter property
    String counterPropName = idPrefix + FOREACH_COUNTER;
    int msgCounter = 0;
    synCtx.setProperty(counterPropName, msgCounter);
    if (synLog.isTraceOrDebugEnabled()) {
        synLog.traceOrDebug("Saved original message property : " + originalMsgPropName + " = " + originalEnvelope + "Initialized foreach counter property, " + counterPropName + " = " + msgCounter);
    }
    SOAPEnvelope processingEnvelope = synCtx.getEnvelope();
    // get the iteration elements and iterate through the list, this call
    // will also detach all the iteration elements from the message and deduce the
    // parent node to merge back the mediated content
    DetachedElementContainer detachedElementContainer = getDetachedMatchingElements(processingEnvelope, synCtx, expression);
    List<?> splitElements = detachedElementContainer.getDetachedElements();
    int splitElementCount = splitElements.size();
    if (splitElementCount == 0) {
        // Continue the message flow if no matching elements found
        return true;
    }
    OMContainer parent = detachedElementContainer.getParent();
    if (parent == null) {
        handleException("Error detecting parent element to merge", synCtx);
    }
    if (synLog.isTraceOrDebugEnabled()) {
        synLog.traceOrDebug("Splitting with XPath : " + expression + " resulted in " + splitElementCount + " elements. Parent node for merging is : " + parent.toString());
    }
    // iterate through the split elements
    for (Object element : splitElements) {
        if (!(element instanceof OMNode)) {
            handleException("Error splitting message with XPath : " + expression + " - result not an OMNode", synCtx);
        }
        if (synLog.isTraceOrDebugEnabled()) {
            synLog.traceOrDebug("Submitting " + msgCounter + " of " + splitElementCount + " messages for processing in sequentially, in a general loop");
        }
        MessageContext iteratedMsgCtx = null;
        try {
            iteratedMsgCtx = getIteratedMessage(synCtx, processingEnvelope, (OMNode) element);
        } catch (AxisFault axisFault) {
            handleException("Error creating an iterated copy of the message", axisFault, synCtx);
        }
        boolean mediateResult = mediateSequence(iteratedMsgCtx);
        // add the mediated element to the parent from original message context
        parent.addChild(iteratedMsgCtx.getEnvelope().getBody().getFirstElement());
        msgCounter++;
        if (synLog.isTraceOrDebugEnabled()) {
            synLog.traceOrDebug("Incrementing foreach counter , " + counterPropName + " = " + msgCounter);
        }
        synCtx.setProperty(counterPropName, msgCounter);
        if (!mediateResult) {
            // break the loop if mediate result is false
            break;
        }
    }
    // set the modified envelop to message context
    try {
        synCtx.setEnvelope(processingEnvelope);
    } catch (AxisFault axisFault) {
        handleException("Error while setting the envelope to the message context", axisFault, synCtx);
    }
    if (synLog.isTraceOrDebugEnabled()) {
        synLog.traceOrDebug("After mediation foreach counter, " + counterPropName + " = " + msgCounter);
        synLog.traceOrDebug("End : For Each mediator");
    }
    return true;
}
Also used : AxisFault(org.apache.axis2.AxisFault) OMNode(org.apache.axiom.om.OMNode) SynapseLog(org.apache.synapse.SynapseLog) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) MessageContext(org.apache.synapse.MessageContext) OMContainer(org.apache.axiom.om.OMContainer)

Example 44 with SynapseLog

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

the class LogMediator method mediate.

/**
 * Logs the current message according to the supplied semantics
 *
 * @param synCtx (current) message to be logged
 * @return true always
 */
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 : Log mediator");
        if (synLog.isTraceTraceEnabled()) {
            synLog.traceTrace("Message : " + synCtx.getEnvelope());
        }
    }
    switch(category) {
        case CATEGORY_INFO:
            synLog.auditLog(getLogMessage(synCtx));
            break;
        case CATEGORY_TRACE:
            if (synLog.isTraceEnabled()) {
                synLog.auditTrace(getLogMessage(synCtx));
            }
            break;
        case CATEGORY_DEBUG:
            if (synLog.isDebugEnabled()) {
                synLog.auditDebug(getLogMessage(synCtx));
            }
            break;
        case CATEGORY_WARN:
            synLog.auditWarn(getLogMessage(synCtx));
            break;
        case CATEGORY_ERROR:
            synLog.auditError(getLogMessage(synCtx));
            break;
        case CATEGORY_FATAL:
            synLog.auditFatal(getLogMessage(synCtx));
            break;
    }
    synLog.traceOrDebug("End : Log mediator");
    return true;
}
Also used : SynapseLog(org.apache.synapse.SynapseLog)

Example 45 with SynapseLog

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

the class LoopBackMediator method mediate.

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 : Loopback Mediator");
        if (synLog.isTraceTraceEnabled()) {
            synLog.traceTrace("Message : " + synCtx.getEnvelope());
        }
    }
    // If message flow is inflow this will be executed.
    if (!synCtx.isResponse()) {
        // clear the message context properties related to endpoint in last service invocation
        Set keySet = synCtx.getPropertyKeySet();
        if (keySet != null) {
            keySet.remove(SynapseConstants.RECEIVING_SEQUENCE);
            keySet.remove(SynapseConstants.CONTINUATION_CALL);
            keySet.remove(EndpointDefinition.DYNAMIC_URL_VALUE);
        }
        synCtx.setResponse(true);
        synCtx.setTo(null);
        synCtx.getEnvironment().injectMessage(synCtx);
    }
    if (synLog.isTraceOrDebugEnabled()) {
        synLog.traceOrDebug("End : Loopback Mediator");
    }
    return false;
}
Also used : SynapseLog(org.apache.synapse.SynapseLog) Set(java.util.Set)

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