Book Image

Mastering Apache Camel

By : Bilgin Ismet Ibryam, Jean Baptiste Onofre, Jean-Baptiste Onofré
5 (1)
Book Image

Mastering Apache Camel

5 (1)
By: Bilgin Ismet Ibryam, Jean Baptiste Onofre, Jean-Baptiste Onofré

Overview of this book

Table of Contents (15 chapters)
Mastering Apache Camel
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Type converter


Even without a data format, when you route a message from one endpoint to another, it's common to convert the body of the message from one type to another. For instance, in an exchange created by a file endpoint, the body of the in message will be an InputStream. Depending on the target endpoint or processor, we may want to convert this InputStream to a String.

When you use the getBody() method on a message, you can specify the expected type. Camel will use a type converter to try to convert the actual body of the message into the specified type.

For instance, in a processor, if you do the following:

Message in = exchange.getIn();
Document document = in.getBody(Document.class);

Camel will try to convert the body of the in message into a DOM document. A type converter is defined by the org.apache.camel.TypeConverter interface. The type converters are loaded into the Camel context, in a type converter's registry.

The type converter's registry contains the type converter with the...