Package org.forgerock.openig.http
Class ContextAndRequest
- java.lang.Object
-
- org.forgerock.openig.http.ContextAndRequest
-
public class ContextAndRequest extends Object
This a value class to hold aContext
and aRequest
during the processing of a request. It can be used as a parameter in aFunction
. 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<Response, 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<Response, NeverThrowsException> apply( Exception cause) throws NeverThrowsException { Response response = new Response(Status.INTERNAL_SERVER_ERROR); response.setCause(cause); return newResponsePromise(response); } }); } }
- See Also:
ThrottlingFilter
-
-
Constructor Summary
Constructors Constructor Description ContextAndRequest(Context context, Request request)
Constructs a new ContextAndRequest.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Context
getContext()
Returns the context.Request
getRequest()
Returns the request.
-