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