Browse Source

StandardServletAsyncWebRequest handling for onError

This change ensures that an onError outcome from an async request is
also routed to onCompletion handlers registered with
StandardServletAsyncWebRequest.

Issue: SPR-13292
pull/851/head
Rossen Stoyanchev 9 years ago
parent
commit
27cd87926a
  1. 1
      spring-web/src/main/java/org/springframework/web/context/request/async/StandardServletAsyncWebRequest.java
  2. 27
      spring-web/src/test/java/org/springframework/web/context/request/async/StandardServletAsyncWebRequestTests.java

1
spring-web/src/main/java/org/springframework/web/context/request/async/StandardServletAsyncWebRequest.java

@ -134,6 +134,7 @@ public class StandardServletAsyncWebRequest extends ServletWebRequest implements @@ -134,6 +134,7 @@ public class StandardServletAsyncWebRequest extends ServletWebRequest implements
@Override
public void onError(AsyncEvent event) throws IOException {
onComplete(event);
}
@Override

27
spring-web/src/test/java/org/springframework/web/context/request/async/StandardServletAsyncWebRequestTests.java

@ -121,7 +121,7 @@ public class StandardServletAsyncWebRequestTests { @@ -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 { @@ -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());
}
}

Loading…
Cancel
Save