Early registration of WriteListener

At present Tomcat expects a WriteListener to be registered immediately
on the initial thread so for the time being this commit ensures the
WriteListener is registered unconditionally for every request.

Issue: SPR-14772, SPR-14803
This commit is contained in:
Rossen Stoyanchev 2016-10-21 15:24:12 -04:00
parent 61cf9fdda5
commit 5c9c5e0b45
2 changed files with 8 additions and 3 deletions

View File

@ -69,6 +69,7 @@ public class ServletServerHttpRequest extends AbstractServerHttpRequest {
Assert.notNull(bufferFactory, "'bufferFactory' must not be null");
Assert.isTrue(bufferSize > 0, "'bufferSize' must be higher than 0");
this.request = request;
this.dataBufferFactory = bufferFactory;
this.bufferSize = bufferSize;

View File

@ -61,11 +61,16 @@ public class ServletServerHttpResponse extends AbstractListenerServerHttpRespons
DataBufferFactory dataBufferFactory, int bufferSize) throws IOException {
super(dataBufferFactory);
Assert.notNull(response, "HttpServletResponse must not be null");
Assert.notNull(dataBufferFactory, "DataBufferFactory must not be null");
Assert.isTrue(bufferSize > 0, "Buffer size must be higher than 0");
this.response = response;
this.bufferSize = bufferSize;
// Tomcat expects WriteListener registration on initial thread
registerListener();
}
@ -119,14 +124,13 @@ public class ServletServerHttpResponse extends AbstractListenerServerHttpRespons
@Override
protected Processor<Publisher<DataBuffer>, Void> createBodyFlushProcessor() {
ResponseBodyFlushProcessor processor = new ResponseBodyFlushProcessor();
registerListener();
bodyFlushProcessor = processor;
this.bodyFlushProcessor = processor;
return processor;
}
private void registerListener() {
try {
outputStream().setWriteListener(writeListener);
outputStream().setWriteListener(this.writeListener);
}
catch (IOException ex) {
throw new UncheckedIOException(ex);