1 | <%-- $Id: exception.jsp 3679 2007-08-17 07:18:29Z jari $ |
---|
2 | ------------------------------------------------------------------ |
---|
3 | Copyright (C) 2005 Nicklas Nordborg |
---|
4 | Copyright (C) 2006 Johan Enell, Jari Hakkinen, Nicklas Nordborg, Martin Svensson |
---|
5 | Copyright (C) 2007 Johan Enell, Nicklas Nordborg |
---|
6 | |
---|
7 | This file is part of BASE - BioArray Software Environment. |
---|
8 | Available at http://base.thep.lu.se/ |
---|
9 | |
---|
10 | BASE is free software; you can redistribute it and/or |
---|
11 | modify it under the terms of the GNU General Public License |
---|
12 | as published by the Free Software Foundation; either version 2 |
---|
13 | of the License, or (at your option) any later version. |
---|
14 | |
---|
15 | BASE is distributed in the hope that it will be useful, |
---|
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
18 | GNU General Public License for more details. |
---|
19 | |
---|
20 | You should have received a copy of the GNU General Public License |
---|
21 | along with this program; if not, write to the Free Software |
---|
22 | Foundation, Inc., 59 Temple Place - Suite 330, |
---|
23 | Boston, MA 02111-1307, USA. |
---|
24 | ------------------------------------------------------------------ |
---|
25 | |
---|
26 | All exceptions are directed to this page, by the server configuration |
---|
27 | See <error-page> tag in the /WEB-INF/web.xml file. |
---|
28 | |
---|
29 | Some exceptions are fowarded to other pages to be able to |
---|
30 | display a more appropriate error message. |
---|
31 | |
---|
32 | Only severe, unexpected exceptions, are handled by this page, |
---|
33 | which will only display a stack trace! |
---|
34 | |
---|
35 | @author Nicklas |
---|
36 | @version 2.0 |
---|
37 | --%> |
---|
38 | <%@ page session="false" |
---|
39 | import="net.sf.basedb.core.Application" |
---|
40 | import="net.sf.basedb.core.Config" |
---|
41 | import="net.sf.basedb.core.NotLoggedInException" |
---|
42 | import="net.sf.basedb.core.PermissionDeniedException" |
---|
43 | import="net.sf.basedb.core.InvalidDataException" |
---|
44 | import="net.sf.basedb.core.SessionControl" |
---|
45 | import="net.sf.basedb.clients.web.WebException" |
---|
46 | import="net.sf.basedb.clients.web.DuplicateWizardException" |
---|
47 | import="net.sf.basedb.clients.web.Base" |
---|
48 | import="net.sf.basedb.clients.web.util.HTML" |
---|
49 | import="net.sf.basedb.util.Values" |
---|
50 | import="javax.servlet.ServletException" |
---|
51 | import="java.sql.Driver" |
---|
52 | import="java.util.Properties" |
---|
53 | isErrorPage="true" |
---|
54 | %> |
---|
55 | <%@ |
---|
56 | taglib prefix="base" uri="/WEB-INF/base.tld" %> |
---|
57 | <% |
---|
58 | final SessionControl sc = Base.getSessionControl(pageContext, false); |
---|
59 | final String reportbuglink = sc == null ? "" : Values.getStringOrNull(sc.getClientDefaultSetting("server.links.reportbug")); |
---|
60 | Throwable ex = exception; |
---|
61 | |
---|
62 | if (ex instanceof org.apache.jasper.JasperException) |
---|
63 | { |
---|
64 | org.apache.jasper.JasperException jex = (org.apache.jasper.JasperException)ex; |
---|
65 | ex = jex.getRootCause(); |
---|
66 | } |
---|
67 | |
---|
68 | if (ex instanceof ServletException) |
---|
69 | { |
---|
70 | ServletException sex = (ServletException)ex; |
---|
71 | if (sex.getRootCause() != null) ex = sex.getRootCause(); |
---|
72 | } |
---|
73 | |
---|
74 | if (ex instanceof WebException) |
---|
75 | { |
---|
76 | pageContext.forward("/exception/web.jsp"); |
---|
77 | return; |
---|
78 | } |
---|
79 | else if (ex instanceof DuplicateWizardException) |
---|
80 | { |
---|
81 | pageContext.forward("/exception/duplicate_wizard.jsp"); |
---|
82 | return; |
---|
83 | } |
---|
84 | else if (ex instanceof NotLoggedInException) |
---|
85 | { |
---|
86 | pageContext.forward("/exception/not_logged_in.jsp"); |
---|
87 | return; |
---|
88 | } |
---|
89 | else if (ex instanceof PermissionDeniedException) |
---|
90 | { |
---|
91 | pageContext.forward("/exception/permission_denied.jsp"); |
---|
92 | return; |
---|
93 | } |
---|
94 | else if (ex instanceof InvalidDataException) |
---|
95 | { |
---|
96 | pageContext.forward("/exception/invalid_data.jsp"); |
---|
97 | return; |
---|
98 | } |
---|
99 | |
---|
100 | final String jdbcDriver = Config.getString("db.driver"); |
---|
101 | String driverVersion = ""; |
---|
102 | try |
---|
103 | { |
---|
104 | final Driver driver = (Driver)Class.forName(jdbcDriver).newInstance(); |
---|
105 | driverVersion = "(version " + driver.getMajorVersion() + "." + driver.getMinorVersion() + ")"; |
---|
106 | } |
---|
107 | catch (Throwable t) |
---|
108 | {} |
---|
109 | final Properties properties = System.getProperties(); |
---|
110 | final Runtime runtime = Runtime.getRuntime(); |
---|
111 | String exceptionClassName = ex.getClass().getName().replaceAll("net.sf.basedb.core.", ""); |
---|
112 | %> |
---|
113 | <base:page type="default" menu="exception" title="Unexpected error"> |
---|
114 | <base:head> |
---|
115 | <script language="JavaScript"> |
---|
116 | // Hide and display some elements that should not be displayed at all times |
---|
117 | function fixWindow() |
---|
118 | { |
---|
119 | if (history.length <= 1) // > |
---|
120 | { |
---|
121 | Main.hide('goback'); |
---|
122 | } |
---|
123 | if (window.opener != null) |
---|
124 | { |
---|
125 | // popup window --> Hide menubar |
---|
126 | Main.hide('menubar'); |
---|
127 | var width = Main.getWindowWidth(); |
---|
128 | var height = Main.getWindowHeight(); |
---|
129 | if (height < 600) height = 600; |
---|
130 | if (width < 800) width = 800; // > |
---|
131 | window.resizeTo(width, height); |
---|
132 | } |
---|
133 | else |
---|
134 | { |
---|
135 | // Hide close button |
---|
136 | Main.hide('close'); |
---|
137 | // If inside a second frameset, hide menubar |
---|
138 | if (window.parent != window.top) |
---|
139 | { |
---|
140 | Main.hide('menubar'); |
---|
141 | } |
---|
142 | } |
---|
143 | } |
---|
144 | </script> |
---|
145 | </base:head> |
---|
146 | <base:body onload="fixWindow()"> |
---|
147 | <base:note type="error" title="<%=exceptionClassName + " on page "+request.getAttribute("javax.servlet.error.request_uri")%>" |
---|
148 | style="width:90%;" messagestyle="height: 450px;"> |
---|
149 | <table border="0" cellpadding="0" cellspacing="0" class="form"> |
---|
150 | <tr> |
---|
151 | <td class="prompt">Version</td> |
---|
152 | <td class="info"><%=Application.getVersionString()%></td> |
---|
153 | </tr> |
---|
154 | <tr> |
---|
155 | <td class="prompt">Web server</td> |
---|
156 | <td class="info"><%=application.getServerInfo()%></td> |
---|
157 | </tr> |
---|
158 | <tr> |
---|
159 | <td class="prompt">Database Server</td> |
---|
160 | <td class="info"><%=Application.getDatabaseVersionString()%></td> |
---|
161 | </tr> |
---|
162 | <tr> |
---|
163 | <td class="prompt">Database Dialect</td> |
---|
164 | <td class="info"><%=Config.getString("db.dialect")%></td> |
---|
165 | </tr> |
---|
166 | <tr> |
---|
167 | <td class="prompt">JDBC Driver</td> |
---|
168 | <td class="info"><%=jdbcDriver%> <%=driverVersion%></td> |
---|
169 | </tr> |
---|
170 | <tr> |
---|
171 | <td class="prompt">Java runtime</td> |
---|
172 | <td class="info"><%=properties.getProperty("java.runtime.name")%> |
---|
173 | (<%=properties.getProperty("java.runtime.version")%>), |
---|
174 | <a href="<%=properties.getProperty("java.vendor.url")%>" target="_new"><%=properties.getProperty("java.vendor")%></a></td> |
---|
175 | </tr> |
---|
176 | <tr> |
---|
177 | <td class="prompt">Operating system</td> |
---|
178 | <td class="info"><%=properties.getProperty("os.name")%> |
---|
179 | <%=properties.getProperty("os.arch")%> |
---|
180 | <%=properties.getProperty("os.version")%> |
---|
181 | </td> |
---|
182 | </tr> |
---|
183 | <tr> |
---|
184 | <td class="prompt">Memory</td> |
---|
185 | <td class="info">Total: <%=Values.formatBytes(runtime.totalMemory())%><br> |
---|
186 | Free: <%=Values.formatBytes(runtime.freeMemory()) %><br> |
---|
187 | Max: <%=Values.formatBytes(runtime.maxMemory()) %></td> |
---|
188 | </tr> |
---|
189 | <tr> |
---|
190 | <td class="prompt">Browser</td> |
---|
191 | <td class="info"><%=HTML.encodeTags(request.getHeader("User-Agent"))%></td> |
---|
192 | </tr> |
---|
193 | <tr> |
---|
194 | <td class="prompt">Error message</td> |
---|
195 | <td class="info"><%=HTML.formatLineBreaks(HTML.encodeTags(ex.getMessage(), ""))%></td> |
---|
196 | </tr> |
---|
197 | <tr> |
---|
198 | <td class="prompt">Stack trace</td> |
---|
199 | <td class="info"></td> |
---|
200 | </tr> |
---|
201 | </table> |
---|
202 | |
---|
203 | <% |
---|
204 | StackTraceElement[] st = ex.getStackTrace(); |
---|
205 | out.println("<pre>"); |
---|
206 | int i = 0; |
---|
207 | for (i=0; i < st.length && i < 8; i++) |
---|
208 | { |
---|
209 | out.print("...at "); |
---|
210 | out.println(st[i].toString().replaceAll("net.sf.basedb.core.", "")); |
---|
211 | } |
---|
212 | out.println("</pre>"); |
---|
213 | if ((i < st.length) || (ex.getCause() != null)) |
---|
214 | { |
---|
215 | out.println("<pre id=\"error_detail\" style=\"display:none;\">"); |
---|
216 | while (ex != null) |
---|
217 | { |
---|
218 | for (int j=i; j < st.length; j++) |
---|
219 | { |
---|
220 | out.print("...at "); |
---|
221 | out.println(st[j].toString().replaceAll("net.sf.basedb.core.", "")); |
---|
222 | } |
---|
223 | ex = ex.getCause(); |
---|
224 | if (ex != null) |
---|
225 | { |
---|
226 | st = ex.getStackTrace(); |
---|
227 | i = 0; |
---|
228 | out.print("\nCaused by: "+ex.getClass().getName()+"\n"); |
---|
229 | } |
---|
230 | } |
---|
231 | out.println("</pre>"); |
---|
232 | } |
---|
233 | %> |
---|
234 | <span id="more_detail"> |
---|
235 | <base:icon image="bullet.gif" clazz="" /> |
---|
236 | <a href="javascript:Main.show('error_detail');Main.hide('more_detail');"><%=st.length-i%> more...</a> |
---|
237 | </span> |
---|
238 | </base:note> |
---|
239 | <base:buttongroup align="center"> |
---|
240 | <base:button id="goback" onclick="<%="history.go(-1)"%>" title="Back"/> |
---|
241 | <base:button id="close" onclick="<%="window.close()"%>" title="Close"/> |
---|
242 | <base:button id="reportbug" onclick="<%="window.open('"+reportbuglink+"','Reportbug')"%>" |
---|
243 | title="Report bug…" image="bug.gif" |
---|
244 | visible="<%=HTML.isValidUrl(reportbuglink)%>"/> |
---|
245 | </base:buttongroup> |
---|
246 | |
---|
247 | </base:body> |
---|
248 | </base:page> |
---|
249 | |
---|