* @param synCtx - MessageContext to be mediated
* @return boolean false if need to stop processing of the parent message
*/
public boolean mediate(MessageContext synCtx) {
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());
// get the iteration elements and iterate through the list,
// this call will also detach all the iteration elements
List splitElements = EIPUtils.getDetachedMatchingElements(envelope, 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 " + msgNumber +
" messages for processing in parallel");
}
target.mediate(
getIteratedMessage(synCtx, msgNumber++, msgCount, envelope, (OMNode) o));
}
} 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);
}
// 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;
}