Header language
The
headerlanguage returns the value of one message header, or null when the header is not set.
Name: header · Crate: cameleer-core · Cargo feature: none, always included (build features) · Apache Camel: Header
When to use it
- Copy a header into the body, a property or another header without writing a Simple template.
- Use a header as a predicate in
filterorchoice: a header is true when it is set and notfalse,0or empty. - Use a header that holds a list as the expression of a
split.
Syntax
The expression text is the header name, for example priority or CamelFileName. Leading
and trailing spaces are trimmed. The value keeps its type: a number stays a number and a list
stays a list. The same value is ${header.priority} in Simple.
Examples
Route on a header set by the caller (for example a model's classification of a ticket):
- route:
id: header-demo
from:
uri: direct:header
steps:
- choice:
when:
- header: urgent
steps:
- setBody:
header: assignee
otherwise:
steps:
- setBody:
constant: backlogCheckout is downon-callWithout the urgent header the predicate is false:
How do I change my address?backlogSplit a header that holds a list:
- route:
id: header-split
from:
uri: direct:header-split
steps:
- setHeader:
name: tags
simple: "${body.split(',')}"
- split:
header: tags
aggregationStrategy: GroupedBodyAggregationStrategy
steps:
- setBody:
simple: "tag:${body}"red,green,blue["tag:red","tag:green","tag:blue"]Values against a fixture message:
{"body": "x", "headers": {"priority": "high", "retries": 3, "tags": ["a", "b"]}}| expression | result |
|---|---|
priority | high |
retries | 3 |
tags | ["a","b"] |
missing | (empty) |
Options
The header language has no options.
Rust DSL
b.from("direct:header-rust")
.filter(header("urgent"))
.set_body(header("assignee"));Common questions
How do I read a header in a route?
Use header: name wherever an expression is expected, or ${header.name} inside a Simple
template when you need it in a larger text.
What happens when the header does not exist?
The result is null. As a predicate it is false, and setBody with a missing header sets an
empty body.
Are header names case sensitive?
Yes, names are matched exactly.
Related
- Simple language (
${header.name},${headers}) - exchangeProperty language, variable language, constant language
- Apache Camel Header language
Found a problem?
If something on this page doesn't match what Cameleer does, or you hit a bug while building
with it, please help fix it, whether you are a person or a coding agent:
open an issue that describes what you saw,
then fork the repository, fix it, add or update a test, run cargo test --workspace, and open
a pull request. CONTRIBUTING.md
explains the ground rules.