Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

...

Variable

Type

Description

this

Exchange

the Exchange is the root object

exchange

Exchange

the Exchange object

exception

Throwable

the Exchange exception (if any)

exchangeId

String

the exchange id

fault

Message

the Fault message (if any)

body

Object

Camel 2.11: The IN message body.

request

Message

the exchange.in message

response

Message

the exchange.out message (if any)

properties

Map

the exchange properties

property(name)

Object

the property by the given name

property(name, type)

Type

the property by the given name as the given type

...

SpEL expressions need to be surrounded by #{ }@ delimiters since expression templating is enabled. This allows you to combine SpEL expressions with regular text and use this as extremely lightweight template language.

...

Code Block
from("direct:example").setBody(spel("Hello #{request.body}! What a beautiful #{request.headers['dayOrNight']}")).to("mock:result");

In the route above, notice spel is a static method which we need to import from org.apache.camel.language.spel.SpelExpression.spel, as we use spel as an Expression passed in as a parameter to the setBody method. Though if we use the fluent API we can do this instead:

Code Block

from("direct:example").setBody().spel("Hello #{request.body}! What a beautiful #{request.headers['dayOrNight']}").to("mock:result");

Notice we now use the spel method from the setBody() method. And this does not require us to static import the spel method from org.apache.camel.language.spel.SpelExpression.spel.

And sent a message with the string "World" in the body, and a header "dayOrNight" with value "day":

...

Code Block
#{@foo.bar == 'xyz'}

...

SpEL in enterprise integration patterns

...

Code Block
   from("direct:foo").filter().spel("#{request.headers['foo'] == 'bar'}").to("direct:bar");

Loading script from external resource

Available as of Camel 2.11

You can externalize the script and have Camel load it from a resource such as "classpath:", "file:", or "http:".
This is done using the following syntax: "resource:scheme:location", eg to refer to a file on the classpath you can do:

Code Block

.setHeader("myHeader").spel("resource:classpath:myspel.txt")

Dependencies

You need Spring 23.7 0 or higher to use Spring Expression Language. If you use Maven you could just add the following to your pom.xml:

...