The PayloadFactory Mediator transforms or replaces the contents of a message. Each argument in the mediator configuration can be a static value, or you can specify an XPath expression to get the value at runtime by evaluating the provided expression against the existing SOAP message. You can configure the format of the request or response and map it to the arguments provided.
For example, in the following configuration, the values for format parameters code
and price
will be assigned with values that are evaluated from arguments given in the specified order.
<payloadFactory> <format> <m:checkpriceresponse xmlns:m="http://services.samples/xsd"> <m:code>$1</m:code> <m:price>$2</m:price> </m:checkpriceresponse> </format> <args> <arg expression="//m0:symbol" xmlns:m0="http://services.samples/xsd"> <arg expression="//m0:last" xmlns:m0="http://services.samples/xsd"> </arg></arg></args> </payloadFactory>
Syntax
<payloadFactory> <format ../> <args> <arg (value="string" | expression=" {xpath} ")/>* </args> </payloadFactory>
UI Configuration
When adding a mediator to a sequence, click Transform -> PayloadFactory.
PayloadFactory Mediator Field Descriptions
- Payload Format - Define the format of the payload in the text field that appears. To add content to the payload, enter variables for each value you want to add using the format $n (starting with 1 and incrementing with each additional variable, i.e., $1, $2, etc.). You will then create arguments in the same order as the variables to specify each variable's actual value.
- Arguments - For each variable in the format definition, click Add Argument and add an argument that defines the actual value.
The arguments must be entered in the same order as the variables in the format, so that the first argument defines the value for variable $1, the second argument defines the value for variable $2, etc. An argument can specify a literal string (e.g., "John") or an XPath expression that extracts the value from the content in the incoming payload.