I have a SpringMVC web service for uploading files that look like this:
@RequestMapping(value="/upload.json", method = RequestMethod.POST)
public @ResponseBody Map<String, Object> upload(MultipartHttpServletRequest request) {
}
and all dandy. But if one of the consumers submits a non-multipart form, I get this exception
java.lang.IllegalStateException: Current request is not of type [org.springframework.web.multipart.MultipartHttpServletRequest]
Which makes sense. However, I do not want my end users to see 500 servlet exceptions. I want a welcome error message.
I just tried this (to be like other POSTs):
@RequestMapping(value="/upload.json", method = RequestMethod.POST)
public @ResponseBody Map<String, Object> upload2(){
}
but I get this error:
java.lang.IllegalStateException: Ambiguous handler methods mapped for HTTP path '/upload.json'
Is there a way to safely handle both multiple and non-multipart POST requests? in one method or in two different methods that I do not need.
source
share