First cut at migrating to Jetty 6 and prep for using an external

Jetty 6 package.

- Add several jars from the Jetty 6 distribution
- Update jetty.xml
- Add context XML files
- Update WorkingDir to migrate the content XML files
- Update RouterConsoleRunner and LocaleWebAppHandler
- Remove all old Jetty 5.1.15 local mods;
  this will break Seedless using a custom Server() constructor
- Update I2PRequestLog to be a mod of NCSARequestLog from 6.1.26
- Put I2PRequestLog in its own jar
- Copy MultiPartRequest and other required classes from Jetty 5.1.15
  and add it to susimail, as the replacement MultiPartFilter in
  Jetty 6 is difficult to migrate to, and does not support content-type
- Update i2psnark for Jetty 6
- Disable i2psnark RunStandalone, unused and instantiated Jetty 5
- Fix up all webapp build.xml to reference new jars

Not yet working: Plugin/webapp run detection and stopping, eepsite CGI
Not well tested: Plugins, classpaths, webapps
This commit is contained in:
zzz
2011-12-23 00:56:48 +00:00
parent bd14dc3112
commit 92b9d0a996
49 changed files with 757 additions and 6607 deletions

View File

@ -14,10 +14,12 @@ import net.i2p.util.Log;
import net.i2p.util.SecureDirectory;
import net.i2p.util.PortMapper;
import org.mortbay.http.HttpContext;
import org.mortbay.http.HttpListener;
import org.mortbay.jetty.Connector;
import org.mortbay.jetty.Handler;
import org.mortbay.jetty.Server;
import org.mortbay.jetty.servlet.WebApplicationContext;
import org.mortbay.jetty.webapp.WebAppContext;
import org.mortbay.jetty.handler.ContextHandler;
import org.mortbay.jetty.handler.ContextHandlerCollection;
/**
@ -49,9 +51,10 @@ public class WebAppStarter {
* adds and starts
* @throws just about anything, caller would be wise to catch Throwable
*/
static void startWebApp(I2PAppContext ctx, Server server, String appName, String warPath) throws Exception {
static void startWebApp(I2PAppContext ctx, ContextHandlerCollection server,
String appName, String warPath) throws Exception {
File tmpdir = new SecureDirectory(ctx.getTempDir(), "jetty-work-" + appName + ctx.random().nextInt());
WebApplicationContext wac = addWebApp(ctx, server, appName, warPath, tmpdir);
WebAppContext wac = addWebApp(ctx, server, appName, warPath, tmpdir);
_log.debug("Loading war from: " + warPath);
wac.start();
}
@ -61,12 +64,13 @@ public class WebAppStarter {
* This is used only by RouterConsoleRunner, which adds all the webapps first
* and then starts all at once.
*/
static WebApplicationContext addWebApp(I2PAppContext ctx, Server server, String appName, String warPath, File tmpdir) throws IOException {
static WebAppContext addWebApp(I2PAppContext ctx, ContextHandlerCollection server,
String appName, String warPath, File tmpdir) throws IOException {
// Jetty will happily load one context on top of another without stopping
// the first one, so we remove any previous one here
try {
stopWebApp(server, appName);
stopWebApp(appName);
} catch (Throwable t) {}
// To avoid ZipErrors from JarURLConnetion caching,
@ -91,7 +95,7 @@ public class WebAppStarter {
warPath = tmpPath;
}
WebApplicationContext wac = server.addWebApplication("/"+ appName, warPath);
WebAppContext wac = new WebAppContext(warPath, "/"+ appName);
tmpdir.mkdir();
wac.setTempDirectory(tmpdir);
@ -101,12 +105,14 @@ public class WebAppStarter {
// see WebAppConfiguration for info
String[] classNames = server.getWebApplicationConfigurationClassNames();
String[] classNames = wac.getConfigurationClasses();
String[] newClassNames = new String[classNames.length + 1];
for (int j = 0; j < classNames.length; j++)
newClassNames[j] = classNames[j];
newClassNames[classNames.length] = WebAppConfiguration.class.getName();
wac.setConfigurationClassNames(newClassNames);
wac.setConfigurationClasses(newClassNames);
server.addHandler(wac);
server.mapContexts();
return wac;
}
@ -114,38 +120,55 @@ public class WebAppStarter {
* stop it and remove the context
* @throws just about anything, caller would be wise to catch Throwable
*/
static void stopWebApp(Server server, String appName) {
// this will return a new context if one does not exist
HttpContext wac = server.getContext('/' + appName);
static void stopWebApp(String appName) {
ContextHandler wac = getWebApp(appName);
if (wac == null)
return;
try {
// false -> not graceful
wac.stop(false);
} catch (InterruptedException ie) {}
// not graceful is default in Jetty 6?
wac.stop();
} catch (Exception ie) {}
ContextHandlerCollection server = getConsoleServer();
if (server == null)
return;
try {
server.removeContext(wac);
server.removeHandler(wac);
server.mapContexts();
} catch (IllegalStateException ise) {}
}
static boolean isWebAppRunning(String appName) {
Server server = WebAppStarter.getConsoleServer();
if (server == null)
ContextHandler wac = getWebApp(appName);
if (wac == null)
return false;
// this will return a new context if one does not exist
HttpContext wac = server.getContext('/' + appName);
return wac.isStarted();
}
/** see comments in ConfigClientsHandler */
static Server getConsoleServer() {
Collection c = Server.getHttpServers();
for (int i = 0; i < c.size(); i++) {
Server s = (Server) c.toArray()[i];
HttpListener[] hl = s.getListeners();
for (int j = 0; j < hl.length; j++) {
if (hl[j].getPort() == I2PAppContext.getGlobalContext().portMapper().getPort(PortMapper.SVC_CONSOLE))
return s;
}
/** @since Jetty 6 */
static ContextHandler getWebApp(String appName) {
ContextHandlerCollection server = getConsoleServer();
if (server == null)
return null;
Handler handlers[] = server.getHandlers();
if (handlers == null)
return null;
String path = '/'+ appName;
for (int i = 0; i < handlers.length; i++) {
ContextHandler ch = (ContextHandler) handlers[i];
if (appName.equals(ch.getContextPath()))
return ch;
}
return null;
}
/** see comments in ConfigClientsHandler */
static ContextHandlerCollection getConsoleServer() {
Server s = RouterConsoleRunner.getConsoleServer();
if (s == null)
return null;
Handler h = s.getChildHandlerByClass(ContextHandlerCollection.class);
if (h == null)
return null;
return (ContextHandlerCollection) h;
}
}