Set Header
The Set Header EIP defines or modifies a message header.
Parameters
Parameter | Description | Default value | Type |
---|---|---|---|
Name |
The name of the message header to be configured. |
String |
|
Expression |
Defines the value to be set in the header. It is mandatory and can use various supported expression languages such as Simple, XPath, JSONPath. |
ExpressionDefinition |
Expression
The expression allows dynamically calculating or defining values during message processing in the integration flow. It is a way to configure behaviors that may vary based on the context of the in-transit message.
Expressions are divided into two hierarchical levels, enabling a more extensible and adaptable structure for different contexts:
-
First level: specifies the type of logic to be applied (constant, simple, jsonpath, etc.).
-
Second level: defines the actual value of the expression, that is, the data that will be assigned to the header.
Common types of expressions
-
constant
: defines a fixed value. In the example, it will always return"400"
.
- setHeader:
name: my-header-name
expression:
constant:
expression: "400"
-
simple
: allows using placeholders and simple logic to access message data. In the example, it returns the value of theoperacao
header.
- setHeader:
name: my-header-name
expression:
simple:
expression: "${header.operacao}"
-
jsonpath
: extracts information from messages with a JSON body. In the example, it returns the value of thetoken
field within thedata
object.
- setHeader:
name: my-header-name
expression:
jsonpath:
expression: "$.data.token"
-
xpath
: extracts information from messages with an XML body. In the example, it returns theid
attribute of thecustomer
node withinorder
.
- setHeader:
name: my-header-name
expression:
xpath:
expression: "/order/customer/@id"
-
groovy/javascript/python
(or another scripting language): uses custom scripts for complex operations. In the example, the expression checks the length of the message body. If the body contains data, it sets the header toValid
; if it is empty, it sets it toInvalid
. It uses Groovy to perform this conditional check.
- setHeader:
name: my-header-name
expression:
groovy:
expression: "return request.body.length() > 0 ? 'Valid' : 'Invalid'"
Example
-
The following example defines the header name as
Content-Type
. -
The expression parameter is set to
constant
, meaning it will have a fixed value. This value will always beapplication/json
, indicating that the request body will be in JSON format.
- setHeader:
id: setHeader-4103186938
description: Set header urlencoded
expression:
constant:
expression: application/json
name: Content-Type
Share your suggestions with us!
Click here and then [+ Submit idea]