From d7d058e772aa70230338b356d1407a2745459f06 Mon Sep 17 00:00:00 2001 From: zzz Date: Sun, 29 Nov 2009 17:58:24 +0000 Subject: [PATCH] addressbook servlet cleanup --- .../java/src/net/i2p/addressbook/Servlet.java | 31 +++++++++++-------- apps/addressbook/web.xml | 2 +- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/apps/addressbook/java/src/net/i2p/addressbook/Servlet.java b/apps/addressbook/java/src/net/i2p/addressbook/Servlet.java index c5239609e..fceecfe53 100644 --- a/apps/addressbook/java/src/net/i2p/addressbook/Servlet.java +++ b/apps/addressbook/java/src/net/i2p/addressbook/Servlet.java @@ -21,6 +21,8 @@ package net.i2p.addressbook; +import java.io.IOException; +import java.io.PrintWriter; import java.util.Random; import javax.servlet.ServletConfig; @@ -39,8 +41,8 @@ import javax.servlet.http.HttpServletResponse; * */ public class Servlet extends HttpServlet { - private Thread _thread; - private String _nonce; + private Thread thread; + private String nonce; private static final String PROP_NONCE = "addressbook.nonce"; /** @@ -50,14 +52,17 @@ public class Servlet extends HttpServlet { * (non-Javadoc) * see javax.servlet.Servlet#service(javax.servlet.ServletRequest, javax.servlet.ServletResponse) */ - public void service(HttpServletRequest request, HttpServletResponse response) { + public void service(HttpServletRequest request, HttpServletResponse response) throws IOException { //System.err.println("Got request nonce = " + request.getParameter("nonce")); - if (_thread != null && request.getParameter("wakeup") != null && - _nonce != null && _nonce.equals(request.getParameter("nonce"))) { + if (this.thread != null && request.getParameter("wakeup") != null && + this.nonce != null && this.nonce.equals(request.getParameter("nonce"))) { //System.err.println("Sending interrupt"); - _thread.interrupt(); + this.thread.interrupt(); + // no output + } else { + PrintWriter out = response.getWriter(); + out.write("I2P addressbook OK"); } - // no output } /* (non-Javadoc) @@ -70,15 +75,15 @@ public class Servlet extends HttpServlet { } catch (ServletException exp) { System.err.println("Addressbook init exception: " + exp); } - _nonce = "" + Math.abs((new Random()).nextLong()); + this.nonce = "" + Math.abs((new Random()).nextLong()); // put the nonce where susidns can get it - System.setProperty(PROP_NONCE, _nonce); + System.setProperty(PROP_NONCE, this.nonce); String[] args = new String[1]; args[0] = config.getInitParameter("home"); - _thread = new DaemonThread(args); - _thread.setDaemon(true); - _thread.setName("Addressbook"); - _thread.start(); + this.thread = new DaemonThread(args); + this.thread.setDaemon(true); + this.thread.setName("Addressbook"); + this.thread.start(); System.out.println("INFO: Starting Addressbook " + Daemon.VERSION); //System.out.println("INFO: config root under " + args[0]); } diff --git a/apps/addressbook/web.xml b/apps/addressbook/web.xml index c5fe302a6..6dd20ea1b 100644 --- a/apps/addressbook/web.xml +++ b/apps/addressbook/web.xml @@ -16,7 +16,7 @@ addressbook - / + *