To simplify 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.
The type of a message's body depends on the component that produced the message.
If you want to process the body of a message as a string, you may have to convert it, depending on the flow in which you're using the Script component.
request.getBody(java.lang.String.class) returns the body as a string.
The attributes that can be accessed and modified by the Script component are described in the documentation of Apache's Camel project.
The Script component has the following configuration options:
|The script that should be evaluated for each message passing through the component.|
|The script that should be evaluated for each message in the form of a file.|
|The language used for the script.|
|A list of comma-separated name-value pairs representing headers for testing purposes. The names and values should be quoted.|
|A list of comma-separated name-value pairs representing properties for testing purposes. The names and values should be quoted.|
|A body for testing purposes|
|The list of headers after evaluating the script.|
|The list of properties after evaluating the script.|
|The body of the message after evaluation.|
Import third party libraries in JS scripts
By using the
load function third party libraries can be imported and used in
load( "https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.9-1/crypto-js.min.js", "https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.9-1/hmac-sha256.min.js", "https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.9-1/enc-base64.min.js" );
The image below shows the result of evaluating a script for a given body, set of headers and set of properties.
implementation as in web browsers. It is an open source implementation of
ES5. Newer syntax and other features are not supported at the moment.
- The Groovy version that is used in the script component is
result = request.bodyat the end of the script to keep the original message body when you only change some headers in the script.