Rename `RestTemplateBuilder` 'set' methods
Rename `RestTemplateBuilder` methods for consistency: * `setConnectTimeout` -> `connectTimeout` * `setReadTimeout` -> `readTimeout` * `setSslBundle` -> `sslBundle` Closes gh-42884
This commit is contained in:
parent
8feba568da
commit
0a4ac283d0
|
@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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<T ext
|
|||
@SuppressWarnings("unchecked")
|
||||
void connectTimeoutCanBeConfiguredOnFactory() {
|
||||
ClientHttpRequestFactory requestFactory = this.builder.requestFactory(this.factoryType)
|
||||
.setConnectTimeout(Duration.ofMillis(1234))
|
||||
.connectTimeout(Duration.ofMillis(1234))
|
||||
.build()
|
||||
.getRequestFactory();
|
||||
assertThat(connectTimeout((T) requestFactory)).isEqualTo(1234);
|
||||
|
@ -55,7 +55,7 @@ abstract class AbstractRestTemplateBuilderRequestFactoryConfigurationTests<T ext
|
|||
@SuppressWarnings("unchecked")
|
||||
void readTimeoutCanBeConfiguredOnFactory() {
|
||||
ClientHttpRequestFactory requestFactory = this.builder.requestFactory(this.factoryType)
|
||||
.setReadTimeout(Duration.ofMillis(1234))
|
||||
.readTimeout(Duration.ofMillis(1234))
|
||||
.build()
|
||||
.getRequestFactory();
|
||||
assertThat(readTimeout((T) requestFactory)).isEqualTo(1234);
|
||||
|
@ -64,7 +64,7 @@ abstract class AbstractRestTemplateBuilderRequestFactoryConfigurationTests<T ext
|
|||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
void connectTimeoutCanBeConfiguredOnDetectedFactory() {
|
||||
ClientHttpRequestFactory requestFactory = this.builder.setConnectTimeout(Duration.ofMillis(1234))
|
||||
ClientHttpRequestFactory requestFactory = this.builder.connectTimeout(Duration.ofMillis(1234))
|
||||
.build()
|
||||
.getRequestFactory();
|
||||
assertThat(connectTimeout((T) requestFactory)).isEqualTo(1234);
|
||||
|
@ -73,7 +73,7 @@ abstract class AbstractRestTemplateBuilderRequestFactoryConfigurationTests<T ext
|
|||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
void readTimeoutCanBeConfiguredOnDetectedFactory() {
|
||||
ClientHttpRequestFactory requestFactory = this.builder.setReadTimeout(Duration.ofMillis(1234))
|
||||
ClientHttpRequestFactory requestFactory = this.builder.readTimeout(Duration.ofMillis(1234))
|
||||
.build()
|
||||
.getRequestFactory();
|
||||
assertThat(readTimeout((T) requestFactory)).isEqualTo(1234);
|
||||
|
|
Loading…
Reference in New Issue