Search in sources :

Example 6 with Mediator

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

the class ForwardingService 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 7 with Mediator

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

the class InMediator method mediate.

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

use of org.apache.synapse.Mediator 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 9 with Mediator

use of org.apache.synapse.Mediator 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 10 with Mediator

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

the class MessageStoreMediator method mediate.

public boolean mediate(MessageContext synCtx) {
    boolean produceStatus;
    if (synCtx.getEnvironment().isDebuggerEnabled()) {
        if (super.divertMediationRoute(synCtx)) {
            return true;
        }
    }
    if (synCtx != null) {
        MessageStore messageStore;
        if (messageStoreExp != null) {
            messageStore = synCtx.getConfiguration().getMessageStore(messageStoreExp.stringValueOf(synCtx));
        } else {
            messageStore = synCtx.getConfiguration().getMessageStore(messageStoreName);
        }
        if (messageStore != null) {
            if (messageStore.getParameters().get(PRODUCER_GUARANTEED_DELIVERY) != null) {
                isGuaranteedDeliveryEnabled = Boolean.parseBoolean(messageStore.getParameters().get(PRODUCER_GUARANTEED_DELIVERY).toString());
            }
            if (messageStore.getParameters().get(FAILOVER_MESSAGE_STORE_NAME) != null) {
                failoverMessageStoreName = (String) messageStore.getParameters().get(FAILOVER_MESSAGE_STORE_NAME);
            }
            if (onStoreSequence != null) {
                Mediator sequence = synCtx.getSequence(onStoreSequence);
                if (sequence != null) {
                    sequence.mediate(synCtx);
                }
            }
            if (log.isDebugEnabled()) {
                log.debug("Message Store mediator storing the message : \n " + synCtx.getEnvelope());
            }
            // Ensure that the message is fully read
            synCtx.getEnvelope().buildWithAttachments();
            // Clone the message before sending to the producer
            // Fix ESBJAVA-3650
            MessageContext newCtx = null;
            try {
                newCtx = MessageHelper.cloneMessageContext(synCtx);
                ContinuationStackManager.clearStack(newCtx);
            } catch (AxisFault af) {
                handleException("Error when cloning the message context", af, synCtx);
            }
            synchronized (storeMessageLock) {
                produceStatus = messageStore.getProducer().storeMessage(newCtx);
            }
            if (!produceStatus) {
                // Fix ESBJAVA-5011, since connection is already null need to nullify producer also
                if (messageStore instanceof JmsStore) {
                    ((JmsStore) messageStore).setProducer(null);
                }
                if (isGuaranteedDeliveryEnabled && failoverMessageStoreName != null && !failoverMessageStoreName.isEmpty()) {
                    MessageStore failoverMessageStore = synCtx.getConfiguration().getMessageStore(failoverMessageStoreName);
                    boolean failoverProduceStatus = failoverMessageStore.getProducer().storeMessage(newCtx);
                    if (!failoverProduceStatus) {
                        synCtx.setProperty(NhttpConstants.HTTP_SC, 500);
                        synCtx.setProperty(NhttpConstants.ERROR_DETAIL, "Failed to store message.");
                        synCtx.setProperty(NhttpConstants.ERROR_MESSAGE, "Failed to store message [" + synCtx.getMessageID() + "] in store [" + messageStore.getName() + "].");
                        handleException("Failed to store message [" + synCtx.getMessageID() + "] in failover store [" + failoverMessageStoreName + "].", synCtx);
                    }
                    if (shouldTrace(synCtx)) {
                        trace.error("Message [" + synCtx.getMessageID() + "] store in the failover message store [" + failoverMessageStoreName + "]");
                    }
                } else {
                    synCtx.setProperty(NhttpConstants.HTTP_SC, 500);
                    synCtx.setProperty(NhttpConstants.ERROR_DETAIL, "Failed to store message.");
                    synCtx.setProperty(NhttpConstants.ERROR_MESSAGE, "Failed to store message [" + synCtx.getMessageID() + "] in store [" + messageStore.getName() + "].");
                    handleException("Failed to store message [" + synCtx.getMessageID() + "] in store [" + messageStore.getName() + "].", 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 msgCtx = (Axis2MessageContext) synCtx;
            if (null != msgCtx.getAxis2MessageContext() && null != msgCtx.getAxis2MessageContext().getOperationContext()) {
                msgCtx.getAxis2MessageContext().getOperationContext().setProperty(org.apache.axis2.Constants.RESPONSE_WRITTEN, "SKIP");
            }
            return true;
        } else {
            handleException("Message Store does not exist.", synCtx);
        }
    }
    return false;
}
Also used : MessageStore(org.apache.synapse.message.store.MessageStore) AxisFault(org.apache.axis2.AxisFault) JmsStore(org.apache.synapse.message.store.impl.jms.JmsStore) AbstractMediator(org.apache.synapse.mediators.AbstractMediator) Mediator(org.apache.synapse.Mediator) MessageContext(org.apache.synapse.MessageContext) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext)

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