Cloud Pak for Integration

 View Only

IBM DataPower and GatewayScript

By Anders Wasen posted Wed February 24, 2021 02:24 PM

  

GatewayScript is a great addition to DataPower’s already extensive tool-box and it gives a wide variety of things we can do!

For anyone not fully familiar with what GatewayScript is it a new scripting language in DataPower based upon Node.js, or rather ECMA Script which is basically a server side implementation of JavaScript.

GatewayScript can be seen as a ”replacement” for XSLT and is used the same in Processing Policy actions. There is a new transform action on the tool bar of a Processing Policy in DataPower:

image 1.png

The GatewayScript Action can be used in the same way as any other Action in a Processing Policy and can be used in any combination with XSLT transform as well.

GatewayScript can also now be used as a B2B pre-processor instead of XSLT which is great as many B2B messages are not XML based.

Writing GWS code is the same as writing Node.js code (more or less) and your first GWS script can be as easy as the following line: 

 

console.log(”Hello GatewayScript”);

 

If you save that into a file called ”hello.js” and upload into your GWS Action you will end up with a line in the debug log saying ”Hello GatewayScript” obviously.

There are several sample scripts supplied with the newer firmwares in store:///gatewayscirpt/ all named ”example” something, e.g. ”example-fs.js” which will show you have to read and write to/from the file system of DataPower (Yes! That’s right GWS can actually read and write files directly to the internal disk!).

As two samples of what I’ve helped our customers doing using the power of GWS is to build PGP encryption/decryption into DataPower and also create a RosettaNet RNIF gateway implementation enveloping and de-enveloping the rather complex RosettaNet messages.

Looking at what IBM set out to achieve with GWS they mention the goals as:

  • A superior development experience – servicing, debugging, monitoring mission-critical apps with flexible error handling and logging
  • Familiar and friendly programming language – leverage common programming skills
  • Highly secure environment – transaction isolation, prevention of dynamic code execution
  • Ability to consume, produce, and transform JSON and binary data using transport agnostic API
  • Efficient processing and propagation of information between existing Policy Actions
  • Wire-speed processing of scripts – leverage DataPower's techniques and technologies

Especially the point of the “ability to consume, produce, and transform JSON and binary data” is what have been lacking in DataPower previously (or it has been an arduous task to get it done).

The Do’s and Don’t’s of GWS is debated somewhat but the general principle is this:

Do:

  • Use GatewayScript for JSON Processing.
  • Use GatewayScript for Mobile and RESTful applications.
  • Use GatewayScript on differing content-types in the same service (XML, JSON, Binary, Text).
  • Consider using GatewayScript for Binary transformations.
  • Consider using GatewayScript to implement business logic.

Don't:

  • Rewrite all your stylesheets. Instead, bring in GatewayScript where appropriate using the dp:gatewayscript() extension function/element or adding a GatewayScript action to process and output contexts.

I have encountered a few customers who actually want to do the “don’t” and transform all of their XSLT’s into GWS. The reason in their case is that they have Node.js developers in-house but no resources for XSLT and they have a very few services using XML processing. SOAP, sure, but not really any Processing Policies handling XML, just standard WebService Proxy functions.

For them it kind of makes sense to jump the gun and make all GWS but for must simply live with the fact that you can (and should!) mix and match between GWS and XSLT!

With the option to run DataPower as a developer locally (on your own laptop/computer) the Debugger for GWS is also available. You can debug your JavaScript just as in a “normal” programming environment!

This works on all form factors of DataPower so if you sit on a VMWare image or a Docker container you are ready to go!

 

If you like, leave a comment to this post and I can bring up debugging in a new post maybe… So, if you haven’t already, take a close look at GWS and see what it can do for you! Take care! - Anders

 

1 comment
73 views

Permalink

Comments

Thu September 01, 2022 06:40 PM

Hello - We have integration GatewayScript + XSLT code currently on DataPower. Can the same be supported / ported on ACE (App Connect)? 

Thanks!