Interface Interceptor
-
- All Known Implementing Classes:
BackwardsCompatibilityInterceptor,HttpLoggingInterceptor,ImpersonatorInterceptor,TokenRefreshInterceptor
public interface InterceptorA collection of callback methods invoked through the various stages of the HTTP request lifecycle. Each invocation ofbefore(BasicBuilder, HttpRequest, RequestTags)will be matched with a call to one ofafterConnectionFailure(HttpRequest, Throwable)orafter(HttpRequest, HttpResponse, AsyncBody.Consumer). Callbacks that lead to a request being sent allow for that request to be customised.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interfaceInterceptor.RequestTags
-
Method Summary
All Methods Instance Methods Default Methods Modifier and Type Method Description default voidafter(HttpRequest request, HttpResponse<?> response, AsyncBody.Consumer<List<ByteBuffer>> consumer)Called after a non-WebSocket HTTP response is received.default voidafterConnectionFailure(HttpRequest request, Throwable failure)Called after a connection attempt fails.default CompletableFuture<Boolean>afterFailure(BasicBuilder builder, HttpResponse<?> response, Interceptor.RequestTags tags)Called after a websocket failure or by default from a normal request.default CompletableFuture<Boolean>afterFailure(HttpRequest.Builder builder, HttpResponse<?> response, Interceptor.RequestTags tags)Called after a non-websocket failuredefault voidbefore(BasicBuilder builder, HttpRequest request, Interceptor.RequestTags tags)Called before a request to allow for the manipulation of the requestdefault AsyncBody.Consumer<List<ByteBuffer>>consumer(AsyncBody.Consumer<List<ByteBuffer>> consumer, HttpRequest request)Called before a request to allow the encapsulation of the provided consumer.
-
-
-
Method Detail
-
before
default void before(BasicBuilder builder, HttpRequest request, Interceptor.RequestTags tags)
Called before a request to allow for the manipulation of the request- Parameters:
builder- used to modify the requestrequest- the current request
-
after
default void after(HttpRequest request, HttpResponse<?> response, AsyncBody.Consumer<List<ByteBuffer>> consumer)
Called after a non-WebSocket HTTP response is received. The body might or might not be already consumed.Should be used to analyze response codes and headers, original response shouldn't be altered.
- Parameters:
request- the original request sent to the server.response- the response received from the server.
-
consumer
default AsyncBody.Consumer<List<ByteBuffer>> consumer(AsyncBody.Consumer<List<ByteBuffer>> consumer, HttpRequest request)
Called before a request to allow the encapsulation of the provided consumer.- Parameters:
consumer- the original consumer.request- the HTTP request.- Returns:
- the consumer to use.
-
afterFailure
default CompletableFuture<Boolean> afterFailure(BasicBuilder builder, HttpResponse<?> response, Interceptor.RequestTags tags)
Called after a websocket failure or by default from a normal request.Failure is determined by HTTP status code and will be invoked in addition to
after(HttpRequest, HttpResponse, AsyncBody.Consumer)- Parameters:
builder- used to modify the requestresponse- the failed response- Returns:
- true if the builder should be used to execute a new request
-
afterFailure
default CompletableFuture<Boolean> afterFailure(HttpRequest.Builder builder, HttpResponse<?> response, Interceptor.RequestTags tags)
Called after a non-websocket failureFailure is determined by HTTP status code and will be invoked in addition to
after(HttpRequest, HttpResponse, AsyncBody.Consumer)- Parameters:
builder- used to modify the requestresponse- the failed response- Returns:
- true if the builder should be used to execute a new request
-
afterConnectionFailure
default void afterConnectionFailure(HttpRequest request, Throwable failure)
Called after a connection attempt fails.This method will be invoked on each failed connection attempt.
- Parameters:
request- the HTTP request.failure- the Java exception that caused the failure.
-
-