Reputation: 1290
According to the documentation
ForEach does not allow using Call , Send and Callout mediators in the sequence.
But it is possible to use a Call/Send/Callout mediator inside a ForEach mediator if you place it inside a sequence, and invoke this sequence inside of it, like in this example:
<!-- myProxy.xml -->
<for-each expression="//foo" >
<sequence>
<sequence key="myCallSequence"/>
</sequence>
</for-each>
<!-- myCallSequence.xml -->
<call>
<endpoint>
<address format="soap11" uri="http://my.uri.com"/>
</endpoint>
</call>
Which I observed could result in some very unexpected results, especially regarding the aggregated payload after the for each being mixed with the return of a callout.
I stumbled accross this while dealing with a situation where I had to split my original message and validate some data from the splitted parts with an external service, but still needed to do more processing with the original message if the validations where successfull.
Is this kind of configuration considered a bad practice? And if so, why?
Upvotes: 2
Views: 1800
Reputation: 2093
ForEach mediator should only be used if you need to transform a payload in an iterative manner (for example, an array). ForEach mediator is not implemented to support calling back-ends. If you need to achieve this use case, use the Iterate mediator which allows you to call back-end. Please refer https://docs.wso2.com/display/EI611/Iterate+Mediator for more information.
Upvotes: 3