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
(@Nullable HttpRequest<?> request, @NonNull Runnable runnable) Return a new runnable by instrumenting the given runnable with request context handling.static void
with
(@Nullable HttpRequest<?> request, @NonNull Runnable runnable) Wrap the execution of the given runnable in request context processing.static <T> T
with
(@Nullable HttpRequest<?> request, @NonNull Callable<T> callable) Wrap the execution of the given callable in request context processing.static <T> T
with
(@Nullable HttpRequest<?> request, @NonNull Supplier<T> supplier) Wrap the execution of the given callable in request context processing.
-
Field Details
-
KEY
- See Also:
-
-
Method Details
-
with
public static void with(@Nullable @Nullable HttpRequest<?> request, @NonNull @NonNull Runnable runnable) Wrap the execution of the given runnable in request context processing.- Parameters:
request
- The requestrunnable
- The runnable
-
instrument
public static Runnable instrument(@Nullable @Nullable HttpRequest<?> request, @NonNull @NonNull Runnable runnable) 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
public static <T> T with(@Nullable @Nullable HttpRequest<?> request, @NonNull @NonNull Supplier<T> supplier) Wrap the execution of the given callable in request context processing.- Type Parameters:
T
- The return type of the callable- Parameters:
request
- The requestsupplier
- The callable- Returns:
- The return value of the callable
-
with
public static <T> T with(@Nullable @Nullable HttpRequest<?> request, @NonNull @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
-