javaspringspring-webfluxspring-reactor

How to the get wildcard path variable in the controller


I have a controller:

@PostMapping("/name/**")
public Mono<String> doSomething(HttpEntity<byte[]> requestEntity,
                                ServerHttpRequest serverHttpRequest) {
    String restOfTheUrl = //the ** part is what i need here
    return webClient.forwardRequest(requestEntity, serviceUrl + "/" +     restOfTheUrl);
}

How do I obtain the URL string (including all query params) thats after the /name/ ?? basically I need the ** part. Of course I can remove the /name/ from serverHttpRequest.getPath(..) but is there a better way?


Solution

  • @PostMapping("/name/{*path}")
    public Mono<String> doSomething(@PathVariable("path") String path) {...