Support for JavaScript (a.k.a. GatewayScript) is the most noticeable new feature in DataPower firmware Version 7. GatewayScript can be used as part of any processing policy as an alternative to the XSLT-based rules.
It looks as though DataPower runs a subset of node.js as its JavaScript engine. Objects like “console” and “buffer” appear to be borrowed from node.
DPBuddy can be used to copy JavaScript files to the appliance and to perform other chores.
You can develop your JavaScript files locally and then run this command to copy them to the device:
dpbuddy copy -toDir js -flatten -includes "js/*.js"
This will copy all JavaScript files from the directory “js” to the “local://js” directory on the appliance.
You can use console.log()
calls in your JavaScript code to help with troubleshooting. If you’re using the “debug” or “info” level, you need to enable it on the device:
dpbuddy setLogLevel -level INFO
Once the files have been copied, you can start exercising DataPower services using curl or SoapUI. If you’re using SoapUI, you can actually do copying as part of the “setup” directly from SoapUI as explained here.
You can also tail the logs remotely from your machine:
dpbuddy tail -f | find "your service name" dpbuddy tail -f | grep "your service name"
In DPBuddy 3.1.1, the “tail” command also displays the log message category, so you’d be able to do “grep gatewayscript” since all messages from GatewayScript are logged under the “gatewayscript-user” category.
Finally, you may want to disable the JavaScript debugger when you deploy your configuration to the environment other than development. This can achieved by using this transformation rule as part of import or export tasks:
<setText xpath="//ActionDebug" value="off" />
To get started with the GatewayScript development, download the current version of DPBuddy and give it a try.
Automate without scripting, monitor your services, check for compliance
Realize full potential of DataPower gateways