21
21
import java .util .concurrent .CompletableFuture ;
22
22
import java .util .concurrent .ExecutionException ;
23
23
24
- import jakarta .servlet .ServletException ;
25
24
import reactor .core .publisher .Mono ;
26
25
27
26
import org .springframework .graphql .server .WebGraphQlHandler ;
@@ -70,8 +69,7 @@ public GraphQlHttpHandler(WebGraphQlHandler graphQlHandler, @Nullable HttpMessag
70
69
71
70
72
71
@ Override
73
- protected ServerResponse prepareResponse (ServerRequest request , Mono <WebGraphQlResponse > responseMono )
74
- throws ServletException {
72
+ protected ServerResponse prepareResponse (ServerRequest request , Mono <WebGraphQlResponse > responseMono ) {
75
73
76
74
CompletableFuture <ServerResponse > future = responseMono .map ((response ) -> {
77
75
MediaType contentType = selectResponseMediaType (request );
@@ -87,15 +85,15 @@ protected ServerResponse prepareResponse(ServerRequest request, Mono<WebGraphQlR
87
85
}
88
86
}).toFuture ();
89
87
90
- if (future .isDone ()) {
88
+ // This won't be needed with a Spring Framework 6.2 baseline:
89
+ // https://github.com/spring-projects/spring-framework/issues/32223
90
+
91
+ if (future .isDone () && !future .isCancelled () && !future .isCompletedExceptionally ()) {
91
92
try {
92
93
return future .get ();
93
94
}
94
- catch (ExecutionException ex ) {
95
- throw new ServletException (ex .getCause ());
96
- }
97
- catch (InterruptedException ex ) {
98
- throw new ServletException (ex );
95
+ catch (InterruptedException | ExecutionException ignored ) {
96
+ // fall through to use DefaultAsyncServerResponse
99
97
}
100
98
}
101
99
0 commit comments