Package org.forgerock.openig.filter
Class ConditionalFilter
- java.lang.Object
-
- org.forgerock.openig.filter.ConditionalFilter
-
-
Constructor Summary
Constructors Constructor Description ConditionalFilter(Filter delegate, boolean condition)
Constructs aConditionalFilter
.ConditionalFilter(Filter delegate, AsyncFunction<ContextAndRequest,Boolean,Exception> condition)
Constructs aConditionalFilter
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Promise<Response,NeverThrowsException>
filter(Context context, Request request, Handler next)
Filters the request and/or response of an exchange.
-
-
-
Constructor Detail
-
ConditionalFilter
public ConditionalFilter(Filter delegate, boolean condition)
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 Detail
-
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.
-
-