diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/io/restclient/resttemplate/customization/MyRestTemplateBuilderConfiguration.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/io/restclient/resttemplate/customization/MyRestTemplateBuilderConfiguration.java index 7a13e2df9be..539b2c03f51 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/io/restclient/resttemplate/customization/MyRestTemplateBuilderConfiguration.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/io/restclient/resttemplate/customization/MyRestTemplateBuilderConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,8 +29,8 @@ public class MyRestTemplateBuilderConfiguration { @Bean public RestTemplateBuilder restTemplateBuilder(RestTemplateBuilderConfigurer configurer) { return configurer.configure(new RestTemplateBuilder()) - .setConnectTimeout(Duration.ofSeconds(5)) - .setReadTimeout(Duration.ofSeconds(2)); + .connectTimeout(Duration.ofSeconds(5)) + .readTimeout(Duration.ofSeconds(2)); } } diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/io/restclient/resttemplate/ssl/MyService.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/io/restclient/resttemplate/ssl/MyService.java index 5d5407faf9c..1948d18cad7 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/io/restclient/resttemplate/ssl/MyService.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/io/restclient/resttemplate/ssl/MyService.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,7 +28,7 @@ public class MyService { private final RestTemplate restTemplate; public MyService(RestTemplateBuilder restTemplateBuilder, SslBundles sslBundles) { - this.restTemplate = restTemplateBuilder.setSslBundle(sslBundles.getBundle("mybundle")).build(); + this.restTemplate = restTemplateBuilder.sslBundle(sslBundles.getBundle("mybundle")).build(); } public Details someRestCall(String name) { diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/testing/utilities/testresttemplate/MySpringBootTests.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/testing/utilities/testresttemplate/MySpringBootTests.java index 6a3403385da..56ef2a42edc 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/testing/utilities/testresttemplate/MySpringBootTests.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/testing/utilities/testresttemplate/MySpringBootTests.java @@ -48,8 +48,7 @@ class MySpringBootTests { @Bean RestTemplateBuilder restTemplateBuilder() { - return new RestTemplateBuilder().setConnectTimeout(Duration.ofSeconds(1)) - .setReadTimeout(Duration.ofSeconds(1)); + return new RestTemplateBuilder().connectTimeout(Duration.ofSeconds(1)).readTimeout(Duration.ofSeconds(1)); } } diff --git a/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/io/restclient/resttemplate/customization/MyRestTemplateBuilderConfiguration.kt b/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/io/restclient/resttemplate/customization/MyRestTemplateBuilderConfiguration.kt index cbf8edfe543..d4312d5731e 100644 --- a/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/io/restclient/resttemplate/customization/MyRestTemplateBuilderConfiguration.kt +++ b/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/io/restclient/resttemplate/customization/MyRestTemplateBuilderConfiguration.kt @@ -27,8 +27,8 @@ class MyRestTemplateBuilderConfiguration { @Bean fun restTemplateBuilder(configurer: RestTemplateBuilderConfigurer): RestTemplateBuilder { - return configurer.configure(RestTemplateBuilder()).setConnectTimeout(Duration.ofSeconds(5)) - .setReadTimeout(Duration.ofSeconds(2)) + return configurer.configure(RestTemplateBuilder()).connectTimeout(Duration.ofSeconds(5)) + .readTimeout(Duration.ofSeconds(2)) } } diff --git a/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/io/restclient/resttemplate/ssl/MyService.kt b/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/io/restclient/resttemplate/ssl/MyService.kt index 5787b7f4d89..4e5f6e623bb 100644 --- a/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/io/restclient/resttemplate/ssl/MyService.kt +++ b/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/io/restclient/resttemplate/ssl/MyService.kt @@ -27,7 +27,7 @@ class MyService(restTemplateBuilder: RestTemplateBuilder, sslBundles: SslBundles private val restTemplate: RestTemplate init { - restTemplate = restTemplateBuilder.setSslBundle(sslBundles.getBundle("mybundle")).build() + restTemplate = restTemplateBuilder.sslBundle(sslBundles.getBundle("mybundle")).build() } fun someRestCall(name: String): Details { diff --git a/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/testing/utilities/testresttemplate/MySpringBootTests.kt b/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/testing/utilities/testresttemplate/MySpringBootTests.kt index 6f47e39d801..9f592c34cdd 100644 --- a/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/testing/utilities/testresttemplate/MySpringBootTests.kt +++ b/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/testing/utilities/testresttemplate/MySpringBootTests.kt @@ -41,8 +41,8 @@ class MySpringBootTests(@Autowired val template: TestRestTemplate) { @Bean fun restTemplateBuilder(): RestTemplateBuilder { - return RestTemplateBuilder().setConnectTimeout(Duration.ofSeconds(1)) - .setReadTimeout(Duration.ofSeconds(1)) + return RestTemplateBuilder().connectTimeout(Duration.ofSeconds(1)) + .readTimeout(Duration.ofSeconds(1)) } } diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/client/RestTemplateBuilder.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/client/RestTemplateBuilder.java index 59baed729a1..f3b7aa9c73e 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/client/RestTemplateBuilder.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/client/RestTemplateBuilder.java @@ -413,8 +413,21 @@ public class RestTemplateBuilder { * @param connectTimeout the connection timeout * @return a new builder instance. * @since 2.1.0 + * @deprecated since 3.4.0 for removal in 3.6.0 in favor of + * {@link #connectTimeout(Duration)} */ + @Deprecated(since = "3.4.0", forRemoval = true) public RestTemplateBuilder setConnectTimeout(Duration connectTimeout) { + return connectTimeout(connectTimeout); + } + + /** + * Sets the connection timeout on the underlying {@link ClientHttpRequestFactory}. + * @param connectTimeout the connection timeout + * @return a new builder instance. + * @since 3.4.0 + */ + public RestTemplateBuilder connectTimeout(Duration connectTimeout) { return new RestTemplateBuilder(this.requestFactorySettings.withConnectTimeout(connectTimeout), this.detectRequestFactory, this.rootUri, this.messageConverters, this.interceptors, this.requestFactory, this.uriTemplateHandler, this.errorHandler, this.basicAuthentication, this.defaultHeaders, @@ -426,8 +439,21 @@ public class RestTemplateBuilder { * @param readTimeout the read timeout * @return a new builder instance. * @since 2.1.0 + * @deprecated since 3.4.0 for removal in 3.6.0 in favor of + * {@link #readTimeout(Duration)} */ + @Deprecated(since = "3.4.0", forRemoval = true) public RestTemplateBuilder setReadTimeout(Duration readTimeout) { + return readTimeout(readTimeout); + } + + /** + * Sets the read timeout on the underlying {@link ClientHttpRequestFactory}. + * @param readTimeout the read timeout + * @return a new builder instance. + * @since 3.4.0 + */ + public RestTemplateBuilder readTimeout(Duration readTimeout) { return new RestTemplateBuilder(this.requestFactorySettings.withReadTimeout(readTimeout), this.detectRequestFactory, this.rootUri, this.messageConverters, this.interceptors, this.requestFactory, this.uriTemplateHandler, this.errorHandler, this.basicAuthentication, this.defaultHeaders, @@ -439,8 +465,21 @@ public class RestTemplateBuilder { * @param sslBundle the SSL bundle * @return a new builder instance * @since 3.1.0 + * @deprecated since 3.4.0 for removal in 3.6.0 in favor of + * {@link #sslBundle(SslBundle)} */ + @Deprecated(since = "3.4.0", forRemoval = true) public RestTemplateBuilder setSslBundle(SslBundle sslBundle) { + return sslBundle(sslBundle); + } + + /** + * Sets the SSL bundle on the underlying {@link ClientHttpRequestFactory}. + * @param sslBundle the SSL bundle + * @return a new builder instance + * @since 3.4.0 + */ + public RestTemplateBuilder sslBundle(SslBundle sslBundle) { return new RestTemplateBuilder(this.requestFactorySettings.withSslBundle(sslBundle), this.detectRequestFactory, this.rootUri, this.messageConverters, this.interceptors, this.requestFactory, this.uriTemplateHandler, this.errorHandler, this.basicAuthentication, this.defaultHeaders, this.customizers, diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/client/AbstractRestTemplateBuilderRequestFactoryConfigurationTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/client/AbstractRestTemplateBuilderRequestFactoryConfigurationTests.java index d9f3e332f84..15195775a6f 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/client/AbstractRestTemplateBuilderRequestFactoryConfigurationTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/client/AbstractRestTemplateBuilderRequestFactoryConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -45,7 +45,7 @@ abstract class AbstractRestTemplateBuilderRequestFactoryConfigurationTests