Change the status code of a deferredResult HTTP message on timeout
I am using deferredResult
in Spring MVC but using this code the timeout still sends 503 HTTP code to the client.
future.onCompletion(new Runnable() {
@Override
public void run() {
if(future.isSetOrExpired()){
response.setStatus(HttpServletResponse.SC_NO_CONTENT);
}
}
});
Any idea what else to try?
+3
source to share
1 answer
I faced the same problem. My Spring MVC Controller method initially returned a DeferredResult <Object> but then I realized I wanted to control the HTTP status code. I found the answer here:
http://www.jayway.com/2014/09/09/asynchronous-spring-service/
Just use DeferredResult <ResponseEntity> and you can set both the response and the Http response code in the ResponseEntity.
+5
source to share