Skip to main content
Version: 4.15.0

Enrich component

The Enrich component lets you take a 'sample' of a message in your flow and enrich it with another set of data or files.

Configuration

The Enrich component has the following configuration options:

File Type

Type of merging you want to do. See the Using Enrich section below for an example per File Type.

Options

  • XML (default)
  • JSON
  • Override
  • Add as attachment
  • Add to zip

Use error route?

If disabled, failed exchanges won't go into the error route. This option is only available when File Type is set to Override.

Using Enrich

An Enrich component has one input and two outputs. When the Enrich input receives a message this takes place:

  1. The bottom output starts a new 'thread' with a sample of the message (body and headers) entering the input.
  2. The bottom flow is followed and the result is returned to the Enrich component. During this process the right side output waits.
  3. The component enriches the input with this result (following the File Type setting) and sends this enriched message out the right side output.
note

The component will wait for a response from the bottom part of the flow before continuing the flow on the right side output.

scope of headers

The sampled message runs in its own separate 'thread' and doesn't affect the main flow. Therefore, headers that are set and/or received on the bottom output flow do not persist on the right side output (except when File Type is set to Override).

Simple JSON example

In the example below both Velocity components contain JSON data and File Type is set to JSON.

Simple Enrich example

Example JSON data

JSON in input Velocity
{
"original": {
"first_element": "something",
"second_element": "else"
}
}
JSON in Enrich bottom route Velocity
{
"new": {
"element_one": "this",
"element_two": "that"
}
}
Result JSON after enrichment
[
{
"original": {
"first_element": "something",
"second_element": "else"
}
},
{
"new": {
"element_one": "this",
"element_two": "that"
}
}
]
note

The Enrich component combines the two JSON files into one array [...].

valid JSON

For this enrichment to function properly both the input and bottom result JSON have to be valid.

Advanced XML Example

Below is a more advanced example of an Enrich use case where File Type is set to XML. In this case XML order data is enriched with XML data from a SOAP call, this enrichment is transformed and sent to an HTTP endpoint.

Enrich example

In this example:

  1. A body with XML is received on an Inbound HTTP component.
  2. This XML is enriched with the response of a SOAP call:
    1. First the received XML is transformed with an XSLT component to build the SOAP request.
    2. This 'transformed' body is sent to a SOAP endpoint with the SOAP component.
    3. The SOAP response XML is returned to the Enrich component that has been waiting for this response.
  3. The enriched XML is transformed with an XSLT component in the top part of the flow.
  4. This transformed body is posted to an HTTP endpoint with the HTTP component.

Example XML data

Received XML on Inbound HTTP component
<?xml version="1.0"?>
<inbound_http_order>
<order_id>1234</order_id>
<order_date>25-11-2023</order_date>
<order_contact>John Doe</order_contact>
<order_contact_id>9874</order_contact_id>
</inbound_http_order>
Transformed XML for SOAP request
<?xml version="1.0"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://www.w3.org/...">

<SOAP-ENV:Body xmlns:m="http://www.xyz.org/orders">
<m:GetOrder>
<m:OrderId>1234</m:OrderId>
</m:GetOrder>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
SOAP response XML
<?xml version="1.0"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://www.w3.org/...">

<SOAP-ENV:Body xmlns:m="http://www.xyz.org/orders">
<m:GetOrderResponse>
<m:OrderId>1234</m:OrderId>
<m:OrderDeliveryDate>26-11-2023</m:OrderDeliveryDate>
<m:OrderCompany>A Company</m:OrderCompany>
<m:OrderCompanyId>6543</m:OrderCompanyId>
</m:GetOrderResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Enriched XML
<?xml version="1.0" encoding="UTF-8"?>
<Enriched>
<inbound_http_order>
<order_id>1234</order_id>
<order_date>25-11-2023</order_date>
<order_contact>John Doe</order_contact>
<order_contact_id>9874</order_contact_id>
</inbound_http_order>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://www.w3.org/...">
<SOAP-ENV:Body xmlns:m="http://www.xyz.org/orders">
<m:GetOrderResponse>
<m:OrderId>1234</m:OrderId>
<m:OrderDeliveryDate>26-11-2023</m:OrderDeliveryDate>
<m:OrderCompany>A Company</m:OrderCompany>
<m:OrderCompanyId>6543</m:OrderCompanyId>
</m:GetOrderResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
</Enriched>
note

The Enrich component combines the two XML by wrapping them into one element called Enriched.

valid XML

For this enrichment to function properly both the input and bottom result XML have to be valid.

Example XML for HTTP call
<?xml version="1.0" encoding="UTF-8"?>
<NewOrder>
<id>1234</id>
<date>25-11-2023</date>
<delivery_date>26-11-2023</delivery_date>
<contact>John Doe</contact>
<company>A Company</company>
<contact_id>9874</contact_id>
<company_id>6543</company_id>
</NewOrder>
note

The XSLT component transforms the enriched XML into a new format that's sent to the HTTP endpoint.

tip

To learn how to make an XSLT with MapForce read this tutorial

Override type

When File Type is set to Override you force the Enrich component to override the input with the result of the bottom output flow. The result body that overrides the original input body can be any filetype because it is read as a binary.

A use case for this is:

  1. A request is received on an Inbound HTTP component (with Exchange pattern set to Request reply).
  2. An external PDF file is fetched in the bottom output flow of the Enrich component.
  3. This PDF overrides the original body, returns it to the Inbound HTTP component that responds to the original request.
ignore error route empty body

Disable the Use error route? property to avoid the flow entering the error route when the result of the Enrich is an empty body.

Add as attachment

This option is primarily used to send (multiple) attachments with the Email component. Imagine there's already a text or html body for your email, but you need to get and/or add some attachments.

Below is an example of adding attachments to an email with the File Type set to Add as attachment.

Enrich as attachment example

The Enrich component uses Multipart to add attachments to an existing body to ensure they are seperate attachments in an email. It is important to know that after you have used the Enrich with "Add as attachment" the body is transformed into Multipart.

set CamelFileName

With a SetHeaders component you can specify the CamelFileName header to set the filename of the email attachment. In general the type of attachment is set accordingly, set the Content-Type header to override it.

Add to zip

This option allows you to enrich an existing zip archive with a new body. Keep in mind while using this option:

  1. There has to be a zip archive in your body before the enrichment, otherwise a new body cannot be added.
  2. Specify the target location in the zip archive with the CamelFileName header.
  3. A binary body can be added.
set CamelFileName

Every file that is added to the zip archive needs to have a CamelFileName header. Set it with a SetHeaders component when necessary. Make sure to add the correct extension for the filetype of the body.

Below is an example of an Enrich use case where File Type is set to Add to zip.

Enrich to zip example

In this example:

  1. A SetHeaders component sets the CamelFileName header of the current body, i.e. order.xml or contacts.json.
  2. An archive is created with the Archive component.
  3. The first Enrich component enriches the archive with a Velocity component body. In it's bottom output flow:
    1. A SetHeaders component sets the CamelFileName for the body in the Velocity that follows.
    2. The result is returned to the Enrich component that adds it to the archive.
  4. The second Enrich component enriches the archive with a file that is fetched from an FTP server:
    1. Files fetched with the FTP component already have a CamelFileName header, it doesn't need to be specified.
  5. The final FTP component writes the archive to an FTP server. Use the FTP File Name option to define the filename of the archive.
tip

Use this option in combination with an Enrich component File Type that's set to Override if you want to get a zip archive from an external location and add bodies to that archive.