Skip to content

Commit

Permalink
Align future handling with AsyncServerResponse
Browse files Browse the repository at this point in the history
See gh-959
  • Loading branch information
rstoyanchev committed Apr 25, 2024
1 parent 21a7c81 commit f61dfc5
Showing 1 changed file with 7 additions and 9 deletions.
Expand Up @@ -21,7 +21,6 @@
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

import jakarta.servlet.ServletException;
import reactor.core.publisher.Mono;

import org.springframework.graphql.server.WebGraphQlHandler;
Expand Down Expand Up @@ -70,8 +69,7 @@ public GraphQlHttpHandler(WebGraphQlHandler graphQlHandler, @Nullable HttpMessag


@Override
protected ServerResponse prepareResponse(ServerRequest request, Mono<WebGraphQlResponse> responseMono)
throws ServletException {
protected ServerResponse prepareResponse(ServerRequest request, Mono<WebGraphQlResponse> responseMono) {

CompletableFuture<ServerResponse> future = responseMono.map((response) -> {
MediaType contentType = selectResponseMediaType(request);
Expand All @@ -87,15 +85,15 @@ protected ServerResponse prepareResponse(ServerRequest request, Mono<WebGraphQlR
}
}).toFuture();

if (future.isDone()) {
// This won't be needed with a Spring Framework 6.2 baseline:
// https://github.com/spring-projects/spring-framework/issues/32223

if (future.isDone() && !future.isCancelled() && !future.isCompletedExceptionally()) {
try {
return future.get();
}
catch (ExecutionException ex) {
throw new ServletException(ex.getCause());
}
catch (InterruptedException ex) {
throw new ServletException(ex);
catch (InterruptedException | ExecutionException ignored) {
// fall through to use DefaultAsyncServerResponse
}
}

Expand Down

0 comments on commit f61dfc5

Please sign in to comment.