SusiDNS: Add addressbook.jar to classpath, don't fail to start

if it's still not found (ticket #1973)
This fix covers:
1) Old wrapper.config without addressbook in the classpath
2) Java 9 together with 1)
3) Completely missing addressbook.jar
This does not fix addressbook.jar missing from Debian build.
This commit is contained in:
zzz
2017-03-27 14:43:20 +00:00
parent c1991241e4
commit ed590cd6f5
2 changed files with 42 additions and 11 deletions

View File

@ -98,7 +98,11 @@ public class WebAppConfiguration implements Configuration {
// Ticket #957... don't know why...
// Only really required if started manually, but we don't know that from here
cp = "jetty-util.jar";
} else ****/ if (pluginDir.exists()) {
****/
if (ctxPath.equals("/susidns")) {
// Old installs don't have this in their wrapper.config classpath
cp = "addressbook.jar";
} else if (pluginDir.exists()) {
File consoleDir = new File(pluginDir, "console");
Properties props = RouterConsoleRunner.webAppProperties(consoleDir.getAbsolutePath());
cp = props.getProperty(RouterConsoleRunner.PREFIX + appName + CLASSPATH);
@ -174,11 +178,13 @@ public class WebAppConfiguration implements Configuration {
}
} else {
// Java 9 - assume everything in lib/ is in the classpath
// except addressbook.jar
File libDir = new File(ctx.getBaseDir(), "lib");
File[] files = libDir.listFiles();
if (files != null) {
for (int i = 0; i < files.length; i++) {
if (files[i].getName().endsWith(".jar"))
String name = files[i].getName();
if (name.endsWith(".jar") && !name.equals("addressbook.jar"))
rv.add(files[i].toURI());
}
}

View File

@ -30,7 +30,9 @@ import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import net.i2p.addressbook.DaemonThread;
import net.i2p.I2PAppContext;
//import net.i2p.addressbook.DaemonThread;
import net.i2p.util.Log;
/**
* A wrapper for addressbook to allow it to be started as a web application.
@ -45,7 +47,7 @@ import net.i2p.addressbook.DaemonThread;
public class Servlet extends HttpServlet {
private static final long serialVersionUID = 1L;
private transient DaemonThread thread;
private transient Thread thread;
//private String nonce;
//private static final String PROP_NONCE = "addressbook.nonce";
@ -71,6 +73,7 @@ public class Servlet extends HttpServlet {
/* (non-Javadoc)
* @see javax.servlet.Servlet#init(javax.servlet.ServletConfig)
*/
@SuppressWarnings("unchecked")
@Override
public void init(ServletConfig config) {
try {
@ -83,17 +86,39 @@ public class Servlet extends HttpServlet {
//System.setProperty(PROP_NONCE, this.nonce);
String[] args = new String[1];
args[0] = config.getInitParameter("home");
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]);
try {
ClassLoader cl = getServletContext().getClassLoader();
Class cls = Class.forName("net.i2p.addressbook.DaemonThread", true, cl);
// We do it this way so that if we can't find addressbook,
// the whole thing doesn't die.
// We do add addressbook.jar in WebAppConfiguration,
// so this is just in case.
//Thread t = new DaemonThread(args);
Thread t = (Thread) cls.getConstructor(String[].class).newInstance((Object)args);
t.setDaemon(true);
t.setName("Addressbook");
t.start();
this.thread = t;
//System.out.println("INFO: Starting Addressbook " + Daemon.VERSION);
//System.out.println("INFO: config root under " + args[0]);
} catch (Throwable t) {
// addressbook.jar may not be in the classpath
I2PAppContext.getGlobalContext().logManager().getLog(Servlet.class).logAlways(Log.WARN, "Addressbook thread not started: " + t);
}
}
@SuppressWarnings("unchecked")
@Override
public void destroy() {
this.thread.halt();
if (this.thread != null) {
//((DaemonThread)this.thread).halt();
try {
ClassLoader cl = getServletContext().getClassLoader();
Class<?> cls = Class.forName("net.i2p.addressbook.DaemonThread", true, cl);
Object t = cls.cast(this.thread);
cls.getDeclaredMethod("halt").invoke(t);
} catch (Throwable t) {}
}
super.destroy();
}
}