spring-hateoas icon indicating copy to clipboard operation
spring-hateoas copied to clipboard

LinkTo does not resolve Request mapping placeholder

Open roll57 opened this issue 3 years ago • 3 comments
trafficstars

Spring framework allows to use placeholder in the request mapping.

@RequestMapping("${people.path:/people}")
interface PersonController {}

Using hateoas 1.1.0 and the linkTo(PersonController.class).toUri() method, the url is resolved as "/people}" with convert to "/people%7D"

Using hateaos 1.4.4 it just throw an error "Illegal character in path at index 30: http://localhost:55407/people}"

roll57 avatar Jul 15 '22 08:07 roll57

I can confirm this still causes errors using HATEOAS version 2.1.0. But now the error seems to look a bit different:

java.net.URISyntaxException: Illegal character in path at index 23: http://localhost:8080/${api.base-path}/method

Note that the controller is configured with @RequestMapping("${api.base-path:}"), i.e. somewhere the colon : in the template gets removed.

I don't find pretty workarounds for this issue. Something like

new PropertyPlaceholderHelper("\${", "}").replacePlaceholders(
            value,
            environment::getProperty
        )

does not work well for empty path properties, because the result will be http://localhost:8080//method (double slash), which breaks things.

cureaid avatar Jul 13 '23 15:07 cureaid

I confirm @RequestMapping("${openapi.myapi.base-path:/v1}") is not resolved using spring-hatoas:2.2.0 ink selfRel = linkTo (methodOn(MyApi.class).resourceGet(resource.getId().toString())).withSelfRel(); return :

 "links": [
      {
        "rel": "self",
        "href": "http://localhost:8080/${openapi.myapi.base-path/v1}/resource/01cd1d5f-8336-4a0b-b295-21e54a7af459"
}

sebwt avatar Feb 26 '24 18:02 sebwt

+1

wilx avatar Mar 25 '24 15:03 wilx