Skip to content

Headers

Raymond Meester edited this page Mar 6, 2023 · 11 revisions

What are headers?

Every message 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. Assimbly (Apache 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

On a connector flow 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 headers. When set on a to or error endpoint only this specific endpoint will receives the headers.

On routes headers can be set on the XML:

<route>
    <from uri="direct:a"/>
    <setHeader name="myHeader">
        <constant>test</constant>
    </setHeader>
    <to uri="direct:b"/>
</route>

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

RemoveHeaders

To remove on or multiple headers you can add the following header

Header key: RemoveHeaders (constant) Header value: {pattern} (for example: JMS*)

Special headers

!This only counts for Assimbly 3.x. For 4.x or higher use the action step!

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 inputstream message

Enrich

The 'Enrich' header, sets an endpoint to enrich data. Example values are 'to' or 'response'. This means it doesn't send data, but pulls (enrich) the data from the endpoint.

Header Key Header Value Remark
Enrich to Enrich to endpoint
Enrich response Enrich response endpoint
Clone this wiki locally