Skip to content

Commit

Permalink
Update RestTemplateBuilder to use ClientHttpRequestFactoryBuilder
Browse files Browse the repository at this point in the history
Refactor the internals of `RestTemplateBuilder` so that the new
`ClientHttpRequestFactoryBuilder` is used to create
`ClientHttpRequestFactory` instance.

See gh-36266
  • Loading branch information
philwebb committed Oct 25, 2024
1 parent 78458af commit 3679127
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
import org.apache.hc.core5.ssl.SSLContextBuilder;
import org.apache.hc.core5.ssl.TrustStrategy;

import org.springframework.boot.web.client.ClientHttpRequestFactorySettings;
import org.springframework.boot.http.client.ClientHttpRequestFactorySettings;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.boot.web.client.RootUriTemplateHandler;
import org.springframework.core.ParameterizedTypeReference;
Expand Down Expand Up @@ -146,7 +146,7 @@ public TestRestTemplate(RestTemplateBuilder builder, String username, String pas
if (httpClientOptions != null) {
ClientHttpRequestFactory requestFactory = builder.buildRequestFactory();
if (requestFactory instanceof HttpComponentsClientHttpRequestFactory) {
builder = builder.requestFactory(
builder = builder.requestFactoryBuilder(
(settings) -> new CustomHttpComponentsClientHttpRequestFactory(httpClientOptions, settings));
}
}
Expand Down Expand Up @@ -1007,6 +1007,26 @@ protected static class CustomHttpComponentsClientHttpRequestFactory extends Http

private final boolean enableRedirects;

/**
* Create a new {@link CustomHttpComponentsClientHttpRequestFactory} instance.
* @param httpClientOptions the {@link HttpClient} options
* @param settings the settings to apply
* @deprecated since 3.4.0 for removal in 3.6.0 in favor of
* {@link #CustomHttpComponentsClientHttpRequestFactory(HttpClientOption[], ClientHttpRequestFactorySettings)}
*/
@Deprecated(since = "3.4.0", forRemoval = true)
@SuppressWarnings("removal")
public CustomHttpComponentsClientHttpRequestFactory(HttpClientOption[] httpClientOptions,
org.springframework.boot.web.client.ClientHttpRequestFactorySettings settings) {
this(httpClientOptions, new ClientHttpRequestFactorySettings(settings.connectTimeout(),
settings.readTimeout(), settings.sslBundle()));
}

/**
* Create a new {@link CustomHttpComponentsClientHttpRequestFactory} instance.
* @param httpClientOptions the {@link HttpClient} options
* @param settings the settings to apply
*/
public CustomHttpComponentsClientHttpRequestFactory(HttpClientOption[] httpClientOptions,
ClientHttpRequestFactorySettings settings) {
Set<HttpClientOption> options = new HashSet<>(Arrays.asList(httpClientOptions));
Expand Down
Loading

0 comments on commit 3679127

Please sign in to comment.