Package io.micronaut.http.context
Class ServerRequestContext
- java.lang.Object
-
- io.micronaut.http.context.ServerRequestContext
-
public final class ServerRequestContext extends java.lang.ObjectThe holder for the currentHttpRequestthat is bound to instrumented threads. Allowing lookup of the current request if it is present.- Since:
- 1.0
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringKEY
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> java.util.Optional<HttpRequest<T>>currentRequest()Retrieve the current server request context.static java.lang.Runnableinstrument(HttpRequest request, java.lang.Runnable runnable)Return a new runnable by instrumenting the given runnable with request context handling.static voidset(HttpRequest request)SetHttpRequest.static voidwith(HttpRequest request, java.lang.Runnable runnable)Wrap the execution of the given runnable in request context processing.static <T> Twith(HttpRequest request, java.util.concurrent.Callable<T> callable)Wrap the execution of the given callable in request context processing.static <T> Twith(HttpRequest request, java.util.function.Supplier<T> callable)Wrap the execution of the given callable in request context processing.
-
-
-
Field Detail
-
KEY
public static final java.lang.String KEY
- See Also:
- Constant Field Values
-
-
Method Detail
-
set
public static void set(@Nullable HttpRequest request)SetHttpRequest.- Parameters:
request- newHttpRequest
-
with
public static void with(@Nullable HttpRequest request, @NonNull java.lang.Runnable runnable)Wrap the execution of the given runnable in request context processing.- Parameters:
request- The requestrunnable- The runnable
-
instrument
public static java.lang.Runnable instrument(@Nullable HttpRequest request, @NonNull java.lang.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 HttpRequest request, @NonNull java.util.function.Supplier<T> callable)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 java.util.concurrent.Callable<T> callable) throws java.lang.ExceptionWrap 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:
java.lang.Exception- If the callable throws an exception
-
currentRequest
public static <T> java.util.Optional<HttpRequest<T>> currentRequest()
Retrieve the current server request context.- Type Parameters:
T- The body type- Returns:
- The request context if it is present
-
-