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