forked from I2P_Developers/i2p.i2p
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:
@ -98,7 +98,11 @@ public class WebAppConfiguration implements Configuration {
|
|||||||
// Ticket #957... don't know why...
|
// Ticket #957... don't know why...
|
||||||
// Only really required if started manually, but we don't know that from here
|
// Only really required if started manually, but we don't know that from here
|
||||||
cp = "jetty-util.jar";
|
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");
|
File consoleDir = new File(pluginDir, "console");
|
||||||
Properties props = RouterConsoleRunner.webAppProperties(consoleDir.getAbsolutePath());
|
Properties props = RouterConsoleRunner.webAppProperties(consoleDir.getAbsolutePath());
|
||||||
cp = props.getProperty(RouterConsoleRunner.PREFIX + appName + CLASSPATH);
|
cp = props.getProperty(RouterConsoleRunner.PREFIX + appName + CLASSPATH);
|
||||||
@ -174,11 +178,13 @@ public class WebAppConfiguration implements Configuration {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Java 9 - assume everything in lib/ is in the classpath
|
// Java 9 - assume everything in lib/ is in the classpath
|
||||||
|
// except addressbook.jar
|
||||||
File libDir = new File(ctx.getBaseDir(), "lib");
|
File libDir = new File(ctx.getBaseDir(), "lib");
|
||||||
File[] files = libDir.listFiles();
|
File[] files = libDir.listFiles();
|
||||||
if (files != null) {
|
if (files != null) {
|
||||||
for (int i = 0; i < files.length; i++) {
|
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());
|
rv.add(files[i].toURI());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,9 @@ import javax.servlet.http.HttpServlet;
|
|||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
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.
|
* 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 {
|
public class Servlet extends HttpServlet {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
private transient DaemonThread thread;
|
private transient Thread thread;
|
||||||
//private String nonce;
|
//private String nonce;
|
||||||
//private static final String PROP_NONCE = "addressbook.nonce";
|
//private static final String PROP_NONCE = "addressbook.nonce";
|
||||||
|
|
||||||
@ -71,6 +73,7 @@ public class Servlet extends HttpServlet {
|
|||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see javax.servlet.Servlet#init(javax.servlet.ServletConfig)
|
* @see javax.servlet.Servlet#init(javax.servlet.ServletConfig)
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public void init(ServletConfig config) {
|
public void init(ServletConfig config) {
|
||||||
try {
|
try {
|
||||||
@ -83,17 +86,39 @@ public class Servlet extends HttpServlet {
|
|||||||
//System.setProperty(PROP_NONCE, this.nonce);
|
//System.setProperty(PROP_NONCE, this.nonce);
|
||||||
String[] args = new String[1];
|
String[] args = new String[1];
|
||||||
args[0] = config.getInitParameter("home");
|
args[0] = config.getInitParameter("home");
|
||||||
this.thread = new DaemonThread(args);
|
try {
|
||||||
this.thread.setDaemon(true);
|
ClassLoader cl = getServletContext().getClassLoader();
|
||||||
this.thread.setName("Addressbook");
|
Class cls = Class.forName("net.i2p.addressbook.DaemonThread", true, cl);
|
||||||
this.thread.start();
|
// 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: Starting Addressbook " + Daemon.VERSION);
|
||||||
//System.out.println("INFO: config root under " + args[0]);
|
//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
|
@Override
|
||||||
public void destroy() {
|
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();
|
super.destroy();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user