Chapter 4. Transformation

In this chapter, we will cover:

  • Transforming using a Simple Expression
  • Transforming inline with XQuery
  • Transforming with XSLT
  • Transforming from Java to XML with JAXB
  • Transforming from Java to JSON
  • Transforming from XML to JSON
  • Parsing comma-separated values (CSV)
  • Enriching your content with some help from other endpoints
  • Normalizing messages into a common XML format

Introduction

In this chapter, we will be looking at a few of the ways that Camel allows you to transform or change the content of messages being processed. The book Enterprise Integration Patterns by Gregor Hohpe and Bobby Woolf defines the responsibility of translating data from one format to another within the Message Translator pattern (http://www.enterpriseintegrationpatterns.com/MessageTranslator.html). This is what Camel has based its transformation capabilities on.

Introduction

In this chapter we will explore a number of ways in which Camel performs message content transformation:

  • Using the transform statement. This allows you to reference Camel Expression Language code within the route to do message transformations.
  • Calling a templating component, such as Camel's XSLT or Velocity template style components. This will typically reference an external template resource that is used in transforming your message.
  • Calling a Java method (for example, beanref), defined by you, within a Camel route to perform the transformation. This is a special case processor that can invoke any referenced Java object method.
  • Camel's Type Converter capability that can automatically cast data from one type to another transparently within your Camel route. This capability is extensible, so you can add your own Type Converters.
  • Camel's Data Format capability that allows us to use built-in, or add our own, higher order message format converters. A Camel Data Format goes beyond simple data type converters, which handle simple data type translations such as String to int, or File to String. Data Formats are used to translate between a low-level representation (XML) and a high-level one (Java objects). Other examples include encrypting/decrypting data, and compressing/decompressing data. For more, see http://camel.apache.org/data-format.html.

A number of Camel architectural concepts are used throughout this chapter. There is a broader overview of Camel concepts in the Preface. Full details can be found at the Apache Camel website at http://camel.apache.org.

The code for this chapter is contained within the camel-cookbook-transformation module of the examples.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.150.41