Cameleer

Constant language

The constant language returns its text unchanged, optionally converted to a type with resultType.

Name: constant · Crate: cameleer-core · Cargo feature: none, always included (build features) · Apache Camel: Constant

When to use it

  • Set a header, property or body to a fixed value: a content type, a status, a model name.
  • Pass a literal where an expression is required, without Simple parsing ${...} in it.
  • Set a typed value (a number or a boolean) with resultType.

Syntax

The expression text is the value. Nothing in it is evaluated, so ${body} stays the literal text ${body}.

In YAML, a plain number or boolean in an expression position is also a constant: setHeader: {name: retries, expression: 3} gives the integer 3.

Example

Set a header and the body to fixed values.

yaml example: constant-set-header-and-body
- route:
    id: constant-demo
    from:
      uri: direct:constant
      steps:
        - setHeader:
            name: Content-Type
            constant: application/json
        - setHeader:
            name: retries
            constant:
              expression: "3"
              resultType: int
        - setBody:
            simple: '{"type":"${header.Content-Type}","retries":${header.retries},"retriesType":"${header.retries.getClass()}"}'
text
anything
json
{"type":"application/json","retries":3,"retriesType":"java.lang.Integer"}

The text is not evaluated:

json
{"body": "Hello"}
expressionresult
application/jsonapplication/json
${body}${body}
4242

Options

optiondefaultdescription
resultType(none)Convert the text to this type: int, Integer, long, double, boolean, String...

Rust DSL

rust
b.from("direct:constant-rust")
    .set_header("Content-Type", constant("application/json"))
    .set_body(constant("fixed body"));

Common questions

How do I set a header to a fixed value?

Use setHeader with constant: value. A plain string under expression: is parsed as Simple, so prefer constant: when the value contains ${.

How do I set a number instead of a string?

Add resultType: int (or long, double, boolean), or write the number unquoted as the expression in YAML.

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.

Edit this page on GitHub