Class ServerRequestContext

java.lang.Object
io.micronaut.http.context.ServerRequestContext

public final class ServerRequestContext extends Object
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 Details

  • 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 request
      runnable - 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 request
      runnable - 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 request
      supplier - 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 request
      callable - The callable
      Returns:
      The return value of the callable
      Throws:
      Exception - If the callable throws an exception
    • currentRequest

      public static <T> Optional<HttpRequest<T>> currentRequest()
      Retrieve the current server request context.
      Type Parameters:
      T - The body type
      Returns:
      The request context if it is present