Skip to content

Commit ae8b797

Browse files
committed
Improve Javadoc on RequestEntity#getUrl
Closes gh-28930
1 parent a7f430b commit ae8b797

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

spring-web/src/main/java/org/springframework/http/RequestEntity.java

+15-2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.springframework.lang.Nullable;
2929
import org.springframework.util.MultiValueMap;
3030
import org.springframework.util.ObjectUtils;
31+
import org.springframework.web.util.UriTemplateHandler;
3132

3233
/**
3334
* Extension of {@link HttpEntity} that also exposes the HTTP method and the
@@ -158,11 +159,23 @@ public HttpMethod getMethod() {
158159
}
159160

160161
/**
161-
* Return the URL of the request.
162+
* Return the {@link URI} for the target HTTP endpoint.
163+
* <p><strong>Note:</strong> This method raises
164+
* {@link UnsupportedOperationException} if the {@code RequestEntity} was
165+
* created with a URI template and variables rather than with a {@link URI}
166+
* instance. This is because a URI cannot be created without further input
167+
* on how to expand template and encode the URI. In such cases, the
168+
* {@code URI} is prepared by the
169+
* {@link org.springframework.web.client.RestTemplate} with the help of the
170+
* {@link UriTemplateHandler} it is configured with.
162171
*/
163172
public URI getUrl() {
164173
if (this.url == null) {
165-
throw new UnsupportedOperationException();
174+
throw new UnsupportedOperationException(
175+
"The RequestEntity was created with a URI template and variables, " +
176+
"and there is not enough information on how to correctly expand and " +
177+
"encode the URI template. This will be done by the RestTemplate instead " +
178+
"with help from the UriTemplateHandler it is configured with.");
166179
}
167180
return this.url;
168181
}

0 commit comments

Comments
 (0)