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

@ -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());
}
}
}