31
31
import org .springframework .graphql .execution .SubscriptionPublisherException ;
32
32
import org .springframework .graphql .server .WebGraphQlHandler ;
33
33
import org .springframework .graphql .server .WebGraphQlResponse ;
34
- import org .springframework .util .AlternativeJdkIdGenerator ;
35
- import org .springframework .util .IdGenerator ;
36
34
import org .springframework .web .context .request .async .AsyncRequestTimeoutException ;
37
35
import org .springframework .web .servlet .function .ServerRequest ;
38
36
import org .springframework .web .servlet .function .ServerResponse ;
49
47
*/
50
48
public class GraphQlSseHandler extends AbstractGraphQlHttpHandler {
51
49
52
- private final IdGenerator idGenerator = new AlternativeJdkIdGenerator ();
53
-
54
-
55
50
public GraphQlSseHandler (WebGraphQlHandler graphQlHandler ) {
56
51
super (graphQlHandler , null );
57
52
}
@@ -94,12 +89,7 @@ private static final class SseSubscriber extends BaseSubscriber<Map<String, Obje
94
89
95
90
private SseSubscriber (ServerResponse .SseBuilder sseBuilder ) {
96
91
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 ()));
103
93
}
104
94
105
95
@ Override
@@ -113,11 +103,15 @@ private void writeResult(Map<String, Object> value) {
113
103
this .sseBuilder .data (value );
114
104
}
115
105
catch (IOException exception ) {
116
- cancel ();
117
- hookOnError (exception );
106
+ cancelWithError (exception );
118
107
}
119
108
}
120
109
110
+ private void cancelWithError (Throwable ex ) {
111
+ this .cancel ();
112
+ this .sseBuilder .error (ex );
113
+ }
114
+
121
115
@ Override
122
116
protected void hookOnError (Throwable ex ) {
123
117
if (ex instanceof SubscriptionPublisherException spe ) {
0 commit comments