Skip to content

Implement UriTemplateRequestEntity::getUrl #27790

@EricC-59

Description

@EricC-59

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: webIssues in web modules (web, webmvc, webflux, websocket)status: declinedA suggestion or change that we don't feel we should currently applytype: enhancementA general enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions