Script

Available as of Camel 2.16

 

Is used to execute a script which does not change the message (by default). This is useful when you need to invoke some logic that are not in Java code such as JavaScript, Groovy or any of the other Languages. The message body is not changed (by default) however the scripting context has access to the current Exchange and can essentially change the message or headers directly. But the return value from the script is discarded and not used. If the return value should be used as a changed message body then use Message Translator EIP instead.

Using from Java DSL

The route below will read the file contents and validate them against a regular expression.

Using from Spring DSL

And from XML its easy as well

Mind that you can use CDATA in XML if the groovy scrip uses < > etc

 

Using external script files

You can refer to external script files instead of inlining the script. For example to load a groovy script from the classpath you need to prefix the value with resource: as shown:

You can also refer to the script from the file system with file: instead of classpath: such as file:/var/myscript.groovy

 

Using This Pattern

If you would like to use this EIP Pattern then please read the Getting Started, you may also find the Architecture useful particularly the description of Endpoint and URIs. Then you could try out some of the Examples first before trying this pattern out.

© 2004-2015 The Apache Software Foundation.
Apache Camel, Camel, Apache, the Apache feather logo, and the Apache Camel project logo are trademarks of The Apache Software Foundation. All other marks mentioned may be trademarks or registered trademarks of their respective owners.
Graphic Design By Hiram