1

Here is my spring boot controller

@GetMapping(value = "/{id}/{fileName}")
@ResponseStatus(HttpStatus.OK)
public Response getDocument(@PathVariable Long id, @PathVariable String filename)

When a request is send with fileName="test.docx", the controller pathvariable value is test (missing .docx). Is there anyway to get the parameters passed by the user?

I tried using

@GetMapping(value = "/{id}/{**fileName:.***}"). 

However, I got below status code 406 message on server (without even hitting the controller code path)

"exception": "org.springframework.web.HttpMediaTypeNotAcceptableException", "message": "Could not find acceptable representation",

Spring boot version 1.5.7.RELEASE

Sasikumar Murugesan
  • 4,412
  • 10
  • 51
  • 74
Chetan
  • 29
  • 4
  • The fix for the issue was 2 folds: 1. use :.+ in the controller rest endpoint i.e. @GetMapping(value = "/{id}/{name:.+}") and 2. Extend webmvcconfigurereadapter to override below method public void configureContentNegotiation(ContentNegotiationConfigurer configurer) { configurer.favorPathExtension(false); } Here is ref url: https://spring.io/blog/2013/05/11/content-negotiation-using-spring-mvc – Chetan Jan 05 '18 at 21:11

1 Answers1

2

Use .+ like this

@GetMapping("/{id}/{fileName:.+}") 
@ResponseStatus(HttpStatus.OK) public Response getDocument(@PathVariable Long id, @PathVariable String filename)
pvpkiran
  • 25,582
  • 8
  • 87
  • 134