...
Variable | Type | Description | ||
---|---|---|---|---|
id | String | the input message id | ||
body | Object | the input body | ||
in.body | Object | the input body | ||
bodyAs(type) | Type | Camel 2.3: Converts the body to the given type determined by its classname . | ||
out.body | Object | the output body | ||
header.foo | Object | refer to the input foo header | ||
headers.foo | Object | refer to the input foo header | ||
in.header.foo | Object | refer to the input foo header | ||
in.headers.foo | Object | refer to the input foo header | ||
out.header.foo | Object | refer to the out header foo | ||
out.headers.foo | Object | refer to the out header foo | ||
property.foo | Object | refer to the foo property on the exchange | ||
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="fbc8c1bd-b8bb-40f6-9ee3-f6e6841a4840"><ac:plain-text-body><![CDATA[ | header.foo[bar] | Object | Camel 2.3: regard input foo header as a map and perform lookup on the map with bar as key | ]]></ac:plain-text-body></ac:structured-macro> |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="1abff61a-444d-4548-9b0f-77cf0f4a14cd"><ac:plain-text-body><![CDATA[ | in.header.foo[bar] | Object | Camel 2.3: regard input foo header as a map and perform lookup on the map with bar as key | ]]></ac:plain-text-body></ac:structured-macro> |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="f374e9dc-a671-41e0-8c3e-4992cb172b26"><ac:plain-text-body><![CDATA[ | in.headers.foo[bar] | Object | Camel 2.3: regard input foo header as a map and perform lookup on the map with bar as key | ]]></ac:plain-text-body></ac:structured-macro> |
out.header.foo | Object | refer to the out header foo | ||
out.headers.foo | Object | refer to the out header foo | ||
property.foo | Object | refer to the foo property on the exchange | ||
sys.foo | sys.foo | String | refer to the system property | |
sysenv.foo | String | Camel 2.3: refer to the system environment | ||
exception.message | String | Camel 2.0. Refer to the exception.message on the exchange, is null if no exception set on exchange. Will fallback and grab caught exceptions ( | ||
date:command:pattern | String | Camel 1.5. Date formatting using the | ||
bean:bean expression | Object | Camel 1.5. Invoking a bean expression using the Bean language. Specifying a method name you must use dot as separator. In Camel 2.0 we also support the ?method=methodname syntax that is used by the Bean component. | ||
properties:locations:key | String | Camel 2.3: Lookup a property with the given key. The |
...
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 DSLin the deep blue sea .
The same example in Java DSL:
Code Block | ||||
---|---|---|---|---|
| ||||
from("seda:orders")
.filter().simple("in.header.foo").to("seda:fooOrders");
|
You can also use the simple language for simple text concatenations such as:
Code Block | ||||
---|---|---|---|---|
| ||||
from("sedadirect:ordershello") .filter.transform().simple("Hello ${in.header.foouser} how are you?").to("sedamock:fooOrdersreply"); |
Notice that we must use ${ } placeholders in the expression now to let Camel be able to parse it correctly.
And this sample uses the date command to output current date.You can also use the simple language for simple text concatenations such as:
Code Block | ||||
---|---|---|---|---|
| ||||
from("direct:hello").transform().simple("HelloThe today is ${in.header.user} how are you?date:now:yyyyMMdd} and its a great day.").to("mock:reply"); |
Notice that we must use ${ } placeholders in the expression now to let Camel be able to parse it correctly.
And this sample uses the date command to output current date.And in the sample below we invoke the bean language to invoke a method on a bean to be included in the returned string:
Code Block | ||||
---|---|---|---|---|
| ||||
from("direct:helloorder").transform().simple("The today isOrderId: ${datebean:now:yyyyMMdd} and its a great day.orderIdGenerator}").to("mock:reply"); ); |
Where orderIdGenerator
is the id of the bean registered in the Registry. If using Spring then its the Spring bean id.
If we want to declare which method to invoke on the order id generator bean we must prepend .method name
such as below where we invoke the generateId
method.And in the sample below we invoke the bean language to invoke a method on a bean to be included in the returned string:
Code Block | ||||
---|---|---|---|---|
| ||||
from("direct:order").transform().simple("OrderId: ${bean:orderIdGenerator.generateId}").to("mock:reply");
|
Where orderIdGenerator
is the id of the bean registered in the Registry. If using Spring then its the Spring bean id.
If we want to declare which method to invoke on the order id generator bean we must prepend .method name
such as below where we invoke the generateId
method.And in Camel 2.0 we can use the ?method=methodname
option that we are familiar with the Bean component itself:
Code Block | ||||
---|---|---|---|---|
| ||||
from("direct:order").transform().simple("OrderId: ${bean:orderIdGenerator.?method=generateId}").to("mock:reply"); |
And in from Camel 2.0 we can use the ?method=methodname
option that we are familiar with the Bean component itself3 onwards you can also convert the body to a given type, for example to ensure its a String you can do:
Code Block | ||||
---|---|---|---|---|
| ||||
<transform> from("direct:order").transform().simple("OrderId: ${bean:orderIdGenerator?method=generateId}").to("mock:reply"); <simple>Hello ${bodyAs(String)} how are you?</simple> </transform> |
There is a few types which have a shorthand notation, hence why we can use String
instead of java.lang.String
. These are: byte[], String, Integer, Long
. All other types must use their FQN name, e.g. org.w3c.dom.Document
.
Its also possible to lookup a value from a header Map
in Camel 2.3 onwardsAnd from Camel 2.3 onwards you can also convert the body to a given type, for example to ensure its a String you can do:
Code Block | ||||
---|---|---|---|---|
| ||||
<transform> <simple>Hello<simple>The gold value is ${bodyAs(String)} how are you?header.type[gold]}</simple> </transform> |
There is a few types which have a shorthand notation, hence why we can use String
instead of java.lang.String
. These are: byte[], String, Integer, Long
. All other types must use their FQN name, e.g. org.w3c.dom.Document
In the code above we lookup the header with name type
and regard it as a java.util.Map
and we then lookup with the key gold
and return the value.
If the header is not convertible to Map an exception is thrown. If the header with name type
does not exists null
is returned.
Dependencies
The Bean language is part of camel-core.