ScriptEval
The Do It All Swiss Army Knife Valve
Introduction
Valve for evaluating scripts using the Java Scripting API (javax.script) and GraalJS/GraalVM.
Type of script supported (JavaScript/ECMA, Python, Ruby etc) is depending on the script engine used. By default this valve (and the examples) uses the graal.js
engine with support for JavaScript.
For more information, see:
Configuration
Valve name: ScriptEval
Name | Description | Default value | Mandatory | Expanded |
---|---|---|---|---|
| The script engine to use. |
| ||
| The script to evaluate (Mandatory unless config.path is configured) | |||
| Path to script to evaluate. |
Context
During script evaluation the following objects are available in the script context:
Name | Description |
---|---|
| The current Flow (Type: |
| The current valve logger (Type: |
| The current request (JS) |
| The current Flow state (Type: |
| The current Session (Type: |
Request, state and session is also available through Flow
Examples
Request parameters
Pipe request parameters are accessed using the request
object in script context:
Flow state
Flow state can be accessed using the flow
or the state
script context object
Logging
Logging in scripts can be done using the standard console object:
or using the Fortified Logging API Logger object available in script context:
Troubleshooting
Syntax error
Bad script syntax result in a syntax error in the log (WARN
) and a flow failure.
A syntax error typically looks like this and contains a location, description and the bad line:
Advanced
Java types
To access java types in script use:
or (backwards-compatible syntax):
For more information regarding script interoperability with java, see: https://www.graalvm.org/reference-manual/js/JavaInteroperability/
Engine configuration
Script engine log can be configured using the following system property: