Pipes
2.1.0 Pipes
2.1.0 Pipes
  • Introduction
  • Configuration
  • Valves
    • Debug
      • Dump Request
      • Dump Session
      • Dump State
    • Flow
      • Flow Fail
      • Flow State Add
      • Assert Value
      • Pipe Exec
      • Pipe Call
    • Item
      • Item Create
      • Item Merge
      • Item Remove
      • Items Remove
      • Item Property Add
      • Item Property Split
      • Item Property Rename
      • Item Property Token Replace
      • MV Property To Items
      • MV Property Join
    • Freja
    • BankID
      • BidOperation
      • BidToItems
    • DateTime
      • Instant Generator
      • Instant Transformer
    • HTTP
      • GET
      • PUT
      • POST
      • DELETE
    • JWT
      • CreateJwt
      • ParseJwt
    • JSON
      • JsonObjectCreate
    • LDAP
      • LDAP Search
      • LDAP Group Filter
      • LDAP Bind
      • LDAP Add
      • LDAP Modify
      • LDAP Move
      • DN Parse
    • JDBC Query
    • Cef event
    • Request
      • RequestParameterExist
      • RequestParameterRename
    • Session
      • Session Put
      • CopyFromSession
    • ScriptEval
    • Codecs
      • Base64 Encode
      • Base64 Decode
    • Tokens
      • Token Authentication
    • PKI
      • X509 Certificate Extractor
      • X509 Certificate Validator
    • Delivery
      • Clean Mobile Valve
      • SMS Valve
      • Voice Valve
      • SMTP Valve
    • OTP
      • OTP Generation
      • OTP Validation
    • Misc
      • Basic Auth
Powered by GitBook
On this page
  • Introduction
  • Configuration
  • Context
  • Examples
  • Request parameters
  • Flow state
  • Logging
  • Troubleshooting
  • Syntax error
  • Advanced
  • Java types
  • Engine configuration
  1. Valves

ScriptEval

The Do It All Swiss Army Knife Valve

PreviousCopyFromSessionNextCodecs

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

engine

The script engine to use.

"graal.js"

source

The script to evaluate (Mandatory unless config.path is configured)

path

Path to script to evaluate.

{
    "name": "ScriptEval",
    "config": {
        "source": "print('Hello, World!');"
    }
}

Context

During script evaluation the following objects are available in the script context:

Name
Description

flow

The current Flow

(Type: fortified.pipes.api.Flow)

log

The current valve logger

(Type: fortified.platform.logging.Logger)

request

The current request (JS)

state

The current Flow state

(Type: java.util.Map<String, Object>)

session

The current Session

(Type: fortified.pipes.api.Session)

Request, state and session is also available through Flow

Examples

Request parameters

Pipe request parameters are accessed using the request object in script context:

var msg = request.get('message');
console.log('Message: ' + msg);

Flow state

Flow state can be accessed using the flow or the state script context object

// Update state
flow.state().put('name01','value01');
state.put('name02', 1234);

// Read state
var name01 = flow.state().get('name01');
var name02 = state.get('name02');

Logging

Logging in scripts can be done using the standard console object:

console.log('log'); // Same as 'console.debug'
console.trace('trace')
console.debug('debug');
console.info('info');
console.warn('warn');
console.error('error');

or using the Fortified Logging API Logger object available in script context:

log.trace('trace');
log.debug('debug');
log.info('info');
log.warn('warn');
log.error('error');

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:

SyntaxError: <eval>:43:24 Missing close quote
print('Hello, World!'');
                        ^

Advanced

Java types

To access java types in script use:

var FileClass = Java.type("java.io.File");

or (backwards-compatible syntax):

var FileClass = java.io.File;
var file = new FileClass("myFile.md");

Engine configuration

Script engine log can be configured using the following system property:

-Dpolyglot.log.file=<path>

For more information regarding script interoperability with java, see:

https://www.graalvm.org/
https://www.graalvm.org/reference-manual/js/JavaInteroperability/