Constructor and Description |
---|
ConditionalFilter(Filter delegate,
AsyncFunction<ContextAndRequest,Boolean,Exception> condition)
Constructs a
ConditionalFilter . |
ConditionalFilter(Filter delegate,
boolean condition)
Constructs a
ConditionalFilter . |
Modifier and Type | Method and Description |
---|---|
Promise<Response,NeverThrowsException> |
filter(Context context,
Request request,
Handler next)
Filters the request and/or response of an exchange.
|
public ConditionalFilter(Filter delegate, boolean condition)
ConditionalFilter
.
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);
}
};
}
delegate
- the filter that will be executed if the condition is true.condition
- the condition that controls the delegate filter's executionpublic ConditionalFilter(Filter delegate, AsyncFunction<ContextAndRequest,Boolean,Exception> condition)
ConditionalFilter
.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.public Promise<Response,NeverThrowsException> filter(Context context, Request request, Handler next)
Filter
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.
Copyright 2011-2017 ForgeRock AS.