Changeset ed590cd


Ignore:
Timestamp:
Mar 27, 2017 2:43:20 PM (3 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
04e0cfe
Parents:
c199124
Message:

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.

Location:
apps
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • apps/routerconsole/java/src/net/i2p/router/web/WebAppConfiguration.java

    rc199124 red590cd  
    9999            // Only really required if started manually, but we don't know that from here
    100100            cp = "jetty-util.jar";
    101         } else ****/ if (pluginDir.exists()) {
     101****/
     102        if (ctxPath.equals("/susidns")) {
     103            // Old installs don't have this in their wrapper.config classpath
     104            cp = "addressbook.jar";
     105        } else if (pluginDir.exists()) {
    102106            File consoleDir = new File(pluginDir, "console");
    103107            Properties props = RouterConsoleRunner.webAppProperties(consoleDir.getAbsolutePath());
     
    175179        } else {
    176180            // Java 9 - assume everything in lib/ is in the classpath
     181            // except addressbook.jar
    177182            File libDir = new File(ctx.getBaseDir(), "lib");
    178183            File[] files = libDir.listFiles();
    179184            if (files != null) {
    180185                for (int i = 0; i < files.length; i++) {
    181                     if (files[i].getName().endsWith(".jar"))
     186                    String name = files[i].getName();
     187                    if (name.endsWith(".jar") && !name.equals("addressbook.jar"))
    182188                        rv.add(files[i].toURI());
    183189                }
  • apps/susidns/src/java/src/net/i2p/addressbook/servlet/Servlet.java

    rc199124 red590cd  
    3131import javax.servlet.http.HttpServletResponse;
    3232
    33 import net.i2p.addressbook.DaemonThread;
     33import net.i2p.I2PAppContext;
     34//import net.i2p.addressbook.DaemonThread;
     35import net.i2p.util.Log;
    3436
    3537/**
     
    4648
    4749    private static final long serialVersionUID = 1L;
    48     private transient DaemonThread thread;
     50    private transient Thread thread;
    4951    //private String nonce;
    5052    //private static final String PROP_NONCE = "addressbook.nonce";
     
    7274     * @see javax.servlet.Servlet#init(javax.servlet.ServletConfig)
    7375     */
     76    @SuppressWarnings("unchecked")
    7477    @Override
    7578    public void init(ServletConfig config) {
     
    8487        String[] args = new String[1];
    8588        args[0] = config.getInitParameter("home");
    86         this.thread = new DaemonThread(args);
    87         this.thread.setDaemon(true);
    88         this.thread.setName("Addressbook");
    89         this.thread.start();
    90         //System.out.println("INFO: Starting Addressbook " + Daemon.VERSION);
    91         //System.out.println("INFO: config root under " + args[0]);
     89        try {
     90            ClassLoader cl = getServletContext().getClassLoader();
     91            Class cls = Class.forName("net.i2p.addressbook.DaemonThread", true, cl);
     92            // We do it this way so that if we can't find addressbook,
     93            // the whole thing doesn't die.
     94            // We do add addressbook.jar in WebAppConfiguration,
     95            // so this is just in case.
     96            //Thread t = new DaemonThread(args);
     97            Thread t = (Thread) cls.getConstructor(String[].class).newInstance((Object)args);
     98            t.setDaemon(true);
     99            t.setName("Addressbook");
     100            t.start();
     101            this.thread = t;
     102            //System.out.println("INFO: Starting Addressbook " + Daemon.VERSION);
     103            //System.out.println("INFO: config root under " + args[0]);
     104        } catch (Throwable t) {
     105            // addressbook.jar may not be in the classpath
     106            I2PAppContext.getGlobalContext().logManager().getLog(Servlet.class).logAlways(Log.WARN, "Addressbook thread not started: " + t);
     107        }
    92108    }
    93109
     110    @SuppressWarnings("unchecked")
    94111    @Override
    95112    public void destroy() {
    96         this.thread.halt();
     113        if (this.thread != null) {
     114            //((DaemonThread)this.thread).halt();
     115            try {
     116                ClassLoader cl = getServletContext().getClassLoader();
     117                Class<?> cls = Class.forName("net.i2p.addressbook.DaemonThread", true, cl);
     118                Object t = cls.cast(this.thread);
     119                cls.getDeclaredMethod("halt").invoke(t);
     120            } catch (Throwable t) {}
     121        }
    97122        super.destroy();
    98123    }
Note: See TracChangeset for help on using the changeset viewer.