DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
Securing Your Software Supply Chain with JFrog and Azure
Register Today

Trending

  • The SPACE Framework for Developer Productivity
  • Implementing a Serverless DevOps Pipeline With AWS Lambda and CodePipeline
  • Mastering Time Series Analysis: Techniques, Models, and Strategies
  • Auditing Tools for Kubernetes

Trending

  • The SPACE Framework for Developer Productivity
  • Implementing a Serverless DevOps Pipeline With AWS Lambda and CodePipeline
  • Mastering Time Series Analysis: Techniques, Models, and Strategies
  • Auditing Tools for Kubernetes
  1. DZone
  2. Software Design and Architecture
  3. Integration
  4. WSO2 ESB Enrich Mediator Fast Tutorial

WSO2 ESB Enrich Mediator Fast Tutorial

Madhuka  Udantha user avatar by
Madhuka Udantha
CORE ·
May. 18, 13 · Interview
Like (0)
Save
Tweet
Share
14.82K Views

Join the DZone community and get the full member experience.

Join For Free

Enrich Mediator can be used to perform transformations with in integration logic. It process a message based on a given source configuration and perform the specified action on the message by using the target configuration.


syntax

<enrich>
    <source \[clone=true\|false\] \[type=custom\|envelope\|body\|property\|inline\] xpath="" property="" />
    <target \[action=replace\|child\|sibiling\] \[type=custom\|envelope\|body\|property\|inline\] xpath="" property="" />
</enrich>

As above you can see there is main two configuration

  • Source
  • Target

Source Configuration

Clone : By this you can clone or used as a reference during enrich mediation. (default value is false)
Type :  Part that use from the original message to enrich the modified message
XPath Expression : Expression 


Target Configuration

Action : Action can be applied to outgoing messages and it is define by type
  Replace - replaces the XML message based on the target type specified (default action)
  Child  - Adding chile for the specified target type.
  Sibling  - Adding as a sibling of the specified target type.


eg:

<enrich xmlns="[a href="http://ws.apache.org/ns/synapse%22"]http://ws.apache.org/ns/synapse">
  <source clone="false" type="envelope" xpath="" property="" />
  <target action="replace" type="body" xpath="" property="" />
</enrich>


replacing xml part in payload

<proxy xmlns="http://ws.apache.org/ns/synapse" name="testingProxy4" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
   <target>
      <inSequence>
         <log level="full"/>
         <enrich>
            <source type="inline">
               <tran:rootId xmlns:tran="http://transport.org">5</tran:rootId>
            </source>
            <target xmlns:tran="http://transport.org" xpath="//tran:getBusNo/tran:rootId"/>
         </enrich>
         <log level="full"/>
         <send>
            <endpoint key="conf:/getBus"/>
         </send>
      </inSequence>
      <outSequence>
         <send/>
      </outSequence>
   </target>
   <publishWSDL uri="http://localhost:9763/services/BusServices?wsdl"/>
   <description></description>
</proxy>

Here is sample proxy for Console:

image

Check with SOAP UI

image

Changing text in payload

<enrich>
  <source type="inline" clone="true">8</source>
  <target xmlns:tran="http://transport.org" xpath="//tran:getBusNo/tran:rootId/text()"/>
</enrich>
image

image

Adding new Property for that request body

      <enrich>
            <source type="inline" clone="true">
               <busName xmlns="">Testing</busName>
            </source>
            <target type="body" action="child"/>
        </enrich>

Adding body or any customer Xpath in to property (new Property)

     <enrich>
           <source type="body"/>
           <target type="property" property="REQUEST_PAYLOAD"/>
      </enrich>
        <log>
               <property name="Request Payload" expression="get-property('REQUEST_PAYLOAD')"/>
        </log>

image

Here is the last Proxy code in here

<proxy xmlns="http://ws.apache.org/ns/synapse" name="testingProxy4" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
   <target>
      <inSequence>
         <log level="full"/>
         <enrich>
            <source type="inline" clone="true">
               <busName xmlns="">Testing</busName>
            </source>
            <target type="body" action="child"/>
         </enrich>
         <enrich>
            <source type="body" clone="true"/>
            <target type="property" property="REQUEST_PAYLOAD"/>
         </enrich>
         <log>
            <property name="Request Payload" expression="get-property('REQUEST_PAYLOAD')"/>
         </log>
         <log level="full"/>
         <send>
            <endpoint key="conf:/getBus"/>
         </send>
      </inSequence>
      <outSequence>
         <send/>
      </outSequence>
   </target>
   <publishWSDL uri="http://localhost:9763/services/BusServices?wsdl"/>
   <description></description>
</proxy> 

Enterprise service bus Mediator (software)

Published at DZone with permission of Madhuka Udantha, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Trending

  • The SPACE Framework for Developer Productivity
  • Implementing a Serverless DevOps Pipeline With AWS Lambda and CodePipeline
  • Mastering Time Series Analysis: Techniques, Models, and Strategies
  • Auditing Tools for Kubernetes

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: