Interface ExchangeInterceptor<A extends ExchangeContext,B extends InterceptableExchange<A>>
- Type Parameters:
A
- the type of the exchange contextB
- the type of the interceptable exchange
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
An client exchange interceptor is used to intercept a client exchange before a request is actually sent to the server.
A client exchange interceptor operates on a InterceptableExchange
which allows to perform some processing or instrumentation that will be applied to the actual Exchange
, to the request first
before it is sent to the endpoint and to the response when it is received from the endpoint.
Multiple exchange interceptors can be chained on an HttpClient.EndpointBuilder
.
An interceptor can also prevent a request from being sent to the endpoint by returning an empty Mono, in which case the interceptable exchange is returned instead of an actual exchange.
- Since:
- 1.6
- Author:
- Jeremy Kuhn
-
Method Summary
Modifier and TypeMethodDescriptiondefault ExchangeInterceptor
<A, B> andThen
(ExchangeInterceptor<? super A, B> after) Returns a composed interceptor that invokes this interceptor first and then invokes the specified interceptor.default ExchangeInterceptor
<A, B> compose
(ExchangeInterceptor<? super A, B> before) Returns a composed interceptor that invokes the specified interceptor first and then invokes this interceptor.Intercepts the exchange before the request is sent.static <A extends ExchangeContext,
B extends InterceptableExchange<A>>
ExchangeInterceptor<A, B> of
(ExchangeInterceptor<? super A, B>... interceptors) Returns an interceptor resulting from chaining the specified interceptors in sequence.
-
Method Details
-
intercept
Intercepts the exchange before the request is sent.
- Parameters:
exchange
- the interceptable exchange to handle- Returns:
- a Mono emitting the exchange or an instrumented exchange to continue the exchange processing or an empty Mono to stop the exchange processing and prevent the request from being sent to the endpoint in which case the interceptable exchange shall be returned by the sent operation.
-
andThen
Returns a composed interceptor that invokes this interceptor first and then invokes the specified interceptor.
- Parameters:
after
- the interceptor to invoke after this interceptor- Returns:
- a composed interceptor that invokes in sequence this interceptor followed by the specified interceptor
-
compose
Returns a composed interceptor that invokes the specified interceptor first and then invokes this interceptor.
- Parameters:
before
- the interceptor to invoke before this interceptor- Returns:
- a composed interceptor that invokes in sequence this interceptor followed by the specified interceptor
-
of
@SafeVarargs static <A extends ExchangeContext,B extends InterceptableExchange<A>> ExchangeInterceptor<A,B> of(ExchangeInterceptor<? super A, B>... interceptors) Returns an interceptor resulting from chaining the specified interceptors in sequence.
- Type Parameters:
A
- the type of the exchange contextB
- the type of the interceptable exchange- Parameters:
interceptors
- the interceptors to chain- Returns:
- a composed interceptor
-