|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| package org.apache.tapestry.engine; |
|
16 |
| |
|
17 |
| import java.io.IOException; |
|
18 |
| import java.util.ArrayList; |
|
19 |
| import java.util.List; |
|
20 |
| import java.util.Locale; |
|
21 |
| |
|
22 |
| import org.apache.commons.logging.Log; |
|
23 |
| import org.apache.commons.logging.LogFactory; |
|
24 |
| import org.apache.hivemind.ApplicationRuntimeException; |
|
25 |
| import org.apache.hivemind.ClassResolver; |
|
26 |
| import org.apache.hivemind.util.Defense; |
|
27 |
| import org.apache.hivemind.util.ToStringBuilder; |
|
28 |
| import org.apache.tapestry.Constants; |
|
29 |
| import org.apache.tapestry.IEngine; |
|
30 |
| import org.apache.tapestry.IPage; |
|
31 |
| import org.apache.tapestry.IRequestCycle; |
|
32 |
| import org.apache.tapestry.PageRedirectException; |
|
33 |
| import org.apache.tapestry.RedirectException; |
|
34 |
| import org.apache.tapestry.StaleLinkException; |
|
35 |
| import org.apache.tapestry.StaleSessionException; |
|
36 |
| import org.apache.tapestry.listener.ListenerMap; |
|
37 |
| import org.apache.tapestry.services.DataSqueezer; |
|
38 |
| import org.apache.tapestry.services.Infrastructure; |
|
39 |
| import org.apache.tapestry.spec.IApplicationSpecification; |
|
40 |
| import org.apache.tapestry.web.WebRequest; |
|
41 |
| import org.apache.tapestry.web.WebResponse; |
|
42 |
| |
|
43 |
| |
|
44 |
| |
|
45 |
| |
|
46 |
| |
|
47 |
| |
|
48 |
| |
|
49 |
| |
|
50 |
| |
|
51 |
| |
|
52 |
| |
|
53 |
| |
|
54 |
| |
|
55 |
| |
|
56 |
| |
|
57 |
| |
|
58 |
| |
|
59 |
| |
|
60 |
| |
|
61 |
| |
|
62 |
| |
|
63 |
| |
|
64 |
| |
|
65 |
| |
|
66 |
| |
|
67 |
| |
|
68 |
| |
|
69 |
| |
|
70 |
| |
|
71 |
| |
|
72 |
| |
|
73 |
| |
|
74 |
| |
|
75 |
| |
|
76 |
| |
|
77 |
| |
|
78 |
| |
|
79 |
| |
|
80 |
| |
|
81 |
| |
|
82 |
| |
|
83 |
| |
|
84 |
| |
|
85 |
| |
|
86 |
| |
|
87 |
| |
|
88 |
| |
|
89 |
| public abstract class AbstractEngine implements IEngine |
|
90 |
| { |
|
91 |
| private static final Log LOG = LogFactory.getLog(AbstractEngine.class); |
|
92 |
| |
|
93 |
| |
|
94 |
| |
|
95 |
| |
|
96 |
| |
|
97 |
| |
|
98 |
| private Infrastructure _infrastructure; |
|
99 |
| |
|
100 |
| private ListenerMap _listeners; |
|
101 |
| |
|
102 |
| |
|
103 |
| |
|
104 |
| |
|
105 |
| |
|
106 |
| private Locale _locale; |
|
107 |
| |
|
108 |
| |
|
109 |
| |
|
110 |
| |
|
111 |
| |
|
112 |
| |
|
113 |
| public static final String VISIT_CLASS_PROPERTY_NAME = "org.apache.tapestry.visit-class"; |
|
114 |
| |
|
115 |
| |
|
116 |
| |
|
117 |
| |
|
118 |
| |
|
119 |
60
| protected void activateExceptionPage(IRequestCycle cycle, Throwable cause)
|
|
120 |
| { |
|
121 |
60
| _infrastructure.getExceptionPresenter().presentException(cycle, cause);
|
|
122 |
| } |
|
123 |
| |
|
124 |
| |
|
125 |
| |
|
126 |
| |
|
127 |
| |
|
128 |
| |
|
129 |
| |
|
130 |
0
| public void reportException(String reportTitle, Throwable ex)
|
|
131 |
| { |
|
132 |
0
| _infrastructure.getRequestExceptionReporter().reportRequestException(reportTitle, ex);
|
|
133 |
| } |
|
134 |
| |
|
135 |
| |
|
136 |
| |
|
137 |
| |
|
138 |
| |
|
139 |
| |
|
140 |
0
| protected void cleanupAfterRequest(IRequestCycle cycle)
|
|
141 |
| { |
|
142 |
| |
|
143 |
| } |
|
144 |
| |
|
145 |
| |
|
146 |
| |
|
147 |
| |
|
148 |
| |
|
149 |
| |
|
150 |
930
| public Locale getLocale()
|
|
151 |
| { |
|
152 |
930
| return _locale;
|
|
153 |
| } |
|
154 |
| |
|
155 |
| |
|
156 |
| |
|
157 |
| |
|
158 |
| |
|
159 |
| |
|
160 |
| |
|
161 |
| |
|
162 |
0
| public IEngineService getService(String name)
|
|
163 |
| { |
|
164 |
0
| return _infrastructure.getServiceMap().getService(name);
|
|
165 |
| } |
|
166 |
| |
|
167 |
| |
|
168 |
| |
|
169 |
18
| public IApplicationSpecification getSpecification()
|
|
170 |
| { |
|
171 |
18
| return _infrastructure.getApplicationSpecification();
|
|
172 |
| } |
|
173 |
| |
|
174 |
| |
|
175 |
| |
|
176 |
0
| public ISpecificationSource getSpecificationSource()
|
|
177 |
| { |
|
178 |
0
| return _infrastructure.getSpecificationSource();
|
|
179 |
| } |
|
180 |
| |
|
181 |
| |
|
182 |
| |
|
183 |
| |
|
184 |
| |
|
185 |
| |
|
186 |
0
| protected void redirect(String pageName, IRequestCycle cycle,
|
|
187 |
| ApplicationRuntimeException exception) throws IOException |
|
188 |
| { |
|
189 |
0
| IPage page = cycle.getPage(pageName);
|
|
190 |
| |
|
191 |
0
| cycle.activate(page);
|
|
192 |
| |
|
193 |
0
| renderResponse(cycle);
|
|
194 |
| } |
|
195 |
| |
|
196 |
| |
|
197 |
| |
|
198 |
| |
|
199 |
| |
|
200 |
| |
|
201 |
6
| public void renderResponse(IRequestCycle cycle) throws IOException
|
|
202 |
| { |
|
203 |
6
| _infrastructure.getResponseRenderer().renderResponse(cycle);
|
|
204 |
| } |
|
205 |
| |
|
206 |
| |
|
207 |
| |
|
208 |
| |
|
209 |
| |
|
210 |
369
| public void service(WebRequest request, WebResponse response) throws IOException
|
|
211 |
| { |
|
212 |
369
| IRequestCycle cycle = null;
|
|
213 |
369
| IMonitor monitor = null;
|
|
214 |
369
| IEngineService service = null;
|
|
215 |
| |
|
216 |
369
| if (_infrastructure == null)
|
|
217 |
141
| _infrastructure = (Infrastructure) request.getAttribute(Constants.INFRASTRUCTURE_KEY);
|
|
218 |
| |
|
219 |
| |
|
220 |
| |
|
221 |
| |
|
222 |
369
| try
|
|
223 |
| { |
|
224 |
369
| cycle = _infrastructure.getRequestCycleFactory().newRequestCycle(this);
|
|
225 |
| } |
|
226 |
| catch (RuntimeException ex) |
|
227 |
| { |
|
228 |
0
| throw ex;
|
|
229 |
| } |
|
230 |
| catch (Exception ex) |
|
231 |
| { |
|
232 |
0
| throw new IOException(ex.getMessage());
|
|
233 |
| } |
|
234 |
| |
|
235 |
369
| try
|
|
236 |
| { |
|
237 |
369
| try
|
|
238 |
| { |
|
239 |
369
| monitor = cycle.getMonitor();
|
|
240 |
| |
|
241 |
369
| service = cycle.getService();
|
|
242 |
| |
|
243 |
369
| monitor.serviceBegin(service.getName(), _infrastructure.getRequest()
|
|
244 |
| .getRequestURI()); |
|
245 |
| |
|
246 |
| |
|
247 |
| |
|
248 |
369
| service.service(cycle);
|
|
249 |
| |
|
250 |
291
| return;
|
|
251 |
| } |
|
252 |
| catch (PageRedirectException ex) |
|
253 |
| { |
|
254 |
9
| handlePageRedirectException(cycle, ex);
|
|
255 |
| } |
|
256 |
| catch (RedirectException ex) |
|
257 |
| { |
|
258 |
0
| handleRedirectException(cycle, ex);
|
|
259 |
| } |
|
260 |
| catch (StaleLinkException ex) |
|
261 |
| { |
|
262 |
3
| handleStaleLinkException(cycle, ex);
|
|
263 |
| } |
|
264 |
| catch (StaleSessionException ex) |
|
265 |
| { |
|
266 |
9
| handleStaleSessionException(cycle, ex);
|
|
267 |
| } |
|
268 |
| } |
|
269 |
| catch (Exception ex) |
|
270 |
| { |
|
271 |
60
| monitor.serviceException(ex);
|
|
272 |
| |
|
273 |
| |
|
274 |
| |
|
275 |
| |
|
276 |
| |
|
277 |
60
| if (LOG.isDebugEnabled())
|
|
278 |
0
| LOG.debug("Uncaught exception", ex);
|
|
279 |
| |
|
280 |
60
| activateExceptionPage(cycle, ex);
|
|
281 |
| } |
|
282 |
| finally |
|
283 |
| { |
|
284 |
369
| if (service != null)
|
|
285 |
369
| monitor.serviceEnd(service.getName());
|
|
286 |
| |
|
287 |
369
| try
|
|
288 |
| { |
|
289 |
369
| cycle.cleanup();
|
|
290 |
369
| _infrastructure.getApplicationStateManager().flush();
|
|
291 |
| } |
|
292 |
| catch (Exception ex) |
|
293 |
| { |
|
294 |
0
| reportException(EngineMessages.exceptionDuringCleanup(ex), ex);
|
|
295 |
| } |
|
296 |
| } |
|
297 |
| } |
|
298 |
| |
|
299 |
| |
|
300 |
| |
|
301 |
| |
|
302 |
| |
|
303 |
| |
|
304 |
| |
|
305 |
| |
|
306 |
| |
|
307 |
| |
|
308 |
| |
|
309 |
9
| protected void handlePageRedirectException(IRequestCycle cycle, PageRedirectException exception)
|
|
310 |
| throws IOException |
|
311 |
| { |
|
312 |
9
| List pageNames = new ArrayList();
|
|
313 |
| |
|
314 |
9
| String pageName = exception.getTargetPageName();
|
|
315 |
| |
|
316 |
9
| while (true)
|
|
317 |
| { |
|
318 |
15
| if (pageNames.contains(pageName))
|
|
319 |
| { |
|
320 |
3
| pageNames.add(pageName);
|
|
321 |
| |
|
322 |
3
| throw new ApplicationRuntimeException(EngineMessages.validateCycle(pageNames));
|
|
323 |
| } |
|
324 |
| |
|
325 |
| |
|
326 |
| |
|
327 |
12
| pageNames.add(pageName);
|
|
328 |
| |
|
329 |
12
| try
|
|
330 |
| { |
|
331 |
| |
|
332 |
| |
|
333 |
12
| cycle.activate(pageName);
|
|
334 |
| |
|
335 |
6
| break;
|
|
336 |
| } |
|
337 |
| catch (PageRedirectException secondRedirectException) |
|
338 |
| { |
|
339 |
6
| pageName = secondRedirectException.getTargetPageName();
|
|
340 |
| } |
|
341 |
| } |
|
342 |
| |
|
343 |
6
| renderResponse(cycle);
|
|
344 |
| } |
|
345 |
| |
|
346 |
| |
|
347 |
| |
|
348 |
| |
|
349 |
| |
|
350 |
| |
|
351 |
| |
|
352 |
| |
|
353 |
| |
|
354 |
| |
|
355 |
| |
|
356 |
| |
|
357 |
| |
|
358 |
| |
|
359 |
| |
|
360 |
| |
|
361 |
| |
|
362 |
| |
|
363 |
| |
|
364 |
| |
|
365 |
| |
|
366 |
| |
|
367 |
3
| protected void handleStaleLinkException(IRequestCycle cycle, StaleLinkException exception)
|
|
368 |
| throws IOException |
|
369 |
| { |
|
370 |
3
| _infrastructure.getStaleLinkExceptionPresenter()
|
|
371 |
| .presentStaleLinkException(cycle, exception); |
|
372 |
| } |
|
373 |
| |
|
374 |
| |
|
375 |
| |
|
376 |
| |
|
377 |
| |
|
378 |
| |
|
379 |
| |
|
380 |
| |
|
381 |
| |
|
382 |
| |
|
383 |
| |
|
384 |
| |
|
385 |
| |
|
386 |
| |
|
387 |
9
| protected void handleStaleSessionException(IRequestCycle cycle, StaleSessionException exception)
|
|
388 |
| throws IOException |
|
389 |
| { |
|
390 |
9
| _infrastructure.getStaleSessionExceptionPresenter().presentStaleSessionException(
|
|
391 |
| cycle, |
|
392 |
| exception); |
|
393 |
| } |
|
394 |
| |
|
395 |
| |
|
396 |
| |
|
397 |
| |
|
398 |
| |
|
399 |
186
| public void setLocale(Locale value)
|
|
400 |
| { |
|
401 |
186
| Defense.notNull(value, "locale");
|
|
402 |
| |
|
403 |
186
| _locale = value;
|
|
404 |
| |
|
405 |
| |
|
406 |
| |
|
407 |
186
| if (_infrastructure != null)
|
|
408 |
36
| _infrastructure.setLocale(value);
|
|
409 |
| } |
|
410 |
| |
|
411 |
| |
|
412 |
| |
|
413 |
| |
|
414 |
| |
|
415 |
219
| public ClassResolver getClassResolver()
|
|
416 |
| { |
|
417 |
219
| return _infrastructure.getClassResolver();
|
|
418 |
| } |
|
419 |
| |
|
420 |
| |
|
421 |
| |
|
422 |
| |
|
423 |
| |
|
424 |
| |
|
425 |
| |
|
426 |
| |
|
427 |
0
| public String toString()
|
|
428 |
| { |
|
429 |
0
| ToStringBuilder builder = new ToStringBuilder(this);
|
|
430 |
| |
|
431 |
0
| builder.append("locale", _locale);
|
|
432 |
| |
|
433 |
0
| return builder.toString();
|
|
434 |
| } |
|
435 |
| |
|
436 |
| |
|
437 |
| |
|
438 |
| |
|
439 |
| |
|
440 |
| |
|
441 |
| |
|
442 |
| |
|
443 |
| |
|
444 |
| |
|
445 |
6
| public Object getVisit()
|
|
446 |
| { |
|
447 |
6
| return _infrastructure.getApplicationStateManager().get("visit");
|
|
448 |
| } |
|
449 |
| |
|
450 |
0
| public void setVisit(Object visit)
|
|
451 |
| { |
|
452 |
0
| _infrastructure.getApplicationStateManager().store("visit", visit);
|
|
453 |
| } |
|
454 |
| |
|
455 |
| |
|
456 |
| |
|
457 |
| |
|
458 |
| |
|
459 |
| |
|
460 |
| |
|
461 |
3
| public Object getVisit(IRequestCycle cycle)
|
|
462 |
| { |
|
463 |
3
| return getVisit();
|
|
464 |
| } |
|
465 |
| |
|
466 |
0
| public boolean getHasVisit()
|
|
467 |
| { |
|
468 |
0
| return _infrastructure.getApplicationStateManager().exists("visit");
|
|
469 |
| } |
|
470 |
| |
|
471 |
| |
|
472 |
| |
|
473 |
| |
|
474 |
| |
|
475 |
| |
|
476 |
| |
|
477 |
| |
|
478 |
| |
|
479 |
| |
|
480 |
| |
|
481 |
| |
|
482 |
3
| public Object getGlobal()
|
|
483 |
| { |
|
484 |
3
| return _infrastructure.getApplicationStateManager().get("global");
|
|
485 |
| } |
|
486 |
| |
|
487 |
0
| public IScriptSource getScriptSource()
|
|
488 |
| { |
|
489 |
0
| return _infrastructure.getScriptSource();
|
|
490 |
| } |
|
491 |
| |
|
492 |
| |
|
493 |
| |
|
494 |
| |
|
495 |
| |
|
496 |
| |
|
497 |
| |
|
498 |
0
| public ListenerMap getListeners()
|
|
499 |
| { |
|
500 |
0
| if (_listeners == null)
|
|
501 |
0
| _listeners = _infrastructure.getListenerMapSource().getListenerMapForObject(this);
|
|
502 |
| |
|
503 |
0
| return _listeners;
|
|
504 |
| } |
|
505 |
| |
|
506 |
| |
|
507 |
| |
|
508 |
| |
|
509 |
| |
|
510 |
| |
|
511 |
| |
|
512 |
| |
|
513 |
| |
|
514 |
| |
|
515 |
0
| protected void handleRedirectException(IRequestCycle cycle, RedirectException redirectException)
|
|
516 |
| { |
|
517 |
0
| String location = redirectException.getRedirectLocation();
|
|
518 |
| |
|
519 |
0
| if (LOG.isDebugEnabled())
|
|
520 |
0
| LOG.debug("Redirecting to: " + location);
|
|
521 |
| |
|
522 |
0
| _infrastructure.getRequest().forward(location);
|
|
523 |
| } |
|
524 |
| |
|
525 |
| |
|
526 |
| |
|
527 |
| |
|
528 |
| |
|
529 |
0
| public DataSqueezer getDataSqueezer()
|
|
530 |
| { |
|
531 |
0
| return _infrastructure.getDataSqueezer();
|
|
532 |
| } |
|
533 |
| |
|
534 |
| |
|
535 |
| |
|
536 |
0
| public IPropertySource getPropertySource()
|
|
537 |
| { |
|
538 |
0
| return _infrastructure.getApplicationPropertySource();
|
|
539 |
| } |
|
540 |
| |
|
541 |
| |
|
542 |
72
| public Infrastructure getInfrastructure()
|
|
543 |
| { |
|
544 |
72
| return _infrastructure;
|
|
545 |
| } |
|
546 |
| |
|
547 |
945
| public String getOutputEncoding()
|
|
548 |
| { |
|
549 |
945
| return _infrastructure.getOutputEncoding();
|
|
550 |
| } |
|
551 |
| } |