|
24 | 24 | import org.slf4j.Logger; |
25 | 25 | import org.slf4j.LoggerFactory; |
26 | 26 |
|
27 | | -import javax.servlet.*; |
| 27 | +import javax.servlet.AsyncContext; |
| 28 | +import javax.servlet.AsyncEvent; |
| 29 | +import javax.servlet.AsyncListener; |
| 30 | +import javax.servlet.Servlet; |
| 31 | +import javax.servlet.ServletException; |
28 | 32 | import javax.servlet.http.HttpServlet; |
29 | 33 | import javax.servlet.http.HttpServletRequest; |
30 | 34 | import javax.servlet.http.HttpServletResponse; |
@@ -66,7 +70,7 @@ public abstract class AbstractGraphQLHttpServlet extends HttpServlet implements |
66 | 70 | private static final String[] MULTIPART_KEYS = new String[]{"operations", "graphql", "query"}; |
67 | 71 |
|
68 | 72 | private GraphQLConfiguration configuration; |
69 | | - |
| 73 | + |
70 | 74 | /** |
71 | 75 | * @deprecated override {@link #getConfiguration()} instead |
72 | 76 | */ |
@@ -285,11 +289,19 @@ private void mapMultipartVariables(GraphQLRequest request, |
285 | 289 | } |
286 | 290 |
|
287 | 291 | public void addListener(GraphQLServletListener servletListener) { |
288 | | - configuration.add(servletListener); |
| 292 | + if (configuration != null) { |
| 293 | + configuration.add(servletListener); |
| 294 | + } else { |
| 295 | + listeners.add(servletListener); |
| 296 | + } |
289 | 297 | } |
290 | 298 |
|
291 | 299 | public void removeListener(GraphQLServletListener servletListener) { |
292 | | - configuration.remove(servletListener); |
| 300 | + if (configuration != null) { |
| 301 | + configuration.remove(servletListener); |
| 302 | + } else { |
| 303 | + listeners.remove(servletListener); |
| 304 | + } |
293 | 305 | } |
294 | 306 |
|
295 | 307 | @Override |
@@ -343,11 +355,13 @@ private void doRequest(HttpServletRequest request, HttpServletResponse response, |
343 | 355 |
|
344 | 356 | @Override |
345 | 357 | protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { |
| 358 | + init(); |
346 | 359 | doRequestAsync(req, resp, getHandler); |
347 | 360 | } |
348 | 361 |
|
349 | 362 | @Override |
350 | 363 | protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { |
| 364 | + init(); |
351 | 365 | doRequestAsync(req, resp, postHandler); |
352 | 366 | } |
353 | 367 |
|
@@ -498,23 +512,28 @@ default void accept(HttpServletRequest request, HttpServletResponse response) { |
498 | 512 |
|
499 | 513 | private static class SubscriptionAsyncListener implements AsyncListener { |
500 | 514 | private final AtomicReference<Subscription> subscriptionRef; |
| 515 | + |
501 | 516 | public SubscriptionAsyncListener(AtomicReference<Subscription> subscriptionRef) { |
502 | 517 | this.subscriptionRef = subscriptionRef; |
503 | 518 | } |
504 | 519 |
|
505 | | - @Override public void onComplete(AsyncEvent event) { |
| 520 | + @Override |
| 521 | + public void onComplete(AsyncEvent event) { |
506 | 522 | subscriptionRef.get().cancel(); |
507 | 523 | } |
508 | 524 |
|
509 | | - @Override public void onTimeout(AsyncEvent event) { |
| 525 | + @Override |
| 526 | + public void onTimeout(AsyncEvent event) { |
510 | 527 | subscriptionRef.get().cancel(); |
511 | 528 | } |
512 | 529 |
|
513 | | - @Override public void onError(AsyncEvent event) { |
| 530 | + @Override |
| 531 | + public void onError(AsyncEvent event) { |
514 | 532 | subscriptionRef.get().cancel(); |
515 | 533 | } |
516 | 534 |
|
517 | | - @Override public void onStartAsync(AsyncEvent event) { |
| 535 | + @Override |
| 536 | + public void onStartAsync(AsyncEvent event) { |
518 | 537 | } |
519 | 538 | } |
520 | 539 |
|
|
0 commit comments