forked from I2P_Developers/i2p.i2p
propagate from branch 'i2p.i2p' (head 5737078c5993e2fcf73520cc610a71125b12520b)
to branch 'i2p.i2p.zzz.jetty7' (head a93a47d79b1db119ec8c62b46a4a4e226043bd17)
This commit is contained in:
@ -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
|
||||
|
@ -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
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -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.
|
||||
@ -293,7 +296,7 @@ public class RouterConsoleRunner implements RouterApp {
|
||||
// System.err.println("INFO: I2P Jetty logging class not found, logging to wrapper log");
|
||||
//}
|
||||
// This way it doesn't try to load Slf4jLog first
|
||||
System.setProperty("org.mortbay.log.class", "net.i2p.jetty.I2PLogger");
|
||||
System.setProperty("org.eclipse.jetty.util.log.class", "net.i2p.jetty.I2PLogger");
|
||||
|
||||
// so Jetty can find WebAppConfiguration
|
||||
System.setProperty("jetty.class.path", _context.getBaseDir() + "/lib/routerconsole.jar");
|
||||
@ -302,7 +305,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...
|
||||
@ -315,7 +319,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());
|
||||
|
||||
@ -351,7 +357,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 {
|
||||
@ -507,17 +513,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) {
|
||||
@ -727,7 +730,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);
|
||||
@ -737,14 +740,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();
|
||||
@ -843,11 +845,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() **/
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
||||
/**
|
||||
@ -38,23 +38,15 @@ import org.mortbay.jetty.webapp.WebAppContext;
|
||||
* @author zzz
|
||||
*/
|
||||
public class WebAppConfiguration implements Configuration {
|
||||
private WebAppContext _wac;
|
||||
|
||||
private static final String CLASSPATH = ".classpath";
|
||||
|
||||
public void setWebAppContext(WebAppContext context) {
|
||||
_wac = context;
|
||||
}
|
||||
|
||||
public WebAppContext getWebAppContext() {
|
||||
return _wac;
|
||||
}
|
||||
|
||||
/**
|
||||
* This was the interface in Jetty 5, now it's configureClassLoader()
|
||||
* This was the interface in Jetty 5, in Jetty 6 was configureClassLoader(),
|
||||
* now it's configure()
|
||||
*/
|
||||
private void configureClassPath() throws Exception {
|
||||
String ctxPath = _wac.getContextPath();
|
||||
private void configureClassPath(WebAppContext wac) throws Exception {
|
||||
String ctxPath = wac.getContextPath();
|
||||
//System.err.println("Configure Class Path " + ctxPath);
|
||||
if (ctxPath.equals("/"))
|
||||
return;
|
||||
@ -110,7 +102,7 @@ public class WebAppConfiguration implements Configuration {
|
||||
}
|
||||
if (buf.length() <= 0)
|
||||
return;
|
||||
ClassLoader cl = _wac.getClassLoader();
|
||||
ClassLoader cl = wac.getClassLoader();
|
||||
if (cl != null && cl instanceof WebAppClassLoader) {
|
||||
WebAppClassLoader wacl = (WebAppClassLoader) cl;
|
||||
wacl.addClassPath(buf.toString());
|
||||
@ -118,7 +110,7 @@ public class WebAppConfiguration implements Configuration {
|
||||
// This was not working because the WebAppClassLoader already exists
|
||||
// and it calls getExtraClasspath in its constructor
|
||||
// Not sure why WACL already exists...
|
||||
_wac.setExtraClasspath(buf.toString());
|
||||
wac.setExtraClasspath(buf.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@ -133,14 +125,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 {
|
||||
configureClassPath();
|
||||
/** @since Jetty 7 */
|
||||
public void configure(WebAppContext context) throws Exception {
|
||||
configureClassPath(context);
|
||||
}
|
||||
|
||||
/** @since Jetty 7 */
|
||||
public void cloneConfigure(WebAppContext template, WebAppContext context) {
|
||||
// no state, nothing to be done
|
||||
}
|
||||
|
||||
/** @since Jetty 7 */
|
||||
public void destroy(WebAppContext context) {}
|
||||
|
||||
/** @since Jetty 7 */
|
||||
public void preConfigure(WebAppContext context) {}
|
||||
|
||||
/** @since Jetty 7 */
|
||||
public void postConfigure(WebAppContext context) {}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
@ -155,6 +155,8 @@ public class WebAppStarter {
|
||||
return null;
|
||||
String path = '/'+ appName;
|
||||
for (int i = 0; i < handlers.length; i++) {
|
||||
if (!(handlers[i] instanceof ContextHandler))
|
||||
continue;
|
||||
ContextHandler ch = (ContextHandler) handlers[i];
|
||||
if (path.equals(ch.getContextPath()))
|
||||
return ch;
|
||||
|
Reference in New Issue
Block a user