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

Document that RestTemplateBuilder's rootUri only applies when String variants are used for specifying the request URL #15343

Closed
ryonday opened this issue Nov 29, 2018 · 3 comments
Labels
type: documentation A documentation update
Milestone

Comments

@ryonday
Copy link

ryonday commented Nov 29, 2018

The RestTemplateBuilder documentation for the rootUri() method states:

Set a root URL that should be applied to each request that starts with '/'.

However, the following code does not result in RestTemplate expanding the URI:

 UriTemplate template = new UriTemplate("/foo?bar={bar}");


this.restTemplate = restTemplateBuilder
            .rootUri(URI.create("http://foo.bar"))
            .build();
.
.
.
URI uri = template.expand("baz");

 RequestEntity<Void> req = RequestEntity.get(uri)
                .accept(MediaType.APPLICATION_JSON)
                .header(accountLinkHeader, accountLinksHeader)
                .build();

String response = restTemplate.exchange(req, String.class);

Moreover, the exception received is EXTREMELY ambiguous when this doesn't work. In fact, the Spring exception thrown occludes the initial Apache exception (which states there's no host).

@ryonday ryonday closed this as completed Nov 29, 2018
@ryonday
Copy link
Author

ryonday commented Nov 29, 2018

Will open this against the framework.

@bclozel
Copy link
Member

bclozel commented Nov 29, 2018

Hello @ryonday

The RestTemplateBuilder javadoc does point to RootUriTemplateHandler - all UriTemplateHandler are about expanding a String uri template + variables into a proper URI.

Because you're using a RequestEntity here, you're taking full control of the request and you're not expanding a URI template. There might be room for improvement in the RestTemplateBuilder / RootUriTemplateHandler javadoc on the Spring Boot side.

Now about the exception you're seeing, this is something indeed that should be considered in Spring Framework.

@wilkinsona
Copy link
Member

Re-opening to consider if any improvements to our javadoc could be made.

@wilkinsona wilkinsona reopened this Nov 30, 2018
@wilkinsona wilkinsona added the status: waiting-for-triage An issue we've not yet triaged label Nov 30, 2018
@philwebb philwebb added type: documentation A documentation update and removed status: waiting-for-triage An issue we've not yet triaged labels Dec 3, 2018
@philwebb philwebb added this to the 2.1.x milestone Dec 3, 2018
@mbhave mbhave changed the title RestTemplate does not apply uriTemplateHandler for most methods Document that RestTemplateBuilder's rootUri only applies when String variants are used for specifying the request URL Aug 1, 2019
@mbhave mbhave modified the milestones: 2.1.x, 2.1.7 Aug 1, 2019
@mbhave mbhave closed this as completed in 80f568b Aug 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: documentation A documentation update
Projects
None yet
Development

No branches or pull requests

5 participants