Set Body
The Set Body EIP defines or modifies the message body.
Parameters
Parameter | Description | Default value | Type |
---|---|---|---|
Expression |
Defines the value to be set in the message body. |
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 organized 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, jsonPath, xPath, etc.).
-
Second level: defines the actual value of the expression, that is, the data that will be assigned to the message body.
Common types of expressions
-
constant
: sets a fixed value, useful for static messages. For example, it always sets the message body to the static JSON{"status": "error"}
.
- setBody:
expression:
constant:
expression: '{"status": "error"}'
-
jsonpath
: extracts data from the message body when it is in JSON format. For example, it extracts the value located at$.data.attributes
from the JSON in the message body.
- setBody:
expression:
jsonpath:
path: '$.data.attributes'
-
xpath
: extracts information when the message body is in XML format. For example, it selects the XML node corresponding to/response/body/item
from the message body.
- setBody:
expression:
xpath:
path: '/response/body/item'
-
script
: allows using scripting languages (JavaScript, Groovy, etc.) to create a dynamic body. For example, it runs a JavaScript script to dynamically generate the message body.
- setBody:
expression:
script:
language: 'javascript'
expression: 'return {"status": "ok"};'
-
binary
: sets a binary body, useful for sending files or non-textual data. For example, it sets the message body as Base64-encoded data.
- setBody:
expression:
binary:
content: 'base64encodedData'
Example
- setBody:
id: setBody-2360
expression:
simple:
expression: "<request><id>${header.id}</id></request>"
-
The snippet defines the message body as dynamic XML containing an
<id>
element. -
The
expression
parameter uses the simple language, which allows inserting dynamic values and performing basic string manipulations. -
The expression
${header.id}
inserts the value of the header named "id" into the XML. -
For example, if the "id" header has the value 123, the message body will be set as follows:
<request><id>123</id></request>
Share your suggestions with us!
Click here and then [+ Submit idea]