Skip to content

Commit 27cd879

Browse files
committed
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
1 parent 2428595 commit 27cd879

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ public void onStartAsync(AsyncEvent event) throws IOException {
134134

135135
@Override
136136
public void onError(AsyncEvent event) throws IOException {
137+
onComplete(event);
137138
}
138139

139140
@Override

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

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public void onTimeoutDefaultBehavior() throws Exception {
121121
}
122122

123123
@Test
124-
public void onTimeoutTimeoutHandler() throws Exception {
124+
public void onTimeoutHandler() throws Exception {
125125
Runnable timeoutHandler = mock(Runnable.class);
126126
this.asyncRequest.addTimeoutHandler(timeoutHandler);
127127
this.asyncRequest.onTimeout(new AsyncEvent(null));
@@ -134,4 +134,29 @@ public void setTimeoutDuringConcurrentHandling() {
134134
this.asyncRequest.setTimeout(25L);
135135
}
136136

137+
@Test
138+
public void onCompletionHandler() throws Exception {
139+
Runnable handler = mock(Runnable.class);
140+
this.asyncRequest.addCompletionHandler(handler);
141+
142+
this.asyncRequest.startAsync();
143+
this.asyncRequest.onComplete(new AsyncEvent(null));
144+
145+
verify(handler).run();
146+
assertTrue(this.asyncRequest.isAsyncComplete());
147+
}
148+
149+
// SPR-13292
150+
151+
@Test
152+
public void onCompletionHandlerAfterOnErrorEvent() throws Exception {
153+
Runnable handler = mock(Runnable.class);
154+
this.asyncRequest.addCompletionHandler(handler);
155+
156+
this.asyncRequest.startAsync();
157+
this.asyncRequest.onError(new AsyncEvent(null));
158+
159+
verify(handler).run();
160+
assertTrue(this.asyncRequest.isAsyncComplete());
161+
}
137162
}

0 commit comments

Comments
 (0)