Search in sources :

Example 66 with Mediator

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

the class ForwardingService 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)

Example 67 with Mediator

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

the class ForwardingService method sendThroughReplySeq.

/**
 * Sending the out message through the reply sequence.
 *
 * @param outCtx Synapse out {@link MessageContext} to be sent through the
 *               reply sequence.
 */
public void sendThroughReplySeq(MessageContext outCtx) {
    if (replySeq == null) {
        deactivateMessageProcessor(outCtx);
        log.error("Failed to send the out message. Reply sequence does not Exist. " + "Deactivated the message processor.");
        return;
    }
    Mediator mediator = outCtx.getSequence(replySeq);
    if (mediator == null) {
        deactivateMessageProcessor(outCtx);
        log.error("Failed to send the out message. Reply sequence [" + replySeq + "] does not exist. Deactivated the message processor.");
        return;
    }
    mediator.mediate(outCtx);
}
Also used : Mediator(org.apache.synapse.Mediator)

Example 68 with Mediator

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

the class SamplingService method dispatch.

/**
 * Sends the message to a given sequence.
 *
 * @param messageContext
 *            message to be injected.
 */
public void dispatch(final MessageContext messageContext) {
    setSoapHeaderBlock(messageContext);
    final ExecutorService executor = messageContext.getEnvironment().getExecutorService();
    executor.submit(new Runnable() {

        public void run() {
            try {
                Mediator processingSequence = messageContext.getSequence(sequence);
                if (processingSequence != null) {
                    processingSequence.mediate(messageContext);
                }
            } catch (SynapseException syne) {
                if (!messageContext.getFaultStack().isEmpty()) {
                    (messageContext.getFaultStack().pop()).handleFault(messageContext, syne);
                }
                log.error("Error occurred while executing the message", syne);
            } catch (Throwable t) {
                log.error("Error occurred while executing the message", t);
            }
        }
    });
}
Also used : SynapseException(org.apache.synapse.SynapseException) ExecutorService(java.util.concurrent.ExecutorService) Mediator(org.apache.synapse.Mediator)

Example 69 with Mediator

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

the class API method handleResourceNotFound.

/**
 * Helper method to use when no matching resource found
 *
 * @param synCtx
 */
private void handleResourceNotFound(MessageContext synCtx) {
    auditDebug("No matching resource was found for the request: " + synCtx.getMessageID());
    Mediator sequence = synCtx.getSequence(RESTConstants.NO_MATCHING_RESOURCE_HANDLER);
    if (sequence != null) {
        sequence.mediate(synCtx);
    } else {
        // Matching resource with method not found
        org.apache.axis2.context.MessageContext msgCtx = ((Axis2MessageContext) synCtx).getAxis2MessageContext();
        msgCtx.setProperty(SynapseConstants.HTTP_SC, HttpStatus.SC_NOT_FOUND);
        msgCtx.removeProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS);
        msgCtx.setProperty("NIO-ACK-Requested", true);
    }
}
Also used : Mediator(org.apache.synapse.Mediator) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext)

Example 70 with Mediator

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

the class ThrottleMediatorSerializer method serializeSpecificMediator.

public OMElement serializeSpecificMediator(Mediator m) {
    if (!(m instanceof ThrottleMediator)) {
        handleException("Invalid Mediator has passed to serializer");
    }
    ThrottleMediator throttleMediator = (ThrottleMediator) m;
    OMElement throttle = fac.createOMElement("throttle", synNS);
    OMElement policy = fac.createOMElement("policy", synNS);
    String key = throttleMediator.getPolicyKey();
    if (key != null) {
        policy.addAttribute(fac.createOMAttribute("key", nullNS, key));
        throttle.addChild(policy);
    } else {
        OMNode inlinePolicy = throttleMediator.getInLinePolicy();
        if (inlinePolicy != null) {
            policy.addChild(inlinePolicy);
            throttle.addChild(policy);
        }
    }
    saveTracingState(throttle, throttleMediator);
    String id = throttleMediator.getId();
    if (id != null) {
        throttle.addAttribute(fac.createOMAttribute("id", nullNS, id));
    }
    String onReject = throttleMediator.getOnRejectSeqKey();
    if (onReject != null) {
        throttle.addAttribute(fac.createOMAttribute(XMLConfigConstants.ONREJECT, nullNS, onReject));
    } else {
        Mediator mediator = throttleMediator.getOnRejectMediator();
        SequenceMediatorSerializer serializer = new SequenceMediatorSerializer();
        if (mediator != null && mediator instanceof SequenceMediator) {
            OMElement element = serializer.serializeAnonymousSequence(null, (SequenceMediator) mediator);
            element.setLocalName(XMLConfigConstants.ONREJECT);
            throttle.addChild(element);
        }
    }
    String onAccept = throttleMediator.getOnAcceptSeqKey();
    if (onAccept != null) {
        throttle.addAttribute(fac.createOMAttribute(XMLConfigConstants.ONACCEPT, nullNS, onAccept));
    } else {
        Mediator mediator = throttleMediator.getOnAcceptMediator();
        SequenceMediatorSerializer serializer = new SequenceMediatorSerializer();
        if (mediator != null && mediator instanceof SequenceMediator) {
            OMElement element = serializer.serializeAnonymousSequence(null, (SequenceMediator) mediator);
            element.setLocalName(XMLConfigConstants.ONACCEPT);
            throttle.addChild(element);
        }
    }
    return throttle;
}
Also used : OMNode(org.apache.axiom.om.OMNode) OMElement(org.apache.axiom.om.OMElement) Mediator(org.apache.synapse.Mediator) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator) SequenceMediatorSerializer(org.apache.synapse.config.xml.SequenceMediatorSerializer) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator)

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