use of org.apache.synapse.SynapseLog in project wso2-synapse by wso2.
the class DetachMediator method mediate.
public boolean mediate(MessageContext synCtx) {
SynapseLog synLog = getLog(synCtx);
OMNode node = source.selectOMNode(synCtx, synLog);
node.detach();
synCtx.setProperty(property, node);
return true;
}
use of org.apache.synapse.SynapseLog in project wso2-synapse by wso2.
the class ReplaceMediator method mediate.
public boolean mediate(MessageContext synCtx) {
SynapseLog synLog = getLog(synCtx);
OMNode replacement = (OMNode) synCtx.getProperty(property);
OMNode node = target.selectOMNode(synCtx, synLog);
node.insertSiblingAfter(replacement);
node.detach();
synCtx.setProperty(property, null);
return true;
}
use of org.apache.synapse.SynapseLog in project wso2-synapse by wso2.
the class ForEachMediator 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 : Foreach mediator");
}
if (expression == null) {
handleException("ForEach: expression is null", synCtx);
}
if (synLog.isTraceOrDebugEnabled()) {
synLog.traceOrDebug("ForEach expression : " + expression.toString());
}
String idPrefix = (getId() == null) ? "" : getId() + "_";
// Set original message property
String originalMsgPropName = idPrefix + FOREACH_ORIGINAL_MESSAGE;
SOAPEnvelope originalEnvelope = MessageHelper.cloneSOAPEnvelope(synCtx.getEnvelope());
synCtx.setProperty(originalMsgPropName, originalEnvelope);
// Set counter property
String counterPropName = idPrefix + FOREACH_COUNTER;
int msgCounter = 0;
synCtx.setProperty(counterPropName, msgCounter);
if (synLog.isTraceOrDebugEnabled()) {
synLog.traceOrDebug("Saved original message property : " + originalMsgPropName + " = " + originalEnvelope + "Initialized foreach counter property, " + counterPropName + " = " + msgCounter);
}
SOAPEnvelope processingEnvelope = synCtx.getEnvelope();
// get the iteration elements and iterate through the list, this call
// will also detach all the iteration elements from the message and deduce the
// parent node to merge back the mediated content
DetachedElementContainer detachedElementContainer = getDetachedMatchingElements(processingEnvelope, synCtx, expression);
List<?> splitElements = detachedElementContainer.getDetachedElements();
int splitElementCount = splitElements.size();
if (splitElementCount == 0) {
// Continue the message flow if no matching elements found
return true;
}
OMContainer parent = detachedElementContainer.getParent();
if (parent == null) {
handleException("Error detecting parent element to merge", synCtx);
}
if (synLog.isTraceOrDebugEnabled()) {
synLog.traceOrDebug("Splitting with XPath : " + expression + " resulted in " + splitElementCount + " elements. Parent node for merging is : " + parent.toString());
}
// iterate through the split elements
for (Object element : splitElements) {
if (!(element instanceof OMNode)) {
handleException("Error splitting message with XPath : " + expression + " - result not an OMNode", synCtx);
}
if (synLog.isTraceOrDebugEnabled()) {
synLog.traceOrDebug("Submitting " + msgCounter + " of " + splitElementCount + " messages for processing in sequentially, in a general loop");
}
MessageContext iteratedMsgCtx = null;
try {
iteratedMsgCtx = getIteratedMessage(synCtx, processingEnvelope, (OMNode) element);
} catch (AxisFault axisFault) {
handleException("Error creating an iterated copy of the message", axisFault, synCtx);
}
boolean mediateResult = mediateSequence(iteratedMsgCtx);
// add the mediated element to the parent from original message context
parent.addChild(iteratedMsgCtx.getEnvelope().getBody().getFirstElement());
msgCounter++;
if (synLog.isTraceOrDebugEnabled()) {
synLog.traceOrDebug("Incrementing foreach counter , " + counterPropName + " = " + msgCounter);
}
synCtx.setProperty(counterPropName, msgCounter);
if (!mediateResult) {
// break the loop if mediate result is false
break;
}
}
// set the modified envelop to message context
try {
synCtx.setEnvelope(processingEnvelope);
} catch (AxisFault axisFault) {
handleException("Error while setting the envelope to the message context", axisFault, synCtx);
}
if (synLog.isTraceOrDebugEnabled()) {
synLog.traceOrDebug("After mediation foreach counter, " + counterPropName + " = " + msgCounter);
synLog.traceOrDebug("End : For Each mediator");
}
return true;
}
use of org.apache.synapse.SynapseLog in project wso2-synapse by wso2.
the class LogMediator method mediate.
/**
* Logs the current message according to the supplied semantics
*
* @param synCtx (current) message to be logged
* @return true always
*/
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 : Log mediator");
if (synLog.isTraceTraceEnabled()) {
synLog.traceTrace("Message : " + synCtx.getEnvelope());
}
}
switch(category) {
case CATEGORY_INFO:
synLog.auditLog(getLogMessage(synCtx));
break;
case CATEGORY_TRACE:
if (synLog.isTraceEnabled()) {
synLog.auditTrace(getLogMessage(synCtx));
}
break;
case CATEGORY_DEBUG:
if (synLog.isDebugEnabled()) {
synLog.auditDebug(getLogMessage(synCtx));
}
break;
case CATEGORY_WARN:
synLog.auditWarn(getLogMessage(synCtx));
break;
case CATEGORY_ERROR:
synLog.auditError(getLogMessage(synCtx));
break;
case CATEGORY_FATAL:
synLog.auditFatal(getLogMessage(synCtx));
break;
}
synLog.traceOrDebug("End : Log mediator");
return true;
}
use of org.apache.synapse.SynapseLog in project wso2-synapse by wso2.
the class LoopBackMediator 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 : Loopback Mediator");
if (synLog.isTraceTraceEnabled()) {
synLog.traceTrace("Message : " + synCtx.getEnvelope());
}
}
// If message flow is inflow this will be executed.
if (!synCtx.isResponse()) {
// clear the message context properties related to endpoint in last service invocation
Set keySet = synCtx.getPropertyKeySet();
if (keySet != null) {
keySet.remove(SynapseConstants.RECEIVING_SEQUENCE);
keySet.remove(SynapseConstants.CONTINUATION_CALL);
keySet.remove(EndpointDefinition.DYNAMIC_URL_VALUE);
}
synCtx.setResponse(true);
synCtx.setTo(null);
synCtx.getEnvironment().injectMessage(synCtx);
}
if (synLog.isTraceOrDebugEnabled()) {
synLog.traceOrDebug("End : Loopback Mediator");
}
return false;
}
Aggregations