spring-projects / spring-projects/spring-data-commons
PagedResourcesAssembler does not have current request params in links [DATACMNS-1017]
@odrotbohm is already working on this.
Since Dec 30, 2020.
- Dominant language
- Java
- Stars
- 838
- Forks
- 730
- PR merge metrics
- No merged PRs in 30d
Description
Marcel Overdijk opened DATACMNS-1017 and commented
When calling pagedResourcesAssembler.toResource(page, myResourceAssembler) the generated links do not have the current request parameters included.
It's related to this code in PagedResourcesAssembler:
private UriTemplate getUriTemplate(Link baseLink) {
String href = baseLink != null ? baseLink.getHref()
: baseUri == null ? ServletUriComponentsBuilder.fromCurrentRequest().build().toString() : baseUri.toString();
return new UriTemplate(href);
}
When injecting the pagedResourcesAssembler as a method argument the baseUrl is not null so it will base the link the current request.
As discussed with Oliver on Gitter I can workaround it by creating the link manually from the current request like:
Link link = new Link(ServletUriComponentsBuilder.fromCurrentRequest().build().toString());
PagedResources<BookResource> resources =
pagedResourcesAssembler.toResource(page, bookResourceAssembler, link);
Affects: 1.13.1 (Ingalls SR1)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.