diff --git a/module/spring-boot-restclient-test/src/main/java/org/springframework/boot/restclient/test/RootUriRequestExpectationManager.java b/module/spring-boot-restclient-test/src/main/java/org/springframework/boot/restclient/test/RootUriRequestExpectationManager.java index 579da177588..486188c2f44 100644 --- a/module/spring-boot-restclient-test/src/main/java/org/springframework/boot/restclient/test/RootUriRequestExpectationManager.java +++ b/module/spring-boot-restclient-test/src/main/java/org/springframework/boot/restclient/test/RootUriRequestExpectationManager.java @@ -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; 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:
- * 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
 	/**
 	 * 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;
 	}
 
diff --git a/module/spring-boot-restclient-test/src/test/java/org/springframework/boot/restclient/test/MockServerRestTemplateCustomizerTests.java b/module/spring-boot-restclient-test/src/test/java/org/springframework/boot/restclient/test/MockServerRestTemplateCustomizerTests.java
index 404f92ed7d6..fe380c19fd2 100644
--- a/module/spring-boot-restclient-test/src/test/java/org/springframework/boot/restclient/test/MockServerRestTemplateCustomizerTests.java
+++ b/module/spring-boot-restclient-test/src/test/java/org/springframework/boot/restclient/test/MockServerRestTemplateCustomizerTests.java
@@ -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 {
 	@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);
 	}
diff --git a/module/spring-boot-restclient-test/src/test/java/org/springframework/boot/restclient/test/RootUriRequestExpectationManagerTests.java b/module/spring-boot-restclient-test/src/test/java/org/springframework/boot/restclient/test/RootUriRequestExpectationManagerTests.java
index acdb2d9fd44..7e912d342c1 100644
--- a/module/spring-boot-restclient-test/src/test/java/org/springframework/boot/restclient/test/RootUriRequestExpectationManagerTests.java
+++ b/module/spring-boot-restclient-test/src/test/java/org/springframework/boot/restclient/test/RootUriRequestExpectationManagerTests.java
@@ -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 {
 		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 {
 	}
 
 	@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 {
 
 	@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)
diff --git a/module/spring-boot-restclient-test/src/test/java/org/springframework/boot/restclient/test/autoconfigure/AnotherExampleRestTemplateService.java b/module/spring-boot-restclient-test/src/test/java/org/springframework/boot/restclient/test/autoconfigure/AnotherExampleRestTemplateService.java
index 511f1473062..7402effc3fd 100644
--- a/module/spring-boot-restclient-test/src/test/java/org/springframework/boot/restclient/test/autoconfigure/AnotherExampleRestTemplateService.java
+++ b/module/spring-boot-restclient-test/src/test/java/org/springframework/boot/restclient/test/autoconfigure/AnotherExampleRestTemplateService.java
@@ -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() {
diff --git a/module/spring-boot-restclient-test/src/test/java/org/springframework/boot/restclient/test/autoconfigure/AutoConfigureMockRestServiceServerWithRestTemplateRootUriIntegrationTests.java b/module/spring-boot-restclient-test/src/test/java/org/springframework/boot/restclient/test/autoconfigure/AutoConfigureMockRestServiceServerWithRestTemplateRootUriIntegrationTests.java
index a02b1c8efc0..ec9de9d2fea 100644
--- a/module/spring-boot-restclient-test/src/test/java/org/springframework/boot/restclient/test/autoconfigure/AutoConfigureMockRestServiceServerWithRestTemplateRootUriIntegrationTests.java
+++ b/module/spring-boot-restclient-test/src/test/java/org/springframework/boot/restclient/test/autoconfigure/AutoConfigureMockRestServiceServerWithRestTemplateRootUriIntegrationTests.java
@@ -68,7 +68,7 @@ class AutoConfigureMockRestServiceServerWithRestTemplateRootUriIntegrationTests
 
 		@Bean
 		RestTemplate restTemplate(RestTemplateBuilder restTemplateBuilder) {
-			return restTemplateBuilder.rootUri("/rest").build();
+			return restTemplateBuilder.baseUri("/rest").build();
 		}
 
 	}
diff --git a/module/spring-boot-restclient-test/src/test/java/org/springframework/boot/restclient/test/autoconfigure/ExampleRestTemplateService.java b/module/spring-boot-restclient-test/src/test/java/org/springframework/boot/restclient/test/autoconfigure/ExampleRestTemplateService.java
index 4f04ecdd472..5acc9d7b83d 100644
--- a/module/spring-boot-restclient-test/src/test/java/org/springframework/boot/restclient/test/autoconfigure/ExampleRestTemplateService.java
+++ b/module/spring-boot-restclient-test/src/test/java/org/springframework/boot/restclient/test/autoconfigure/ExampleRestTemplateService.java
@@ -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() {
diff --git a/module/spring-boot-restclient/src/main/java/org/springframework/boot/restclient/RestTemplateBuilder.java b/module/spring-boot-restclient/src/main/java/org/springframework/boot/restclient/RestTemplateBuilder.java
index d39a04aa96d..37848d57e6f 100644
--- a/module/spring-boot-restclient/src/main/java/org/springframework/boot/restclient/RestTemplateBuilder.java
+++ b/module/spring-boot-restclient/src/main/java/org/springframework/boot/restclient/RestTemplateBuilder.java
@@ -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 {
 		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.
+	 * 

+ * 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 { * {@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 { /** * Set the {@link UriTemplateHandler} that should be used with the * {@link RestTemplate}. + *

+ * 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 { * @see RestTemplateBuilder#build() * @see RestTemplateBuilder#build(Class) */ + @SuppressWarnings("removal") public T configure(T restTemplate) { ClientHttpRequestFactory requestFactory = buildRequestFactory(); if (requestFactory != null) { diff --git a/module/spring-boot-restclient/src/main/java/org/springframework/boot/restclient/RootUriBuilderFactory.java b/module/spring-boot-restclient/src/main/java/org/springframework/boot/restclient/RootUriBuilderFactory.java index 1a65e2bea39..19b9846cca6 100644 --- a/module/spring-boot-restclient/src/main/java/org/springframework/boot/restclient/RootUriBuilderFactory.java +++ b/module/spring-boot-restclient/src/main/java/org/springframework/boot/restclient/RootUriBuilderFactory.java @@ -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; * * @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 { /** diff --git a/module/spring-boot-restclient/src/main/java/org/springframework/boot/restclient/RootUriTemplateHandler.java b/module/spring-boot-restclient/src/main/java/org/springframework/boot/restclient/RootUriTemplateHandler.java index 85f4471bff5..19020191490 100644 --- a/module/spring-boot-restclient/src/main/java/org/springframework/boot/restclient/RootUriTemplateHandler.java +++ b/module/spring-boot-restclient/src/main/java/org/springframework/boot/restclient/RootUriTemplateHandler.java @@ -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; * @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; diff --git a/module/spring-boot-restclient/src/test/java/org/springframework/boot/restclient/RestClientWithRestTemplateBuilderTests.java b/module/spring-boot-restclient/src/test/java/org/springframework/boot/restclient/RestClientWithRestTemplateBuilderTests.java index e9a28524fdb..3a6dcb313d6 100644 --- a/module/spring-boot-restclient/src/test/java/org/springframework/boot/restclient/RestClientWithRestTemplateBuilderTests.java +++ b/module/spring-boot-restclient/src/test/java/org/springframework/boot/restclient/RestClientWithRestTemplateBuilderTests.java @@ -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 { @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(); diff --git a/module/spring-boot-restclient/src/test/java/org/springframework/boot/restclient/RestTemplateBuilderTests.java b/module/spring-boot-restclient/src/test/java/org/springframework/boot/restclient/RestTemplateBuilderTests.java index 84dc48e7ffa..e23285d1a8a 100644 --- a/module/spring-boot-restclient/src/test/java/org/springframework/boot/restclient/RestTemplateBuilderTests.java +++ b/module/spring-boot-restclient/src/test/java/org/springframework/boot/restclient/RestTemplateBuilderTests.java @@ -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 { } @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 { } @Test + @SuppressWarnings("removal") void rootUriShouldApplyAfterUriTemplateHandler() { UriTemplateHandler uriTemplateHandler = mock(UriTemplateHandler.class); RestTemplate template = this.builder.uriTemplateHandler(uriTemplateHandler) @@ -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); diff --git a/module/spring-boot-restclient/src/test/java/org/springframework/boot/restclient/RootUriBuilderFactoryTests.java b/module/spring-boot-restclient/src/test/java/org/springframework/boot/restclient/RootUriBuilderFactoryTests.java index 7251decdd0b..b4460c71851 100644 --- a/module/spring-boot-restclient/src/test/java/org/springframework/boot/restclient/RootUriBuilderFactoryTests.java +++ b/module/spring-boot-restclient/src/test/java/org/springframework/boot/restclient/RootUriBuilderFactoryTests.java @@ -33,6 +33,7 @@ import static org.mockito.Mockito.mock; * * @author Scott Frederick */ +@SuppressWarnings("removal") class RootUriBuilderFactoryTests { @Test diff --git a/module/spring-boot-restclient/src/test/java/org/springframework/boot/restclient/RootUriTemplateHandlerTests.java b/module/spring-boot-restclient/src/test/java/org/springframework/boot/restclient/RootUriTemplateHandlerTests.java index 9140f2e8c82..b646dcf4480 100644 --- a/module/spring-boot-restclient/src/test/java/org/springframework/boot/restclient/RootUriTemplateHandlerTests.java +++ b/module/spring-boot-restclient/src/test/java/org/springframework/boot/restclient/RootUriTemplateHandlerTests.java @@ -43,6 +43,7 @@ import static org.mockito.Mockito.mock; * @author Phillip Webb */ @ExtendWith(MockitoExtension.class) +@SuppressWarnings("removal") class RootUriTemplateHandlerTests { private URI uri; diff --git a/module/spring-boot-resttestclient/src/main/java/org/springframework/boot/resttestclient/TestRestTemplate.java b/module/spring-boot-resttestclient/src/main/java/org/springframework/boot/resttestclient/TestRestTemplate.java index 48118a3680e..b9988d6d48b 100644 --- a/module/spring-boot-resttestclient/src/main/java/org/springframework/boot/resttestclient/TestRestTemplate.java +++ b/module/spring-boot-resttestclient/src/main/java/org/springframework/boot/resttestclient/TestRestTemplate.java @@ -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 { } /** - * 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(); diff --git a/module/spring-boot-resttestclient/src/test/java/org/springframework/boot/resttestclient/TestRestTemplateTests.java b/module/spring-boot-resttestclient/src/test/java/org/springframework/boot/resttestclient/TestRestTemplateTests.java index c59889e850a..932376a8fcf 100644 --- a/module/spring-boot-resttestclient/src/test/java/org/springframework/boot/resttestclient/TestRestTemplateTests.java +++ b/module/spring-boot-resttestclient/src/test/java/org/springframework/boot/resttestclient/TestRestTemplateTests.java @@ -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 diff --git a/smoke-test/spring-boot-smoke-test-test/src/main/java/smoketest/test/service/RemoteVehicleDetailsService.java b/smoke-test/spring-boot-smoke-test-test/src/main/java/smoketest/test/service/RemoteVehicleDetailsService.java index 7fb5bb87cd3..ef4939d8e1b 100644 --- a/smoke-test/spring-boot-smoke-test-test/src/main/java/smoketest/test/service/RemoteVehicleDetailsService.java +++ b/smoke-test/spring-boot-smoke-test-test/src/main/java/smoketest/test/service/RemoteVehicleDetailsService.java @@ -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 diff --git a/system-test/spring-boot-deployment-system-tests/src/systemTest/java/org/springframework/boot/deployment/AbstractDeploymentTests.java b/system-test/spring-boot-deployment-system-tests/src/systemTest/java/org/springframework/boot/deployment/AbstractDeploymentTests.java index f16cbdb4a5e..51a7477f10e 100644 --- a/system-test/spring-boot-deployment-system-tests/src/systemTest/java/org/springframework/boot/deployment/AbstractDeploymentTests.java +++ b/system-test/spring-boot-deployment-system-tests/src/systemTest/java/org/springframework/boot/deployment/AbstractDeploymentTests.java @@ -97,7 +97,7 @@ abstract class AbstractDeploymentTests { private void test(Consumer 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)))