Interface PostInvocationInterceptor

@Beta @Contract @ConstrainedTo(CLIENT) public interface PostInvocationInterceptor
The interceptor of a client request invocation that is executed after the request invocation itself, i.e. after the ClientResponseFilters are executed.

It is ensured that all PostInvocationInterceptors are executed after the request, in the reverse order given by the Priority, the higher the priority the later the execution. Any Throwable thrown when the afterRequest(ClientRequestContext, ClientResponseContext) or onException(ClientRequestContext, ExceptionContext) is being processed is accumulated and a multi RuntimeException with other exceptions supressed is being thrown at the end (possibly encapsulated in a ProcessingException if not a single RuntimeException), unless resolved by onException(ClientRequestContext, ExceptionContext). During the PostInvocationInterceptor processing, the accumulated Deque of the Throwables is available in the PostInvocationInterceptor.ExceptionContext.

For asynchronous invocation, the PostInvocationInterceptor is invoked in the request thread, i.e. in the thread provided by ExecutorService.

When the lowest priority PostInvocationInterceptor is executed first, one of the two methods can be invoked. afterRequest(ClientRequestContext, ClientResponseContext) in a usual case when no previous Throwable was caught, or onException(ClientRequestContext, ExceptionContext) when the Throwable was caught. Should the PostInvocationInterceptor.ExceptionContext.resolve(Response) be utilized in that case, the next PostInvocationInterceptor's afterRequest method will be invoked. Similarly, when a Throwable is caught during the PostInvocationInterceptor execution, the next PostInvocationInterceptor's onException method will be invoked.

  • Method Details

    • afterRequest

      void afterRequest(ClientRequestContext requestContext, ClientResponseContext responseContext)
      The method is invoked after a request when no Throwable is thrown, or the Throwables are resolved by previous PostInvocationInterceptor.
      requestContext - the request context.
      responseContext - the response context of the original Response or response context defined by the new resolving Response.
    • onException

      void onException(ClientRequestContext requestContext, PostInvocationInterceptor.ExceptionContext exceptionContext)
      The method is invoked after a Throwable is caught during the client request chain processing.
      requestContext - the request context.
      exceptionContext - the context available to handle the caught Throwables.