2 // ========================================================================
3 // Copyright (c) 1995-2014 Mort Bay Consulting Pty. Ltd.
4 // ------------------------------------------------------------------------
5 // All rights reserved. This program and the accompanying materials
6 // are made available under the terms of the Eclipse Public License v1.0
7 // and Apache License v2.0 which accompanies this distribution.
9 // The Eclipse Public License is available at
10 // http://www.eclipse.org/legal/epl-v10.html
12 // The Apache License v2.0 is available at
13 // http://www.opensource.org/licenses/apache2.0.php
15 // You may elect to redistribute this code under either of these licenses.
16 // ========================================================================
19 package org.eclipse.jetty.server;
22 import javax.servlet.AsyncContext;
23 import javax.servlet.AsyncEvent;
24 import javax.servlet.RequestDispatcher;
25 import javax.servlet.ServletContext;
26 import javax.servlet.ServletRequest;
27 import javax.servlet.ServletResponse;
29 import org.eclipse.jetty.server.handler.ContextHandler.Context;
30 import org.eclipse.jetty.util.thread.Scheduler;
32 public class AsyncContextEvent extends AsyncEvent implements Runnable
34 final private Context _context;
35 final private AsyncContextState _asyncContext;
36 private volatile HttpChannelState _state;
37 private ServletContext _dispatchContext;
38 private String _dispatchPath;
39 private volatile Scheduler.Task _timeoutTask;
40 private Throwable _throwable;
42 public AsyncContextEvent(Context context,AsyncContextState asyncContext, HttpChannelState state, Request baseRequest, ServletRequest request, ServletResponse response)
44 super(null,request,response,null);
46 _asyncContext=asyncContext;
49 // If we haven't been async dispatched before
50 if (baseRequest.getAttribute(AsyncContext.ASYNC_REQUEST_URI)==null)
52 // We are setting these attributes during startAsync, when the spec implies that
53 // they are only available after a call to AsyncContext.dispatch(...);
55 // have we been forwarded before?
56 String uri=(String)baseRequest.getAttribute(RequestDispatcher.FORWARD_REQUEST_URI);
59 baseRequest.setAttribute(AsyncContext.ASYNC_REQUEST_URI,uri);
60 baseRequest.setAttribute(AsyncContext.ASYNC_CONTEXT_PATH,baseRequest.getAttribute(RequestDispatcher.FORWARD_CONTEXT_PATH));
61 baseRequest.setAttribute(AsyncContext.ASYNC_SERVLET_PATH,baseRequest.getAttribute(RequestDispatcher.FORWARD_SERVLET_PATH));
62 baseRequest.setAttribute(AsyncContext.ASYNC_PATH_INFO,baseRequest.getAttribute(RequestDispatcher.FORWARD_PATH_INFO));
63 baseRequest.setAttribute(AsyncContext.ASYNC_QUERY_STRING,baseRequest.getAttribute(RequestDispatcher.FORWARD_QUERY_STRING));
67 baseRequest.setAttribute(AsyncContext.ASYNC_REQUEST_URI,baseRequest.getRequestURI());
68 baseRequest.setAttribute(AsyncContext.ASYNC_CONTEXT_PATH,baseRequest.getContextPath());
69 baseRequest.setAttribute(AsyncContext.ASYNC_SERVLET_PATH,baseRequest.getServletPath());
70 baseRequest.setAttribute(AsyncContext.ASYNC_PATH_INFO,baseRequest.getPathInfo());
71 baseRequest.setAttribute(AsyncContext.ASYNC_QUERY_STRING,baseRequest.getQueryString());
76 public ServletContext getSuspendedContext()
81 public Context getContext()
86 public ServletContext getDispatchContext()
88 return _dispatchContext;
91 public ServletContext getServletContext()
93 return _dispatchContext==null?_context:_dispatchContext;
97 * @return The path in the context
99 public String getPath()
101 return _dispatchPath;
104 public void setTimeoutTask(Scheduler.Task task)
109 public void cancelTimeoutTask()
111 Scheduler.Task task=_timeoutTask;
118 public AsyncContext getAsyncContext()
120 return _asyncContext;
124 public Throwable getThrowable()
129 public void setThrowable(Throwable throwable)
131 _throwable=throwable;
134 public void setDispatchContext(ServletContext context)
136 _dispatchContext=context;
139 public void setDispatchPath(String path)
144 public void completed()
147 _asyncContext.reset();
150 public HttpChannelState getHttpChannelState()
158 Scheduler.Task task=_timeoutTask;