[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [exonerator/master] Prepare ExoneraTorServlet for integration into Tor Metrics.
commit bd235118ebe2505c571fd028f981dd3481dcfedd
Author: Karsten Loesing <karsten.loesing@xxxxxxx>
Date: Fri Aug 10 09:33:56 2018 +0200
Prepare ExoneraTorServlet for integration into Tor Metrics.
Also add a new ExoneraTorRedirectServlet that redirects to Tor
Metrics, and make it the default.
Implements #23549.
---
CHANGELOG.md | 11 +++++
src/build | 2 +-
.../exonerator/ExoneraTorRedirectServlet.java | 24 ++++++++++
.../metrics/exonerator/ExoneraTorServlet.java | 54 ++++++++++++----------
src/main/resources/web.xml | 11 ++++-
.../web/jsps/{index.jsp => exonerator.jsp} | 0
6 files changed, 76 insertions(+), 26 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4aa9c79..1faf5ed 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,14 @@
+# Changes in version 2.2.0 - 2018-08-??
+
+ * Medium changes
+ - Prepare ExoneraTorServlet for integration into Tor Metrics.
+ - Add a new ExoneraTorRedirectServlet that redirects to Tor
+ Metrics, and make it the default.
+
+ * Minor changes
+ - Provide a thin jar file without dependencies.
+
+
# Changes in version 2.1.0 - 2018-05-29
* Medium changes
diff --git a/src/build b/src/build
index 23c6e0b..08514a3 160000
--- a/src/build
+++ b/src/build
@@ -1 +1 @@
-Subproject commit 23c6e0be5fab9463f137615053ef412e4da2315e
+Subproject commit 08514a32afefbeef848b80f9a338ee840c282604
diff --git a/src/main/java/org/torproject/metrics/exonerator/ExoneraTorRedirectServlet.java b/src/main/java/org/torproject/metrics/exonerator/ExoneraTorRedirectServlet.java
new file mode 100644
index 0000000..fbe4e49
--- /dev/null
+++ b/src/main/java/org/torproject/metrics/exonerator/ExoneraTorRedirectServlet.java
@@ -0,0 +1,24 @@
+/* Copyright 2018 The Tor Project
+ * See LICENSE for licensing information */
+
+package org.torproject.metrics.exonerator;
+
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+public class ExoneraTorRedirectServlet extends HttpServlet {
+
+ private static final long serialVersionUID = 526889516976914884L;
+
+ @Override
+ public void doGet(HttpServletRequest request, HttpServletResponse response) {
+ String redirectUrl = "https://metrics.torproject.org/exonerator.html";
+ if (null != request.getQueryString()) {
+ redirectUrl += "?" + request.getQueryString();
+ }
+ response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
+ response.setHeader("Location", redirectUrl);
+ }
+}
+
diff --git a/src/main/java/org/torproject/metrics/exonerator/ExoneraTorServlet.java b/src/main/java/org/torproject/metrics/exonerator/ExoneraTorServlet.java
index 659f494..9099025 100644
--- a/src/main/java/org/torproject/metrics/exonerator/ExoneraTorServlet.java
+++ b/src/main/java/org/torproject/metrics/exonerator/ExoneraTorServlet.java
@@ -141,6 +141,9 @@ public class ExoneraTorServlet extends HttpServlet {
PrintWriter out = new PrintWriter(so);
this.writeHeader(out, rb, langStr);
+ /* Obtain request URL without query string parameters for links. */
+ String requestUrl = request.getRequestURL().toString();
+
/* Write form. */
boolean timestampOutOfRange = requestedDate.valid
&& (firstDate.valid && requestedDate.date.isBefore(firstDate.date)
@@ -155,43 +158,43 @@ public class ExoneraTorServlet extends HttpServlet {
/* If both parameters are empty, don't print any summary and exit.
* This is the start page. */
if ("".equals(relayIp) && requestedDate.empty) {
- this.writeFooter(out, rb, null, null);
+ this.writeFooter(out, rb, requestUrl, null, null);
/* If only one parameter is empty and the other is not, print summary
* with warning message and exit. */
} else if ("".equals(relayIp)) {
this.writeSummaryNoIp(out, rb);
- this.writeFooter(out, rb, null, null);
+ this.writeFooter(out, rb, requestUrl, null, null);
} else if (requestedDate.empty) {
this.writeSummaryNoTimestamp(out, rb);
- this.writeFooter(out, rb, null, null);
+ this.writeFooter(out, rb, requestUrl, null, null);
/* If there's an issue with parsing either of the parameters, print
* summary with error message and exit. */
} else if (relayIpHasError) {
this.writeSummaryInvalidIp(out, rb, ipParameter);
- this.writeFooter(out, rb, null, null);
+ this.writeFooter(out, rb, requestUrl, null, null);
} else if (!requestedDate.valid) {
this.writeSummaryInvalidTimestamp(out, rb, requestedDate.asRequested);
- this.writeFooter(out, rb, null, null);
+ this.writeFooter(out, rb, requestUrl, null, null);
/* If the timestamp is too recent, print summary with error message and
* exit. */
} else if (requestedDate.tooRecent) {
this.writeSummaryTimestampTooRecent(out, rb);
- this.writeFooter(out, rb, null, null);
+ this.writeFooter(out, rb, requestUrl, null, null);
/* If we were unable to connect to the database,
* write an error message. */
} else if (!successfullyConnectedToBackend) {
this.writeSummaryUnableToConnectToBackend(out, rb);
- this.writeFooter(out, rb, null, null);
+ this.writeFooter(out, rb, requestUrl, null, null);
/* Similarly, if we found the database to be empty,
* write an error message, too. */
} else if (firstDate.empty || lastDate.empty) {
this.writeSummaryNoData(out, rb);
- this.writeFooter(out, rb, null, null);
+ this.writeFooter(out, rb, requestUrl, null, null);
/* If the requested date is out of range, tell the user. */
} else if (timestampOutOfRange) {
@@ -199,11 +202,11 @@ public class ExoneraTorServlet extends HttpServlet {
this.writeSummaryTimestampOutsideRange(out, rb, requestedDate.asString,
firstDate.asString, lastDate.date.isBefore(dayBeforeYesterday)
? lastDate.asString : dayBeforeYesterday.format(ISO_LOCAL_DATE));
- this.writeFooter(out, rb, relayIp, requestedDate.asString);
+ this.writeFooter(out, rb, requestUrl, relayIp, requestedDate.asString);
} else if (noRelevantConsensuses) {
this.writeSummaryNoDataForThisInterval(out, rb);
- this.writeFooter(out, rb, relayIp, requestedDate.asString);
+ this.writeFooter(out, rb, requestUrl, relayIp, requestedDate.asString);
/* Print out result. */
} else {
@@ -218,15 +221,15 @@ public class ExoneraTorServlet extends HttpServlet {
} else {
this.writeSummaryNegative(out, rb, relayIp, requestedDate.asString);
}
- this.writePermanentLink(out, rb, relayIp, requestedDate.asString,
- langStr);
- this.writeFooter(out, rb, relayIp, requestedDate.asString);
+ this.writePermanentLink(out, rb, requestUrl, relayIp,
+ requestedDate.asString, langStr);
+ this.writeFooter(out, rb, requestUrl, relayIp, requestedDate.asString);
}
/* Forward to the JSP that adds header and footer. */
request.setAttribute("lang", langStr);
request.setAttribute("body", so.toString());
- request.getRequestDispatcher("WEB-INF/index.jsp").forward(request,
+ request.getRequestDispatcher("WEB-INF/exonerator.jsp").forward(request,
response);
} catch (Throwable th) {
logger.error("Some problem in doGet. Returning error.", th);
@@ -334,7 +337,7 @@ public class ExoneraTorServlet extends HttpServlet {
+ " <div class=\"col-xs-12\">\n"
+ " <div class=\"text-center\">\n"
+ " <div class=\"row vbottom15\">\n"
- + " <h4>%s</h4>\n"
+ + " <p>%s</p>\n"
+ " </div> <!-- row -->\n"
+ " <form class=\"form-inline\">\n"
+ " <div class=\"form-group%s\">\n"
@@ -605,22 +608,24 @@ public class ExoneraTorServlet extends HttpServlet {
}
private void writePermanentLink(PrintWriter out, ResourceBundle rb,
- String relayIp, String timestampStr, String langStr) throws IOException {
+ String requestUrl, String relayIp, String timestampStr, String langStr)
+ throws IOException {
String encodedAddress = relayIp.contains(":")
? "[" + relayIp.replaceAll(":", "%3A") + "]" : relayIp;
out.printf(" <div class=\"row\">\n"
+ " <div class=\"col-xs-12\">\n"
+ " <h2>%s</h2>\n"
- + " <pre>https://exonerator.torproject.org/?ip=%s&"
+ + " <pre>%s?ip=%s&"
+ "timestamp=%s&lang=%s</pre>\n"
+ " </div><!-- col -->\n"
+ " </div><!-- row -->\n",
- rb.getString("permanentlink.heading"),
+ rb.getString("permanentlink.heading"), requestUrl,
encodedAddress, timestampStr, langStr);
}
- private void writeFooter(PrintWriter out, ResourceBundle rb, String relayIp,
- String timestampStr) throws IOException {
+ private void writeFooter(PrintWriter out, ResourceBundle rb,
+ String requestUrl, String relayIp, String timestampStr)
+ throws IOException {
out.printf(" </div><!-- container -->\n"
+ " <div class=\"container\">\n"
+ " <div class=\"row\">\n"
@@ -651,11 +656,12 @@ public class ExoneraTorServlet extends HttpServlet {
for (Map.Entry<String, String> entry
: this.availableLanguageNames.entrySet()) {
if (null != relayIp && null != timestampStr) {
- out.printf(" <a href=\"/?ip=%s×tamp=%s&lang=%s\">%s</a>",
- relayIp, timestampStr, entry.getKey(), entry.getValue());
+ out.printf(" <a href=\"%s?ip=%s×tamp=%s&lang=%s\">%s</a>",
+ requestUrl, relayIp, timestampStr, entry.getKey(),
+ entry.getValue());
} else {
- out.printf(" <a href=\"/?lang=%s\">%s</a>",
- entry.getKey(), entry.getValue());
+ out.printf(" <a href=\"%s?lang=%s\">%s</a>",
+ requestUrl, entry.getKey(), entry.getValue());
}
}
out.printf("</p>\n"
diff --git a/src/main/resources/web.xml b/src/main/resources/web.xml
index 62bf96f..f2ebbec 100644
--- a/src/main/resources/web.xml
+++ b/src/main/resources/web.xml
@@ -6,10 +6,19 @@
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
metadata-complete="false" >
+ <!--
+
+ Notice: By default, we redirect all requests to:
+ https://metrics.torproject.org/exonerator.html
+
+ If this is not the desired behavior, simply replace the servlet-class below
+ with org.torproject.metrics.exonerator.ExoneraTorServlet and redeploy.
+
+ -->
<servlet>
<servlet-name>ExoneraTor</servlet-name>
<servlet-class>
- org.torproject.metrics.exonerator.ExoneraTorServlet
+ org.torproject.metrics.exonerator.ExoneraTorRedirectServlet
</servlet-class>
</servlet>
<servlet-mapping>
diff --git a/src/main/resources/web/jsps/index.jsp b/src/main/resources/web/jsps/exonerator.jsp
similarity index 100%
rename from src/main/resources/web/jsps/index.jsp
rename to src/main/resources/web/jsps/exonerator.jsp
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits