Skip to main content
Version: 4.14.7

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:

PropertyDescription
Header NameThe name of the header you wish to set.
Expression TypeThe language of the expression.
ExpressionHow you wish to set or change header

Header Names

  • Header Names can not contain spaces
  • Header Names in Dovetail are case-insensitive so setting a header named subject on an exchange that already has a header with the name Subject will just replace the value of the existing header named Subject.

Expression Types

Expressions can be defined using the following types:

Expression TypeDescription
SimpleSimple Expression Language, which also supports File Expression Language. It only returns plain text, no xml.
XPathXPath 2.0 language. It only returns plain text, no xml.
JsonPathJsonPath language.
GroovyGroovy. It only supports one-line expressions. Use the script component for multiline scripts.
ConstantWhen 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&currency=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&currency=${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.