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.
Quick evaluation
Use this button to evaluate your script without having to install the flow. The In Headers, In Properties and In Body are used for the validation. The Out Headers, Out Properties and Out Body will be shown in their respective fields.
Quick evaluation may yield different results than runtime; always verify your script within the installed flow. Is the result of the evalaution unexpected? Keep in mind there can be false positives and/or false negatives, for example:
- Validation output is blue, but in runtime the script is not functioning or functioning differently
- Validation output is red, but in runtime the script is actually functiong properly
- Difference between the Out Headers, Out Properties and/or Out Body at the time of validation and the actual message headers, properties and/or body in runtime
Additionally, if you use Flow properties, the Test environment value is be used for evaluation.
Using scripts
Before incorporating scripts into your flows, please note the following:
Limited Support
Our support team cannot assist with the development, debugging or maintenance of scripts. It is the user's sole responsibility to ensure their functionality and reliability.
Version and Library Changes
The versions of scripting engines and associated libraries used in the platform are subject to change during updates. These changes may impact the compatibility or behavior of your scripts.
User Responsibility
Users are responsible for maintaining and updating their scripts to ensure compatibility with any updates or changes.
By using scripts, you acknowledge and accept these limitations. For stable and predictable integrations, we recommend using our built in components.
Using Groovy
This section shows you examples of how to 'interact' with Camel messages using Groovy in the Script component.
See the Using time guide for more Groovy script examples related to time.