# Payload-factory Mediator

Payload-factory mediator creates a new SOAP payload for the message, replacing the existing one. `printf()` style formatting is used in the mediator configuration to create the new payload. New payload format and necessary arguments could be provided through the UI.

Each argument could be a static value or an XPath expression. When an expression is used, argument value is fetched at runtime by evaluating the provided XPath expression against the existing message.

Figure 1: Configuring payloadFactory mediator

## Example configuration

### Mediator Configuration

`<payloadFactory>
<format>
<m:CheckPriceRequest xmlns:m="http://foo.com">
<m:Code>$1</m:Code>
<m:User>$2</m:User>
</m:CheckPriceRequest>
</format>
<args>
<arg xmlns:m0="http://services.samples" expression="//m0:getQuote/m0:request/m0:symbol"/>
<arg value="John Smith"/>
</args>
</payloadFactory>
`

### Input SOAP Payload

`<m:getQuote xmlns:m="http://foo.com">
<m:request>
<m:symbol>IBM</m:symbol>
</m:request>
</m:getQuote>
`

### Output SOAP Payload

`<m:CheckPriceRequest xmlns:m="http://foo.com">
<m:Code>IBM</m:Code>
<m:User>John Smith</m:User>
</m:CheckPriceRequest>
`