RouterConsole compile fixes for Jetty 7.

Convert LocaleWebAppHandler from extending WebAppContext to
extending HandlerWrapper, since handle() is now final in WebAppContext.
Untested.
This commit is contained in:
zzz
2012-11-21 20:49:18 +00:00
parent be8697cb9a
commit f1dd77982a
11 changed files with 130 additions and 87 deletions

View File

@ -60,9 +60,13 @@
<pathelement location="../../../core/java/build/i2p.jar" />
<pathelement location="../../../router/java/build/router.jar" />
<pathelement location="../../jetty/jettylib/org.mortbay.jetty.jar" />
<pathelement location="../../jetty/jettylib/jetty-http.jar" />
<pathelement location="../../jetty/jettylib/jetty-io.jar" />
<pathelement location="../../jetty/jettylib/jetty-security.jar" />
<pathelement location="../../jetty/jettylib/jetty-servlet.jar" />
<pathelement location="../../jetty/jettylib/jetty-servlets.jar" />
<pathelement location="../../jetty/jettylib/jetty-util.jar" />
<pathelement location="../../jetty/jettylib/jetty-sslengine.jar" />
<pathelement location="../../jetty/jettylib/jetty-java5-threadpool.jar" />
<pathelement location="../../jetty/jettylib/jetty-webapp.jar" />
<pathelement location="../../jetty/jettylib/javax.servlet.jar" />
<pathelement location="../../jetty/jettylib/jsp-api.jar" />
<pathelement location="../../jetty/jettylib/jetty-i2p.jar" />

View File

@ -17,7 +17,7 @@ import net.i2p.router.startup.LoadClientAppsJob;
import net.i2p.router.update.ConsoleUpdateManager;
import static net.i2p.update.UpdateType.*;
import org.mortbay.jetty.handler.ContextHandlerCollection;
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
/**
* Saves changes to clients.config or webapps.config

View File

@ -12,7 +12,7 @@ import net.i2p.router.Router;
import net.i2p.router.RouterContext;
import net.i2p.router.util.RouterPasswordManager;
//import org.mortbay.jetty.security.UnixCrypt;
//import org.eclipse.jetty.util.security.UnixCrypt;
/**
* Manage both plaintext and salted/hashed password storage in

View File

@ -1,5 +1,6 @@
package net.i2p.router.web;
import java.io.File;
import java.io.IOException;
import java.util.Locale;
import java.util.Map;
@ -10,7 +11,11 @@ import javax.servlet.http.HttpServletResponse;
import net.i2p.I2PAppContext;
import org.mortbay.jetty.webapp.WebAppContext;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.handler.HandlerWrapper;
import org.eclipse.jetty.server.session.SessionHandler;
import org.eclipse.jetty.servlet.ServletHandler;
import org.eclipse.jetty.webapp.WebAppContext;
/**
* Convert foo.jsp to foo_xx.jsp for language xx.
@ -21,14 +26,22 @@ import org.mortbay.jetty.webapp.WebAppContext;
*
* @author zzz
*/
public class LocaleWebAppHandler extends WebAppContext
public class LocaleWebAppHandler extends HandlerWrapper
{
private final I2PAppContext _context;
private final WebAppContext _wac;
public LocaleWebAppHandler(I2PAppContext ctx, String path, String warPath) {
super(warPath, path);
public LocaleWebAppHandler(I2PAppContext ctx, String path, String warPath,
File tmpdir, ServletHandler servletHandler) {
super();
_context = ctx;
_wac = new WebAppContext(warPath, path);
setInitParams(WebAppStarter.INIT_PARAMS);
_wac.setTempDirectory(tmpdir);
_wac.setExtractWAR(false);
_wac.setSessionHandler(new SessionHandler());
_wac.setServletHandler(servletHandler);
setHandler(_wac);
}
/**
@ -37,19 +50,12 @@ public class LocaleWebAppHandler extends WebAppContext
* or as specified in the routerconsole.lang property.
* Unless language == "en".
*/
@Override
public void handle(String pathInContext,
Request baseRequest,
HttpServletRequest httpRequest,
HttpServletResponse httpResponse,
int dispatch)
HttpServletResponse httpResponse)
throws IOException, ServletException
{
// Handle OPTIONS (nothing to override)
if ("OPTIONS".equals(httpRequest.getMethod()))
{
handleOptions(httpRequest, httpResponse);
return;
}
// transparent rewriting
if (pathInContext.equals("/") || pathInContext.equals("/index.html")) {
@ -77,7 +83,7 @@ public class LocaleWebAppHandler extends WebAppContext
if (lang != null && lang.length() > 0 && !lang.equals("en")) {
String testPath = pathInContext.substring(0, len - 4) + '_' + lang + ".jsp";
// Do we have a servlet for the new path that isn't the catchall *.jsp?
Map.Entry servlet = getServletHandler().getHolderEntry(testPath);
Map.Entry servlet = _wac.getServletHandler().getHolderEntry(testPath);
if (servlet != null) {
String servletPath = (String) servlet.getKey();
if (servletPath != null && !servletPath.startsWith("*")) {
@ -90,7 +96,7 @@ public class LocaleWebAppHandler extends WebAppContext
}
}
//System.err.println("New path: " + newPath);
super.handle(newPath, httpRequest, httpResponse, dispatch);
super.handle(newPath, baseRequest, httpRequest, httpResponse);
//System.err.println("Was handled? " + httpRequest.isHandled());
}
@ -112,10 +118,28 @@ public class LocaleWebAppHandler extends WebAppContext
* Not an override
* @since 0.8
*/
/**** not in Jetty 7
public void handleOptions(HttpServletRequest request,
HttpServletResponse response)
throws IOException
{
response.sendError(405);
}
****/
/**
* Mysteriously removed from Jetty 7
*/
private void setInitParams(Map params) {
setInitParams(_wac, params);
}
/**
* @since Jetty 7
*/
public static void setInitParams(WebAppContext context, Map<?,?> params) {
for (Map.Entry e : params.entrySet()) {
context.setInitParameter((String)e.getKey(), (String)e.getValue());
}
}
}

View File

@ -7,7 +7,7 @@ import net.i2p.I2PAppContext;
import net.i2p.util.FileUtil;
import net.i2p.util.VersionComparator;
import org.mortbay.jetty.Server;
import org.eclipse.jetty.server.Server;
import org.tanukisoftware.wrapper.WrapperManager;
public class LogsHelper extends HelperBase {

View File

@ -34,7 +34,7 @@ import net.i2p.util.Log;
import net.i2p.util.Translate;
import net.i2p.util.VersionComparator;
import org.mortbay.jetty.handler.ContextHandlerCollection;
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
/**

View File

@ -42,30 +42,33 @@ import net.i2p.util.ShellCommand;
import net.i2p.util.SystemVersion;
import net.i2p.util.VersionComparator;
import org.mortbay.jetty.AbstractConnector;
import org.mortbay.jetty.Connector;
import org.mortbay.jetty.NCSARequestLog;
import org.mortbay.jetty.Server;
import org.mortbay.jetty.bio.SocketConnector;
import org.mortbay.jetty.handler.ContextHandlerCollection;
import org.mortbay.jetty.handler.DefaultHandler;
import org.mortbay.jetty.handler.HandlerCollection;
import org.mortbay.jetty.handler.RequestLogHandler;
import org.mortbay.jetty.nio.SelectChannelConnector;
import org.mortbay.jetty.security.Credential.MD5;
import org.mortbay.jetty.security.DigestAuthenticator;
import org.mortbay.jetty.security.HashUserRealm;
import org.mortbay.jetty.security.Constraint;
import org.mortbay.jetty.security.ConstraintMapping;
import org.mortbay.jetty.security.SecurityHandler;
import org.mortbay.jetty.security.SslSocketConnector;
import org.mortbay.jetty.security.SslSelectChannelConnector;
import org.mortbay.jetty.servlet.ServletHandler;
import org.mortbay.jetty.servlet.ServletHolder;
import org.mortbay.jetty.servlet.SessionHandler;
import org.mortbay.jetty.webapp.WebAppContext;
import org.mortbay.thread.QueuedThreadPool;
import org.mortbay.thread.concurrent.ThreadPool;
import org.eclipse.jetty.security.HashLoginService;
import org.eclipse.jetty.security.ConstraintMapping;
import org.eclipse.jetty.security.ConstraintSecurityHandler;
import org.eclipse.jetty.security.SecurityHandler;
import org.eclipse.jetty.security.authentication.DigestAuthenticator;
import org.eclipse.jetty.server.AbstractConnector;
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.NCSARequestLog;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.bio.SocketConnector;
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
import org.eclipse.jetty.server.handler.DefaultHandler;
import org.eclipse.jetty.server.handler.HandlerCollection;
import org.eclipse.jetty.server.handler.HandlerWrapper;
import org.eclipse.jetty.server.handler.RequestLogHandler;
import org.eclipse.jetty.server.nio.SelectChannelConnector;
import org.eclipse.jetty.server.ssl.SslSocketConnector;
import org.eclipse.jetty.server.ssl.SslSelectChannelConnector;
import org.eclipse.jetty.servlet.ServletHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.eclipse.jetty.webapp.WebAppContext;
import org.eclipse.jetty.util.security.Constraint;
import org.eclipse.jetty.util.security.Credential;
import org.eclipse.jetty.util.security.Credential.MD5;
import org.eclipse.jetty.util.thread.ExecutorThreadPool;
import org.eclipse.jetty.util.thread.QueuedThreadPool;
import org.eclipse.jetty.util.thread.ThreadPool;
/**
* Start the router console.
@ -306,7 +309,8 @@ public class RouterConsoleRunner implements RouterApp {
try {
ThreadPool ctp = new CustomThreadPoolExecutor();
ctp.prestartAllCoreThreads();
// Gone in Jetty 7
//ctp.prestartAllCoreThreads();
_server.setThreadPool(ctp);
} catch (Throwable t) {
// class not found...
@ -319,7 +323,9 @@ public class RouterConsoleRunner implements RouterApp {
HandlerCollection hColl = new HandlerCollection();
ContextHandlerCollection chColl = new ContextHandlerCollection();
_server.addHandler(hColl);
// gone in Jetty 7
//_server.addHandler(hColl);
_server.setHandler(hColl);
hColl.addHandler(chColl);
hColl.addHandler(new DefaultHandler());
@ -355,7 +361,7 @@ public class RouterConsoleRunner implements RouterApp {
if (!_webAppsDir.endsWith("/"))
_webAppsDir += '/';
WebAppContext rootWebApp = null;
HandlerWrapper rootWebApp = null;
ServletHandler rootServletHandler = null;
List<Connector> connectors = new ArrayList(4);
try {
@ -511,17 +517,14 @@ public class RouterConsoleRunner implements RouterApp {
return;
}
rootWebApp = new LocaleWebAppHandler(_context,
"/", _webAppsDir + ROUTERCONSOLE + ".war");
File tmpdir = new SecureDirectory(workDir, ROUTERCONSOLE + "-" +
(_listenPort != null ? _listenPort : _sslListenPort));
tmpdir.mkdir();
rootWebApp.setTempDirectory(tmpdir);
rootWebApp.setExtractWAR(false);
rootWebApp.setSessionHandler(new SessionHandler());
rootServletHandler = new ServletHandler();
rootWebApp.setServletHandler(rootServletHandler);
initialize(_context, rootWebApp);
rootWebApp = new LocaleWebAppHandler(_context,
"/", _webAppsDir + ROUTERCONSOLE + ".war",
tmpdir, rootServletHandler);
initialize(_context, (WebAppContext)(rootWebApp.getHandler()));
chColl.addHandler(rootWebApp);
} catch (Exception ioe) {
@ -731,7 +734,7 @@ public class RouterConsoleRunner implements RouterApp {
* Add all users and passwords.
*/
static void initialize(RouterContext ctx, WebAppContext context) {
SecurityHandler sec = new SecurityHandler();
ConstraintSecurityHandler sec = new ConstraintSecurityHandler();
List<ConstraintMapping> constraints = new ArrayList(4);
ConsolePasswordManager mgr = new ConsolePasswordManager(ctx);
boolean enable = ctx.getBooleanProperty(PROP_PW_ENABLE);
@ -741,14 +744,13 @@ public class RouterConsoleRunner implements RouterApp {
enable = false;
ctx.router().saveConfig(PROP_CONSOLE_PW, "false");
} else {
HashUserRealm realm = new HashUserRealm(JETTY_REALM);
sec.setUserRealm(realm);
HashLoginService realm = new HashLoginService(JETTY_REALM);
sec.setLoginService(realm);
sec.setAuthenticator(authenticator);
for (Map.Entry<String, String> e : userpw.entrySet()) {
String user = e.getKey();
String pw = e.getValue();
realm.put(user, MD5.__TYPE + pw);
realm.addUserToRole(user, JETTY_ROLE);
realm.putUser(user, Credential.getCredential(MD5.__TYPE + pw), new String[] {JETTY_ROLE});
Constraint constraint = new Constraint(user, JETTY_ROLE);
constraint.setAuthenticate(true);
ConstraintMapping cm = new ConstraintMapping();
@ -847,11 +849,13 @@ public class RouterConsoleRunner implements RouterApp {
* Just to set the name and set Daemon
* @since Jetty 6
*/
private static class CustomThreadPoolExecutor extends ThreadPool {
private static class CustomThreadPoolExecutor extends ExecutorThreadPool {
public CustomThreadPoolExecutor() {
super(MIN_THREADS, MAX_THREADS, MAX_IDLE_TIME, TimeUnit.MILLISECONDS,
new SynchronousQueue(), new CustomThreadFactory(),
new ThreadPoolExecutor.CallerRunsPolicy());
new SynchronousQueue() /** , following args not available in Jetty 7
new CustomThreadFactory(),
new ThreadPoolExecutor.CallerRunsPolicy() **/
);
}
}

View File

@ -10,9 +10,9 @@ import java.util.StringTokenizer;
import net.i2p.I2PAppContext;
import org.mortbay.jetty.webapp.Configuration;
import org.mortbay.jetty.webapp.WebAppClassLoader;
import org.mortbay.jetty.webapp.WebAppContext;
import org.eclipse.jetty.webapp.Configuration;
import org.eclipse.jetty.webapp.WebAppClassLoader;
import org.eclipse.jetty.webapp.WebAppContext;
/**
@ -133,14 +133,25 @@ public class WebAppConfiguration implements Configuration {
return rv;
}
public void configureDefaults() {}
public void configureWebApp() {}
/** @since Jetty 7 */
public void deconfigure(WebAppContext context) {}
/** @since Jetty 6 */
public void deconfigureWebApp() {}
/** @since Jetty 6 */
public void configureClassLoader() throws Exception {
/** @since Jetty 7 */
public void configure(WebAppContext context) throws Exception {
configureClassPath();
}
/** @since Jetty 7 */
public void cloneConfigure(WebAppContext template, WebAppContext context) {
throw new UnsupportedOperationException();
}
/** @since Jetty 7 */
public void destroy(WebAppContext context) {}
/** @since Jetty 7 */
public void preConfigure(WebAppContext context) {}
/** @since Jetty 7 */
public void postConfigure(WebAppContext context) {}
}

View File

@ -10,11 +10,11 @@ import net.i2p.router.RouterContext;
import net.i2p.util.FileUtil;
import net.i2p.util.SecureDirectory;
import org.mortbay.jetty.Handler;
import org.mortbay.jetty.Server;
import org.mortbay.jetty.webapp.WebAppContext;
import org.mortbay.jetty.handler.ContextHandler;
import org.mortbay.jetty.handler.ContextHandlerCollection;
import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
import org.eclipse.jetty.webapp.WebAppContext;
/**
@ -56,7 +56,7 @@ public class WebAppStarter {
File tmpdir = new SecureDirectory(ctx.getTempDir(), "jetty-work-" + appName + ctx.random().nextInt());
WebAppContext wac = addWebApp(ctx, server, appName, warPath, tmpdir);
//_log.debug("Loading war from: " + warPath);
wac.setInitParams(INIT_PARAMS);
LocaleWebAppHandler.setInitParams(wac, INIT_PARAMS);
wac.start();
}

View File

@ -4,9 +4,9 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%
// Let's make this easy...
final Integer ERROR_CODE = (Integer) request.getAttribute(org.mortbay.jetty.servlet.ServletHandler.__J_S_ERROR_STATUS_CODE);
final String ERROR_URI = (String) request.getAttribute(org.mortbay.jetty.servlet.ServletHandler.__J_S_ERROR_REQUEST_URI);
final String ERROR_MESSAGE = (String) request.getAttribute(org.mortbay.jetty.servlet.ServletHandler.__J_S_ERROR_MESSAGE);
final Integer ERROR_CODE = (Integer) request.getAttribute(org.eclipse.jetty.server.Dispatcher.ERROR_STATUS_CODE);
final String ERROR_URI = (String) request.getAttribute(org.eclipse.jetty.server.Dispatcher.ERROR_REQUEST_URI);
final String ERROR_MESSAGE = (String) request.getAttribute(org.eclipse.jetty.server.Dispatcher.ERROR_MESSAGE);
if (ERROR_CODE != null && ERROR_MESSAGE != null) {
// this is deprecated but we don't want sendError()
response.setStatus(ERROR_CODE.intValue(), ERROR_MESSAGE);

View File

@ -3,11 +3,11 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%
// Let's make this easy...
final Integer ERROR_CODE = (Integer) request.getAttribute(org.mortbay.jetty.servlet.ServletHandler.__J_S_ERROR_STATUS_CODE);
final String ERROR_URI = (String) request.getAttribute(org.mortbay.jetty.servlet.ServletHandler.__J_S_ERROR_REQUEST_URI);
final String ERROR_MESSAGE = (String) request.getAttribute(org.mortbay.jetty.servlet.ServletHandler.__J_S_ERROR_MESSAGE);
final Class ERROR_CLASS = (Class)request.getAttribute(org.mortbay.jetty.servlet.ServletHandler.__J_S_ERROR_EXCEPTION_TYPE);
final Throwable ERROR_THROWABLE = (Throwable)request.getAttribute(org.mortbay.jetty.servlet.ServletHandler.__J_S_ERROR_EXCEPTION);
final Integer ERROR_CODE = (Integer) request.getAttribute(org.eclipse.jetty.server.Dispatcher.ERROR_STATUS_CODE);
final String ERROR_URI = (String) request.getAttribute(org.eclipse.jetty.server.Dispatcher.ERROR_REQUEST_URI);
final String ERROR_MESSAGE = (String) request.getAttribute(org.eclipse.jetty.server.Dispatcher.ERROR_MESSAGE);
final Class ERROR_CLASS = (Class)request.getAttribute(org.eclipse.jetty.server.Dispatcher.ERROR_EXCEPTION_TYPE);
final Throwable ERROR_THROWABLE = (Throwable)request.getAttribute(org.eclipse.jetty.server.Dispatcher.ERROR_EXCEPTION);
if (ERROR_CODE != null && ERROR_MESSAGE != null) {
// this is deprecated but we don't want sendError()
response.setStatus(ERROR_CODE.intValue(), ERROR_MESSAGE);