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 basically 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.
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>
UI Configuration
The main properties of the Enrich Mediator available are:
Source Configuration
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 false.
- True
- False
- 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.
- Inline - Specifies an inline XML value.
- XPath Expression
Tip
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.
Target Configuration
The following properties are available:
- 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 - Refer to "Source Configuration" above.
Note
You can configure the Mediator using XML. Click on "switch to source view" in the "Mediator" window.
Example 1: Setting the property symbol
<enrich xmlns="http://ws.apache.org/ns/synapse"> <source clone="false" type="envelope" xpath="" property="" /> <target action="replace" type="body" xpath="" property="" /> </enrich>
In this example, we are setting the property symbol. Later, you can log it using the Log Mediator.
Example 2: Adding a child object to a property
- Open the ESB management console and go to the Main tab.
- Click on the required service link (e.g.
StockQuoteProxy
) to open the service dashboard for that service. - Click Edit under Specific Configuration in the service dashboard. The Modify Proxy Service page will open.
- Click Next.
- Click the Create or Edit link next to the Define Inline option under Define In Sequence. (Note that a link is displayed only if the option is selected. The Create or Edit link is displayed depending on whether an in sequence is already defined.)
- Specify whether you want to add the child property using the source view or the design view by selecting the required value for the Sequence field.
If you are using the source view, enter the following and then click Save & Close.
<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>
- If you are using the design view, enter the path in which the sequence you want to modify is located in the On Error Sequence field. You can browse for the required path in the configuration registry or the governance registry.
- Click on the Root of the navigator and then click Add Child. Move the curser to Core and then click Enrich. As a result, Enrich will be added under Root. (You can skip this step if the Enrich mediator already exists under Root.)
- Click on Enrich to open the Enrich Mediator tab.
- Select Property in the Type field (under Source). As a result, the Property field will be displayed under the Type field.
- Enter a name for the property in the Property field.
- Select Child in the Action field.
- Select Property in the Type field (under Target).
- Enter a name for the child property in the Property field (under Target).
- Click Update and then click Save.
For another example using the Enrich mediator, see Sample 440: Converting JSON to XML Using XSLT.