public final class RequestAccessor extends Object
HttpServletRequest
.Modifier and Type | Method and Description |
---|---|
static <T> T |
executeWithFallbackRequest(Supplier<javax.servlet.http.HttpServletRequest> fallbackRequest,
Callable<T> callable)
Execute the given
Callable , using the given request as fallback if there is no other request available. |
static void |
executeWithFallbackRequest(Supplier<javax.servlet.http.HttpServletRequest> fallbackRequest,
Executable executable)
Execute the given
Executable , using the given request as fallback if there is no other request available. |
static <T> T |
executeWithRequest(javax.servlet.http.HttpServletRequest request,
Callable<T> callable)
Execute the given
Callable with a given request. |
static void |
executeWithRequest(javax.servlet.http.HttpServletRequest request,
Executable executable)
Execute the given
Executable with a given request. |
static javax.servlet.http.HttpServletRequest |
getCurrentRequest()
Returns the current
HttpServletRequest , delegating to tryGetCurrentRequest() and unwrapping the
Try . |
static Supplier<javax.servlet.http.HttpServletRequest> |
getFallbackRequest()
Global fallback
HttpServletRequest . |
static RequestFacade |
getRequestFacade()
The
RequestFacade instance. |
static void |
setFallbackRequest(Supplier<javax.servlet.http.HttpServletRequest> fallbackRequest)
Global fallback
HttpServletRequest . |
static void |
setRequestFacade(RequestFacade requestFacade)
Replaces the default
RequestFacade instance. |
static io.vavr.control.Try<javax.servlet.http.HttpServletRequest> |
tryGetCurrentRequest()
Returns a
Try of the current HttpServletRequest , or, if the Try is a failure, the global
fallback. |
public static void setRequestFacade(@Nullable RequestFacade requestFacade)
RequestFacade
instance.requestFacade
- An instance of RequestFacade
. Use null
to reset the facade.@Nonnull public static javax.servlet.http.HttpServletRequest getCurrentRequest() throws RequestAccessException
HttpServletRequest
, delegating to tryGetCurrentRequest()
and unwrapping the
Try
.HttpServletRequest
.RequestAccessException
- If there is an issue while accessing the HttpServletRequest
.@Nonnull public static io.vavr.control.Try<javax.servlet.http.HttpServletRequest> tryGetCurrentRequest()
Try
of the current HttpServletRequest
, or, if the Try
is a failure, the global
fallback.Try
of the current HttpServletRequest
.@Nullable public static <T> T executeWithRequest(@Nonnull javax.servlet.http.HttpServletRequest request, @Nonnull Callable<T> callable) throws ThreadContextExecutionException
Callable
with a given request.T
- The type of the callable.request
- The request to execute with.callable
- The callable to execute.ThreadContextExecutionException
- If there is an issue while running the code with the request.public static void executeWithRequest(@Nonnull javax.servlet.http.HttpServletRequest request, @Nonnull Executable executable) throws ThreadContextExecutionException
Executable
with a given request.request
- The request to execute with.ThreadContextExecutionException
- If there is an issue while running the code with the request.@Nullable public static <T> T executeWithFallbackRequest(@Nonnull Supplier<javax.servlet.http.HttpServletRequest> fallbackRequest, @Nonnull Callable<T> callable) throws ThreadContextExecutionException
Callable
, using the given request as fallback if there is no other request available.T
- The type of the callable.fallbackRequest
- The request to fall back to.callable
- The callable to execute.ThreadContextExecutionException
- If there is an issue while running the code with the request.public static void executeWithFallbackRequest(@Nonnull Supplier<javax.servlet.http.HttpServletRequest> fallbackRequest, @Nonnull Executable executable) throws ThreadContextExecutionException
Executable
, using the given request as fallback if there is no other request available.fallbackRequest
- The request to fall back to.ThreadContextExecutionException
- If there is an issue while running the code with the request.@Nonnull public static RequestFacade getRequestFacade()
RequestFacade
instance.@Nullable public static Supplier<javax.servlet.http.HttpServletRequest> getFallbackRequest()
HttpServletRequest
. By default, no fallback is used, i.e., the fallback is null
.
A global fallback can be useful to ease testing with a mocked request.Copyright © 2019 SAP SE. All rights reserved.