Package org.forgerock.openig.filter
Class ConditionalFilter
java.lang.Object
org.forgerock.openig.filter.ConditionalFilter
- All Implemented Interfaces:
Filter
This filter conditionally executes a delegate Filter given the result of a 'condition' function. If the condition is
true then the delegated filter is executed, skipped otherwise.
-
Constructor Summary
ConstructorDescriptionConditionalFilter
(Filter delegate, boolean condition) Constructs aConditionalFilter
.ConditionalFilter
(Filter delegate, AsyncFunction<ContextAndRequest, Boolean, Exception> condition) Constructs aConditionalFilter
. -
Method Summary
-
Constructor Details
-
ConditionalFilter
Constructs aConditionalFilter
.This constructor is provided as an ease to write some code : since you have access to the boolean, you may optimise the code like this :
if (condition) { return delegate; } else { return new Filter() { @Override public Promise<Response, NeverThrowsException> filter(Context context, Request request, Handler handler) { return handler.handle(context, request); } }; }
- Parameters:
delegate
- the filter that will be executed if the condition is true.condition
- the condition that controls the delegate filter's execution
-
ConditionalFilter
public ConditionalFilter(Filter delegate, AsyncFunction<ContextAndRequest, Boolean, Exception> condition) Constructs aConditionalFilter
.- Parameters:
delegate
- the filter that will be executed if the condition is true.condition
- the function that will be executed at each request and will allow or not to execute the delegate filter.
-
-
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 callsnext.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.
-