How to Implement Gatewayscript in IBM Datapower Gateway?
GatewayScript –
GatewayScript is a programming model in IBM Datapower Gateway which is a combination of ECMA Script(ES6), Common JS 1.0, and many popular JS crypto libraries.
To implement the Gateway script in service we will make use of the gateway script action in the processing policy.
GatewayScript Action –
- A GatewayScript action can run a gateway script file located in the Datapower directory or in context.
- The script file must be located in local: store: or temporary: directories for it to be accessed by GatewayScript action.
- You can specify the location of the file by using a URL or by using a variable.
- For GatewayScript to be accessed from context, a fetch action should precede the GatewayScript action and add the script content to the context. Then GatewayScript action will read from the context.
- Sample GatewayScript is available in the store:///gatewayscript/ directory and as the store:///healthcheck.js.
Adding a GatewayScript action to run the script by taking from a Directory
- Let’s create a sample loopback service to demonstrate the gateway script action functionality
- Let’s create a sample gateway script that takes in JSON data and generate a successful JSON response
- Upload the GatewayScript file to the Datapower local directory.
- Create a processing policy and processing rule.
- Drag the GatewayScript action onto the rule.
- Double tap the GatewayScript icon
- Give the path of the GatewayScript file in the GatewayScript file field.
- Click DONE and Configure the remaining service as required.
- Use any testing tool to test the Service.
Adding a GatewayScript action to run the script by taking the content from the context
- We can use the same script we used earlier to demonstrate the gateway script execution from context.
- Drag the GatewayScript action onto the rule
- Drag the Fetch action and place it before the GatewayScript action
- When you define the GatewayScript action, reference the context with one of the following formats.
-
- var://context/name
- var://context/name/
- In the Fetch action specify the gateway script file to read and add to the context.
- In the Gateway Script action Input Field, specify the context of the message to process
- In the GatewayScript File field, specify the location of the script file.
- In the output, field Specify the context of the message after processing.
- Click on Done.
- Use any testing tool to test the Service.