Package org.springframework.http.client
Interface ClientHttpRequestInterceptor
- All Known Implementing Classes:
BasicAuthenticationInterceptor
,BasicAuthorizationInterceptor
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
@FunctionalInterface public interface ClientHttpRequestInterceptor
Intercepts client-side HTTP requests. Implementations of this interface can be registered with theRestTemplate
, as to modify the outgoingClientHttpRequest
and/or the incomingClientHttpResponse
.The main entry point for interceptors is
intercept(HttpRequest, byte[], ClientHttpRequestExecution)
.- Since:
- 3.1
- Author:
- Arjen Poutsma
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description ClientHttpResponse
intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution)
Intercept the given request, and return a response.
Method Detail
intercept
ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException
Intercept the given request, and return a response. The givenClientHttpRequestExecution
allows the interceptor to pass on the request and response to the next entity in the chain.A typical implementation of this method would follow the following pattern:
- Examine the request and body
- Optionally wrap the request to filter HTTP attributes.
- Optionally modify the body of the request.
- Either
- execute the request using
ClientHttpRequestExecution.execute(org.springframework.http.HttpRequest, byte[])
, or - do not execute the request to block the execution altogether.
- execute the request using
- Optionally wrap the response to filter HTTP attributes.
- Parameters:
request
- the request, containing method, URI, and headersbody
- the body of the requestexecution
- the request execution- Returns:
- the response
- Throws:
IOException
- in case of I/O errors