[tor-commits] [metrics-web/master] Rename servlet providing the consensus-health.

karsten at torproject.org karsten at torproject.org
Thu Mar 22 14:16:25 UTC 2012


commit 4a643a4ed21163dccec4226cb7a1164d9d591118
Author: Karsten Loesing <karsten.loesing at gmx.net>
Date:   Thu Mar 22 14:59:28 2012 +0100

    Rename servlet providing the consensus-health.
---
 etc/web.xml                                        |    6 +-
 .../ernie/web/ConsensusHealthServlet.java          |   57 ++++++++++++++++++
 .../ernie/web/ErnieGeneratedFileServlet.java       |   63 --------------------
 3 files changed, 60 insertions(+), 66 deletions(-)

diff --git a/etc/web.xml b/etc/web.xml
index c831f3f..a5bd7be 100644
--- a/etc/web.xml
+++ b/etc/web.xml
@@ -263,13 +263,13 @@
   </servlet-mapping>
 
   <servlet>
-    <servlet-name>ErnieGeneratedFile</servlet-name>
+    <servlet-name>ConsensusHealthServlet</servlet-name>
     <servlet-class>
-      org.torproject.ernie.web.ErnieGeneratedFileServlet
+      org.torproject.ernie.web.ConsensusHealthServlet
     </servlet-class>
   </servlet>
   <servlet-mapping>
-    <servlet-name>ErnieGeneratedFile</servlet-name>
+    <servlet-name>ConsensusHealthServlet</servlet-name>
     <url-pattern>/consensus-health.html</url-pattern>
   </servlet-mapping>
 
diff --git a/src/org/torproject/ernie/web/ConsensusHealthServlet.java b/src/org/torproject/ernie/web/ConsensusHealthServlet.java
new file mode 100644
index 0000000..2ca26d5
--- /dev/null
+++ b/src/org/torproject/ernie/web/ConsensusHealthServlet.java
@@ -0,0 +1,57 @@
+/* Copyright 2011, 2012 The Tor Project
+ * See LICENSE for licensing information */
+package org.torproject.ernie.web;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+public class ConsensusHealthServlet extends HttpServlet {
+
+  private static final long serialVersionUID = -5230032733057814869L;
+
+  public void doGet(HttpServletRequest request,
+      HttpServletResponse response) throws IOException,
+      ServletException {
+
+    /* Read file from disk and write it to response. */
+    BufferedInputStream input = null;
+    BufferedOutputStream output = null;
+    try {
+      File f = new File("/srv/metrics.torproject.org/ernie/website/"
+          + "consensus-health.html");
+      if (!f.exists()) {
+        response.sendError(HttpServletResponse.SC_NOT_FOUND);
+        return;
+      }
+      response.setContentType(this.getServletContext().getMimeType(f.getName()));
+      response.setHeader("Content-Length", String.valueOf(
+          f.length()));
+      response.setHeader("Content-Disposition",
+          "inline; filename=\"" + f.getName() + "\"");
+      input = new BufferedInputStream(new FileInputStream(f),
+          1024);
+      output = new BufferedOutputStream(response.getOutputStream(), 1024);
+      byte[] buffer = new byte[1024];
+      int length;
+      while ((length = input.read(buffer)) > 0) {
+          output.write(buffer, 0, length);
+      }
+    } finally {
+      if (output != null) {
+        output.close();
+      }
+      if (input != null) {
+        input.close();
+      }
+    }
+  }
+}
+
diff --git a/src/org/torproject/ernie/web/ErnieGeneratedFileServlet.java b/src/org/torproject/ernie/web/ErnieGeneratedFileServlet.java
deleted file mode 100644
index a303225..0000000
--- a/src/org/torproject/ernie/web/ErnieGeneratedFileServlet.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/* Copyright 2011, 2012 The Tor Project
- * See LICENSE for licensing information */
-package org.torproject.ernie.web;
-
-import java.io.BufferedInputStream;
-import java.io.BufferedOutputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-public class ErnieGeneratedFileServlet extends HttpServlet {
-
-  private static final long serialVersionUID = -5230032733057814869L;
-
-  public void doGet(HttpServletRequest request,
-      HttpServletResponse response) throws IOException,
-      ServletException {
-
-    /* Read file from disk and write it to response. */
-    String requestedURL = request.getRequestURI();
-    if (requestedURL.contains("/")) {
-      requestedURL = requestedURL.substring(requestedURL.
-          lastIndexOf("/"));
-    }
-    String fn = "/srv/metrics.torproject.org/ernie/website"
-        + requestedURL;
-    BufferedInputStream input = null;
-    BufferedOutputStream output = null;
-    try {
-      File f = new File(fn);
-      if (!f.exists()) {
-        response.sendError(HttpServletResponse.SC_NOT_FOUND);
-        return;
-      }
-      response.setContentType(this.getServletContext().getMimeType(f.getName()));
-      response.setHeader("Content-Length", String.valueOf(
-          f.length()));
-      response.setHeader("Content-Disposition",
-          "inline; filename=\"" + f.getName() + "\"");
-      input = new BufferedInputStream(new FileInputStream(f),
-          1024);
-      output = new BufferedOutputStream(response.getOutputStream(), 1024);
-      byte[] buffer = new byte[1024];
-      int length;
-      while ((length = input.read(buffer)) > 0) {
-          output.write(buffer, 0, length);
-      }
-    } finally {
-      if (output != null) {
-        output.close();
-      }
-      if (input != null) {
-        input.close();
-      }
-    }
-  }
-}
-



More information about the tor-commits mailing list