Issue
I want to create a mapping for an URI like this.
/reference/download/asdsa/asdas/sad/3c7d38f679a64d101c602da61dad9912.pdf
The request mapping in my controller is:
/reference/download/**
The problem is, that the mapping is only working when I call the URI without the .pdf suffix.
This is my code:
@Controller
@RequestMapping("/reference")
public class ReferenceFilePageController
{
private static final Logger LOG = Logger.getLogger(ReferenceFilePageController.class);
private static final String PATH_VARIABLE_PATTERN_DOWNLOAD = "/download/**";
@Autowired
private ReferenceFileService referenceFileService;
@RequestMapping(value = PATH_VARIABLE_PATTERN_DOWNLOAD, method = RequestMethod.GET, produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
@ResponseBody
public FileSystemResource getFile(HttpServletRequest request) {
String path = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
return new FileSystemResource(referenceFileService.getPathForIdentifier(path.substring(19)));
}
}
Solution
This is called Content Negotiation.
Answered By - Jaiwo99