Helma Logo
main list history
previous version  overview  next version

Version 2 by hannes on 19. May 2009, 13:55

Middleware is a feature of web connectors the Helma NG webapp framework that provides a simple interface to plug in inject additional code between the web server and the web app using a standard interfaceapplication. Another common term for middleware that is used in Middleware uses the Java Servlet API is "Filters"same calling conventions as web app actions: a function that takes a Request object as argument and returns a Response object.

Since middleware wraps the web application (and any middlware stacked upon it), it is in full control of how the request is processed.

* Inspect and modify the request object before processing it further
* Decide not to pass the request on, returning its own response instead
* Inspect and modify the response obtained from the application

Middleware is configured in an exported Array called <code>middleware</code> in the app's <code>config</code> module. By convention, the webapp looks for a function called <code>handleRequest</code> in middleware modules.

The <code>request</code> argument contains a <code>process</code> method that is used to pass the request on in the middleware chain. Thus, a middleware implementation that just passes on the request might look like this:

  exports.handleRequest(req) {
    return req.process();

Have a look at the *modules/helma/middlware|https://dev.helma.org/trac/helma/browser/helma-ng/trunk/modules/helma/middleware* directory for the standard middleware currently shipping with Helma NG.