Skip to content

Commit c784612

Browse files
committed
Polishing in GraphQlSseHandler
See gh-1067
1 parent 3ea216c commit c784612

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

spring-graphql/src/main/java/org/springframework/graphql/server/webmvc/GraphQlSseHandler.java

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@
3131
import org.springframework.graphql.execution.SubscriptionPublisherException;
3232
import org.springframework.graphql.server.WebGraphQlHandler;
3333
import org.springframework.graphql.server.WebGraphQlResponse;
34-
import org.springframework.util.AlternativeJdkIdGenerator;
35-
import org.springframework.util.IdGenerator;
3634
import org.springframework.web.context.request.async.AsyncRequestTimeoutException;
3735
import org.springframework.web.servlet.function.ServerRequest;
3836
import org.springframework.web.servlet.function.ServerResponse;
@@ -49,9 +47,6 @@
4947
*/
5048
public class GraphQlSseHandler extends AbstractGraphQlHttpHandler {
5149

52-
private final IdGenerator idGenerator = new AlternativeJdkIdGenerator();
53-
54-
5550
public GraphQlSseHandler(WebGraphQlHandler graphQlHandler) {
5651
super(graphQlHandler, null);
5752
}
@@ -94,12 +89,7 @@ private static final class SseSubscriber extends BaseSubscriber<Map<String, Obje
9489

9590
private SseSubscriber(ServerResponse.SseBuilder sseBuilder) {
9691
this.sseBuilder = sseBuilder;
97-
this.sseBuilder.onTimeout(this::onTimeout);
98-
}
99-
100-
private void onTimeout() {
101-
this.cancel();
102-
this.sseBuilder.error(new AsyncRequestTimeoutException());
92+
this.sseBuilder.onTimeout(() -> cancelWithError(new AsyncRequestTimeoutException()));
10393
}
10494

10595
@Override
@@ -113,11 +103,15 @@ private void writeResult(Map<String, Object> value) {
113103
this.sseBuilder.data(value);
114104
}
115105
catch (IOException exception) {
116-
cancel();
117-
hookOnError(exception);
106+
cancelWithError(exception);
118107
}
119108
}
120109

110+
private void cancelWithError(Throwable ex) {
111+
this.cancel();
112+
this.sseBuilder.error(ex);
113+
}
114+
121115
@Override
122116
protected void hookOnError(Throwable ex) {
123117
if (ex instanceof SubscriptionPublisherException spe) {

0 commit comments

Comments
 (0)