Simple
Since Camel 1.1
The Simple Expression Language was a really simple language when it was created, but has since grown more powerful. It is primarily intended for being a very small and Camel specific scripting language used anywhere in Camel such as with EIPs and Route.
The simple language is designed with intent to cover almost all the common use cases when little need for scripting in your Camel routes.
However, for much more complex use cases, then a more powerful language is recommended such as: Groovy.
The simple language uses ${body} placeholders for dynamic expressions and functions.
| Alternative syntax You can also use the alternative syntax which uses |
| See also the CSimple language which is pre compiled. |
A quick Simple Language example
You often use Simple together with EIPs such as Content-Based Router EIP.
In the example below we want to route the message depending on whether a message header with key foo is equal to different values:
-
Java
-
XML
-
YAML
from("direct:a")
.choice()
.when(simple("${header.foo} == 'bar'"))
.to("direct:b")
.when(simple("${header.foo} == 'cheese'"))
.to("direct:c")
.otherwise()
.to("direct:d"); <route>
<from uri="direct:a"/>
<choice>
<when>
<simple>${header.foo} == 'bar'</simple>
<to uri="direct:b"/>
</when>
<when>
<simple>${header.foo} == 'cheese'</simple>
<to uri="direct:c"/>
</when>
<otherwise>
<to uri="direct:d"/>
</otherwise>
</choice>
</route> - from:
uri: direct:a
steps:
- choice:
when:
- expression:
simple:
expression: "${header.foo} == 'bar'"
steps:
- to:
uri: direct:b
- expression:
simple:
expression: "${header.foo} == 'cheese'"
steps:
- to:
uri: direct:c
otherwise:
steps:
- to:
uri: direct:d Simple Language options
The Simple Language can be configured globally. However, its seldom needed.
The Simple language supports 5 options, which are listed below.
| Name | Default | Java Type | Description |
|---|---|---|---|
|
| Whether to trim the returned values when this language is in use. | |
|
| To pretty format the output (only JSon or XML supported). | |
|
| If the result is a nested simple expression should this expression be evaluated as well. | |
| The class of the result type (type from output). | ||
|
| Whether to trim the source code to remove leading and trailing whitespaces and line breaks. |
Detailed Reference
For detailed documentation on each topic, see the following sub-pages:
-
Built-in Functions — All function categories (Core, Array/List, Boolean, Date/Time, Math, String, XML/JSON, and more)
-
Built-in Operators — Comparison, numeric, ternary, elvis, chain, and boolean operators
-
OGNL Expressions — OGNL dot-notation for invoking methods on POJOs
-
Advanced Features — Init blocks, EIP examples, custom functions, and JavaScript validator