public class ContextAndRequest extends Object
Context
and a Request
during the processing of a request.
It can be used as a parameter in a Function
.
Example:
public class EnforcementFilter implements Filter {
private final AsyncFunction<ContextAndRequest, Boolean, Exception> condition;
public EnforcementFilter(AsyncFunction<ContextAndRequest, Boolean, Exception> condition) {
this.condition = condition;
}
{@literal @}Override
public Promise<Response, NeverThrowsException> filter(final Context context, final Request request,
final Handler next) {
return condition.apply(new ContextAndRequest(context, request))
.thenAsync(new AsyncFunction<Boolean, Response, NeverThrowsException>() {
{@literal @}Override
public Promise<? extends Response, ? extends NeverThrowsException> apply(
Boolean condition) throws NeverThrowsException {
if (condition) {
return next.handle(context, request);
}
return newResponsePromise(new Response(Status.FORBIDDEN));
}
},
new AsyncFunction<Exception, Response, NeverThrowsException>() {
{@literal @}Override
public Promise<? extends Response, ? extends NeverThrowsException> apply(
Exception cause) throws NeverThrowsException {
Response response = new Response(Status.INTERNAL_SERVER_ERROR);
response.setCause(cause);
return newResponsePromise(response);
}
});
}
}
ThrottlingFilter
Constructor and Description |
---|
ContextAndRequest(org.forgerock.services.context.Context context,
org.forgerock.http.protocol.Request request)
Constructs a new ContextAndRequest.
|
Modifier and Type | Method and Description |
---|---|
org.forgerock.services.context.Context |
getContext()
Returns the context.
|
org.forgerock.http.protocol.Request |
getRequest()
Returns the request.
|
Copyright © 2025 Open Identity Platform Community. All rights reserved.