Cameleer

MVEL language

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

Name: mvel · Crate: cameleer-script · Cargo feature: script · Apache Camel: MVEL

When to use it

  • Port Camel routes that use MVEL predicates and expressions.
  • Write compact property-navigation expressions (request.headers.amount * 2) with Java-like method calls.
  • For MVEL templates (@{...} orb tags), use the mvel component.

Syntax

Cameleer interprets MVEL itself, without the MVEL library or a JVM. Supported: property navigation, method calls, inline lists ['a', 'b'], maps and arrays, contains, is, empty, nil, projections (name in list), ;-separated statements, assignments, typed declarations (int x = 5), with (obj) {...}, if/else, foreach, while, def functions and interceptors (@Name statement, registered from Rust). Arbitrary Java classes are not available.

The root object has these properties:

propertywhat it is
request, inthe message: request.body, request.headers.name
response, outthe message (Camel's out message)
exchangethe exchange: exchange.in.body, exchange.properties
body, headersthe body and headers directly
propertiesthe exchange properties
context, camelContextthe context

Examples

yaml example: mvel-set-header
- route:
    id: mvel-demo
    from:
      uri: direct:mvel
      steps:
        - setHeader:
            name: doubled
            mvel: "request.headers.amount * 2"
        - filter:
            mvel: "request.headers.doubled > 100"
            steps:
              - setBody:
                  mvel: "request.body.toUpperCase() + ' ' + request.headers.doubled"
text
priority
text
PRIORITY 120
json
{"body": "hello", "headers": {"amount": 250, "name": "Ada"}}
expressionresult
request.body.toUpperCase()HELLO
request.headers.amount > 100true
headers.name + '!'Ada!
exchange.in.bodyhello
body.length()5
['a', 'b'].size()2
int x = 5; x * request.headers.amount1250

Options

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

Rust DSL

rust
b.from("direct:mvel-rust")
    .set_header("next", cameleer_script::mvel("request.headers.n + 1"));

Common questions

What is the difference between the mvel language and the mvel component?

The language evaluates one expression inside a route step. The mvel component renders a template file (mvel:template.mvel) into the body.

Can MVEL call my Java classes?

No. There is no JVM; only the Camel root object, values and common JDK-like methods work.

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