Expressions

The pipelite-expression module provides a textual expression evaluation engine used by filter and by the when(…​) of toRoute(…​). It is a small, purpose-built expression language, not Java or SpEL - only the operators and functions listed below are available, no arbitrary method calls.

Syntax

Expressions are plain strings, evaluated at runtime with no wrapping delimiter - this is a different mechanism from the #{…​} text-interpolation syntax used inside dynamic destination strings (see Queue Channel Adapter's own note on it). Two variables are bound automatically before every evaluation:

Variable Resolves to

Payload

The input payload of the Exchange (equivalent to exchange.getInputPayload())

Headers

The headers of the Exchange, indexable by name: Headers['name']

Operators

Operator Aliases

==

=, eq

!=

<>, neq

&&

&, and

||

|, or

>

gt

>=

gte

<

lt

<=

lte

+ - * / % ^

arithmetic (addition/subtraction also work as unary +/-)

Functions

Function Description

NOT(x)

Boolean negation

IF(cond, a, b)

a if cond is true, otherwise b

SQRT(x)

Square root

ROUND(x), ROUND(x, precision)

Rounds a number using the engine’s configured MathContext

beanProperty(bean, 'path')

Reads a property off bean by name - the only way to reach into the fields of Payload, since there is no .property dot-access syntax. Aliased as bp, property, prop, jsonPath.

String literals use single quotes ('ORDER'), not double.

Expression examples

// Filter: continue only if the payload is not null
Payload != null

// Filter on a header value
Headers['type'] == 'ORDER'

// Numeric comparison on a header
Headers['priority'] > 5

// Reading a field off the payload object
beanProperty(Payload, 'totalAmount') > 100

Usage in DSL

In filter

.filter("only-orders", "Headers['type'] == 'ORDER'")

The ExpressionFilterNode evaluates the expression on each Exchange. If the evaluation returns false, message processing stops.

In toRoute

.toRoute(route -> route.dynamic()
    .when("Headers['type'] == 'PAYMENT'").then("queue://payment-flow")
    .otherwise("queue://default-flow")
    .end()
)

Implementation

Both filter and the when(…​) of toRoute(…​) evaluate their expression as a whole, with Payload and Headers bound to the current Exchange, and it must evaluate to a boolean. This is a different mechanism from the {…​} text interpolation used inside dynamic strings such as a routing target, e.g. "queue://{Headers['region']}-orders", which is evaluated inside the string and can produce any text.

The expression engine is intentionally simple - no arbitrary method calls, no user-defined functions. For anything beyond what the operators/functions above express, use a Processor with plain Java code instead.