SetHeader component
In Dovetail each processed message consists of a body
and headers
. The body
of a message is the actual contents of the message, e.g. the data that's being processed. The headers
contain meta data and are usually used only internally by Dovetail components.
The SetHeader component can be used to alter the headers of a message. You can chain multiple setHeader components together to modify multiple headers. You can also set custom headers for your own personal use.
Configuration
This component can not be used as the first component in a flow, as it expects to alter the headers of a message. To use the Set Header component you must provide a valid message header name and a valid expression.
Configuration options
The Setheader component has the following configuration options:
Property | Description |
---|---|
Header Name | The name of the header you wish to set. |
Expression Type | The language of the expression. |
Expression | How you wish to set or change header |
Header Names
Header Names
can not contain spacesHeader Names
in Dovetail are case-insensitive so setting a header namedsubject
on an exchange that already has a header with the nameSubject
will just replace the value of the existing header namedSubject
.
Expression Types
Expressions can be defined using the following types:
Expression Type | Description |
---|---|
Simple | Simple Expression Language, which also supports File Expression Language. It only returns plain text, no xml. |
XPath | XPath 2.0 language. It only returns plain text, no xml. |
JsonPath | JsonPath language. |
Groovy | Groovy. It only supports one-line expressions. Use the script component for multiline scripts. |
Constant | When using ${header.<headername>} as (part of) a Constant the literal string will be set as the Global variable, not it's value. |
Expression examples
1 - Change filename with date
Header Name: CamelFileName
Expression: input_${date:now:yyyyMMdd_HHmmssSS}.xml
Result: The filename will be input_20130618_17121212.xml
2 - Change file extension (using a File Expression Language)
Header Name: CamelFileName
Expression: ${file:onlyname.noext}.test
Result: The extension of the input file will be replace with test. If your input file is file1.xml
, your output will be file1.test
3 - Put the value of a xml node on the header using XPath
Consider the following XML in the body:
<?xml version="1.0"?>
<Root>
<Foo>
<Bar>Value 1</Bar>
</Foo>
<Foo>
<Bar>Value 2</Bar>
</Foo>
<Foo>
<Bar>Value 3</Bar>
</Foo>
</Root>
Header Name: NameItSomething
Expression Type: XPath
Expression: /Root/Foo/Bar[1]/text()
Result: The value of the header NameItSomething
will be Value 1
.
4 - Custom URL
Header Name: CamelHttpUri
Expression: http://bcchanger.com/bitcoin_price_feed.php?feed_type=xml¤cy=EUR
Result: This will override the http uri set in the following http component.
5 - Variable HTTP Query params
This example will show you how you can retrieve variable query params with input of previous actions. In this example we use the bitcoin price feed. Say you want to fetch an xml from that feed you will use the uri http://bcchanger.com/bitcoin_price_feed.php?feed_type=xml¤cy=EUR. Notice the currency in this case is fixed but you want to be more flexible then you can configure the setHeader component as follows
Header Name: CamelHttpQuery
Expression: feed_type=xml¤cy=${bodyAs(String)}
Result: When you have a http component specified after the setHeader component it will use the this http query and append it to the Http URI. The ${bodyAs(String)} in this case will contain the currency value(e.g. EUR or USD)(Note: the previous component was a inbound http component, the body of the request contains the currency)
How do you setup the other components? The http component you only use http: as URI you leave out the query params. Also notice you don't place a ? at the end.