Set Header

The SetHeader EIP is used for setting a message header.

Options

The Set Header eip supports 1 options, which are listed below.

Name Description Default Type

expression

Required Expression to return the value of the header.

ExpressionDefinition

name

Required Name of message header to set a new value The simple language can be used to define a dynamic evaluated header name to be used. Otherwise a constant name will be used.

String

description

Sets the description of this node.

DescriptionDefinition

Using Set Header

The following example shows how to set a header in a Camel route:

from("direct:a")
    .setHeader("myHeader", constant("test"))
    .to("direct:b");

And the same example using XML:

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

In the example the header value is a constant.

Any of the Camel languages can be used, such as Simple.

from("direct:a")
    .setHeader("randomNumber", simple("${random(1,100)}"))
    .to("direct:b");

And in XML:

<route>
    <from uri="direct:a"/>
    <setHeader name="randomNumber">
        <simple>${random(1,100)}</simple>
    </setHeader>
    <to uri="direct:b"/>
</route>

Header can be set using fluent syntax.

from("direct:a")
    .setHeader("randomNumber").simple("${random(1,100)}")
    .to("direct:b");

See JSONPath for another example.

Setting a header from another header

You can also set a header with the value from another header.

In the example we set the header foo with the value from an existing header named bar.

from("direct:a")
    .setHeader("foo", header("bar"))
    .to("direct:b");

And in XML:

<route>
    <from uri="direct:a"/>
    <setHeader name="foo">
        <header>bar</header>
    </setHeader>
    <to uri="direct:b"/>
</route>