Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
XML
XML
<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>

...

UI Configuration

The main available properties of the Enrich Mediator available are as follows:

...

Source Configuration
Anchor
Source
Source

...

Info
titleTip

You can click the Namespaces link to add namespaces if you are providing an expression. You will be provided another panel named "Namespace Editor," where you can provide any number of namespace prefixes and URL URLs that you have used in the XPath expression. 

...

  • Action- By specifying the action type, the relevant action can be applied to outgoing messages.
    • Replace - Replace is the default value of Action. It will be used if a specific value for Action is not given. This replaces the XML message based on the target type specified on the target configuration. 
    • Child - Adding as a child of the specified target type.
    • Sibling - Adding as a sibling of the specified target type.

Type and XPath Expression - expression. Refer to "Source Configuration" above.

Info
titleNote

You can configure the Mediator mediator using XML. Click on "switch to source view" in the "Mediator" window.

...

Code Block
languagehtml/xml
<proxy xmlns="http://ws.apache.org/ns/synapse" name="_TestEnrich" transports="https,http" statistics="disable" trace="enable" startOnLoad="true"> 
   <target> 
      <inSequence> 
         <enrich> 
            <source type="inline" clone="true"> 
               <Cars/> 
            </source> 
            <target type="property" property="Cars"/> 
         </enrich> 
         <log level="custom"> 
            <property name="PekeCarListBeforeEnrich" expression="get-property('Cars')"/> 
         </log> 
         <enrich> 
            <source type="inline" clone="true"> 
               <Car>Lamborghini</Car> 
            </source> 
            <target action="child" xpath="$ctx:Cars"/> 
         </enrich> 
         <log level="custom"> 
            <property name="PekeCarListAfterEnrich" expression="get-property('Cars')"/> 
         </log> 
      </inSequence> 
      <outSequence/> 
   </target> 
   <description></description> 
</proxy>

Example 3 - Addinga SOAPEnvelopetype SOAPEnvelope type object as a property to a message

In this example, we add the SOAP envelope in a SOAP request as a property to a message. The Enrich mediator is useful in this scenario since adding the property directly using the Property mediator results in the SOAPEnvelope object being created as an OM type object. The OM type object created cannot be converted back to a SOAPEnvelope object.

Code Block
languagexml
<enrich> 
<source type="envelope" clone="true"/>
<target type="property" property="ExtractedEnvelope"/>
</enrich>
Excerpt
hiddentrue

Added this content for the FAQ When ExtractedEnvelope is a SOAPEnvelope with OM type, why do we get "EnrichMediator SOAPEnvelope is expected" for SOAP requests?

Excerpt
hiddentrue
Excerpt
hiddentrue

Description of the Enrich Mediator in WSO2 ESB.

Example 2 is written with reference to /wiki/spaces/FAQ/pages/37781537.

 Example 4 - Preserving the original payload

In this example, you copy the original payload to a property using the Enrich mediator.

Code Block
languagexml
<enrich>
      <source clone="false" type="body"/>
      <target action="replace" type="property" property="ORIGINAL_PAYLOAD"/>
   </enrich>

Then, whenever you need the original payload, you replace the message body with this property value using the Enrich mediator as follows:

Code Block
languagexml
<enrich>
      <source clone="false" type="property" property="ORIGINAL_PAYLOAD"/>
      <target action="replace" type="body"/>

  </enrich>

For other example examples using the Enrich mediator, see Sample 15: Using the Enrich Mediator for Message Copying and Content Enrichment and Sample 440: Converting JSON to XML Using XSLT.