spring-projects / spring-projects/spring-data-commons

PagedResourcesAssembler does not have current request params in links [DATACMNS-1017]

Open
#1,466 2 comments 0 reactions 1 assignee View on GitHub

@odrotbohm is already working on this.

Since Dec 30, 2020.

type: bug
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.