How to construct a new payload using the existing payload?

Isuru Uyanage
Think Integration
Published in
1 min readFeb 3, 2019

Adding existing payload as a child element!

image courtesy: https://c4.wallpaperflare.com/

Existing Payload

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
<soapenv:Body>
<order>
<price>12</price>
<productid>IC002</productid>
<quantity>2</quantity>
<reference>ref</reference>
</order>
</soapenv:Body>
</soapenv:Envelope>

Now we want to construct a new payload using the existing payload body as the child element. We get the <order> element as a child of <orders> element in the new payload.

New Payload

<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
<soapenv:Body>
<orders>
<order>
<price>12</price>
<productid>IC002</productid>
<quantity>2</quantity>
<reference>ref</reference>
</order>
</orders>
</soapenv:Body>
</soapenv:Envelope>

We can use the WSO2 Enrich mediator in order to achieve this.

<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="1_6_1_3_Proxy_addCurrentPayloadAsChild"
startOnLoad="true"
statistics="disable"
trace="disable"
transports="http,https">
<target>
<inSequence>
<enrich>
<source clone="true" type="body"/>
<target property="originalPayloadBody" type="property"/>
</enrich>
<enrich>
<source clone="true" type="inline">
<orders xmlns=""/>
</source>
<target type="body"/>
</enrich>
<enrich>
<source clone="true" property="originalPayloadBody" type="property"/>
<target action="child" xpath="//orders"/>
</enrich>
<respond/>
</inSequence>
<outSequence/>
<faultSequence/>
</target>
<description/>
</proxy>

--

--