[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] [metrics-web/master] Add redirects for deleted pages.
Author: Karsten Loesing <karsten.loesing@xxxxxxx>
Date: Tue, 19 Oct 2010 08:25:09 +0200
Subject: Add redirects for deleted pages.
Commit: 4931f5c91bd6a1b37096c4b7a0960ee0cad8c69b
---
etc/web.xml | 43 +++++++++++++++++++
src/org/torproject/ernie/web/RedirectServlet.java | 47 +++++++++++++++++++++
2 files changed, 90 insertions(+), 0 deletions(-)
create mode 100644 src/org/torproject/ernie/web/RedirectServlet.java
diff --git a/etc/web.xml b/etc/web.xml
index 169160b..c1b57fa 100644
--- a/etc/web.xml
+++ b/etc/web.xml
@@ -270,6 +270,49 @@
<url-pattern>/consensus-health-2.html</url-pattern>
</servlet-mapping>
+ <servlet>
+ <servlet-name>Redirect</servlet-name>
+ <servlet-class>
+ org.torproject.ernie.web.RedirectServlet
+ </servlet-class>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>Redirect</servlet-name>
+ <url-pattern>/networksize.html</url-pattern>
+ </servlet-mapping>
+ <servlet-mapping>
+ <servlet-name>Redirect</servlet-name>
+ <url-pattern>/exit-relays-graphs.html</url-pattern>
+ </servlet-mapping>
+ <servlet-mapping>
+ <servlet-name>Redirect</servlet-name>
+ <url-pattern>/bridge-users-graphs.html</url-pattern>
+ </servlet-mapping>
+ <servlet-mapping>
+ <servlet-name>Redirect</servlet-name>
+ <url-pattern>/new-users-graphs.html</url-pattern>
+ </servlet-mapping>
+ <servlet-mapping>
+ <servlet-name>Redirect</servlet-name>
+ <url-pattern>/consensus-graphs.html</url-pattern>
+ </servlet-mapping>
+ <servlet-mapping>
+ <servlet-name>Redirect</servlet-name>
+ <url-pattern>/recurring-users-graphs.html</url-pattern>
+ </servlet-mapping>
+ <servlet-mapping>
+ <servlet-name>Redirect</servlet-name>
+ <url-pattern>/torperf-graphs.html</url-pattern>
+ </servlet-mapping>
+ <servlet-mapping>
+ <servlet-name>Redirect</servlet-name>
+ <url-pattern>/gettor-graphs.html</url-pattern>
+ </servlet-mapping>
+ <servlet-mapping>
+ <servlet-name>Redirect</servlet-name>
+ <url-pattern>/custom-graph.html</url-pattern>
+ </servlet-mapping>
+
<context-param>
<param-name>jdbcUrl</param-name>
<param-value>
diff --git a/src/org/torproject/ernie/web/RedirectServlet.java b/src/org/torproject/ernie/web/RedirectServlet.java
new file mode 100644
index 0000000..6b5e2be
--- /dev/null
+++ b/src/org/torproject/ernie/web/RedirectServlet.java
@@ -0,0 +1,47 @@
+package org.torproject.ernie.web;
+
+import javax.servlet.*;
+import javax.servlet.http.*;
+import java.io.*;
+import java.util.*;
+
+public class RedirectServlet extends HttpServlet {
+
+ private Map<String, String> redirects;
+
+ public void init() {
+
+ /* Initialize map containing redirects. */
+ redirects = new HashMap<String, String>();
+ redirects.put("networksize.html", "/network.html");
+ redirects.put("exit-relays-graphs.html", "/network.html");
+ redirects.put("bridge-users-graphs.html", "/users.html");
+ redirects.put("new-users-graphs.html", "/users.html");
+ redirects.put("consensus-graphs.html", "/network.html");
+ redirects.put("recurring-users-graphs.html", "/users.html");
+ redirects.put("torperf-graphs.html", "/performance.html");
+ redirects.put("gettor-graphs.html", "/packages.html");
+ redirects.put("custom-graph.html", "/graphs.html");
+ }
+
+ public void doGet(HttpServletRequest request,
+ HttpServletResponse response) throws IOException, ServletException {
+
+ /* Find out which page was requested. */
+ String requestedPage = request.getRequestURI();
+ if (requestedPage.contains("/")) {
+ requestedPage = requestedPage.substring(requestedPage.
+ lastIndexOf("/") + 1);
+ }
+
+ /* Make sure we know where to redirect this request. */
+ if (!redirects.containsKey(requestedPage)) {
+ response.sendError(HttpServletResponse.SC_NOT_FOUND, requestedPage);
+ return;
+ }
+
+ /* Redirect the request. */
+ response.sendRedirect(redirects.get(requestedPage));
+ }
+}
+
--
1.7.1