Class ScriptableFilter

All Implemented Interfaces:
Closeable, AutoCloseable, Filter

public class ScriptableFilter extends AbstractScriptableHeapObject<Response> implements Filter
A scriptable filter. This filter acts as a simple wrapper around the scripting engine. Scripts are provided with the bindings provided by AbstractScriptableHeapObject plus :
  • context - the associated request context
  • request - the HTTP request
  • next - the next handler in the filter chain.

Contains also easy access to attributes from the AttributesContext, e.g: attributes.user = "jackson", instead of contexts.attributes.attributes.user = "jackson".

In the same way, it gives access to session from the SessionContext, for example, you can use: session.put(...), instead of contexts.session.session.put(...).

Like Java based filters, scripts are free to choose whether or not they forward the request to the next handler or, instead, return a response immediately.

  • Method Details

    • filter

      public Promise<Response,NeverThrowsException> filter(Context context, Request request, Handler next)
      Description copied from interface: Filter
      Filters the request and/or response of an exchange. To pass the request to the next filter or handler in the chain, the filter calls next.handle(context, request).

      This method may elect not to pass the request to the next filter or handler, and instead handle the request itself. It can achieve this by merely avoiding a call to next.handle(context, request) and creating its own response object. The filter is also at liberty to replace a response with another of its own by intercepting the response returned by the next handler.

      Specified by:
      filter in interface Filter
      Parameters:
      context - The request context.
      request - The request.
      next - The next filter or handler in the chain to handle the request.
      Returns:
      A Promise representing the response to be returned to the client.