OpenIG’s improved configuration files, part II

openig-logoGuillaume, 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.

Advertisements

One thought on “OpenIG’s improved configuration files, part II

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s