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);
}
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);
}
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);
}
}
});
}
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);
}
}
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;
}
Aggregations