Announcement Announcement Module
Collapse
No announcement yet.
ResponseStatus not consistently working Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • ResponseStatus not consistently working

    I'm seeing some issues with the ResponseStatus annotation. Using the below code (scala):

    Code:
        @ExceptionHandler(value=Array(classOf[MethodArgumentNotValidException]))
        @ResponseStatus(value = HttpStatus.BAD_REQUEST)
        @ResponseBody
        def handleMethodArgumentNotValidException(error: MethodArgumentNotValidException):String = {
    	  val o = new JSONObject
    	  val errors = error.getBindingResult().getFieldErrors().groupBy(_.getField())
    	  errors.foreach{case (field, fieldErrors) => {
    	    val jsonErrors = new JSONArray
    	    fieldErrors.foreach(error => {
    	      jsonErrors.put(error.getDefaultMessage())
    	    })
    	    o.put(field, jsonErrors)
    	  }}
    	  o.toString
    	}
    When seeing validation problems, this exception handler gets called. It returns the field errors as JSON in the response body and is supposed to return a BAD_REQUEST status. It always manages to return the correct body but seemingly at random will sometimes return a 200 status code. It seems to only happen in our test environment which runs JBoss-4.2.3.GA. On my local machine using Jetty(6.1.3) I haven't seen this issue. Because it happens seemingly at random it seems to me that some race condition may be involved. Anyone have ideas around this? I can try to provide more information if needed.
Working...
X