Search in sources :

Example 26 with SynapseLog

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

the class SpringMediator 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 : Spring mediator");
        if (synLog.isTraceTraceEnabled()) {
            synLog.traceTrace("Message : " + synCtx.getEnvelope());
        }
    }
    Entry entry = synCtx.getConfiguration().getEntryDefinition(configKey);
    // if the configKey refers to a dynamic property
    if (entry != null && entry.isDynamic()) {
        if (!entry.isCached() || entry.isExpired()) {
            buildAppContext(synCtx, synLog);
        }
    // if the property is not a DynamicProperty, we will create an ApplicationContext only once
    } else {
        if (appContext == null) {
            buildAppContext(synCtx, synLog);
        }
    }
    if (appContext != null) {
        Object o = null;
        try {
            o = appContext.getBean(beanName);
            if (o != null && Mediator.class.isAssignableFrom(o.getClass())) {
                Mediator m = (Mediator) o;
                if (synLog.isTraceOrDebugEnabled()) {
                    synLog.traceOrDebug("Loaded mediator from bean : " + beanName + " executing...");
                }
                return m.mediate(synCtx);
            } else {
                if (synLog.isTraceOrDebugEnabled()) {
                    synLog.traceOrDebug("Unable to load mediator from bean : " + beanName);
                }
                handleException("Could not load bean named : " + beanName + " from the Spring configuration with key : " + configKey, synCtx);
            }
        } catch (Exception e) {
            if (o == null) {
                handleException("No bean named '" + beanName + "' is defined", synCtx);
            } else {
                handleException("Error in " + o.getClass().getName(), synCtx);
            }
        }
    } else {
        handleException("Cannot reference application context with key : " + configKey, synCtx);
    }
    synLog.traceOrDebug("End : Spring mediator");
    return true;
}
Also used : Entry(org.apache.synapse.config.Entry) SynapseLog(org.apache.synapse.SynapseLog) AbstractMediator(org.apache.synapse.mediators.AbstractMediator) Mediator(org.apache.synapse.Mediator)

Example 27 with SynapseLog

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

the class XQueryMediator method mediate.

/**
 * Performs the query and attached the result to the target Node
 *
 * @param synCtx The current message
 * @return true always
 */
public boolean mediate(MessageContext synCtx) {
    try {
        if (synCtx.getEnvironment().isDebuggerEnabled()) {
            if (super.divertMediationRoute(synCtx)) {
                return true;
            }
        }
        SynapseLog synLog = getLog(synCtx);
        if (synLog.isTraceOrDebugEnabled()) {
            synLog.traceOrDebug("Start : XQuery mediator");
            if (synLog.isTraceTraceEnabled()) {
                synLog.traceTrace("Message : " + synCtx.getEnvelope());
            }
            synLog.traceOrDebug("Performing XQuery using query resource with key : " + queryKey);
        }
        // perform the xquery
        performQuery(synCtx, synLog);
        synLog.traceOrDebug("End : XQuery mediator");
        return true;
    } catch (Exception e) {
        handleException("Unable to execute the query ", e);
    }
    return false;
}
Also used : SynapseLog(org.apache.synapse.SynapseLog) XMLStreamException(javax.xml.stream.XMLStreamException) SynapseException(org.apache.synapse.SynapseException) IOException(java.io.IOException)

Example 28 with SynapseLog

use of org.apache.synapse.SynapseLog 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 29 with SynapseLog

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

the class CloneMediator method mediate.

/**
 * This will implement the mediate method of the Mediator interface and will provide the
 * functionality of cloning message into the specified targets and mediation
 *
 * @param synCtx - MessageContext which is subjected to the cloning
 * @return boolean true if this needs to be further mediated (continueParent=true)
 */
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 : Clone mediator");
        if (synLog.isTraceTraceEnabled()) {
            synLog.traceTrace("Message : " + synCtx.getEnvelope());
        }
    }
    synCtx.setProperty(id != null ? EIPConstants.EIP_SHARED_DATA_HOLDER + "." + id : EIPConstants.EIP_SHARED_DATA_HOLDER, new SharedDataHolder());
    // get the targets list, clone the message for the number of targets and then
    // mediate the cloned messages using the targets
    Iterator<Target> iter = targets.iterator();
    int i = 0;
    while (iter.hasNext()) {
        if (synLog.isTraceOrDebugEnabled()) {
            synLog.traceOrDebug("Submitting " + (i + 1) + " of " + targets.size() + " messages for " + (isSequential() ? "sequential processing" : "parallel processing"));
        }
        MessageContext clonedMsgCtx = getClonedMessageContext(synCtx, i++, targets.size());
        ContinuationStackManager.addReliantContinuationState(clonedMsgCtx, i - 1, getMediatorPosition());
        iter.next().mediate(clonedMsgCtx);
    }
    // if the continuation of the parent message is stopped from here set the RESPONSE_WRITTEN
    // property to SKIP to skip the blank http response
    OperationContext opCtx = ((Axis2MessageContext) synCtx).getAxis2MessageContext().getOperationContext();
    if (!continueParent && opCtx != null) {
        opCtx.setProperty(Constants.RESPONSE_WRITTEN, "SKIP");
    }
    // finalize tracing and debugging
    synLog.traceOrDebug("End : Clone mediator");
    // mediation of the message which is subjected for clonning (parent message)
    return continueParent;
}
Also used : OperationContext(org.apache.axis2.context.OperationContext) Target(org.apache.synapse.mediators.eip.Target) SynapseLog(org.apache.synapse.SynapseLog) SharedDataHolder(org.apache.synapse.mediators.eip.SharedDataHolder) MessageContext(org.apache.synapse.MessageContext) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext) Endpoint(org.apache.synapse.endpoints.Endpoint)

Example 30 with SynapseLog

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

the class IterateMediator method mediate.

/**
 * Splits the message by iterating over the results of the given XPath expression
 *
 * @param synCtx - MessageContext to be mediated
 * @return boolean false if need to stop processing of the parent message
 */
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 : Iterate mediator");
        if (synLog.isTraceTraceEnabled()) {
            synLog.traceTrace("Message : " + synCtx.getEnvelope());
        }
    }
    try {
        // get a copy of the message for the processing, if the continueParent is set to true
        // this original message can go in further mediations and hence we should not change
        // the original message context
        SOAPEnvelope envelope = MessageHelper.cloneSOAPEnvelope(synCtx.getEnvelope());
        synCtx.setProperty(id != null ? EIPConstants.EIP_SHARED_DATA_HOLDER + "." + id : EIPConstants.EIP_SHARED_DATA_HOLDER, new SharedDataHolder());
        // get the iteration elements and iterate through the list,
        // this call will also detach all the iteration elements
        List splitElements = EIPUtils.getDetachedMatchingElements(envelope, synCtx, expression);
        if (synLog.isTraceOrDebugEnabled()) {
            synLog.traceOrDebug("Splitting with XPath : " + expression + " resulted in " + splitElements.size() + " elements");
        }
        // if not preservePayload remove all the child elements
        if (!preservePayload && envelope.getBody() != null) {
            for (Iterator itr = envelope.getBody().getChildren(); itr.hasNext(); ) {
                ((OMNode) itr.next()).detach();
            }
        }
        int msgCount = splitElements.size();
        int msgNumber = 0;
        // iterate through the list
        for (Object o : splitElements) {
            // for the moment iterator will look for an OMNode as the iteration element
            if (!(o instanceof OMNode)) {
                handleException("Error splitting message with XPath : " + expression + " - result not an OMNode", synCtx);
            }
            if (synLog.isTraceOrDebugEnabled()) {
                synLog.traceOrDebug("Submitting " + (msgNumber + 1) + " of " + msgCount + (target.isAsynchronous() ? " messages for processing in parallel" : " messages for processing in sequentially"));
            }
            MessageContext iteratedMsgCtx = getIteratedMessage(synCtx, msgNumber++, msgCount, envelope, (OMNode) o);
            ContinuationStackManager.addReliantContinuationState(iteratedMsgCtx, 0, getMediatorPosition());
            if (target.isAsynchronous()) {
                target.mediate(iteratedMsgCtx);
            } else {
                try {
                    /*
                         * if Iteration is sequential we won't be able to execute correct fault
                         * handler as data are lost with clone message ending execution. So here we
                         * copy fault stack of clone message context to original message context
                         */
                    target.mediate(iteratedMsgCtx);
                } catch (SynapseException synEx) {
                    copyFaultyIteratedMessage(synCtx, iteratedMsgCtx);
                    throw synEx;
                } catch (Exception e) {
                    copyFaultyIteratedMessage(synCtx, iteratedMsgCtx);
                    handleException("Exception occurred while executing sequential iteration " + "in the Iterator Mediator", e, synCtx);
                }
            }
        }
    } catch (JaxenException e) {
        handleException("Error evaluating split XPath expression : " + expression, e, synCtx);
    } catch (AxisFault af) {
        handleException("Error creating an iterated copy of the message", af, synCtx);
    } catch (SynapseException synEx) {
        throw synEx;
    } catch (Exception e) {
        handleException("Exception occurred while executing the Iterate Mediator", e, synCtx);
    }
    // if the continuation of the parent message is stopped from here set the RESPONSE_WRITTEN
    // property to SKIP to skip the blank http response
    OperationContext opCtx = ((Axis2MessageContext) synCtx).getAxis2MessageContext().getOperationContext();
    if (!continueParent && opCtx != null) {
        opCtx.setProperty(Constants.RESPONSE_WRITTEN, "SKIP");
    }
    synLog.traceOrDebug("End : Iterate mediator");
    // whether to continue mediation on the original message
    return continueParent;
}
Also used : AxisFault(org.apache.axis2.AxisFault) OperationContext(org.apache.axis2.context.OperationContext) SynapseException(org.apache.synapse.SynapseException) SharedDataHolder(org.apache.synapse.mediators.eip.SharedDataHolder) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) Endpoint(org.apache.synapse.endpoints.Endpoint) JaxenException(org.jaxen.JaxenException) SynapseException(org.apache.synapse.SynapseException) OMNode(org.apache.axiom.om.OMNode) SynapseLog(org.apache.synapse.SynapseLog) JaxenException(org.jaxen.JaxenException) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) MessageContext(org.apache.synapse.MessageContext) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext)

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