Guillaume, Matt, and Violette’s recent work has made OpenIG configuration a lot easier to read and write. To try this at home, grab the latest nightly build of OpenIG. (The changes in the server are backwards compatible, too, so you don’t have to move right away. But you will want to.)
Imagine that you are working with OpenIG 3.0.0, debugging one of your basic routes. You want to capture requests and responses going through your route to see what is going on. Your route definition looks something like this:
{ "heap": { "objects": [ { "name": "LoginChain", "type": "Chain", "config": { "filters": [ "CaptureFilter", "LoginRequest" ], "handler": "ClientHandler" } }, { "name": "CaptureFilter", "type": "CaptureFilter", "config": { "file": "/tmp/gateway.log" } }, { "name": "LoginRequest", "type": "StaticRequestFilter", "config": { "method": "POST", "uri": "http://www.example.com", "form": { "username": [ "george" ], "password": [ "costanza" ] } } }, { "name": "ClientHandler", "type": "ClientHandler", "config": {} } ] }, "handler": "LoginChain" }
Fast forward to last night’s build of OpenIG, taking into account Guillaume’s inlining and capture decorator, Violette’s removal of empty “config” settings, Matt’s streamlining of the “heap” when not necessary and updates to the way decorations can be done.
Here is that same route, seriously improved.
{ "handler": { "type": "Chain", "config": { "filters": [ { "type": "StaticRequestFilter", "config": { "method": "POST", "uri": "http://www.example.com", "form": { "username": [ "george" ], "password": [ "costanza" ] } } } ], "handler": { "type": "ClientHandler" } } }, "capture": "all" }
Well, almost the same route. You now capture requests and responses at many more points in the flow.
Notice that the very first thing in the configuration is the “handler” that produces a response.
The “Chain” is much easier to read, too.
When you start writing scripts or get stuck with a complex configuration, add a “CaptureDecorator” definition with "captureExchange": true
for even more debugging information at each capture point.
You can now go utterly minimalist in your default route, assuming you define a “ClientHandler” in the top-level config.json
file.
{ "handler": "ClientHandler" }
For more on what’s happening in the configuration and around OpenIG, see the draft, in-progress What’s New chapter of the release notes.