2. Enterprise Integration Patterns

setBody

Version

Sets the body of the current HTTP message to a static string or a computed expression. SpEL template expressions are supported by default; Groovy, JsonPath, and XPath are also available. For conditional output or loops, use the template interceptor instead. See tutorials/getting-started/65-SetBody.yaml.

Example Configuration

api:
port: 2000
flow:
- setBody:
value: |
Name: ${header.X-Name}
Method: ${method}
Path: ${path}

- return:
status: 200
api:
   port: 2000
   flow:
     - setBody:
         value: |
           Name: ${header.X-Name}
           Method: ${method}
           Path: ${path}
     - return:
         status: 200

Syntax

setBody:
'$ref': <string>
contentType: <string>
language: groovy
value: <string>
xmlConfig: {}
setBody:
  '$ref': <string>
  contentType: <string>
  language: groovy
  value: <string>
  xmlConfig: {}

Attributes

NameRequiredDefaultDescriptionExamples
$reffalse-Reference a component defined under components.-
contentTypefalse-Content-Type applied to the message after the body is written. When set to a JSON media type, expression values are automatically escaped to prevent injection. When omitted, no escaping is applied.application/json
languagefalseSpELScripting language used to evaluate the value expression.SpEL | groovy | jsonpath | xpath
valuefalse-Body content to set, evaluated as a SpEL template expression by default. The result is encoded as UTF-8 bytes.Name: ${header.X-Name}

Child Structure

ElementCardinalityDescription
xmlConfig0..1XML namespace declarations for XPath expressions in the value.

Can be used in