Package io.micronaut.http.context
Class ServerRequestContext
java.lang.Object
io.micronaut.http.context.ServerRequestContext
The holder for the current
HttpRequest
that is bound to instrumented threads.
Allowing lookup of the current request if it is present.- Since:
- 1.0
- Author:
- Graeme Rocher
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Optional<HttpRequest<T>>
Retrieve the current server request context.static Runnable
instrument
(HttpRequest request, Runnable runnable) Return a new runnable by instrumenting the given runnable with request context handling.static void
set
(HttpRequest request) SetHttpRequest
.static void
with
(HttpRequest request, Runnable runnable) Wrap the execution of the given runnable in request context processing.static <T> T
with
(HttpRequest request, Callable<T> callable) Wrap the execution of the given callable in request context processing.static <T> T
with
(HttpRequest request, Supplier<T> callable) Wrap the execution of the given callable in request context processing.
-
Field Details
-
KEY
- See Also:
-
-
Method Details
-
set
SetHttpRequest
.- Parameters:
request
- newHttpRequest
-
with
Wrap the execution of the given runnable in request context processing.- Parameters:
request
- The requestrunnable
- The runnable
-
instrument
Return a new runnable by instrumenting the given runnable with request context handling.- Parameters:
request
- The requestrunnable
- The runnable- Returns:
- The newly instrumented runnable
-
with
Wrap the execution of the given callable in request context processing.- Type Parameters:
T
- The return type of the callable- Parameters:
request
- The requestcallable
- The callable- Returns:
- The return value of the callable
-
with
public static <T> T with(@Nullable HttpRequest request, @NonNull Callable<T> callable) throws Exception Wrap the execution of the given callable in request context processing.- Type Parameters:
T
- The return type of the callable- Parameters:
request
- The requestcallable
- The callable- Returns:
- The return value of the callable
- Throws:
Exception
- If the callable throws an exception
-
currentRequest
Retrieve the current server request context.- Type Parameters:
T
- The body type- Returns:
- The request context if it is present
-