source: trunk/www/exception/exception.jsp @ 6309

Last change on this file since 6309 was 6309, checked in by Nicklas Nordborg, 10 years ago

References #1729 and #1730. Fixed on exception handling pages.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 6.8 KB
Line 
1<%-- $Id: exception.jsp 6309 2013-08-21 11:42:30Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) 2005 Nicklas Nordborg
4  Copyright (C) 2006 Johan Enell, Jari Häkkinen, 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 3
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 BASE. If not, see <http://www.gnu.org/licenses/>.
22  ------------------------------------------------------------------
23
24  All exceptions are directed to this page, by the server configuration
25  See <error-page> tag in the /WEB-INF/web.xml file.
26
27  Some exceptions are fowarded to other pages to be able to
28  display a more appropriate error message.
29
30  Only severe, unexpected exceptions, are handled by this page,
31  which will only display a stack trace!
32
33  @author Nicklas
34  @version 2.0
35--%>
36<%@ page pageEncoding="UTF-8" session="false"
37  import="net.sf.basedb.core.Application"
38  import="net.sf.basedb.core.Config"
39  import="net.sf.basedb.core.NotLoggedInException"
40  import="net.sf.basedb.core.PermissionDeniedException"
41  import="net.sf.basedb.core.InvalidDataException"
42  import="net.sf.basedb.core.SessionControl"
43  import="net.sf.basedb.clients.web.WebException"
44  import="net.sf.basedb.clients.web.DuplicateWizardException"
45  import="net.sf.basedb.clients.web.Base"
46  import="net.sf.basedb.clients.web.util.HTML"
47  import="net.sf.basedb.util.Values"
48  import="javax.servlet.ServletException"
49  import="java.sql.Driver"
50  import="java.util.Properties"
51  isErrorPage="true"
52%>
53<%@
54  taglib prefix="base" uri="/WEB-INF/base.tld" %>
55<%
56  final SessionControl sc = Base.getSessionControl(pageContext, false);
57  final String reportbuglink = sc == null ? "" : Values.getStringOrNull(sc.getClientDefaultSetting("server.links.reportbug"));
58  Throwable ex = exception;
59 
60  if (ex instanceof org.apache.jasper.JasperException)
61  {
62    org.apache.jasper.JasperException jex = (org.apache.jasper.JasperException)ex;
63    ex = jex.getRootCause();
64  }
65 
66  if (ex instanceof ServletException)
67  {
68    ServletException sex = (ServletException)ex;
69    if (sex.getRootCause() != null) ex = sex.getRootCause();
70  }
71 
72  if (ex instanceof WebException)
73  {
74    pageContext.forward("/exception/web.jsp");
75    return;
76  }
77  else if (ex instanceof DuplicateWizardException)
78  {
79    pageContext.forward("/exception/duplicate_wizard.jsp");
80    return;
81  }
82  else if (ex instanceof NotLoggedInException)
83  {
84    pageContext.forward("/exception/not_logged_in.jsp");
85    return;
86  }
87  else if (ex instanceof PermissionDeniedException)
88  {
89    pageContext.forward("/exception/permission_denied.jsp");
90    return;
91  }
92  else if (ex instanceof InvalidDataException)
93  {
94    pageContext.forward("/exception/invalid_data.jsp");
95    return;
96  }
97
98  final String jdbcDriver = Config.getString("db.driver");
99  String driverVersion = "";
100  try
101  {
102    final Driver driver = (Driver)Class.forName(jdbcDriver).newInstance();
103    driverVersion = "(version " + driver.getMajorVersion() + "." + driver.getMinorVersion() + ")";
104  }
105  catch (Throwable t)
106  {} 
107  final Properties properties = System.getProperties();
108  final Runtime runtime = Runtime.getRuntime();
109  String exceptionClassName = ex.getClass().getName().replaceAll("net.sf.basedb.core.", "");
110%>
111<base:page type="default" menu="exception" title="Unexpected error">
112<base:head scripts="exception.js" styles="popup.css" />
113<base:body data-resize-if-popup="1">
114  <h1><%=exceptionClassName + " on page "+request.getAttribute("javax.servlet.error.request_uri")%></h1>
115 
116  <div class="content bottomborder" style="bottom: 3em;">
117    <table class="fullform outlined topborder">
118    <tr>
119      <th>BASE Version</th>
120      <td><%=Application.getVersionString()%></td>
121    </tr>
122    <tr>
123      <th>Web server</th>
124      <td><%=application.getServerInfo()%></td>
125    </tr>
126    <tr>
127      <th>Database Server</th>
128      <td><%=Application.getDatabaseVersionString()%></td>
129    </tr>
130    <tr>
131      <th>Database Dialect</th>
132      <td><%=Config.getString("db.dialect")%></td>
133    </tr>
134    <tr>
135      <th>JDBC Driver</th>
136      <td><%=jdbcDriver%> <%=driverVersion%></td>
137    </tr>
138    <tr>
139      <th>Operating system</th>
140      <td><%=properties.getProperty("os.name")%> 
141        <%=properties.getProperty("os.arch")%>
142        <%=properties.getProperty("os.version")%>
143        </td>
144    </tr>
145    <tr>
146      <th>Java runtime</th>
147      <td><%=properties.getProperty("java.runtime.name")%> 
148        (<%=properties.getProperty("java.runtime.version")%>),
149        <a href="<%=properties.getProperty("java.vendor.url")%>" target="_blank"><%=properties.getProperty("java.vendor")%></a></td>
150    </tr>
151    <tr>
152      <th class="subprompt">Memory</th>
153      <td>Total: <%=Values.formatBytes(runtime.totalMemory())%><br>
154        Free: <%=Values.formatBytes(runtime.freeMemory()) %><br>
155        Max: <%=Values.formatBytes(runtime.maxMemory()) %></td>
156    </tr>
157    <tr>
158      <th>Browser</th>
159      <td><%=HTML.encodeTags(request.getHeader("User-Agent"))%></td>
160    </tr>
161    <tr>
162      <th>Error message</th>
163      <td><%=HTML.formatLineBreaks(HTML.encodeTags(ex.getMessage(), ""))%></td>
164    </tr>
165    <tr class="dynamic">
166      <th>Stacktrace</th>
167      <td>
168        <%
169        StackTraceElement[] st = ex.getStackTrace();
170        out.println("<pre>");
171        out.println(exceptionClassName);
172        int i = 0;
173        for (i=0; i < st.length && i < 8; i++)
174        {
175          out.print("...at ");
176          out.println(HTML.encodeTags(st[i].toString().replaceAll("net.sf.basedb.core.", "")));
177        }
178        out.println("</pre>");
179        if ((i < st.length) || (ex.getCause() != null))
180        {
181          out.println("<pre id=\"error_detail\" style=\"display:none;\">");
182          while (ex != null)
183          {
184            for (int j=i; j < st.length; j++)
185            {
186              out.print("...at ");
187              out.println(HTML.encodeTags(st[j].toString().replaceAll("net.sf.basedb.core.", "")));
188            }
189            ex = ex.getCause();
190            if (ex != null)
191            {
192              st = ex.getStackTrace();
193              i = 0;
194              out.print("\nCaused by: "+ex.getClass().getName()+": " + ex.getMessage() + "\n");
195            }
196          }
197          out.println("</pre>");
198        }
199        %>
200        <base:icon 
201          id="showMoreDetails"
202          data-show-id="error_detail"
203          image="gonext.png"><%=st.length-i%> more...</base:icon>
204      </td>
205    </table>
206  </div>
207 
208  <base:buttongroup subclass="dialogbuttons">
209    <base:button id="goback" title="Back"/>
210    <base:button id="close" title="Close"/>
211    <base:button id="reportbug" title="Report bug&hellip;" image="bug.png"
212      data-report-link="<%=HTML.encodeTags(reportbuglink) %>"
213      visible="<%=HTML.isValidUrl(reportbuglink)%>"/>
214  </base:buttongroup>
215
216</base:body>
217</base:page>
218
Note: See TracBrowser for help on using the repository browser.