Sunday, June 25, 2017

WSO2 ESB - How to set payload content using enrich mediator?

You can use WSO2 enrich mediator replace a new value to a existing payload as below

We will assume that, ESB received a payload as below:
<?xml version='1.0' encoding='utf-8'?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <soap:Body>
        <person>
            <name>tharanga</name>
        </person>
    </soap:Body>
</soap:Envelope>

And if you need to set the new name of person,  you can use the enrich mediator as below:

<property name="PersonName" value="wijeweera"/>
<enrich>
   <source type="property" clone="true" property="PersonName"/>
   <target xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xpath="//soap:Envelope/soap:Body/person/name/text()"/>
</enrich>

PersonName value (wijeweera) will replace with the old value. Then payload will be as below.

<?xml version='1.0' encoding='utf-8'?> <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <soap:Body> <person> <name>Wijeweera</name> </person> </soap:Body> </soap:Envelope>

Enjoy..!!

No comments:

Post a Comment