From ef3e309c12853378051d294ad82d68c9299d0c17 Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Thu, 15 Jun 2017 13:11:59 -0400 Subject: [PATCH] Adjust timeout in Spring MVC for reactive streaming Issue: SPR-15669 --- .../servlet/mvc/method/annotation/ReactiveTypeHandler.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ReactiveTypeHandler.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ReactiveTypeHandler.java index 2b2a1ba56f..588558c819 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ReactiveTypeHandler.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ReactiveTypeHandler.java @@ -70,6 +70,9 @@ import org.springframework.web.servlet.HandlerMapping; */ class ReactiveTypeHandler { + private static final long STREAMING_TIMEOUT_VALUE = -1; + + private static Log logger = LogFactory.getLog(ReactiveTypeHandler.class); private final ReactiveAdapterRegistry reactiveRegistry; @@ -126,7 +129,7 @@ class ReactiveTypeHandler { if (adapter.isMultiValue()) { if (mediaTypes.stream().anyMatch(MediaType.TEXT_EVENT_STREAM::includes) || ServerSentEvent.class.isAssignableFrom(elementClass)) { - SseEmitter emitter = new SseEmitter(); + SseEmitter emitter = new SseEmitter(STREAMING_TIMEOUT_VALUE); new SseEmitterSubscriber(emitter, this.taskExecutor).connect(adapter, returnValue); return emitter; } @@ -162,7 +165,7 @@ class ReactiveTypeHandler { } private ResponseBodyEmitter getEmitter(MediaType mediaType) { - return new ResponseBodyEmitter() { + return new ResponseBodyEmitter(STREAMING_TIMEOUT_VALUE) { @Override protected void extendResponse(ServerHttpResponse outputMessage) { outputMessage.getHeaders().setContentType(mediaType);