-
Notifications
You must be signed in to change notification settings - Fork 38.6k
Description
Affects: Spring Framework 5.3.13
When creating a RequestEntity
with a template and a parameter list, the resulting URL is not available in the created RequestEntity
object.
For instance, the following code returns a RequestEntity
with a null URL attribute:
RequestEntity<String> r = RequestEntity.post("http://www.example.com/{path}", "myPath").body("");
r.getUrl()
throws an UnsupportedOperationException
When looking at the code in RequestEntity.body(String)
, I see that the returned object is an UriTemplateRequestEntity
extending RequestEntity
, but this object seems to always have a null
URL according to its constructor. Only the uriTemplate
, uriVarsArray
and uriVarsMap
attributes are set. But these attributes are not part of RequestEntity
.
So, the URL information is lost in the RequestEntity and to retrieve it, the resulting object must be cast to an UriTemplateRequestEntity
, which breaks the encapsulation principle.
Shouldn't the getUrl()
method be overridden in UriTemplateRequestEntity
?
A similar issue exists here, but it does not seem to fix the root cause.
I also asked a question about that in Stackoverflow but I guess I only will get workarounds.