1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.jetty.server;
20
21
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;
28
29 import org.eclipse.jetty.server.handler.ContextHandler.Context;
30 import org.eclipse.jetty.util.thread.Scheduler;
31
32 public class AsyncContextEvent extends AsyncEvent
33 {
34 final private Context _context;
35 final private AsyncContextState _asyncContext;
36 volatile HttpChannelState _state;
37 private ServletContext _dispatchContext;
38 private String _pathInContext;
39 private Scheduler.Task _timeoutTask;
40 private Throwable _throwable;
41
42 public AsyncContextEvent(Context context,AsyncContextState asyncContext, HttpChannelState state, Request baseRequest, ServletRequest request, ServletResponse response)
43 {
44 super(null,request,response,null);
45 _context=context;
46 _asyncContext=asyncContext;
47 _state=state;
48
49
50 if (baseRequest.getAttribute(AsyncContext.ASYNC_REQUEST_URI)==null)
51 {
52
53
54
55
56 String uri=(String)baseRequest.getAttribute(RequestDispatcher.FORWARD_REQUEST_URI);
57 if (uri!=null)
58 {
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));
64 }
65 else
66 {
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());
72 }
73 }
74 }
75
76 public ServletContext getSuspendedContext()
77 {
78 return _context;
79 }
80
81 public Context getContext()
82 {
83 return _context;
84 }
85
86 public ServletContext getDispatchContext()
87 {
88 return _dispatchContext;
89 }
90
91 public ServletContext getServletContext()
92 {
93 return _dispatchContext==null?_context:_dispatchContext;
94 }
95
96
97
98
99 public String getPath()
100 {
101 return _pathInContext;
102 }
103
104 public void setTimeoutTask(Scheduler.Task task)
105 {
106 _timeoutTask = task;
107 }
108
109 public void cancelTimeoutTask()
110 {
111 Scheduler.Task task=_timeoutTask;
112 _timeoutTask=null;
113 if (task!=null)
114 task.cancel();
115 }
116
117 @Override
118 public AsyncContext getAsyncContext()
119 {
120 return _asyncContext;
121 }
122
123 @Override
124 public Throwable getThrowable()
125 {
126 return _throwable;
127 }
128
129 public void setThrowable(Throwable throwable)
130 {
131 _throwable=throwable;
132 }
133
134 public void setDispatchTarget(ServletContext context, String path)
135 {
136 if (context!=null)
137 _dispatchContext=context;
138 if (path!=null)
139 _pathInContext=path;
140 }
141
142
143 public void completed()
144 {
145 _asyncContext.reset();
146 }
147
148 public HttpChannelState getHttpChannelState()
149 {
150 return _state;
151 }
152
153 }