Skip to content

Headers

Maarten van Weerd edited this page Jun 2, 2020 · 11 revisions

What are headers?

Every message in Apache Camel consists of a body, headers and attachements:

Headers

Message headers are properties on messages. Each header consist of a key/value pair. For example:

myHeader1=23 myHeader2=someText

In this example 'myHeader1' and 'myHeader2' are the header keys and '23' and 'someText' the header values. A header key is just a name. Values can be set as a constant or by a scripting language (jsonpath, xpath, groovy and simple).

Every message has headers, but every component (protocol) use them differently. For example there are HTTP headers or JMS Headers, whereas file only contains the body. Camel will automatically convert headers between components. For example JMS Headers to HTTP Headers.

What types of headers are there?

The header value can be set as:

  1. Constant: A fixed value
  2. XPATH: Values are set from the message body with a xpath expression.
  3. JSONPATH: Values are set from the message body with a jsonpath expression.
  4. Simple: Values are set with Simple expressions.
  5. Groovy: Values are set with a Groovy expressions.

Headers in Assimbly

In Assimbly a header contains 1 or more key/value pairs. Headers can be set on a from, to or error endpoint. When set on the from endpoint all destinations will receive the header. When set on a to or error endpoint only this specific endpoint will receives the headers.

How to create a header?

There are two ways to create a header

  1. Settings --> Headers --> Create header
  2. Flows --> Create flow --> Endpoint (From/To/Error) --> Header

An example of a header with 5 key/value pairs:

Headers

After creation a header can be selected on every endpoint. It's thus possible to use the same header on multiple flows and endpoints.

How to use a header?

You can use a header to set an option with a value. For example set the fileName property of the camel File scheme from a JMS property "X-Originalfilename":

Headers

Special headers

Within Assimbly there are some special headers. These headers apply an action, like conversion of the message body.

ConvertFormat

This header converts the body of a message from one dataformat to another. For this Assimbly uses Assimbly DocConverter. The following entries are valid:

Header Key Header Value Remark
ConvertFormat XML2JSON Converts XML body to JSON
ConvertFormat XML2YAML Converts XML body to YAML
ConvertFormat XML2CSV Converts XML body to CSV
ConvertFormat JSON2XML Converts JSON body to XML
ConvertFormat JSON2YAML Converts JSON body to YAML
ConvertFormat JSON2CSV Converts JSON body to CSV
ConvertFormat YAML2XML Converts YAML body to XML
ConvertFormat YAML2JSON Converts YAML body to JSON
ConvertFormat YAML2CSV Converts YAML body to CSV
ConvertFormat CSV2XML Converts CSV body to XML
ConvertFormat CSV2JSON Converts CSV body to JSON
ConvertFormat CSV2YAML Converts CSV body to YAML

ConvertType

The output of the body is by default a text message. By adding the header key "convertBodyTo" with the value "bytes" the output will be a bytes message (byte[]). The following entries are valid:

Header Key Header Value Remark
ConvertType Body2Bytes Converts body to a byte[] message
ConvertType Body2String Converts body to a text message
ConvertType Body2File Converts body to a File message
ConvertType Body2InputStream Converts body to a byte[] message

ReplyTo

The 'ReplyTo' header sets the reply destination from an URI. For example 'direct://someDestination' or 'file://C:\saveReply'. When a to endpoint returns a message the destination is used, otherwise ignored.

Header Key Header Value Remark
ReplyTo {Camel URI} The destination of the reply
Clone this wiki locally