spring-projects / spring-projects/spring-hateoas
ControllerLinkBuilderFactory should include all system properties when building a link
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 1.1k
- Forks
- 476
- PR merge metrics
- No merged PRs in 30d
Description
According to spring mvc it is perfectly normal to have a @RequestMapping that looks like this:
@RequestMapping(value = "${spring.data.rest.base-path}/markup")
However when I try to create a link to this controller's method:
2016-09-22 12:20:15,512 org.springframework.data.rest.webmvc.RepositoryRestExceptionHandler [https-jsse-nio-127.0.0.1-8112-exec-6] ERROR: Map has no value for 'spring.data.rest.base-path'
java.lang.IllegalArgumentException: Map has no value for 'spring.data.rest.base-path'
at org.springframework.web.util.UriComponents$MapTemplateVariables.getValue(UriComponents.java:306)
at org.springframework.web.util.UriComponents.expandUriComponent(UriComponents.java:230)
at org.springframework.web.util.HierarchicalUriComponents$FullPathComponent.expand(HierarchicalUriComponents.java:687)
at org.springframework.web.util.HierarchicalUriComponents.expandInternal(HierarchicalUriComponents.java:329)
at org.springframework.web.util.HierarchicalUriComponents.expandInternal(HierarchicalUriComponents.java:47)
at org.springframework.web.util.UriComponents.expand(UriComponents.java:152)
at org.springframework.web.util.UriComponentsBuilder.buildAndExpand(UriComponentsBuilder.java:348)
at org.springframework.hateoas.mvc.ControllerLinkBuilderFactory.linkTo(ControllerLinkBuilderFactory.java:150)
at org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo(ControllerLinkBuilder.java:172)
I also tried adding the property as a FRAGMENT, SEGMENT, REQUEST_PARAM or PATH_VARIABLE:
resource.add(linkTo(methodOn(MarkupController.class, new TemplateVariable(repositoryRestProperties.getBasePath(), TemplateVariable.VariableType.FRAGMENT)).getAllEntityMarkups()).withRel(
"markup"));
unfortunately the produced JSON is:
"markup" : {
"href" : "https://localhost:8112/storefront$%7B%23/rest%7D/markup/"
},
Contributor guide
No contributing guide indexed for this repository
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.
Research direction
Start at ControllerLinkBuilderFactory.linkTo, identified at line 150 in the stack trace, and inspect how URI variables are collected before buildAndExpand. Reproduce the case with a @RequestMapping containing ${spring.data.rest.base-path}, then verify that the generated link resolves the property instead of leaving a template token. Review the existing comment discussion for the expected handling.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100