Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Tip
titleAlternative syntax

From Camel 2.5 onwards you can also use the alternative syntax which uses $simple{ } as placeholders.
This can be used in situations to avoid clashes when using for example Spring property placeholder together with Camel.

Tip
titleConfiguring result type

From Camel 2.8 onwards you can configure the result type of the Simple expression. For example to set the type as a java.lang.Boolean or a java.lang.Integer etc.

To get the body of the in message: "body", or "in.body" or "${body}".

...

Variable

Type

Description

exchangeId

String

Camel 2.3: the exchange id

id

String

the input message id

body

Object

the input body

in.body

Object

the input body

body.OGNL

Object

Camel 2.3: the input body invoked using a Camel OGNL expression.

in.body.OGNL

Object

Camel 2.3: the input body invoked using a Camel OGNL expression.

bodyAs(type)

Type

Camel 2.3: Converts the body to the given type determined by its classname. The converted body can be null.

mandatoryBodyAs(type)

Type

Camel 2.5: Converts the body to the given type determined by its classname, and expects the body to be not null.

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

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="10498e24c3e951f6-5d1e1e7b-4ce24947-85cb83b3-dd80dc177df76dd5ce6ed19f"><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="6dbdfba6656c3116-af26fd2c-450446ba-810fac15-e2c352b8c68f6c50ea692a63"><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="29dc6fbb2f35c71c-a9927b4a-4fcc41b4-8fca90dd-4486428bd0154bb3fe32def1"><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>

header.foo.OGNL

Object

Camel 2.3: refer to the input foo header and invoke its value using a Camel OGNL expression.

in.header.foo.OGNL

Object

Camel 2.3: refer to the input foo header and invoke its value using a Camel OGNL expression.

in.headers.foo.OGNL

Object

Camel 2.3: refer to the input foo header and invoke its value using a Camel OGNL expression.

out.header.foo

Object

refer to the out header foo

out.headers.foo

Object

refer to the out header foo

headerAs(key,type)

Type

Camel 2.5: Converts the header to the given type determined by its classname

property.foo

Object

refer to the foo property on the exchange

property.foo.OGNL

Object

Camel 2.8: refer to the foo property on the exchange and invoke its value using a Camel OGNL expression.

sys.foo

String

refer to the system property

sysenv.foo

String

Camel 2.3: refer to the system environment

exception

Object

Camel 2.4: Refer to the exception object on the exchange, is null if no exception set on exchange. Will fallback and grab caught exceptions (Exchange.EXCEPTION_CAUGHT) if the Exchange has any.

exception.OGNL

Object

Camel 2.4: Refer to the exchange exception invoked using a Camel OGNL expression object

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 (Exchange.EXCEPTION_CAUGHT) if the Exchange has any.

exception.stacktrace

String

Camel 2.6. Refer to the exception.stracktrace on the exchange, is null if no exception set on exchange. Will fallback and grab caught exceptions (Exchange.EXCEPTION_CAUGHT) if the Exchange has any.

date:command:pattern

String

Camel 1.5. Date formatting using the java.text.SimpleDataFormat patterns. Supported commands are: now for current timestamp, in.header.xxx or header.xxx to use the Date object in the IN header with the key xxx. out.header.xxx to use the Date object in the OUT header with the key xxx.

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 locations option is optional. See more at Using PropertyPlaceholder.

threadName

String

Camel 2.3: Returns the name of the current thread. Can be used for logging purpose.

ref:xxx

Object

Camel 2.6: To lookup a bean from the Registry with the given id.

...

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 exist null is returned.

Setting result type

Available as of Camel 2.8

You can now provide a result type to the Simple expression, which means the result of the evaluation will be converted to the desired type. This is most useable to define types such as booleans, integers, etc.

For example to set a header as a boolean type you can do:

Code Block

.setHeader("cool", simple("true", Boolean.class))

And in XML DSL

Code Block
xml
xml

      <setHeader headerName="cool">
        <!-- use resultType to indicate that the type should be a java.lang.Boolean -->
        <simple resultType="java.lang.Boolean">true</simple>
      </setHeader>

Dependencies

The Simple language is part of camel-core.