How to construct a payload with the soap envelope?

Image for post
Image for post

In this example, we are going to construct the payload using Payload Factory mediator. When we are using Payload factory mediator, we get the payload without the soap envelope.

Here, we are looking at how to construct the payload with the soap envelope.

We are going to construct the following payload.

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsd="http://services.samples/xsd" xmlns:ser="http://services.samples">
<soap:Body>
<ser:getQuote>
<ser:request>
<xsd:symbol>IBM</xsd:symbol>
</ser:request>
</ser:getQuote>
</soap:Body>
</soap:Envelope>

We can use payload factory mediator as follow.

<?xml version="1.0" encoding="UTF-8"?>
<payloadFactory media-type="xml" xmlns="http://ws.apache.org/ns/synapse">
<format>
<soap:Envelope xmlns:ser="http://services.samples"
xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsd="http://services.samples/xsd">
<soap:Header/>
<soap:Body>
<ser:getQuote>
<ser:request>
<xsd:symbol>IBM</xsd:symbol>
</ser:request>
</ser:getQuote>
</soap:Body>
</soap:Envelope>
</format>
</payloadFactory>

But if we use this only we don’t get the soap envelope as below.

<ser:getQuote xmlns:ser="http://services.samples">
<ser:request>
<xsd:symbol xmlns:xsd="http://services.samples/xsd">IBM</xsd:symbol>
</ser:request>
</ser:getQuote>

Therefore, we are using the following property mediator.

Image for post
Image for post

The full proxy as below.

<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="PF2"
startOnLoad="true"
statistics="disable"
trace="disable"
transports="http,https">
<target>
<inSequence>
<payloadFactory media-type="xml">
<format>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
xmlns:xsd="http://services.samples/xsd"
xmlns:ser="http://services.samples">
<soap:Header/>
<soap:Body>
<ser:getQuote>
<ser:request>
<xsd:symbol>IBM</xsd:symbol>
</ser:request>
</ser:getQuote>
</soap:Body>
</soap:Envelope>
</format>
<args/>
</payloadFactory>
<property name="messageType" scope="axis2" type="STRING" value="text/xml"/>
<log level="full">
<property name="ChangedEnve" value="----Changed-------"/>
</log>
<respond/>
</inSequence>
</target>
<description/>
</proxy>

Written by

Senior Software Engineer — QA at WSO2

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store