KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > portlet > PortletStaleSessionExceptionPresenter


1 // Copyright 2005 The Apache Software Foundation
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15 package org.apache.tapestry.portlet;
16
17 import javax.portlet.ActionRequest;
18 import javax.portlet.ActionResponse;
19
20 import org.apache.hivemind.ApplicationRuntimeException;
21 import org.apache.tapestry.IRequestCycle;
22 import org.apache.tapestry.StaleSessionException;
23 import org.apache.tapestry.error.RequestExceptionReporter;
24 import org.apache.tapestry.error.StaleSessionExceptionPresenter;
25 import org.apache.tapestry.services.ServiceConstants;
26
27 /**
28  * @author Howard M. Lewis Ship
29  * @since 4.0
30  */

31 public class PortletStaleSessionExceptionPresenter implements StaleSessionExceptionPresenter
32 {
33     private PortletRequestGlobals _globals;
34
35     private RequestExceptionReporter _requestExceptionReporter;
36
37     public void presentStaleSessionException(IRequestCycle cycle, StaleSessionException cause)
38     {
39         try
40         {
41             String JavaDoc markup = PortletMessages.staleSession();
42
43             ActionRequest request = _globals.getActionRequest();
44
45             request.getPortletSession(true).setAttribute(
46                     PortletConstants.PORTLET_EXCEPTION_MARKUP_ATTRIBUTE,
47                     markup);
48
49             ActionResponse response = _globals.getActionResponse();
50
51             response.setRenderParameter(
52                     ServiceConstants.SERVICE,
53                     PortletConstants.EXCEPTION_SERVICE);
54         }
55         catch (Exception JavaDoc ex)
56         {
57             // Worst case scenario. The exception page itself is broken, leaving
58
// us with no option but to write the cause to the output.
59

60             // Also, write the exception thrown when redendering the exception
61
// page, so that can get fixed as well.
62

63             _requestExceptionReporter.reportRequestException(PortletMessages
64                     .errorReportingException(ex), ex);
65
66             // And throw the exception.
67

68             throw new ApplicationRuntimeException(ex.getMessage(), ex);
69         }
70     }
71
72     public void setGlobals(PortletRequestGlobals globals)
73     {
74         _globals = globals;
75     }
76
77     public void setRequestExceptionReporter(RequestExceptionReporter requestExceptionReporter)
78     {
79         _requestExceptionReporter = requestExceptionReporter;
80     }
81 }
82
Popular Tags