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.
The Enrich mediator is a content-aware mediator.
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.
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:
- 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.
For the target type '
envelope', the action type should be
'replace'. Herein, action type '
child' is not acceptable because it adds an envelope within an envelope, and action type '
sibling' is also not acceptable because there will be two envelopes in a message if you use it.
Type and XPath Expression - Refer the Source configuration above.
The target type depends on the source type. For the valid and invalid combinations of source and target types, see below table.
Source type custom envelope body property custom valid invalid valid valid envelope invalid invalid invalid valid body valid invalid invalid valid property valid valid valid valid inline valid valid valid valid
Example 1: Setting the property symbol
In this example, you are setting the property symbol. Later, you can log it using the Log Mediator.
Example 2: Adding a child object to a property
In this example, you add a child property named Lamborghini to a property named Cars. The configuration for this is as follows:
Example 3 - Adding a SOAPEnvelope type object as a property to a message
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
Example 4 - Preserving the original payload
In this example, you copy the original payload to a property using the Enrich mediator.
Then whenever you need the original payload, you replace the message body with this property value using the Enrich mediator as follows:
Example 5 - Enriching in JSON format
For a message to be enriched as a JSON current message in the message flow or incoming message should be a JSON and one of the following conditions should be matched.
Both source and target do not have custom path expressions.
Source has a custom json-path and target does not have any expressions.
Target has a custom json-path and source does not have any expressions.
Both target and source have custom json-path expressions.
The following sample scenarioes can be used to test the differnt JSON enriching scenarioes.
In JSON enriching scenarios if the enrich mediator source defined as a property it should contain a json object or json array.
Sample 1 - Setting the custom path expressions to message body
Sample 2 - Setting the property to custom as a sibling
Sample 3 - Setting the property to custom as a child
Sample 4 - Setting the inline to custom as a child
Sample 5 - Setting the inline to body
Sample 6 - Setting the custom path expressions to property
For other example 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