httpcomponents httpclient5 changed the internal implementation of HttpClientContext with version 5.4
https://github.com/apache/httpcomponents-client/commit/762b18fe6939245443f95e88824e229d4ad0294c using instance variables for standard attributes instead of map-like attributes.
With this change, the current implementationof HttpComponentClientHttpRequestFactory#createRequest does not work (anymore), because it uses the old context.getAttribute()
and context.setAttribute()
Methods which do not have any effect anymore (at least on HttpClientContext
instances)
public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException {
...
// Request configuration not set in the context
if (context.getAttribute(HttpClientContext.REQUEST_CONFIG) == null) {
....
if (config != null) {
context.setAttribute(HttpClientContext.REQUEST_CONFIG, config);
}
}
return new HttpComponentsClientHttpRequest(client, httpRequest, context);
}
As an side effect, the new support for readtimeout isnt working for RestTemplates und RestClients
A solution might be to use the getter/setter Methods for RequestConfig:
HttpClientContext httpClientContext = HttpClientContext.cast(context);
// Request configuration not set in the context
if (httpClientContext.getRequestConfig() == null) {
// Use request configuration given by the user, when available
RequestConfig config = null;
if (httpRequest instanceof Configurable configurable) {
config = configurable.getConfig();
}
if (config == null) {
config = createRequestConfig(client);
}
if (config != null) {
httpClientContext.setRequestConfig(config);
}
}
return new HttpComponentsClientHttpRequest(client, httpRequest, context);
Comment From: jhoeller
@tvahrst please give the latest 6.1.15 or 6.2.0 snapshot a try whether it works for you with Apache HttpClient 5.4 now...
Comment From: tvahrst
@jhoeller looks good, readtimeout values are honored by RestTemplates/RestClients