Hi all,
Let’s discuss about Enrich mediator of WSO2 ESB. You can find it under core mediators.
And you also can find more information from WSO2 ESB Documentation. Before move to functionalities, I will give small description about “Source” and “Target”
Source - What will be using to do enriching ? (Ex: Property, inline content, body content etc.)
Target - Where and Action going to do Within the enrich process ? (Ex: Replace, add child to payload etc.)
I will here, list down main functionalities of Enrich mediator with regard to its available options. (I will give example scenarios for different Target Actions)
There are main three target actions as “Replace”, “Child” and “Sibling”. With the different source types (Inline, Property, Body etc.), you can perform number of different actions. I present basic sample scenarios for Target Actions.
1. Replace
Config
<sequence name="enrich_seq_3" xmlns="http://ws.apache.org/ns/synapse">
<property name="testProperty" scope="default" type="STRING" value="WSO2"/>
<enrich>
<source clone="true" property="testProperty" type="property"/>
<target action="replace" type="custom"
xmlns:ns="http://org.apache.synapse/xsd"
xmlns:ser="http://services.samples" xpath="//ser:getSimpleQuote/ser:symbol/text()"/>
</enrich>
<log level="full"/>
</sequence>
Request
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://services.samples">
<soapenv:Header/>
<soapenv:Body>
<ser:getSimpleQuote>
<!--Optional:-->
<ser:symbol>IBM</ser:symbol>
</ser:getSimpleQuote>
</soapenv:Body>
</soapenv:Envelope>
After Enriching
<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://services.samples">
<soapenv:Body>
<ser:getSimpleQuote>
<!--Optional:-->
<ser:symbol>WSO2</ser:symbol>
</ser:getSimpleQuote>
</soapenv:Body>
</soapenv:Envelope>
2. Adding Child
Config
<sequence name="enrich_seq_11" xmlns="http://ws.apache.org/ns/synapse">
<log level="full"/>
<enrich>
<source clone="true" type="body"/>
<target action="child" type="body"/>
</enrich>
<log level="full"/>
</sequence>
Request
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://services.samples">
<soapenv:Header/>
<soapenv:Body>
<ser:getSimpleQuote>
<!--Optional:-->
<ser:symbol>IBM</ser:symbol>
</ser:getSimpleQuote>
</soapenv:Body>
</soapenv:Envelope>
After Enriching
<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://services.samples">
<soapenv:Header xmlns:wsa="http://www.w3.org/2005/08/addressing"/>
<soapenv:Body>
<ser:getSimpleQuote>
<!--Optional:-->
<ser:symbol>IBM</ser:symbol>
<ser:getSimpleQuote>
<!--Optional:-->
<ser:symbol>IBM</ser:symbol>
</ser:getSimpleQuote>
</ser:getSimpleQuote>
</soapenv:Body>
</soapenv:Envelope>
3. Adding Sibling
Config
<sequence name="enrich_seq_11" xmlns="http://ws.apache.org/ns/synapse">
<log level="full"/>
<enrich>
<source clone="true" type="body"/>
<target action="sibling" type="body"/>
</enrich>
<log level="full"/>
</sequence>
Request
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://services.samples">
<soapenv:Header/>
<soapenv:Body>
<ser:getSimpleQuote>
<!--Optional:-->
<ser:symbol>IBM</ser:symbol>
</ser:getSimpleQuote>
</soapenv:Body>
</soapenv:Envelope>
After enriching
<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://services.samples">
<soapenv:Header xmlns:wsa="http://www.w3.org/2005/08/addressing"/>
<soapenv:Body>
<ser:getSimpleQuote>
<!--Optional:-->
<ser:symbol>IBM</ser:symbol>
</ser:getSimpleQuote>
<ser:getSimpleQuote>
<!--Optional:-->
<ser:symbol>IBM</ser:symbol>
</ser:getSimpleQuote>
</soapenv:Body>
</soapenv:Envelope>
Note: As I mentioned earlier, this is basic functionalities u can do with Enrich mediator. Try out it through different aspects and find new mediation patterns ;)
Value additions are always welcome :)