Allow setting timeout in ResponseBodyEmitter
Issue: SPR-13104
This commit is contained in:
@@ -58,6 +58,8 @@ import org.springframework.util.Assert;
|
||||
*/
|
||||
public class ResponseBodyEmitter {
|
||||
|
||||
private final Long timeout;
|
||||
|
||||
private volatile Handler handler;
|
||||
|
||||
/* Cache for objects sent before handler is set. */
|
||||
@@ -72,6 +74,33 @@ public class ResponseBodyEmitter {
|
||||
private Runnable completionCallback;
|
||||
|
||||
|
||||
/**
|
||||
* Create a new ResponseBodyEmitter instance.
|
||||
*/
|
||||
public ResponseBodyEmitter() {
|
||||
this.timeout = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a ResponseBodyEmitter with a custom timeout value.
|
||||
* <p>By default not set in which case the default configured in the MVC
|
||||
* Java Config or the MVC namespace is used, or if that's not set, then the
|
||||
* timeout depends on the default of the underlying server.
|
||||
* @param timeout timeout value in milliseconds
|
||||
*/
|
||||
public ResponseBodyEmitter(Long timeout) {
|
||||
this.timeout = timeout;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the configured timeout value, if any.
|
||||
*/
|
||||
public Long getTimeout() {
|
||||
return this.timeout;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Invoked after the response is updated with the status code and headers,
|
||||
* if the ResponseBodyEmitter is wrapped in a ResponseEntity, but before the
|
||||
|
||||
@@ -109,7 +109,7 @@ public class ResponseBodyEmitterReturnValueHandler implements HandlerMethodRetur
|
||||
outputMessage.getBody();
|
||||
outputMessage = new StreamingServletServerHttpResponse(outputMessage);
|
||||
|
||||
DeferredResult<?> deferredResult = new DeferredResult<Object>();
|
||||
DeferredResult<?> deferredResult = new DeferredResult<Object>(emitter.getTimeout());
|
||||
WebAsyncUtils.getAsyncManager(webRequest).startDeferredResultProcessing(deferredResult, mavContainer);
|
||||
|
||||
HttpMessageConvertingHandler handler = new HttpMessageConvertingHandler(outputMessage, deferredResult);
|
||||
|
||||
Reference in New Issue
Block a user