Script component
The Script component allows you to modify messages using scripts written in Groovy or JavaScript. The scripts can either be provided directly or uploaded as files. Scripts are able to read and modify the body, headers, and properties of messages that pass through it.
To simplify the development of scripts, the Script component offers the ability to evaluate scripts given a set of test values for the body, headers, and properties of a message.
If you migrate from version 4.14.x or older then check the Scripts migration guide for new version of Groovy and JavaScript.
Configuration
The Script component has the following configuration options:
Upload method
Select if you want to enter the script manually in or through uploading a file.
Options:
Enter script manually
(default)Upload file
Script
The script that should be evaluated for each message passing through the component.
Only available when Upload method is set to Enter script manually
.
Upload File
The script that should be evaluated for each message uploaded in the form of a file.
Only available when Upload method is set to Upload file
.
Language
The language used for the script.
Options:
Groovy
(default)JavaScript
Groovy, like Camel, runs in the JVM (Java Virtual Machine) while Javascript runs via Node.js (and therefore has a higher impact on performance).
The JavaScript that you can use in the Script component is not the same implementation as in web browsers. It is an open source implementation of JavaScript for Java. We advice that you use standard JavaScript syntax also known as ES5
. Newer syntax and other features are not supported at the moment.
In Headers
A list of comma-separated name-value pairs representing headers for testing purposes. The names and values should be quoted.
Use the following format: "headerName"="value","anotherHeaderName"="value",etc
In Properties
A list of comma-separated name-value pairs representing properties for testing purposes. The names and values should be quoted.
Use the following format: "propertyName"="value","anotherPropertyName"="value",etc
In Body
A body for testing purposes.
Out Headers
Shows the list of headers after validating the script. Not user editable.
Out Properties
Shows the list of properties after validating the script. Not user editable.
Out Body
Shows the body of the message after validating the script. Not user editable.