comparison src/org/eclipse/jetty/server/AsyncContinuation.java @ 932:947df3056ddb

remove AsyncEventState
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 09 Oct 2016 20:20:13 -0600
parents 6f7e2ff51879
children c9513d80f305
comparison
equal deleted inserted replaced
931:6f7e2ff51879 932:947df3056ddb
78 78
79 /* ------------------------------------------------------------ */ 79 /* ------------------------------------------------------------ */
80 private int _state; 80 private int _state;
81 private volatile boolean _responseWrapped; 81 private volatile boolean _responseWrapped;
82 private long _timeoutMs=DEFAULT_TIMEOUT; 82 private long _timeoutMs=DEFAULT_TIMEOUT;
83 private AsyncEventState _event;
84 private volatile long _expireAt; 83 private volatile long _expireAt;
85 84
86 /* ------------------------------------------------------------ */ 85 /* ------------------------------------------------------------ */
87 protected AsyncContinuation() 86 protected AsyncContinuation()
88 { 87 {
148 { 147 {
149 return _timeoutMs; 148 return _timeoutMs;
150 } 149 }
151 } 150 }
152 151
153 /* ------------------------------------------------------------ */
154 public AsyncEventState getAsyncEventState()
155 {
156 synchronized(this)
157 {
158 return _event;
159 }
160 }
161
162 /* ------------------------------------------------------------ */ 152 /* ------------------------------------------------------------ */
163 /** 153 /**
164 * @see org.eclipse.jetty.continuation.Continuation#keepWrappers() 154 * @see org.eclipse.jetty.continuation.Continuation#keepWrappers()
165 */ 155 */
166 156
370 { 360 {
371 try 361 try
372 { 362 {
373 if (ex!=null) 363 if (ex!=null)
374 { 364 {
375 _event.getSuppliedRequest().setAttribute(RequestDispatcher.ERROR_EXCEPTION,ex); 365 throw new UnsupportedOperationException();
376 _event.getSuppliedRequest().setAttribute(RequestDispatcher.ERROR_MESSAGE,ex.getMessage());
377 listener.onError(_event);
378 } 366 }
379 else 367 else
380 listener.onComplete(_event); 368 listener.onComplete(null);
381 } 369 }
382 catch(Exception e) 370 catch(Exception e)
383 { 371 {
384 LOG.warn("",e); 372 LOG.warn("",e);
385 } 373 }
432 this.notifyAll(); 420 this.notifyAll();
433 } 421 }
434 } 422 }
435 else 423 else
436 { 424 {
437 final AsyncEventState event=_event;
438 if (event!=null)
439 {
440 ((AsyncEndPoint)endp).cancelTimeout(event._timeout);
441 }
442 } 425 }
443 } 426 }
444 427
445 boolean isUncompleted() 428 boolean isUncompleted()
446 { 429 {
475 } 458 }
476 459
477 /* ------------------------------------------------------------ */ 460 /* ------------------------------------------------------------ */
478 public ServletRequest getRequest() 461 public ServletRequest getRequest()
479 { 462 {
480 if (_event!=null)
481 return _event.getSuppliedRequest();
482 return _connection.getRequest(); 463 return _connection.getRequest();
483 } 464 }
484 465
485 /* ------------------------------------------------------------ */ 466 /* ------------------------------------------------------------ */
486 public ServletResponse getResponse() 467 public ServletResponse getResponse()
487 { 468 {
488 if (_responseWrapped && _event!=null && _event.getSuppliedResponse()!=null)
489 return _event.getSuppliedResponse();
490 return _connection.getResponse(); 469 return _connection.getResponse();
491 } 470 }
492 471
493 /* ------------------------------------------------------------ */ 472 /* ------------------------------------------------------------ */
494 public void start(final Runnable run) 473 public void start(final Runnable run)
495 { 474 {
496 final AsyncEventState event=_event;
497 if (event!=null)
498 {
499 _connection.getServer().threadPool.execute(new Runnable()
500 {
501 public void run()
502 {
503 ((Context)event.getServletContext()).getContextHandler().handle(run);
504 }
505 });
506 }
507 } 475 }
508 476
509 /* ------------------------------------------------------------ */ 477 /* ------------------------------------------------------------ */
510 public boolean hasOriginalRequestAndResponse() 478 public boolean hasOriginalRequestAndResponse()
511 { 479 {
512 synchronized (this) 480 synchronized (this)
513 { 481 {
514 return (_event!=null && _event.getSuppliedRequest()==_connection._request && _event.getSuppliedResponse()==_connection._response); 482 return false;
515 } 483 }
516 } 484 }
517 485
518 /* ------------------------------------------------------------ */ 486 /* ------------------------------------------------------------ */
519 public ContextHandler getContextHandler() 487 public ContextHandler getContextHandler()
520 { 488 {
521 final AsyncEventState event=_event;
522 if (event!=null)
523 return ((Context)event.getServletContext()).getContextHandler();
524 return null; 489 return null;
525 } 490 }
526 491
527 492
528 /* ------------------------------------------------------------ */ 493 /* ------------------------------------------------------------ */
529 /** 494 /**
530 * @see org.eclipse.jetty.continuation.Continuation#getServletResponse() 495 * @see org.eclipse.jetty.continuation.Continuation#getServletResponse()
531 */ 496 */
532 public ServletResponse getServletResponse() 497 public ServletResponse getServletResponse()
533 { 498 {
534 if (_responseWrapped && _event!=null && _event.getSuppliedResponse()!=null)
535 return _event.getSuppliedResponse();
536 return _connection.getResponse(); 499 return _connection.getResponse();
537 } 500 }
538 501
539 /* ------------------------------------------------------------ */ 502 /* ------------------------------------------------------------ */
540 /** 503 /**
579 { 542 {
580 AsyncContinuation.this.expired(); 543 AsyncContinuation.this.expired();
581 } 544 }
582 } 545 }
583 546
584 /* ------------------------------------------------------------ */
585 /* ------------------------------------------------------------ */
586 public class AsyncEventState extends AsyncEvent
587 {
588 private final ServletContext _suspendedContext;
589 private ServletContext _dispatchContext;
590 private String _pathInContext;
591 private Timeout.Task _timeout= new AsyncTimeout();
592
593 public AsyncEventState(ServletContext context, ServletRequest request, ServletResponse response)
594 {
595 super(AsyncContinuation.this, request,response);
596 _suspendedContext=context;
597 // Get the base request So we can remember the initial paths
598 Request r=_connection.getRequest();
599
600 // If we haven't been async dispatched before
601 if (r.getAttribute(AsyncContext.ASYNC_REQUEST_URI)==null)
602 {
603 // We are setting these attributes during startAsync, when the spec implies that
604 // they are only available after a call to AsyncContext.dispatch(...);
605
606 // have we been forwarded before?
607 String uri=(String)r.getAttribute(RequestDispatcher.FORWARD_REQUEST_URI);
608 if (uri!=null)
609 {
610 r.setAttribute(AsyncContext.ASYNC_REQUEST_URI,uri);
611 r.setAttribute(AsyncContext.ASYNC_CONTEXT_PATH,r.getAttribute(RequestDispatcher.FORWARD_CONTEXT_PATH));
612 r.setAttribute(AsyncContext.ASYNC_SERVLET_PATH,r.getAttribute(RequestDispatcher.FORWARD_SERVLET_PATH));
613 r.setAttribute(AsyncContext.ASYNC_PATH_INFO,r.getAttribute(RequestDispatcher.FORWARD_PATH_INFO));
614 r.setAttribute(AsyncContext.ASYNC_QUERY_STRING,r.getAttribute(RequestDispatcher.FORWARD_QUERY_STRING));
615 }
616 else
617 {
618 r.setAttribute(AsyncContext.ASYNC_REQUEST_URI,r.getRequestURI());
619 r.setAttribute(AsyncContext.ASYNC_CONTEXT_PATH,r.getContextPath());
620 r.setAttribute(AsyncContext.ASYNC_SERVLET_PATH,r.getServletPath());
621 r.setAttribute(AsyncContext.ASYNC_PATH_INFO,r.getPathInfo());
622 r.setAttribute(AsyncContext.ASYNC_QUERY_STRING,r.getQueryString());
623 }
624 }
625 }
626
627 public ServletContext getSuspendedContext()
628 {
629 return _suspendedContext;
630 }
631
632 public ServletContext getDispatchContext()
633 {
634 return _dispatchContext;
635 }
636
637 public ServletContext getServletContext()
638 {
639 return _dispatchContext==null?_suspendedContext:_dispatchContext;
640 }
641
642 public void setPath(String path)
643 {
644 _pathInContext=path;
645 }
646
647 /* ------------------------------------------------------------ */
648 /**
649 * @return The path in the context
650 */
651 public String getPath()
652 {
653 return _pathInContext;
654 }
655 }
656 } 547 }