Closed
Description
httpcomponents httpclient5 changed the internal implementation of HttpClientContext with version 5.4
apache/httpcomponents-client@762b18f
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);