Cameleer

OGNL language

The ognl language evaluates OGNL expressions against the exchange, with request, headers, body and exchange as the root object's properties.

Name: ognl · Crate: cameleer-script · Cargo feature: script · Apache Camel: OGNL

When to use it

  • Port Camel routes that use OGNL predicates and expressions.
  • Navigate properties and call methods in one line, with OGNL's projection and selection on lists.

Syntax

Cameleer interprets OGNL itself, without the OGNL library or a JVM. Supported: property and index navigation, method calls, static members of known JDK classes (@java.lang.Math@max(1, 2)), #this, #root and #var, list literals {a, b}, map literals #{k: v}, projection .{expr}, selection .{? expr}, in/not in, word operators (eq, gt, and...), the ternary operator and , sequences. Arbitrary Java classes are not available.

The root object has these properties:

propertywhat it is
requestthe message: request.body, request.headers.name
responsethe message (Camel's out message)
exchangethe exchange: exchange.in.body
body, headersthe body and headers directly
properties, property(name)the exchange properties
contextthe context

Examples

yaml example: ognl-choice
- route:
    id: ognl-demo
    from:
      uri: direct:ognl
      steps:
        - choice:
            when:
              - ognl: "request.headers.n > 10"
                steps:
                  - setBody:
                      ognl: "'large: ' + request.headers.n"
            otherwise:
              steps:
                - setBody:
                    ognl: "request.headers.n > 2 ? 'medium' : 'small'"
text
x
text
large: 42
text
x
text
medium
json
{"body": "hello", "headers": {"amount": 250, "name": "Ada"}}
expressionresult
request.body.toUpperCase()HELLO
request.headers.amount > 100true
request.headers.name + '!'Ada!
exchange.in.bodyhello
body.length()5
request.headers.amount > 100 ? 'big' : 'small'big
@java.lang.Math@max(3, 7)7

Options

optiondefaultdescription
resultType(none)Convert the result to this type.

Rust DSL

rust
b.from("direct:ognl-rust")
    .set_header("twice", cameleer_script::ognl("request.body.length() * 2"));

Common questions

Does OGNL support calling static methods?

Yes for the JDK classes the interpreter knows (Math, Integer, String...), with the @class@member syntax. Other classes are not available.

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