1

I want to configure my web methods to set the http status code to 404 or an other code indicating that something went wrong (e.g. 444 No Response).

Currently the response is http 200 with null in its body.

@RequestMapping(value = "folder", method = RequestMethod.GET)
@ResponseBody
public Folder findFolder(String folderId, WebRequest request) throws PermissionDeniedException, ServiceException {
    return projectService.findFolder(folderId); // should set HttpCode.NO_RESPONSE if the method returns null
}

Is there a central way to configure the web services rather than handling null values one by one in each method?

Alternatively, is there a way to bind an @ExceptionHandler (or rather @SomeGenereicHandler) to null return values?

Mahatma_Fatal_Error
  • 720
  • 1
  • 10
  • 26
  • So I dont want to check for null values and set return new ResponseEntity(HttpStatus.BAD_REQUEST) manually – Mahatma_Fatal_Error Jan 15 '15 at 08:52
  • 1
    check this answer here http://stackoverflow.com/a/26732152/957654 –  Jan 15 '15 at 09:02
  • possible duplicate of [How to send the send status code as response for 404 instead of 404.jsp as a html reponse in spring?](http://stackoverflow.com/questions/26728597/how-to-send-the-send-status-code-as-response-for-404-instead-of-404-jsp-as-a-htm) – Steve Jan 15 '15 at 09:17
  • Since returning a null value is not a exception your comments are no solution to the problem. – Mahatma_Fatal_Error Jan 15 '15 at 09:56

0 Answers0