Class AsyncHooks

    • Constructor Detail

      • AsyncHooks

        public AsyncHooks()
    • Method Detail

      • registerBeforeRequest

        public AsyncHooks registerBeforeRequest​(AsyncHook.BeforeRequest beforeRequest)
        Registers an async before-request hook. Hooks are chained in registration order.
        Parameters:
        beforeRequest - async hook returning CompletableFuture<HttpRequest>
        Returns:
        this
      • registerAfterSuccess

        public AsyncHooks registerAfterSuccess​(AsyncHook.AfterSuccess afterSuccess)
        Registers an async after-success hook. Hooks are chained in registration order.
        Parameters:
        afterSuccess - async hook returning CompletableFuture<HttpResponse>
        Returns:
        this
      • registerAfterError

        public AsyncHooks registerAfterError​(AsyncHook.AfterError afterError)
        Registers an async after-error hook. Hooks are chained in registration order.
        Parameters:
        afterError - async hook for error handling
        Returns:
        this
      • beforeRequest

        public java.util.concurrent.CompletableFuture<java.net.http.HttpRequest> beforeRequest​(Hook.BeforeRequestContext context,
                                                                                               java.net.http.HttpRequest request)
        Description copied from interface: AsyncHook.BeforeRequest
        Transforms the given HttpRequest before sending.

        Note that HttpRequest is immutable. To modify the request you can use HttpRequest#newBuilder(HttpRequest, BiPredicate<String, String>) with JDK 16 and later (which will copy the request for modification in a builder). If that method is not available then use Helpers.copy(java.net.http.HttpRequest) (which also returns a builder).

        Specified by:
        beforeRequest in interface AsyncHook.BeforeRequest
        Parameters:
        context - context for the hook call
        request - request to be transformed
        Returns:
        transformed request
      • afterSuccess

        public java.util.concurrent.CompletableFuture<java.net.http.HttpResponse<Blob>> afterSuccess​(Hook.AfterSuccessContext context,
                                                                                                     java.net.http.HttpResponse<Blob> response)
        Description copied from interface: AsyncHook.AfterSuccess
        Transforms the given response before response processing occurs.
        Specified by:
        afterSuccess in interface AsyncHook.AfterSuccess
        Parameters:
        context - context for the hook call
        response - response to be transformed
        Returns:
        transformed response
      • afterError

        public java.util.concurrent.CompletableFuture<java.net.http.HttpResponse<Blob>> afterError​(Hook.AfterErrorContext context,
                                                                                                   java.net.http.HttpResponse<Blob> response,
                                                                                                   java.lang.Throwable error)
        Description copied from interface: AsyncHook.AfterError
        Either returns an HttpResponse or throws an Exception. Must be passed either a response or an error (both can't be absent).
        Specified by:
        afterError in interface AsyncHook.AfterError
        Parameters:
        context - context for the error
        response - response information if available.
        error - the optional exception. If response present then the error is for-info only, it was the last error in the chain of AfterError hook calls leading to this one
        Returns:
        HTTP response if method decides that an exception is not to be thrown