The 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. It gets an OMElement
using the configuration specified in the source and then modifies the message by putting it on the current message using the configuration in the target.
Table of Contents |
---|
maxLevel | 3 |
---|
minLevel | 3 |
---|
location | top |
---|
style | border:1 |
---|
type | flat |
---|
separator | pipe |
---|
|
Code Block |
---|
|
<enrich>
<source [clone=true|false] [type=custom|envelope|body|property|inline] xpath | json-eval(JSON-Path)="" property="" />
<target [action=replace|child|sibiling] [type=custom|envelope|body|property|inline] xpath | json-eval(JSON-Path)="" property="" />
</enrich> |
The main properties of the Enrich Mediator available are:
The following properties are available:
- Clone- By setting the clone configuration, the message can be cloned or used as a reference during enriching. The default value is true.
- Type- The type that the mediator uses from the original message to enrich the modified message that passes through the mediator.
- Custom - Custom XPath value.
- Envelope - Envelope of the original message used for enriching.
- Body - Body of the original message used for enriching.
- Property - Specifies a property. For information on how you can use the Property mediator to specify properties, see Property Mediator.
- XPath Expression - This field is used to specify the custom XPath value if you selected custom for the Type field.
Info |
---|
|
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 that you have used in the XPath expression. |
The following properties are available:
Note the following when using Enrich mediator with JSON payloads:
Only the add child operation is supported for JSON payloads. Add sibling operation can be achieved via add child indirectly.
Code Block |
---|
{ "Nimal" : { "student_Id" : "001" , "Marks" : [ 23, 34, 45, 56 ] } } Adding a sibling to $.Nimal.Marks[0] is equal to adding a child to $.Nimal.Marks |
When providing inline JSON payloads we can add JSON arrays, objects, and primitives (number
, string
, true
, false
). However, when enriching the inline content to the body, that content should be either a JSON object or an array.
You can add any JSON element (object, array, primitive) as a child if the target is a JSON array.
You can only add a JSON object as a child if the target is a JSON object.
Clone true/false does not apply to JSON as they are applied to XML payloads.
In this example, you are setting the property symbol. Later, you can log it using the Log Mediator.
Code Block |
---|
|
<enrich xmlns="http://ws.apache.org/ns/synapse">
<source clone="false" type="envelope"/>
<target type="property" property="payload" />
</enrich> |
In this example, you add a child property named Lamborghini to a property named Cars. The configuration for this is as follows:
Code Block |
---|
|
<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> |
In this example, you 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 |
---|
|
<enrich>
<source type="envelope" clone="true"/>
<target type="property" property="ExtractedEnvelope"/>
</enrich> |
In this example, you copy the original payload to a property using the Enrich mediator.
Code Block |
---|
|
<enrich>
<source clone="false" type="body"/>
<target action="replace" type="property" property="ORGINAL_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 |
---|
|
<enrich>
<source clone="false" type="property" property="ORIGINAL_PAYLOAD"/>
<target action="replace" type="body"/>
</enrich> |
For other example using the Enrich mediator, see /wiki/spaces/EI6xx/pages/49610946 and /wiki/spaces/EI6xx/pages/49611297.