[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] [ernie/master 4/5] Add servlet to return static content generated by ERNIE.
Author: Karsten Loesing <karsten.loesing@xxxxxxx>
Date: Wed, 19 May 2010 14:59:57 +0200
Subject: Add servlet to return static content generated by ERNIE.
Commit: 314caf945772db84d65bcbd3d92ee0ec9fe75763
---
etc/web.xml | 40 ++++++++++++++++
.../ernie/web/ErnieGeneratedFileServlet.java | 49 ++++++++++++++++++++
2 files changed, 89 insertions(+), 0 deletions(-)
create mode 100644 src/org/torproject/ernie/web/ErnieGeneratedFileServlet.java
diff --git a/etc/web.xml b/etc/web.xml
index 885a632..cf9280d 100644
--- a/etc/web.xml
+++ b/etc/web.xml
@@ -42,5 +42,45 @@
<servlet-name>Consensus</servlet-name>
<url-pattern>/consensus</url-pattern>
</servlet-mapping>
+ <servlet>
+ <servlet-name>ErnieGeneratedFile</servlet-name>
+ <servlet-class>org.torproject.ernie.web.ErnieGeneratedFileServlet</servlet-class>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>ErnieGeneratedFile</servlet-name>
+ <url-pattern>/log.html</url-pattern>
+ </servlet-mapping>
+ <servlet-mapping>
+ <servlet-name>ErnieGeneratedFile</servlet-name>
+ <url-pattern>/papers/*</url-pattern>
+ </servlet-mapping>
+ <servlet-mapping>
+ <servlet-name>ErnieGeneratedFile</servlet-name>
+ <url-pattern>/reports/*</url-pattern>
+ </servlet-mapping>
+ <servlet-mapping>
+ <servlet-name>ErnieGeneratedFile</servlet-name>
+ <url-pattern>/consensus-health.html</url-pattern>
+ </servlet-mapping>
+ <servlet-mapping>
+ <servlet-name>ErnieGeneratedFile</servlet-name>
+ <url-pattern>/consensus-health-1.html</url-pattern>
+ </servlet-mapping>
+ <servlet-mapping>
+ <servlet-name>ErnieGeneratedFile</servlet-name>
+ <url-pattern>/consensus-health-2.html</url-pattern>
+ </servlet-mapping>
+ <servlet-mapping>
+ <servlet-name>ErnieGeneratedFile</servlet-name>
+ <url-pattern>/csv/*</url-pattern>
+ </servlet-mapping>
+ <servlet-mapping>
+ <servlet-name>ErnieGeneratedFile</servlet-name>
+ <url-pattern>/graphs/*</url-pattern>
+ </servlet-mapping>
+ <servlet-mapping>
+ <servlet-name>ErnieGeneratedFile</servlet-name>
+ <url-pattern>/data/*</url-pattern>
+ </servlet-mapping>
</web-app>
diff --git a/src/org/torproject/ernie/web/ErnieGeneratedFileServlet.java b/src/org/torproject/ernie/web/ErnieGeneratedFileServlet.java
new file mode 100644
index 0000000..3670eb2
--- /dev/null
+++ b/src/org/torproject/ernie/web/ErnieGeneratedFileServlet.java
@@ -0,0 +1,49 @@
+package org.torproject.ernie.web;
+
+import javax.servlet.*;
+import javax.servlet.http.*;
+
+import java.io.*;
+import java.util.*;
+
+public class ErnieGeneratedFileServlet extends HttpServlet {
+
+ public void doGet(HttpServletRequest request,
+ HttpServletResponse response) throws IOException,
+ ServletException {
+
+ /* Read file from disk and write it to response. */
+ String fn = "/srv/metrics.torproject.org/ernie/website"
+ + request.getRequestURI();
+ BufferedInputStream input = null;
+ BufferedOutputStream output = null;
+ try {
+ File f = new File(fn);
+ if (!f.exists()) {
+ response.setStatus(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();
+ }
+ }
+ }
+}
+
--
1.6.5