diff --git a/spring-web/src/main/java/org/springframework/http/RequestEntity.java b/spring-web/src/main/java/org/springframework/http/RequestEntity.java index 6dd27d02db20..b5bd28da5c39 100644 --- a/spring-web/src/main/java/org/springframework/http/RequestEntity.java +++ b/spring-web/src/main/java/org/springframework/http/RequestEntity.java @@ -28,6 +28,7 @@ import org.springframework.lang.Nullable; import org.springframework.util.MultiValueMap; import org.springframework.util.ObjectUtils; +import org.springframework.web.util.UriTemplateHandler; /** * Extension of {@link HttpEntity} that also exposes the HTTP method and the @@ -158,11 +159,23 @@ public HttpMethod getMethod() { } /** - * Return the URL of the request. + * Return the {@link URI} for the target HTTP endpoint. + *
Note: This method raises + * {@link UnsupportedOperationException} if the {@code RequestEntity} was + * created with a URI template and variables rather than with a {@link URI} + * instance. This is because a URI cannot be created without further input + * on how to expand template and encode the URI. In such cases, the + * {@code URI} is prepared by the + * {@link org.springframework.web.client.RestTemplate} with the help of the + * {@link UriTemplateHandler} it is configured with. */ public URI getUrl() { if (this.url == null) { - throw new UnsupportedOperationException(); + throw new UnsupportedOperationException( + "The RequestEntity was created with a URI template and variables, " + + "and there is not enough information on how to correctly expand and " + + "encode the URI template. This will be done by the RestTemplate instead " + + "with help from the UriTemplateHandler it is configured with."); } return this.url; }