diff --git a/spring-web/src/main/java/org/springframework/web/context/request/async/StandardServletAsyncWebRequest.java b/spring-web/src/main/java/org/springframework/web/context/request/async/StandardServletAsyncWebRequest.java index a8878e998c..fc0bb98323 100644 --- a/spring-web/src/main/java/org/springframework/web/context/request/async/StandardServletAsyncWebRequest.java +++ b/spring-web/src/main/java/org/springframework/web/context/request/async/StandardServletAsyncWebRequest.java @@ -134,6 +134,7 @@ public class StandardServletAsyncWebRequest extends ServletWebRequest implements @Override public void onError(AsyncEvent event) throws IOException { + onComplete(event); } @Override diff --git a/spring-web/src/test/java/org/springframework/web/context/request/async/StandardServletAsyncWebRequestTests.java b/spring-web/src/test/java/org/springframework/web/context/request/async/StandardServletAsyncWebRequestTests.java index fa40789c15..50d84230de 100644 --- a/spring-web/src/test/java/org/springframework/web/context/request/async/StandardServletAsyncWebRequestTests.java +++ b/spring-web/src/test/java/org/springframework/web/context/request/async/StandardServletAsyncWebRequestTests.java @@ -121,7 +121,7 @@ public class StandardServletAsyncWebRequestTests { } @Test - public void onTimeoutTimeoutHandler() throws Exception { + public void onTimeoutHandler() throws Exception { Runnable timeoutHandler = mock(Runnable.class); this.asyncRequest.addTimeoutHandler(timeoutHandler); this.asyncRequest.onTimeout(new AsyncEvent(null)); @@ -134,4 +134,29 @@ public class StandardServletAsyncWebRequestTests { this.asyncRequest.setTimeout(25L); } + @Test + public void onCompletionHandler() throws Exception { + Runnable handler = mock(Runnable.class); + this.asyncRequest.addCompletionHandler(handler); + + this.asyncRequest.startAsync(); + this.asyncRequest.onComplete(new AsyncEvent(null)); + + verify(handler).run(); + assertTrue(this.asyncRequest.isAsyncComplete()); + } + + // SPR-13292 + + @Test + public void onCompletionHandlerAfterOnErrorEvent() throws Exception { + Runnable handler = mock(Runnable.class); + this.asyncRequest.addCompletionHandler(handler); + + this.asyncRequest.startAsync(); + this.asyncRequest.onError(new AsyncEvent(null)); + + verify(handler).run(); + assertTrue(this.asyncRequest.isAsyncComplete()); + } }