Scripting Language Filter

Contents

Overview

The Scripting Filter uses Java Specification Request (JSR) 223 to embed a scripting environment in the Enterprise Gateway's core engine. This enables you to write bespoke JavaScript or Groovy code to interact with the message as it is processed by the Enterprise Gateway. You can get, set, and evaluate specific message attributes with this filter.

Because the scripting environment is embedded in the Enterprise Gateway engine, it has access to all Java classes on the Enterprise Gateway's classpath, including all JRE classes. If you wish to invoke a Java object, you must place its corresponding class file on the Enterprise Gateway classpath. The recommended way to add classes to the Enterprise Gateway classpath is to place them (or the JAR files that contain them) in the INSTALL_DIR/ext/lib folder. For more details, see the readme.txt in this folder.

Some typical uses of the Scripting Filter include the following:

  • Check the value of a specific message attribute
  • Set the value of a message attribute
  • Remove a message attribute
  • DOM processing on the XML request or response

Writing a Script Filter

To write a script filter, you must implement the invoke() method. This method takes a com.vordel.circuit.Message object as a parameter and returns a boolean result.

The Enterprise Gateway provides a Script library that contains a number of pre-written invoke() methods to manipulate specific message attributes. For example, there are invoke() methods to check the value of the SOAPAction header, to remove a specific message attribute, to manipulate the message using the DOM, and another to assign a particular role to a user.

You can access the script examples provided in the Script library by clicking the Show script library button on the filter's main configuration screen.

For a complete list of available message attributes, see the Message Attribute Reference.

Configuring a Script Filter

You can write the JavaScript or Groovy code in the text area on the Script tab. A JavaScript function skeleton is displayed by default. Use this skeleton code as the basis for your JavaScript code. You can also load an existing JavaScript or Groovy script from the Script library by clicking the Show script library button.

On the Script library dialog, click any of the Configured scripts in the table to display the script in the text area on the right. You can edit a script directly in this text area. Make sure to click the Update button to store the updated script to the Script library.

You can add a new script to the library by clicking the Add button, which displays the Script Details dialog. Enter a Name and a Description for the new script in the fields provided. By default, the Language field is set to JavaScript, but you can also select Groovy from the drop-down list. You can then write the script in the Script text area.

Script Library

Script Library

Important Note:
When writing the JavaScript or Groovy code, you should note the following:

  • The invoke() method must be implemented.
  • The invoke() method takes a com.vordel.circuit.Message object as a parameter, and returns a boolean.
  • You can obtain the value of a message attribute using the getProperty method of the Message object.