Since we're on a major migration process of this website, some component documents here are out of sync right now. In the meantime you may want to look at the early version of the new website
https://camel.apache.org/staging/
We would very much like to receive any feedback on the new site, please join the discussion on the Camel user mailing list.
Spring Expression Language (SpEL)Available as of Camel 2.7 Camel allows SpEL to be used as an Expression or Predicate in the DSL or Xml Configuration. VariablesThe following variables are available in expressions and predicates written in SpEL:
SamplesExpression templatingSpEL expressions need to be surrounded by For example if you construct the following route: 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 from("direct:example").setBody().spel("Hello #{request.body}! What a beautiful #{request.headers['dayOrNight']}").to("mock:result"); Notice we now use the And sent a message with the string "World" in the body, and a header "dayOrNight" with value "day": template.sendBodyAndHeader("direct:example", "World", "dayOrNight", "day"); The output on Bean integrationYou can reference beans defined in the Registry (most likely an #{@foo.bar == 'xyz'} SpEL in enterprise integration patternsYou can use SpEL as an expression for Recipient List or as a predicate inside a Message Filter: <route> <from uri="direct:foo"/> <filter> <spel>#{request.headers['foo'] == 'bar'}</spel> <to uri="direct:bar"/> </filter> </route> And the equivalent in Java DSL: from("direct:foo").filter().spel("#{request.headers['foo'] == 'bar'}").to("direct:bar"); Loading script from external resourceAvailable as of Camel 2.11 You can externalize the script and have Camel load it from a resource such as .setHeader("myHeader").spel("resource:classpath:myspel.txt") DependenciesYou need Spring 3.0 or higher to use Spring Expression Language. If you use Maven you could just add the following to your <dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-spring</artifactId> <version>xxx</version> <!-- use the same version as your Camel core version --> </dependency> |