Note that WSO2 EI is shipped with the following changes to what is mentioned in this documentation :
repository/samples/directory that includes all Integration profile samples is changed to
repository/samples/resources/directory that includes all artifacts related to the Integration profile samples is changed to
This sample demonstrates how the ForEach mediator can be used to transform a payload.
To invoke the main sequence using
curl, a request file should be created as shown below. This file is named
stockQuoteReq.xmlin this example.
- See the prerequisites for starting the ESB Samples for other prerequisites.
Building the sample
The XML configuration for this sample is as follows.
This configuration file
synapse_sample_18.xml is available in the
To build the sample, start the ESB with the sample 18 configuration. For instructions on starting a sample ESB configuration, see Starting the ESB with a sample configuration.
The operation log keeps running until the server starts, which usually takes several seconds. Wait until the server has fully booted up and displays a message similar to "WSO2 Carbon started in n seconds."
Executing the sample
Invoke the main sequence using the following command. This command should be issued from the same location in which the
stockQuoteReq.xml request file you created is saved.
curl -d @stockQuoteReq.xml -H "Content-Type: application/soap+xml;charset=UTF-8" "http://localhost:8280/"
Analyzing the output
The ForEach mediator splits the message to four different elements based on the evaluation of the
//m0:getQuote/m0:request expression. The PayloadFactory mediator produces a result as shown in the following console log.
Note that <m0:request><m0:symbol>IBM</m0:symbol></m0:request> in the request has been changed to
The expression can be changed to perform a transformation or similar selectively. For example if the expression is given as
expression = "//m0:getQuote/m0:request", only the first element will be transformed and the other elements will be left unchanged.
For more information on XPath expressions, see XPath Syntax by w3schools.com.