Browse Source

Deprecate RestTemplateBuilder#rootUri with replacement

This commit deprecates both `RootUriTemplateHandler` and
`RootUriBuilderFactory` types, along their usage in places like
`RestTemplateBuilder`.

`RestTemplateBuilder#rootUri` is now deprecated in favor of
`RestTemplateBuilder#baseUri`, which leverages Framework's
`DefaultUriBuilderFactory`.

Closes gh-48350
pull/49319/head
Brian Clozel 3 weeks ago
parent
commit
4b11e04e78
  1. 16
      module/spring-boot-restclient-test/src/main/java/org/springframework/boot/restclient/test/RootUriRequestExpectationManager.java
  2. 4
      module/spring-boot-restclient-test/src/test/java/org/springframework/boot/restclient/test/MockServerRestTemplateCustomizerTests.java
  3. 16
      module/spring-boot-restclient-test/src/test/java/org/springframework/boot/restclient/test/RootUriRequestExpectationManagerTests.java
  4. 2
      module/spring-boot-restclient-test/src/test/java/org/springframework/boot/restclient/test/autoconfigure/AnotherExampleRestTemplateService.java
  5. 2
      module/spring-boot-restclient-test/src/test/java/org/springframework/boot/restclient/test/autoconfigure/AutoConfigureMockRestServiceServerWithRestTemplateRootUriIntegrationTests.java
  6. 2
      module/spring-boot-restclient-test/src/test/java/org/springframework/boot/restclient/test/autoconfigure/ExampleRestTemplateService.java
  7. 24
      module/spring-boot-restclient/src/main/java/org/springframework/boot/restclient/RestTemplateBuilder.java
  8. 5
      module/spring-boot-restclient/src/main/java/org/springframework/boot/restclient/RootUriBuilderFactory.java
  9. 4
      module/spring-boot-restclient/src/main/java/org/springframework/boot/restclient/RootUriTemplateHandler.java
  10. 4
      module/spring-boot-restclient/src/test/java/org/springframework/boot/restclient/RestClientWithRestTemplateBuilderTests.java
  11. 10
      module/spring-boot-restclient/src/test/java/org/springframework/boot/restclient/RestTemplateBuilderTests.java
  12. 1
      module/spring-boot-restclient/src/test/java/org/springframework/boot/restclient/RootUriBuilderFactoryTests.java
  13. 1
      module/spring-boot-restclient/src/test/java/org/springframework/boot/restclient/RootUriTemplateHandlerTests.java
  14. 6
      module/spring-boot-resttestclient/src/main/java/org/springframework/boot/resttestclient/TestRestTemplate.java
  15. 8
      module/spring-boot-resttestclient/src/test/java/org/springframework/boot/resttestclient/TestRestTemplateTests.java
  16. 2
      smoke-test/spring-boot-smoke-test-test/src/main/java/smoketest/test/service/RemoteVehicleDetailsService.java
  17. 2
      system-test/spring-boot-deployment-system-tests/src/systemTest/java/org/springframework/boot/deployment/AbstractDeploymentTests.java

16
module/spring-boot-restclient-test/src/main/java/org/springframework/boot/restclient/test/RootUriRequestExpectationManager.java

@ -22,7 +22,6 @@ import java.net.URI; @@ -22,7 +22,6 @@ import java.net.URI;
import java.net.URISyntaxException;
import java.time.Duration;
import org.springframework.boot.restclient.RootUriTemplateHandler;
import org.springframework.http.client.ClientHttpRequest;
import org.springframework.http.client.ClientHttpResponse;
import org.springframework.http.client.support.HttpRequestWrapper;
@ -36,13 +35,14 @@ import org.springframework.test.web.client.ResponseActions; @@ -36,13 +35,14 @@ import org.springframework.test.web.client.ResponseActions;
import org.springframework.test.web.client.SimpleRequestExpectationManager;
import org.springframework.util.Assert;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.DefaultUriBuilderFactory;
import org.springframework.web.util.UriTemplateHandler;
/**
* {@link RequestExpectationManager} that strips the specified root URI from the request
* before verification. Can be used to simply test declarations when all REST calls start
* the same way. For example: <pre class="code">
* RestTemplate restTemplate = new RestTemplateBuilder().rootUri("https://example.com").build();
* RestTemplate restTemplate = new RestTemplateBuilder().baseUri("https://example.com").build();
* MockRestServiceServer server = RootUriRequestExpectationManager.bindTo(restTemplate);
* server.expect(requestTo("/hello")).andRespond(withSuccess());
* restTemplate.getForEntity("/hello", String.class);
@ -148,19 +148,25 @@ public class RootUriRequestExpectationManager implements RequestExpectationManag @@ -148,19 +148,25 @@ public class RootUriRequestExpectationManager implements RequestExpectationManag
/**
* Return {@link RequestExpectationManager} to be used for binding with the specified
* {@link RestTemplate}. If the {@link RestTemplate} is using a
* {@link RootUriTemplateHandler} then a {@link RootUriRequestExpectationManager} is
* returned, otherwise the source manager is returned unchanged.
* {@link org.springframework.boot.restclient.RootUriTemplateHandler} then a
* {@link RootUriRequestExpectationManager} is returned, otherwise the source manager
* is returned unchanged.
* @param restTemplate the source REST template
* @param expectationManager the source {@link RequestExpectationManager}
* @return a {@link RequestExpectationManager} to be bound to the template
*/
@SuppressWarnings("removal")
public static RequestExpectationManager forRestTemplate(RestTemplate restTemplate,
RequestExpectationManager expectationManager) {
Assert.notNull(restTemplate, "'restTemplate' must not be null");
UriTemplateHandler templateHandler = restTemplate.getUriTemplateHandler();
if (templateHandler instanceof RootUriTemplateHandler rootHandler && rootHandler.getRootUri() != null) {
if (templateHandler instanceof org.springframework.boot.restclient.RootUriTemplateHandler rootHandler
&& rootHandler.getRootUri() != null) {
return new RootUriRequestExpectationManager(rootHandler.getRootUri(), expectationManager);
}
else if (templateHandler instanceof DefaultUriBuilderFactory defaultHandler && defaultHandler.hasBaseUri()) {
return new RootUriRequestExpectationManager(defaultHandler.expand("").toString(), expectationManager);
}
return expectationManager;
}

4
module/spring-boot-restclient-test/src/test/java/org/springframework/boot/restclient/test/MockServerRestTemplateCustomizerTests.java

@ -97,7 +97,7 @@ class MockServerRestTemplateCustomizerTests { @@ -97,7 +97,7 @@ class MockServerRestTemplateCustomizerTests {
void detectRootUriShouldDefaultToTrue() {
MockServerRestTemplateCustomizer customizer = new MockServerRestTemplateCustomizer(
UnorderedRequestExpectationManager.class);
customizer.customize(new RestTemplateBuilder().rootUri("https://example.com").build());
customizer.customize(new RestTemplateBuilder().baseUri("https://example.com").build());
assertThat(customizer.getServer()).extracting("expectationManager")
.isInstanceOf(RootUriRequestExpectationManager.class);
}
@ -105,7 +105,7 @@ class MockServerRestTemplateCustomizerTests { @@ -105,7 +105,7 @@ class MockServerRestTemplateCustomizerTests {
@Test
void setDetectRootUriShouldDisableRootUriDetection() {
this.customizer.setDetectRootUri(false);
this.customizer.customize(new RestTemplateBuilder().rootUri("https://example.com").build());
this.customizer.customize(new RestTemplateBuilder().baseUri("https://example.com").build());
assertThat(this.customizer.getServer()).extracting("expectationManager")
.isInstanceOf(SimpleRequestExpectationManager.class);
}

16
module/spring-boot-restclient-test/src/test/java/org/springframework/boot/restclient/test/RootUriRequestExpectationManagerTests.java

@ -141,6 +141,7 @@ class RootUriRequestExpectationManagerTests { @@ -141,6 +141,7 @@ class RootUriRequestExpectationManagerTests {
}
@Test
@SuppressWarnings("removal")
void forRestTemplateWhenUsingRootUriTemplateHandlerShouldReturnRootUriRequestExpectationManager() {
RestTemplate restTemplate = new RestTemplateBuilder().rootUri(this.uri).build();
RequestExpectationManager actual = RootUriRequestExpectationManager.forRestTemplate(restTemplate,
@ -149,6 +150,15 @@ class RootUriRequestExpectationManagerTests { @@ -149,6 +150,15 @@ class RootUriRequestExpectationManagerTests {
assertThat(actual).extracting("rootUri").isEqualTo(this.uri);
}
@Test
void forRestTemplateWhenUsingBaseUriTemplateHandlerShouldReturnRootUriRequestExpectationManager() {
RestTemplate restTemplate = new RestTemplateBuilder().baseUri(this.uri).build();
RequestExpectationManager actual = RootUriRequestExpectationManager.forRestTemplate(restTemplate,
this.delegate);
assertThat(actual).isInstanceOf(RootUriRequestExpectationManager.class);
assertThat(actual).extracting("rootUri").isEqualTo(this.uri);
}
@Test
void forRestTemplateWhenNotUsingRootUriTemplateHandlerShouldReturnOriginalRequestExpectationManager() {
RestTemplate restTemplate = new RestTemplateBuilder().build();
@ -158,8 +168,8 @@ class RootUriRequestExpectationManagerTests { @@ -158,8 +168,8 @@ class RootUriRequestExpectationManagerTests {
}
@Test
void boundRestTemplateShouldPrefixRootUri() {
RestTemplate restTemplate = new RestTemplateBuilder().rootUri("https://example.com").build();
void boundRestTemplateShouldPrefixBaseUri() {
RestTemplate restTemplate = new RestTemplateBuilder().baseUri("https://example.com").build();
MockRestServiceServer server = RootUriRequestExpectationManager.bindTo(restTemplate);
server.expect(requestTo("/hello")).andRespond(withSuccess());
restTemplate.getForEntity("/hello", String.class);
@ -167,7 +177,7 @@ class RootUriRequestExpectationManagerTests { @@ -167,7 +177,7 @@ class RootUriRequestExpectationManagerTests {
@Test
void boundRestTemplateWhenUrlIncludesDomainShouldNotPrefixRootUri() {
RestTemplate restTemplate = new RestTemplateBuilder().rootUri("https://example.com").build();
RestTemplate restTemplate = new RestTemplateBuilder().baseUri("https://example.com").build();
MockRestServiceServer server = RootUriRequestExpectationManager.bindTo(restTemplate);
server.expect(requestTo("/hello")).andRespond(withSuccess());
assertThatExceptionOfType(AssertionError.class)

2
module/spring-boot-restclient-test/src/test/java/org/springframework/boot/restclient/test/autoconfigure/AnotherExampleRestTemplateService.java

@ -33,7 +33,7 @@ public class AnotherExampleRestTemplateService { @@ -33,7 +33,7 @@ public class AnotherExampleRestTemplateService {
private final RestTemplate restTemplate;
public AnotherExampleRestTemplateService(RestTemplateBuilder builder) {
this.restTemplate = builder.rootUri("https://example.com").build();
this.restTemplate = builder.baseUri("https://example.com").build();
}
protected RestTemplate getRestTemplate() {

2
module/spring-boot-restclient-test/src/test/java/org/springframework/boot/restclient/test/autoconfigure/AutoConfigureMockRestServiceServerWithRestTemplateRootUriIntegrationTests.java

@ -68,7 +68,7 @@ class AutoConfigureMockRestServiceServerWithRestTemplateRootUriIntegrationTests @@ -68,7 +68,7 @@ class AutoConfigureMockRestServiceServerWithRestTemplateRootUriIntegrationTests
@Bean
RestTemplate restTemplate(RestTemplateBuilder restTemplateBuilder) {
return restTemplateBuilder.rootUri("/rest").build();
return restTemplateBuilder.baseUri("/rest").build();
}
}

2
module/spring-boot-restclient-test/src/test/java/org/springframework/boot/restclient/test/autoconfigure/ExampleRestTemplateService.java

@ -34,7 +34,7 @@ public class ExampleRestTemplateService { @@ -34,7 +34,7 @@ public class ExampleRestTemplateService {
private final RestTemplate restTemplate;
public ExampleRestTemplateService(RestTemplateBuilder builder) {
this.restTemplate = builder.rootUri("https://example.com").build();
this.restTemplate = builder.baseUri("https://example.com").build();
}
protected RestTemplate getRestTemplate() {

24
module/spring-boot-restclient/src/main/java/org/springframework/boot/restclient/RestTemplateBuilder.java

@ -45,6 +45,7 @@ import org.springframework.util.Assert; @@ -45,6 +45,7 @@ import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import org.springframework.web.client.ResponseErrorHandler;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.DefaultUriBuilderFactory;
import org.springframework.web.util.UriTemplateHandler;
/**
@ -138,6 +139,24 @@ public class RestTemplateBuilder { @@ -138,6 +139,24 @@ public class RestTemplateBuilder {
this.requestCustomizers = requestCustomizers;
}
/**
* Set a base URL template that should be applied to each request that starts with
* {@code '/'}. The base URL will only apply when {@code String} variants of the
* {@link RestTemplate} methods are used for specifying the request URL.
* <p>
* This is a specialization of {@link #uriTemplateHandler(UriTemplateHandler)} and
* will override any previously configured uri template handler.
* @param baseUri the base URI
* @return a new builder instance
* @since 4.1.0
*/
public RestTemplateBuilder baseUri(String baseUri) {
return new RestTemplateBuilder(this.clientSettings, this.detectRequestFactory, this.rootUri,
this.messageConverters, this.interceptors, this.requestFactoryBuilder,
new DefaultUriBuilderFactory(baseUri), this.errorHandler, this.basicAuthentication, this.defaultHeaders,
this.customizers, this.requestCustomizers);
}
/**
* Set if the {@link ClientHttpRequestFactory} should be detected based on the
* classpath. Default if {@code true}.
@ -157,7 +176,9 @@ public class RestTemplateBuilder { @@ -157,7 +176,9 @@ public class RestTemplateBuilder {
* {@link RestTemplate} methods are used for specifying the request URL.
* @param rootUri the root URI or {@code null}
* @return a new builder instance
* @deprecated since 4.1.0 for removal in 4.3.0 in favor of {@link #baseUri(String)}
*/
@Deprecated(forRemoval = true, since = "4.1.0")
public RestTemplateBuilder rootUri(@Nullable String rootUri) {
return new RestTemplateBuilder(this.clientSettings, this.detectRequestFactory, rootUri, this.messageConverters,
this.interceptors, this.requestFactoryBuilder, this.uriTemplateHandler, this.errorHandler,
@ -339,6 +360,8 @@ public class RestTemplateBuilder { @@ -339,6 +360,8 @@ public class RestTemplateBuilder {
/**
* Set the {@link UriTemplateHandler} that should be used with the
* {@link RestTemplate}.
* <p>
* This method will override any {@link #baseUri(String)} previously set.
* @param uriTemplateHandler the URI template handler to use
* @return a new builder instance
*/
@ -635,6 +658,7 @@ public class RestTemplateBuilder { @@ -635,6 +658,7 @@ public class RestTemplateBuilder {
* @see RestTemplateBuilder#build()
* @see RestTemplateBuilder#build(Class)
*/
@SuppressWarnings("removal")
public <T extends RestTemplate> T configure(T restTemplate) {
ClientHttpRequestFactory requestFactory = buildRequestFactory();
if (requestFactory != null) {

5
module/spring-boot-restclient/src/main/java/org/springframework/boot/restclient/RootUriBuilderFactory.java

@ -18,6 +18,7 @@ package org.springframework.boot.restclient; @@ -18,6 +18,7 @@ package org.springframework.boot.restclient;
import org.springframework.util.Assert;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.DefaultUriBuilderFactory;
import org.springframework.web.util.UriBuilder;
import org.springframework.web.util.UriBuilderFactory;
import org.springframework.web.util.UriComponentsBuilder;
@ -28,7 +29,11 @@ import org.springframework.web.util.UriTemplateHandler; @@ -28,7 +29,11 @@ import org.springframework.web.util.UriTemplateHandler;
*
* @author Scott Frederick
* @since 4.0.0
* @deprecated since 4.1.0 for removal in 4.3.0 in favor of
* {@link DefaultUriBuilderFactory}.
*/
@Deprecated(forRemoval = true, since = "4.1.0")
@SuppressWarnings("removal")
public class RootUriBuilderFactory extends RootUriTemplateHandler implements UriBuilderFactory {
/**

4
module/spring-boot-restclient/src/main/java/org/springframework/boot/restclient/RootUriTemplateHandler.java

@ -23,6 +23,7 @@ import org.jspecify.annotations.Nullable; @@ -23,6 +23,7 @@ import org.jspecify.annotations.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
import org.springframework.web.util.DefaultUriBuilderFactory;
import org.springframework.web.util.UriTemplateHandler;
/**
@ -31,7 +32,10 @@ import org.springframework.web.util.UriTemplateHandler; @@ -31,7 +32,10 @@ import org.springframework.web.util.UriTemplateHandler;
* @author Phillip Webb
* @author Scott Frederick
* @since 4.0.0
* @deprecated since 4.1.0 for removal in 4.3.0 in favor of
* {@link DefaultUriBuilderFactory}.
*/
@Deprecated(forRemoval = true, since = "4.1.0")
public class RootUriTemplateHandler implements UriTemplateHandler {
private final @Nullable String rootUri;

4
module/spring-boot-restclient/src/test/java/org/springframework/boot/restclient/RestClientWithRestTemplateBuilderTests.java

@ -36,7 +36,7 @@ class RestClientWithRestTemplateBuilderTests { @@ -36,7 +36,7 @@ class RestClientWithRestTemplateBuilderTests {
@Test
void buildUsingRestTemplateBuilderRootUri() {
RestTemplate restTemplate = new RestTemplateBuilder().rootUri("https://resttemplate.example.com").build();
RestTemplate restTemplate = new RestTemplateBuilder().baseUri("https://resttemplate.example.com").build();
RestClient.Builder builder = RestClient.builder(restTemplate);
RestClient client = buildMockedClient(builder, "https://resttemplate.example.com/test");
assertThat(client.get().uri("/test").retrieve().toBodilessEntity().getStatusCode().is2xxSuccessful()).isTrue();
@ -52,7 +52,7 @@ class RestClientWithRestTemplateBuilderTests { @@ -52,7 +52,7 @@ class RestClientWithRestTemplateBuilderTests {
@Test
void buildRestTemplateBuilderRootUriAndRestClientBuilderBaseUrl() {
RestTemplate restTemplate = new RestTemplateBuilder().rootUri("https://resttemplate.example.com").build();
RestTemplate restTemplate = new RestTemplateBuilder().baseUri("https://resttemplate.example.com").build();
RestClient.Builder builder = RestClient.builder(restTemplate).baseUrl("https://restclient.example.com");
RestClient client = buildMockedClient(builder, "https://resttemplate.example.com/test");
assertThat(client.get().uri("/test").retrieve().toBodilessEntity().getStatusCode().is2xxSuccessful()).isTrue();

10
module/spring-boot-restclient/src/test/java/org/springframework/boot/restclient/RestTemplateBuilderTests.java

@ -55,6 +55,7 @@ import org.springframework.test.util.ReflectionTestUtils; @@ -55,6 +55,7 @@ import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.test.web.client.MockRestServiceServer;
import org.springframework.web.client.ResponseErrorHandler;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.DefaultUriBuilderFactory;
import org.springframework.web.util.UriTemplateHandler;
import static org.assertj.core.api.Assertions.assertThat;
@ -121,8 +122,8 @@ class RestTemplateBuilderTests { @@ -121,8 +122,8 @@ class RestTemplateBuilderTests {
}
@Test
void rootUriShouldApply() {
RestTemplate restTemplate = this.builder.rootUri("https://example.com").build();
void baseUriShouldApply() {
RestTemplate restTemplate = this.builder.baseUri("https://example.com").build();
MockRestServiceServer server = MockRestServiceServer.bindTo(restTemplate).build();
server.expect(requestTo("https://example.com/hello")).andRespond(withSuccess());
restTemplate.getForEntity("/hello", String.class);
@ -130,6 +131,7 @@ class RestTemplateBuilderTests { @@ -130,6 +131,7 @@ class RestTemplateBuilderTests {
}
@Test
@SuppressWarnings("removal")
void rootUriShouldApplyAfterUriTemplateHandler() {
UriTemplateHandler uriTemplateHandler = mock(UriTemplateHandler.class);
RestTemplate template = this.builder.uriTemplateHandler(uriTemplateHandler)
@ -466,14 +468,14 @@ class RestTemplateBuilderTests { @@ -466,14 +468,14 @@ class RestTemplateBuilderTests {
ClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
this.builder.interceptors(this.interceptor)
.messageConverters(this.messageConverter)
.rootUri("http://localhost:8080")
.baseUri("http://localhost:8080")
.errorHandler(errorHandler)
.basicAuthentication("spring", "boot")
.requestFactory(() -> requestFactory)
.customizers((restTemplate) -> {
assertThat(restTemplate.getInterceptors()).hasSize(1);
assertThat(restTemplate.getMessageConverters()).contains(this.messageConverter);
assertThat(restTemplate.getUriTemplateHandler()).isInstanceOf(RootUriBuilderFactory.class);
assertThat(restTemplate.getUriTemplateHandler()).isInstanceOf(DefaultUriBuilderFactory.class);
assertThat(restTemplate.getErrorHandler()).isEqualTo(errorHandler);
ClientHttpRequestFactory actualRequestFactory = restTemplate.getRequestFactory();
assertThat(actualRequestFactory).isInstanceOf(InterceptingClientHttpRequestFactory.class);

1
module/spring-boot-restclient/src/test/java/org/springframework/boot/restclient/RootUriBuilderFactoryTests.java

@ -33,6 +33,7 @@ import static org.mockito.Mockito.mock; @@ -33,6 +33,7 @@ import static org.mockito.Mockito.mock;
*
* @author Scott Frederick
*/
@SuppressWarnings("removal")
class RootUriBuilderFactoryTests {
@Test

1
module/spring-boot-restclient/src/test/java/org/springframework/boot/restclient/RootUriTemplateHandlerTests.java

@ -43,6 +43,7 @@ import static org.mockito.Mockito.mock; @@ -43,6 +43,7 @@ import static org.mockito.Mockito.mock;
* @author Phillip Webb
*/
@ExtendWith(MockitoExtension.class)
@SuppressWarnings("removal")
class RootUriTemplateHandlerTests {
private URI uri;

6
module/spring-boot-resttestclient/src/main/java/org/springframework/boot/resttestclient/TestRestTemplate.java

@ -43,7 +43,6 @@ import org.springframework.boot.http.client.HttpComponentsClientHttpRequestFacto @@ -43,7 +43,6 @@ import org.springframework.boot.http.client.HttpComponentsClientHttpRequestFacto
import org.springframework.boot.http.client.HttpComponentsHttpClientBuilder.TlsSocketStrategyFactory;
import org.springframework.boot.http.client.HttpRedirects;
import org.springframework.boot.restclient.RestTemplateBuilder;
import org.springframework.boot.restclient.RootUriTemplateHandler;
import org.springframework.boot.resttestclient.autoconfigure.AutoConfigureTestRestTemplate;
import org.springframework.boot.ssl.SslBundle;
import org.springframework.core.ParameterizedTypeReference;
@ -184,13 +183,14 @@ public class TestRestTemplate { @@ -184,13 +183,14 @@ public class TestRestTemplate {
}
/**
* Returns the root URI applied by {@link RestTemplateBuilder#rootUri(String)} or
* Returns the root URI applied by {@link RestTemplateBuilder#baseUri(String)} or
* {@code ""} if the root URI has not been applied.
* @return the root URI
*/
@SuppressWarnings("removal")
public @Nullable String getRootUri() {
UriTemplateHandler uriTemplateHandler = this.restTemplate.getUriTemplateHandler();
if (uriTemplateHandler instanceof RootUriTemplateHandler rootHandler) {
if (uriTemplateHandler instanceof org.springframework.boot.restclient.RootUriTemplateHandler rootHandler) {
return rootHandler.getRootUri();
}
return uriTemplateHandler.expand("").toString();

8
module/spring-boot-resttestclient/src/test/java/org/springframework/boot/resttestclient/TestRestTemplateTests.java

@ -114,10 +114,10 @@ class TestRestTemplateTests { @@ -114,10 +114,10 @@ class TestRestTemplateTests {
}
@Test
void getRootUriRootUriSetViaRestTemplateBuilder() {
String rootUri = "https://example.com";
RestTemplateBuilder delegate = new RestTemplateBuilder().rootUri(rootUri);
assertThat(new TestRestTemplate(delegate).getRootUri()).isEqualTo(rootUri);
void getBaseUriRootUriSetViaRestTemplateBuilder() {
String baseUri = "https://example.com";
RestTemplateBuilder delegate = new RestTemplateBuilder().baseUri(baseUri);
assertThat(new TestRestTemplate(delegate).getRootUri()).isEqualTo(baseUri);
}
@Test

2
smoke-test/spring-boot-smoke-test-test/src/main/java/smoketest/test/service/RemoteVehicleDetailsService.java

@ -40,7 +40,7 @@ public class RemoteVehicleDetailsService implements VehicleDetailsService { @@ -40,7 +40,7 @@ public class RemoteVehicleDetailsService implements VehicleDetailsService {
private final RestTemplate restTemplate;
public RemoteVehicleDetailsService(ServiceProperties properties, RestTemplateBuilder restTemplateBuilder) {
this.restTemplate = restTemplateBuilder.rootUri(properties.getVehicleServiceRootUrl()).build();
this.restTemplate = restTemplateBuilder.baseUri(properties.getVehicleServiceRootUrl()).build();
}
@Override

2
system-test/spring-boot-deployment-system-tests/src/systemTest/java/org/springframework/boot/deployment/AbstractDeploymentTests.java

@ -97,7 +97,7 @@ abstract class AbstractDeploymentTests { @@ -97,7 +97,7 @@ abstract class AbstractDeploymentTests {
private void test(Consumer<TestRestTemplate> consumer) {
TestRestTemplate rest = new TestRestTemplate(new RestTemplateBuilder()
.rootUri("http://" + this.container.getHost() + ":" + this.container.getMappedPort(this.port)
.baseUri("http://" + this.container.getHost() + ":" + this.container.getMappedPort(this.port)
+ "/spring-boot")
.requestFactory(() -> new HttpComponentsClientHttpRequestFactory(HttpClients.custom()
.setRetryStrategy(new DefaultHttpRequestRetryStrategy(10, TimeValue.of(1, TimeUnit.SECONDS)))

Loading…
Cancel
Save