Skip to content

Commit 0a4ac28

Browse files
committed
Rename RestTemplateBuilder 'set' methods
Rename `RestTemplateBuilder` methods for consistency: * `setConnectTimeout` -> `connectTimeout` * `setReadTimeout` -> `readTimeout` * `setSslBundle` -> `sslBundle` Closes gh-42884
1 parent 8feba56 commit 0a4ac28

File tree

8 files changed

+55
-17
lines changed

8 files changed

+55
-17
lines changed

spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/io/restclient/resttemplate/customization/MyRestTemplateBuilderConfiguration.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -29,8 +29,8 @@ public class MyRestTemplateBuilderConfiguration {
2929
@Bean
3030
public RestTemplateBuilder restTemplateBuilder(RestTemplateBuilderConfigurer configurer) {
3131
return configurer.configure(new RestTemplateBuilder())
32-
.setConnectTimeout(Duration.ofSeconds(5))
33-
.setReadTimeout(Duration.ofSeconds(2));
32+
.connectTimeout(Duration.ofSeconds(5))
33+
.readTimeout(Duration.ofSeconds(2));
3434
}
3535

3636
}

spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/io/restclient/resttemplate/ssl/MyService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -28,7 +28,7 @@ public class MyService {
2828
private final RestTemplate restTemplate;
2929

3030
public MyService(RestTemplateBuilder restTemplateBuilder, SslBundles sslBundles) {
31-
this.restTemplate = restTemplateBuilder.setSslBundle(sslBundles.getBundle("mybundle")).build();
31+
this.restTemplate = restTemplateBuilder.sslBundle(sslBundles.getBundle("mybundle")).build();
3232
}
3333

3434
public Details someRestCall(String name) {

spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/testing/utilities/testresttemplate/MySpringBootTests.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ static class RestTemplateBuilderConfiguration {
4848

4949
@Bean
5050
RestTemplateBuilder restTemplateBuilder() {
51-
return new RestTemplateBuilder().setConnectTimeout(Duration.ofSeconds(1))
52-
.setReadTimeout(Duration.ofSeconds(1));
51+
return new RestTemplateBuilder().connectTimeout(Duration.ofSeconds(1)).readTimeout(Duration.ofSeconds(1));
5352
}
5453

5554
}

spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/io/restclient/resttemplate/customization/MyRestTemplateBuilderConfiguration.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ class MyRestTemplateBuilderConfiguration {
2727

2828
@Bean
2929
fun restTemplateBuilder(configurer: RestTemplateBuilderConfigurer): RestTemplateBuilder {
30-
return configurer.configure(RestTemplateBuilder()).setConnectTimeout(Duration.ofSeconds(5))
31-
.setReadTimeout(Duration.ofSeconds(2))
30+
return configurer.configure(RestTemplateBuilder()).connectTimeout(Duration.ofSeconds(5))
31+
.readTimeout(Duration.ofSeconds(2))
3232
}
3333

3434
}

spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/io/restclient/resttemplate/ssl/MyService.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class MyService(restTemplateBuilder: RestTemplateBuilder, sslBundles: SslBundles
2727
private val restTemplate: RestTemplate
2828

2929
init {
30-
restTemplate = restTemplateBuilder.setSslBundle(sslBundles.getBundle("mybundle")).build()
30+
restTemplate = restTemplateBuilder.sslBundle(sslBundles.getBundle("mybundle")).build()
3131
}
3232

3333
fun someRestCall(name: String): Details {

spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/testing/utilities/testresttemplate/MySpringBootTests.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ class MySpringBootTests(@Autowired val template: TestRestTemplate) {
4141

4242
@Bean
4343
fun restTemplateBuilder(): RestTemplateBuilder {
44-
return RestTemplateBuilder().setConnectTimeout(Duration.ofSeconds(1))
45-
.setReadTimeout(Duration.ofSeconds(1))
44+
return RestTemplateBuilder().connectTimeout(Duration.ofSeconds(1))
45+
.readTimeout(Duration.ofSeconds(1))
4646
}
4747

4848
}

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,8 +413,21 @@ this.errorHandler, this.basicAuthentication, append(this.defaultHeaders, name, v
413413
* @param connectTimeout the connection timeout
414414
* @return a new builder instance.
415415
* @since 2.1.0
416+
* @deprecated since 3.4.0 for removal in 3.6.0 in favor of
417+
* {@link #connectTimeout(Duration)}
416418
*/
419+
@Deprecated(since = "3.4.0", forRemoval = true)
417420
public RestTemplateBuilder setConnectTimeout(Duration connectTimeout) {
421+
return connectTimeout(connectTimeout);
422+
}
423+
424+
/**
425+
* Sets the connection timeout on the underlying {@link ClientHttpRequestFactory}.
426+
* @param connectTimeout the connection timeout
427+
* @return a new builder instance.
428+
* @since 3.4.0
429+
*/
430+
public RestTemplateBuilder connectTimeout(Duration connectTimeout) {
418431
return new RestTemplateBuilder(this.requestFactorySettings.withConnectTimeout(connectTimeout),
419432
this.detectRequestFactory, this.rootUri, this.messageConverters, this.interceptors, this.requestFactory,
420433
this.uriTemplateHandler, this.errorHandler, this.basicAuthentication, this.defaultHeaders,
@@ -426,8 +439,21 @@ public RestTemplateBuilder setConnectTimeout(Duration connectTimeout) {
426439
* @param readTimeout the read timeout
427440
* @return a new builder instance.
428441
* @since 2.1.0
442+
* @deprecated since 3.4.0 for removal in 3.6.0 in favor of
443+
* {@link #readTimeout(Duration)}
429444
*/
445+
@Deprecated(since = "3.4.0", forRemoval = true)
430446
public RestTemplateBuilder setReadTimeout(Duration readTimeout) {
447+
return readTimeout(readTimeout);
448+
}
449+
450+
/**
451+
* Sets the read timeout on the underlying {@link ClientHttpRequestFactory}.
452+
* @param readTimeout the read timeout
453+
* @return a new builder instance.
454+
* @since 3.4.0
455+
*/
456+
public RestTemplateBuilder readTimeout(Duration readTimeout) {
431457
return new RestTemplateBuilder(this.requestFactorySettings.withReadTimeout(readTimeout),
432458
this.detectRequestFactory, this.rootUri, this.messageConverters, this.interceptors, this.requestFactory,
433459
this.uriTemplateHandler, this.errorHandler, this.basicAuthentication, this.defaultHeaders,
@@ -439,8 +465,21 @@ public RestTemplateBuilder setReadTimeout(Duration readTimeout) {
439465
* @param sslBundle the SSL bundle
440466
* @return a new builder instance
441467
* @since 3.1.0
468+
* @deprecated since 3.4.0 for removal in 3.6.0 in favor of
469+
* {@link #sslBundle(SslBundle)}
442470
*/
471+
@Deprecated(since = "3.4.0", forRemoval = true)
443472
public RestTemplateBuilder setSslBundle(SslBundle sslBundle) {
473+
return sslBundle(sslBundle);
474+
}
475+
476+
/**
477+
* Sets the SSL bundle on the underlying {@link ClientHttpRequestFactory}.
478+
* @param sslBundle the SSL bundle
479+
* @return a new builder instance
480+
* @since 3.4.0
481+
*/
482+
public RestTemplateBuilder sslBundle(SslBundle sslBundle) {
444483
return new RestTemplateBuilder(this.requestFactorySettings.withSslBundle(sslBundle), this.detectRequestFactory,
445484
this.rootUri, this.messageConverters, this.interceptors, this.requestFactory, this.uriTemplateHandler,
446485
this.errorHandler, this.basicAuthentication, this.defaultHeaders, this.customizers,

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -45,7 +45,7 @@ protected AbstractRestTemplateBuilderRequestFactoryConfigurationTests(Class<T> f
4545
@SuppressWarnings("unchecked")
4646
void connectTimeoutCanBeConfiguredOnFactory() {
4747
ClientHttpRequestFactory requestFactory = this.builder.requestFactory(this.factoryType)
48-
.setConnectTimeout(Duration.ofMillis(1234))
48+
.connectTimeout(Duration.ofMillis(1234))
4949
.build()
5050
.getRequestFactory();
5151
assertThat(connectTimeout((T) requestFactory)).isEqualTo(1234);
@@ -55,7 +55,7 @@ void connectTimeoutCanBeConfiguredOnFactory() {
5555
@SuppressWarnings("unchecked")
5656
void readTimeoutCanBeConfiguredOnFactory() {
5757
ClientHttpRequestFactory requestFactory = this.builder.requestFactory(this.factoryType)
58-
.setReadTimeout(Duration.ofMillis(1234))
58+
.readTimeout(Duration.ofMillis(1234))
5959
.build()
6060
.getRequestFactory();
6161
assertThat(readTimeout((T) requestFactory)).isEqualTo(1234);
@@ -64,7 +64,7 @@ void readTimeoutCanBeConfiguredOnFactory() {
6464
@Test
6565
@SuppressWarnings("unchecked")
6666
void connectTimeoutCanBeConfiguredOnDetectedFactory() {
67-
ClientHttpRequestFactory requestFactory = this.builder.setConnectTimeout(Duration.ofMillis(1234))
67+
ClientHttpRequestFactory requestFactory = this.builder.connectTimeout(Duration.ofMillis(1234))
6868
.build()
6969
.getRequestFactory();
7070
assertThat(connectTimeout((T) requestFactory)).isEqualTo(1234);
@@ -73,7 +73,7 @@ void connectTimeoutCanBeConfiguredOnDetectedFactory() {
7373
@Test
7474
@SuppressWarnings("unchecked")
7575
void readTimeoutCanBeConfiguredOnDetectedFactory() {
76-
ClientHttpRequestFactory requestFactory = this.builder.setReadTimeout(Duration.ofMillis(1234))
76+
ClientHttpRequestFactory requestFactory = this.builder.readTimeout(Duration.ofMillis(1234))
7777
.build()
7878
.getRequestFactory();
7979
assertThat(readTimeout((T) requestFactory)).isEqualTo(1234);

0 commit comments

Comments
 (0)