Sunday, August 31, 2014

[WSO2 ESB] Enrich Mediator Patterns

WSO2 ESB Enrich Mediator can process a message based on a given source configuration and then perform the specified action on the message by using the target configuration. The following post specifies some of the source/target patterns that can be used with Enrich mediator. The flow is explained in 'description' element of each mediator entry to make it easily understandable.

1. Adding a property value into message body as a sibling

<property name="failureResultProperty" scope="default" description="FailureResultProperty">
        <result xmlns="">failure</result> 

</property>
<enrich>
        <source xpath="$ctx:failureResultProperty"/>
        <target type="body" action="sibling"/> 

</enrich>   
   
2. Append new elements into a property using two enrichs

<property name="testMessages" scope="default" description="Test Messages Property">
        <
testMessages/> 
</property>
          
<property name="testMsg" expression="//testMessage" scope="default" type="OM"/>

<enrich description="Get testMessages into current msg body">
            <source type="property" property="testMessages"/>
            <target type="body"/> 

</enrich>
<enrich description="Append testMsg into testMessages property">
            <source xpath="$ctx:testMsg"/>
            <target type="body" action="child"/> 

</enrich>

<property name="testMessages" description="Set testMessages property back"  expression="//testMessages" scope="default" type="OM"/>
       
       
The final output for 'testMessages' property after enriching will be like this.

 




 
3 . Append direct to a property using single Enrich.
   
<property name="testMessages" scope="default" description="Test Messages Property">
        <
testMessages/> 
</property>
<enrich>
            <source xpath="//testMessage"/>
            <target action="child" xpath="$ctx:testMessages"/>
 </enrich>

    

1 comment:

  1. When adding an enrich mediator using Developer studio to replace an attribute of the soapEnvelope I cannot set any new values. The only available settings are: 'clone', 'type' (custom) and 'xpath' but there is no space to enter the new value..?

    ReplyDelete