I am developing an asynchronous REST client using the helper class spring AsyncRestTemplate .
The client must send a token in the header of each request.
You can add an interceptor when using the HttpAsyncClient ( http://hc.apache.org/httpcomponents-asyncclient-4.0.x/index.html ) as the base http client of the rest of the template:
HttpRequestInterceptor interceptor = (request, context) -> request.addHeader("token", "value"); CloseableHttpAsyncClient client = HttpAsyncClients.custom() .addInterceptorLast(interceptor) .build(); HttpComponentsAsyncClientHttpRequestFactory factory = new HttpComponentsAsyncClientHttpRequestFactory(client); AsyncRestTemplate template = new AsyncRestTemplate(factory);
However, if for some reason I need to change the base client, this interceptor can no longer be used.
Is there any other way to intercept AsyncClientHttpRequest using the main http client interceptor agnostic?
source share