Unlike custom Java interceptors, which have to be uploaded to the Platform via a .jar file, custom JavaScript interceptors are set up directly on the Manager screen.
New interceptors are created on the Interceptors menu page, through the + button on the bottom right corner.

To create a JavaScript interceptor, click or hover the cursor over the + button and select the option Create Custom JavaScript.

This will open up the editor (see image below) and you will be able to configure your interceptor.

Insert the interceptor's Name. The checkbox Abort request if fail can be flagged to abort the request in case an error occurs.
The field to edit code is where the user must insert the script to be executed when the interceptor runs. You can read more about it below.
You can select to create or use existing tags to categorize the interceptor (field: Tags). If you do not enter any tags, the interceptor will be assigned to Uncategorized.
The Visibility field allows you to choose the visibility level of the interceptor. You can read about visibility rules here.
Custom JavaScript interceptors may be added to the request and the response flows. That is, they can be used to modify calls before a request is through or after the backend has sent a response to the gateway.
Existing JavaScript interceptors are displayed on cards clustered by tags; those not assigned to a tag will be listed in the Uncategorized grouping.

To know which tags a custom interceptor is assigned to, click the icon
and a window containing the tags will be displayed.

To edit an interceptor, click its icon on the list, which will open the editor (see images below).


CAUTIONIf you edit a custom interceptor you must remove all instances of this interceptor that had been inserted in API flows before your modifications. That is because changes made to an interceptor will not be reflected upon interceptor instances in API flows.
To remove a custom interceptor, enter the editor and click the Delete Interceptor button. The APIs in which the interceptor is being used will be shown and it will be possible to confirm the exclusion by clicking the Delete button.

In this type of transformation, a snippet of JavaScript code is registered in the API Manager and sent to the Gateway.
The scripts inserted in the editor are the code to be executed to manipulate requests/responses. Each script can include a data structure representing the current request/response and a range of utilities. It can modify the request, the response, or trigger other processes by using the data of the current call.
The script is interpreted by a JavaScript engine running inside the JVM, using Rhino exclusively. Note, however, that there may be performance loss if multiple complex scripts are executed on each call.
The items of this subsection aim to give you a solid grasp on how to create scripts for the actions you need. In addition to these pieces of explanation and more general references, you can find a series of script examples on this page.
You can use a range of implicit variables and utilities in the code of your JavaScript interceptor:
Variable | Description |
|---|---|
| $call | This object groups all data related to the current call, including the request, the response, and other data produced during the processing of the API Gateway. |
| $request | Shortcut to $call.request. |
| $response | Shortcut to $call.response. |
| $base64 | Utility for coding and decoding Base64. |
| $http | Utility for making HTTP calls to other servers. |
| $jdom | Utility for parsing and formatting XML. |
| $json | Utility for parsing and formatting JSON. |
| $cookies | Utility for parsing cookies. |
| $console | Utility to use with custom debug. |
| $gzip | Utility for archive (de)compression. |
| $billing | Utility for manipulating billing service. |
You can access the Javadoc of the objects $call, $request and $response here:
Download: JavaDocs - Custom JavaScript Interceptor
And here the Javadoc on utility classes:
A custom JavaScript interceptor can run in the request or response flows.
When executed in the request, only the $request object values should be changed.
When executed in the response, only the $response object values should be changed.
JavaScript interceptors have the possibility of running a code debug. To use the debug feature, insert the following code line and enable the debug option in the editor (see image below).

To view the results of the debugging, enter the Trace and open the details of the call made. The lines that were executed will be displayed in the Gateway Trace tab, as shown below.

Click the insect icon to view the details of the debug.

We use cookies to enhance your experience on our site. By continuing to browse, you agree to our use of cookies.Learn more