SetHeaders 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 SetHeaders component can be used to alter multiple headers of a message at once. This component is equilivant to a chain of multiple SetHeader
components, for more information on how to set headers see SetHeader Component.
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 Headers component you must provide a valid message header name, expression type 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. Expressions can be defined using the: Simple Expression Language, which also supports File Expression Language, XPath 2.0, JsonPath, Groovy or Constant. |
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
.
Expressions
XPath
only returns plain text, no xmlGroovy
only supports one-line expressions. Use the script component for multiline scripts.Constant
Use constant for fixed values.
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://bcchanger.com/bitcoin_price_feed.php as URI you leave out the query params. Also notice you don't place a ? at the end.