Announcement Announcement Module
Collapse
No announcement yet.
rest ws, automatic parameter conversion from spring, bad request 400 error instead of Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • rest ws, automatic parameter conversion from spring, bad request 400 error instead of

    A rest webservice like this:

    Code:
    @RequestMapping(value = "/test/{number}", method = RequestMethod.GET, produces = "plain/text")
    public void test(@PathVariable final double number, final HttpServletResponse response)
    If the client passes a text such "QQQ" instead of a number, the client gets an error from spring like this:

    Code:
    HTTP Status 500 -
    The server encountered an internal error () that prevented it from fulfilling this request.
    org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert value of type 'java.lang.String' to required type 'double'; nested exception is java.lang.NumberFormatException: For input string: "QQQ"
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:894)
    ...
    This does not make sense. spring should sent a 400 Bad Request, instead of 500 Internal Error.
    Or, am I missing something?

    Is there a way to safely detect such bad request, and return a 400 Bad Request status?


    ps: and how to return a custom error message?
    http://stackoverflow.com/questions/1...invalid-parame
Working...
X