Closed jborgers closed 9 months ago
The API of HttpClient 5 is different from HttpClient 4, for this rule relevant:
Example:
class ExampleTimeouts { @Bean public RestTemplate restTemplate() { HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory(); factory.setHttpClient(httpClient()); // alternative way to set the 3 timeouts: //factory.setConnectionRequestTimeout(connectTimeoutInMillis); // 1 //factory.setConnectTimeout(connectTimeoutInMillis); // 2 return new RestTemplate(factory); } private CloseableHttpClient httpClient() { RequestConfig requestConfig = RequestConfig.custom() .setConnectionRequestTimeout(connectTimeoutInMillis, TimeUnit.MILLISECONDS) // 1 .setResponseTimeout(readTimeoutInMillis, TimeUnit.MILLISECONDS) // 3 .build(); final ConnectionConfig connConfig = ConnectionConfig.custom() .setConnectTimeout(connectTimeoutInMillis, TimeUnit.MILLISECONDS) // 2 .setSocketTimeout(readTimeoutInMillis, TimeUnit.MILLISECONDS).build(); // 3 final PoolingHttpClientConnectionManager connectionManager = new BasicHttpClientConnectionManager(socketFactoryRegistry); connectionManager.setConnectionConfig(connConfig); return HttpClients.custom() .setDefaultRequestConfig(requestConfig) .setConnectionManager(connectionManager) .disableConnectionState() .build(); } }
Fix: The rule now checks if an import of Apache HttpClient 4 is used. We need a new rule for version 5
The API of HttpClient 5 is different from HttpClient 4, for this rule relevant:
Example: