Reinstate support for read timeouts with RestTemplateBuilder

Refactor the way `ClientHttpRequestFactory` instances are created in
order to support setting read timeouts.

Prior to this commit, the reflection based approach would call
`setReadTimeout`. As of Spring Framework 6.0, the
`HttpComponentsClientHttpRequestFactory` class no longer supports this
approach. The timeout must be set on the `HttpClientConnectionManager`
used in the `HttpClient` which can be passed in to the constructor.

In order to support this approach, the `ClientHttpRequestFactory` can
now be created using a `Function` rather than a `Supplier`. The
function accepts a `ClientHttpRequestFactorySettings` which provides
the timeout settings to apply.

The `ClientHttpRequestFactories` utility class provides methods to
create `ClientHttpRequestFactory` instances that respect the settings.
Whenever possible, these are created without using reflection.

Fixes gh-32857

Co-authored-by: Phillip Webb <pwebb@vmware.com>
This commit is contained in:
Andy Wilkinson
2022-10-24 17:41:36 +01:00
committed by Phillip Webb
parent c22e76632c
commit e6c37d698f
23 changed files with 1405 additions and 544 deletions

View File

@@ -134,7 +134,7 @@ class TestRestTemplateTests {
TestRestTemplate template = new TestRestTemplate(HttpClientOption.ENABLE_REDIRECTS);
CustomHttpComponentsClientHttpRequestFactory factory = (CustomHttpComponentsClientHttpRequestFactory) template
.getRestTemplate().getRequestFactory();
RequestConfig config = factory.getRequestConfig();
RequestConfig config = factory.createRequestConfig();
assertThat(config.isRedirectsEnabled()).isTrue();
}