Simple has been edited by Claus Ibsen (Sep 20, 2008).

Change summary:

CAMEL-907

(View changes)

Content:

Simple _expression_ Language

The Simple _expression_ Language is a really simple language you can use. Its primarily intended for being a really small and simple language for testing without requiring any new dependencies or knowledge of XPath; so its ideal for testing in camel-core. However for real world use cases you are generally recommended to choose a more expressive and powerful language such as:

Syntax

_expression_ Description
id the input message id
body the input body
in.body the input body
out.body the output body
header.foo refer to the input foo header
headers.foo refer to the input foo header
in.header.foo refer to the input foo header
in.headers.foo refer to the input foo header
out.header.foo refer to the out header foo
out.headers.foo refer to the out header foo
property.foo refer to the foo property on the exchange
sys.foo refer to the system property

The simple language uses ${body} placeholders for complex expressions where the _expression_ contains constant literals. The ${ } placeholders can be omitted if the _expression_ is only the token itself.

To get the body of the in message: "body", or "in.body" or "${body}".
A complex _expression_ must use ${ } placeholders, such as: "Hello ${in.header.name} how are you?".
You can have multiple tokens in the same _expression_: "Hello ${in.header.name} this is ${in.header.me} speaking".
However you can not nest tokens (i.e. having another ${ } placeholder in an existing, is not allowed).

Samples

In the Spring XML sample below we filter based on a header value:

<from uri="seda:orders">
       <filter>
           <simple>in.header.foo</simple>
           <to uri="mock:fooOrders"/>
       </filter>
    </from>

The Simple language can be used for the predicate test above in the Message Filter pattern, where we test if the in message has a foo header (a header with the key foo exists). If the _expression_ evaluates to true then the message is routed to the mock:foo endpoint, otherwise its lost in the deep blue sea .

The same example in Java DSL:

from("seda:orders")
        .filter().simple("in.header.foo").to("seda:fooOrders");

You can also use the simple language for simple text concatenations such as:

from("direct:hello").transform().simple("Hello ${in.header.user} how are you?").to("mock:reply");

Notice that we must use ${ } placeholders in the _expression_ now to let Camel be able to parse it correctly.

Dependencies

The Bean language is part of camel-core.

Reply via email to