Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RequestEntity throws UnsupportedOperationException when using URI template #26500

Closed
chrylis opened this issue Feb 3, 2021 · 2 comments
Closed
Labels
for: external-project Needs a fix in external project in: web Issues in web modules (web, webmvc, webflux, websocket)

Comments

@chrylis
Copy link

chrylis commented Feb 3, 2021

I'm using Spring Web 5.3.3 with Boot 2.4.2.

When creating a RequestEntity by passing in a URI template, the concrete type created is a UriTemplateRequestEntity, which through its super chain sets this.url = null. Later, when the RequestEntity is passed to RestTemplate#exchange(RequestEntity, Class), the template calls RequestEntity#getUrl. As UriTemplateRequestEntity does not override getUrl, this throws because this.url == null.

Expected use case:

var req = RequestEntity.get("http://localhost/helloworld").build();
var body = restTemplate.exchange(req, String.class);

It appears that what's happening is that the UriTemplateRequestEntity's templating methods are bypassed in the simple exchange flow. While I'm sure that the expectation was that the style above would be used with URI variables, the fact that it throws an obscure exception is Surprising. Instead, I suggest that UriTemplateRequestEntity's getUrl should be overridden, simply returning the string if it is untemplated and possibly throwing an informative exception if it can't be filled out.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Feb 3, 2021
@sbrannen sbrannen added the in: web Issues in web modules (web, webmvc, webflux, websocket) label Feb 3, 2021
@rstoyanchev
Copy link
Contributor

I can't reproduce the issue and I don't see how it can be bypassed. Both exchange methods that take RequestEntity call resolveUrl which does an instanceof check. Please elaborate or provide a sample.

@rstoyanchev rstoyanchev added the status: waiting-for-feedback We need additional information before we can continue label Feb 3, 2021
@chrylis
Copy link
Author

chrylis commented Feb 3, 2021

I think I see the divergence; the root cause seems to actually be upstream in TestRestTemplate. I'll close and re-file against Boot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for: external-project Needs a fix in external project in: web Issues in web modules (web, webmvc, webflux, websocket)
Projects
None yet
Development

No branches or pull requests

4 participants