Guide to Content Filter (Message Transformation)

In some situations, it becomes necessary, when dealing with large messages, to remove and filter unimportant information from a message using a Content Filter integration pattern. This is the opposite of the Content Enricher pattern which was adding and supplementing data.

Content Filter.drawio.png

The Content Filter pattern doesn’t just remove attributes, it is also quite useful in performing simplification via restructuring of the message structure. With complex messages, the structure is often represented as a hierarchical tree structure since many messages are originally from external systems or packaged applications. When these messages are aggregated together the result will tend to be many levels of nested, repeating groups. We have a tendency to create our complex messages modeled after generic, normalized database structures.

Upon closer examination of our message structures, and examination of known constraints and assumptions, we can determine that these complex hierarchies and nestings are superfluous. The role of the Content Filter is often employed to flatten the hierarchy into a simpler list of elements.

Implement Content Filter

A content filter is essentially an application of a message processing technique for a particular purpose. To implement a content filter, you can employ any of the following message processing techniques:

  • Message translator

  • Processors

  • Bean integration

XML Example

<camelContext xmlns="http://camel.apache.org/schema/spring">
  <route>
    <from uri="activemq:My.Queue"/>
    <to uri="xslt:classpath:com/acme/content_filter.xsl"/>
    <to uri="activemq:Another.Queue"/>
  </route>
</camelContext>

XPath Filter Example

You can also use XPath to filter out part of the message you are interested in:

<route>
  <from uri="activemq:Input"/>
  <setBody><xpath resultType="org.w3c.dom.Document">//foo:bar</xpath></setBody>
  <to uri="activemq:Output"/>
</route>