Skip to content

Commit 3679127

Browse files
committed
Update RestTemplateBuilder to use ClientHttpRequestFactoryBuilder
Refactor the internals of `RestTemplateBuilder` so that the new `ClientHttpRequestFactoryBuilder` is used to create `ClientHttpRequestFactory` instance. See gh-36266
1 parent 78458af commit 3679127

File tree

2 files changed

+83
-42
lines changed

2 files changed

+83
-42
lines changed

spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/web/client/TestRestTemplate.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
import org.apache.hc.core5.ssl.SSLContextBuilder;
4747
import org.apache.hc.core5.ssl.TrustStrategy;
4848

49-
import org.springframework.boot.web.client.ClientHttpRequestFactorySettings;
49+
import org.springframework.boot.http.client.ClientHttpRequestFactorySettings;
5050
import org.springframework.boot.web.client.RestTemplateBuilder;
5151
import org.springframework.boot.web.client.RootUriTemplateHandler;
5252
import org.springframework.core.ParameterizedTypeReference;
@@ -146,7 +146,7 @@ public TestRestTemplate(RestTemplateBuilder builder, String username, String pas
146146
if (httpClientOptions != null) {
147147
ClientHttpRequestFactory requestFactory = builder.buildRequestFactory();
148148
if (requestFactory instanceof HttpComponentsClientHttpRequestFactory) {
149-
builder = builder.requestFactory(
149+
builder = builder.requestFactoryBuilder(
150150
(settings) -> new CustomHttpComponentsClientHttpRequestFactory(httpClientOptions, settings));
151151
}
152152
}
@@ -1007,6 +1007,26 @@ protected static class CustomHttpComponentsClientHttpRequestFactory extends Http
10071007

10081008
private final boolean enableRedirects;
10091009

1010+
/**
1011+
* Create a new {@link CustomHttpComponentsClientHttpRequestFactory} instance.
1012+
* @param httpClientOptions the {@link HttpClient} options
1013+
* @param settings the settings to apply
1014+
* @deprecated since 3.4.0 for removal in 3.6.0 in favor of
1015+
* {@link #CustomHttpComponentsClientHttpRequestFactory(HttpClientOption[], ClientHttpRequestFactorySettings)}
1016+
*/
1017+
@Deprecated(since = "3.4.0", forRemoval = true)
1018+
@SuppressWarnings("removal")
1019+
public CustomHttpComponentsClientHttpRequestFactory(HttpClientOption[] httpClientOptions,
1020+
org.springframework.boot.web.client.ClientHttpRequestFactorySettings settings) {
1021+
this(httpClientOptions, new ClientHttpRequestFactorySettings(settings.connectTimeout(),
1022+
settings.readTimeout(), settings.sslBundle()));
1023+
}
1024+
1025+
/**
1026+
* Create a new {@link CustomHttpComponentsClientHttpRequestFactory} instance.
1027+
* @param httpClientOptions the {@link HttpClient} options
1028+
* @param settings the settings to apply
1029+
*/
10101030
public CustomHttpComponentsClientHttpRequestFactory(HttpClientOption[] httpClientOptions,
10111031
ClientHttpRequestFactorySettings settings) {
10121032
Set<HttpClientOption> options = new HashSet<>(Arrays.asList(httpClientOptions));

0 commit comments

Comments
 (0)