[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] [metrics-web/master 2/2] Add error page containing a sitemap.



Author: Karsten Loesing <karsten.loesing@xxxxxxx>
Date: Tue, 19 Oct 2010 12:31:30 +0200
Subject: Add error page containing a sitemap.
Commit: 51ce1dac12bfac7c432342d61163b3c7994c01fb

---
 etc/web.xml                                        |   18 +++++
 src/org/torproject/ernie/web/ConsensusServlet.java |   12 ++--
 .../torproject/ernie/web/DescriptorServlet.java    |    1 -
 .../ernie/web/ErnieGeneratedFileServlet.java       |    2 +-
 .../ernie/web/ExtraInfoDescriptorServlet.java      |   10 ++--
 src/org/torproject/ernie/web/RelayServlet.java     |    1 -
 .../ernie/web/ServerDescriptorServlet.java         |   10 ++--
 web/WEB-INF/error.jsp                              |   75 ++++++++++++++++++++
 8 files changed, 110 insertions(+), 19 deletions(-)
 create mode 100644 web/WEB-INF/error.jsp

diff --git a/etc/web.xml b/etc/web.xml
index c1b57fa..02f682e 100644
--- a/etc/web.xml
+++ b/etc/web.xml
@@ -323,5 +323,23 @@
   <welcome-file-list>
     <welcome-file>index.html</welcome-file>
   </welcome-file-list>
+
+  <error-page>
+    <error-code>400</error-code>
+    <location>/WEB-INF/error.jsp</location>
+  </error-page>
+  <error-page>
+    <error-code>404</error-code>
+    <location>/WEB-INF/error.jsp</location>
+  </error-page>
+  <error-page>
+    <error-code>500</error-code>
+    <location>/WEB-INF/error.jsp</location>
+  </error-page>
+  <error-page>
+    <exception-type>java.lang.Throwable</exception-type>
+    <location>/WEB-INF/error.jsp</location>
+  </error-page>
+
 </web-app>
 
diff --git a/src/org/torproject/ernie/web/ConsensusServlet.java b/src/org/torproject/ernie/web/ConsensusServlet.java
index 7be0600..97577c8 100644
--- a/src/org/torproject/ernie/web/ConsensusServlet.java
+++ b/src/org/torproject/ernie/web/ConsensusServlet.java
@@ -21,14 +21,14 @@ public class ConsensusServlet extends HttpServlet {
         + "directory-archive/consensus");
     if (!archiveDirectory.exists() || !archiveDirectory.isDirectory()) {
       /* Oops, we don't have any descriptors to serve. */
-      response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+      response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
       return;
     }
 
     /* Check valid-after parameter. */
     if (validAfterParameter == null ||
-        validAfterParameter.length() < "yyyy-MM-dd-HH-mm-ss".length()) {
-      response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
+        validAfterParameter.length() != "yyyy-MM-dd-HH-mm-ss".length()) {
+      response.sendError(HttpServletResponse.SC_BAD_REQUEST);
       return;
     }
     SimpleDateFormat timeFormat = new SimpleDateFormat(
@@ -38,11 +38,11 @@ public class ConsensusServlet extends HttpServlet {
     try {
       parsedTimestamp = timeFormat.parse(validAfterParameter);
     } catch (ParseException e) {
-      response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
+      response.sendError(HttpServletResponse.SC_BAD_REQUEST);
       return;
     }
     if (parsedTimestamp == null) {
-      response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
+      response.sendError(HttpServletResponse.SC_BAD_REQUEST);
       return;
     }
     String consensusFilename = archiveDirectory.getAbsolutePath()
@@ -53,7 +53,7 @@ public class ConsensusServlet extends HttpServlet {
     File consensusFile = new File(consensusFilename);
 
     if (!consensusFile.exists()) {
-      response.setStatus(HttpServletResponse.SC_NOT_FOUND);
+      response.sendError(HttpServletResponse.SC_NOT_FOUND);
       return;
     }
 
diff --git a/src/org/torproject/ernie/web/DescriptorServlet.java b/src/org/torproject/ernie/web/DescriptorServlet.java
index fb2443b..b389253 100644
--- a/src/org/torproject/ernie/web/DescriptorServlet.java
+++ b/src/org/torproject/ernie/web/DescriptorServlet.java
@@ -75,7 +75,6 @@ public class DescriptorServlet extends HttpServlet {
         + "              <a class=\"current\">Relay Search</a>\n"
         + "              <a href=\"consensus-health.html\">Consensus "
           + "Health</a>\n"
-        + "              <a href=\"log.html\">Last Log</a>\n"
         + "            </font>\n"
         + "          </td>\n"
         + "          <td class=\"banner-right\"></td>\n"
diff --git a/src/org/torproject/ernie/web/ErnieGeneratedFileServlet.java b/src/org/torproject/ernie/web/ErnieGeneratedFileServlet.java
index 747b16d..f4bd066 100644
--- a/src/org/torproject/ernie/web/ErnieGeneratedFileServlet.java
+++ b/src/org/torproject/ernie/web/ErnieGeneratedFileServlet.java
@@ -25,7 +25,7 @@ public class ErnieGeneratedFileServlet extends HttpServlet {
     try {
       File f = new File(fn);
       if (!f.exists()) {
-        response.setStatus(HttpServletResponse.SC_NOT_FOUND);
+        response.sendError(HttpServletResponse.SC_NOT_FOUND);
         return;
       }
       response.setContentType(this.getServletContext().getMimeType(f.getName()));
diff --git a/src/org/torproject/ernie/web/ExtraInfoDescriptorServlet.java b/src/org/torproject/ernie/web/ExtraInfoDescriptorServlet.java
index aee9be0..3179144 100644
--- a/src/org/torproject/ernie/web/ExtraInfoDescriptorServlet.java
+++ b/src/org/torproject/ernie/web/ExtraInfoDescriptorServlet.java
@@ -39,21 +39,21 @@ public class ExtraInfoDescriptorServlet extends HttpServlet {
 
     /* Check if we have a database connection. */
     if (conn == null) {
-      //response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+      //response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
       return;
     }
 
     /* Check desc-id parameter. */
     String descIdParameter = request.getParameter("desc-id");
     if (descIdParameter == null || descIdParameter.length() < 8) {
-      response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
+      response.sendError(HttpServletResponse.SC_BAD_REQUEST);
       return;
     }
     String descId = descIdParameter.toLowerCase();
     Pattern descIdPattern = Pattern.compile("^[0-9a-f]+$");
     Matcher descIdMatcher = descIdPattern.matcher(descId);
     if (!descIdMatcher.matches()) {
-      response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
+      response.sendError(HttpServletResponse.SC_BAD_REQUEST);
       return;
     }
 
@@ -70,13 +70,13 @@ public class ExtraInfoDescriptorServlet extends HttpServlet {
         rawDescriptor = rs.getBytes(2);
       }
     } catch (SQLException e) {
-      response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+      response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
       return;
     }
 
     /* Write response. */
     if (rawDescriptor == null) {
-      response.setStatus(HttpServletResponse.SC_NOT_FOUND);
+      response.sendError(HttpServletResponse.SC_NOT_FOUND);
       return;
     }
     try {
diff --git a/src/org/torproject/ernie/web/RelayServlet.java b/src/org/torproject/ernie/web/RelayServlet.java
index f6af3d9..052a126 100644
--- a/src/org/torproject/ernie/web/RelayServlet.java
+++ b/src/org/torproject/ernie/web/RelayServlet.java
@@ -82,7 +82,6 @@ public class RelayServlet extends HttpServlet {
         + "              <a class=\"current\">Relay Search</a>\n"
         + "              <a href=\"consensus-health.html\">Consensus "
           + "Health</a>\n"
-        + "              <a href=\"log.html\">Last Log</a>\n"
         + "            </font>\n"
         + "          </td>\n"
         + "          <td class=\"banner-right\"></td>\n"
diff --git a/src/org/torproject/ernie/web/ServerDescriptorServlet.java b/src/org/torproject/ernie/web/ServerDescriptorServlet.java
index 23e4625..1a9cc1f 100644
--- a/src/org/torproject/ernie/web/ServerDescriptorServlet.java
+++ b/src/org/torproject/ernie/web/ServerDescriptorServlet.java
@@ -39,7 +39,7 @@ public class ServerDescriptorServlet extends HttpServlet {
 
     /* Check if we have a database connection. */
     if (conn == null) {
-      response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+      response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
       return;
     }
 
@@ -47,14 +47,14 @@ public class ServerDescriptorServlet extends HttpServlet {
     String descIdParameter = request.getParameter("desc-id");
     if (descIdParameter == null || descIdParameter.length() < 8 ||
         descIdParameter.length() > 40) {
-      response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
+      response.sendError(HttpServletResponse.SC_BAD_REQUEST);
       return;
     }
     String descId = descIdParameter.toLowerCase();
     Pattern descIdPattern = Pattern.compile("^[0-9a-f]+$");
     Matcher descIdMatcher = descIdPattern.matcher(descId);
     if (!descIdMatcher.matches()) {
-      response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
+      response.sendError(HttpServletResponse.SC_BAD_REQUEST);
       return;
     }
 
@@ -71,13 +71,13 @@ public class ServerDescriptorServlet extends HttpServlet {
         rawDescriptor = rs.getBytes(2);
       }
     } catch (SQLException e) {
-      response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+      response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
       return;
     }
 
     /* Write response. */
     if (rawDescriptor == null) {
-      response.setStatus(HttpServletResponse.SC_NOT_FOUND);
+      response.sendError(HttpServletResponse.SC_NOT_FOUND);
       return;
     }
     try {
diff --git a/web/WEB-INF/error.jsp b/web/WEB-INF/error.jsp
new file mode 100644
index 0000000..3c713a3
--- /dev/null
+++ b/web/WEB-INF/error.jsp
@@ -0,0 +1,75 @@
+<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"; %>
+<%@ page isErrorPage="true" %>
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
+<html>
+<head>
+  <title>Tor Metrics Portal: Error</title>
+  <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
+  <link href="/css/stylesheet-ltr.css" type="text/css" rel="stylesheet">
+  <link href="/images/favicon.ico" type="image/x-icon" rel="shortcut icon">
+</head>
+<body>
+  <div class="center">
+    <%@ include file="banner.jsp"%>
+    <div class="main-column">
+<h2>Tor Metrics Portal: Error</h2>
+<br>
+<p>
+Oops! Something went wrong here! We encountered a
+<b>
+<c:choose>
+<c:when test="${pageContext.errorData.statusCode eq 400}">
+400 Bad Request
+</c:when>
+<c:when test="${pageContext.errorData.statusCode eq 404}">
+404 Not Found
+</c:when>
+<c:when test="${pageContext.errorData.statusCode eq 500}">
+500 Internal Server Error
+</c:when>
+<c:when test="${not empty pageContext.errorData.throwable}">
+${pageContext.exception}
+</c:when>
+<c:otherwise>
+Unknown Error
+</c:otherwise>
+</c:choose>
+</b>
+when processing your request!</p>
+
+<p>
+Maybe you find what you're looking for on our sitemap:
+<ul>
+<li><a href="index.html">Home</a></li>
+<li><a href="graphs.html">Graphs</a>
+<ul>
+<li><a href="network.html">Network</a></li>
+<li><a href="users.html">Users</a></li>
+<li><a href="packages.html">Packages</a></li>
+<li><a href="performance.html">Performance</a></li>
+</ul></li>
+<li><a href="research.html">Research</a>
+<ul>
+<li><a href="papers.html">Papers</a></li>
+<li><a href="data.html">Data</a></li>
+<li><a href="tools.html">Tools</a></li>
+</ul></li>
+<li><a href="status.html">Status</a>
+<ul>
+<li><a href="exonerator.html">ExoneraTor</a></li>
+<li><a href="relay-search.html">Relay Search</a></li>
+<li><a href="consensus-health.html">Consensus Health</a></li>
+</ul></li>
+</ul>
+</p>
+
+<p>If this problem persists, please
+<a href="mailto:tor-assistants@xxxxxxxxxxxxx";>let us know</a>!</p>
+
+    </div>
+  </div>
+  <div class="bottom" id="bottom">
+    <%@ include file="footer.jsp"%>
+  </div>
+</body>
+</html>
-- 
1.7.1