Class SwitchFilter

java.lang.Object
org.forgerock.openig.filter.SwitchFilter
All Implemented Interfaces:
Filter

public class SwitchFilter extends Object implements Filter
Conditionally diverts the request to another handler. Before and after the request is handled, associated conditions are evaluated. If a condition evaluates to true, then the processing flow is diverted to the associated handler. If no condition evaluates to true, then the request flows normally through the filter.

Typical behaviours:

  • If a request case yields, only that handler's case is invoked (no next nor response case)
  • If no request case yields, then next handler will be invoked, and maybe a response case will handle it too
  • If neither request nor response case yield, only the next handler is invoked

This filter preserves the filtered request for the response binding.

  • Constructor Details

    • SwitchFilter

      public SwitchFilter()
  • Method Details

    • addRequestCase

      public SwitchFilter addRequestCase(Expression<Boolean> condition, Handler handler)
      Add a request switch case with a condition and the handler to execute if condition yields.
      Parameters:
      condition - expression to evaluate
      handler - handler to be executed if the condition yields
      Returns:
      this filter for fluent invocation.
    • addResponseCase

      public SwitchFilter addResponseCase(Expression<Boolean> condition, Handler handler)
      Add a response switch case with a condition and the handler to execute if condition yields.
      Parameters:
      condition - expression to evaluate
      handler - handler to be executed if the condition yields
      Returns:
      this filter for fluent invocation.
    • 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.