1. Home
  2. Integrations
  3. Set Property

Set Property

Learn how to use EIPs

The Set Property EIP is used in the context of message exchange (exchange). Properties are useful for storing intermediate data that can be accessed in other steps of the flow.

NOTE

Properties are metadata associated with the message, but are not part of either the body or the header of the message.

Parameters

Parameter
Description
Default value
Type
NameName of the property that will be set.String
ExpressionExpression that returns the property value.ExpressionDefinition

Expression

The expression allows you to calculate or dynamically define values during message processing in the integration flow. It is a way to configure behaviors that can vary according to the context of the message in transit.

The expression is organized into two hierarchical levels that allow the structure to be more extensible and adaptable to different contexts:

  • First level: specifies the type of logic that will 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 property.

Common types of expressions

  • constant: assigns fixed values. In the example, the myProperty property will be defined as FixedValue.
  • simple: accesses simple data (headers, body, properties) and manipulates values in a basic way. In the example, the expression ${header.orderId} accesses the orderId header and uses it as the value of the myProperty property.
  • xpath: uses XPath queries to extract data from XML documents. In the example, the XPath expression /order/id extracts the value of the id field from an XML with the structure <order><id>123</id></order>.
  • jsonpath: uses JSONPath queries to extract data from JSON documents. In the example, the expression $.order.id extracts the value of the id field from a JSON object: { "order": { "id": 123 } }.
  • groovy: executes Groovy scripts for advanced data manipulation. In the example, the value of myProperty will be calculated by the Groovy script, which returns the value of the orderId header incremented by 1.

Examples

Example 1

  • name: itemId: name of the property that will be defined. The property will be referenced as itemId in the next steps of the route.

  • expression: simple: ${body['id']}: uses the simple language to extract data from the message body (body). In this case, it is accessing a field called id within a body that is presumably a data structure like a map (JSON or similar). The value extracted from the id field will be assigned to the itemId property.

    Imagine that the message body is something like:

    • Camel will evaluate the expression ${body['id']} and extract the value 12345 from the id field.
    • This value will be stored in the property called itemId.

Example 2

  • name: name of the property that will be created or updated in the exchange context. In this case, the property will be called fullData.

  • expression: defines the property value using an expression. In this case, a simple language expression is used.

    • "${header.id}": extracts the value of the header called id and inserts it as the value of the id key.

    • ${exchangeProperty.customerData}: retrieves the value stored in the customerData property of the exchange and assigns it to the json key.

NOTE

The use of ">-" at the beginning of the expression keeps the text readable in YAML, as it ensures that the processed value is treated as a single line without unnecessary breaks.

How happy are you with this page?

We use cookies to enhance your experience on our site. By continuing to browse, you agree to our use of cookies.Learn more