- Clean up WebAppconfiguration

- Fix eepsite xml files
- First cut at updating migration code (untested)
This commit is contained in:
zzz
2012-11-22 21:17:50 +00:00
parent 02ad4d5200
commit 50df4b53db
8 changed files with 128 additions and 93 deletions

View File

@ -89,8 +89,11 @@
Reasons for inclusion:
start.jar: Needed for clients.config startup of eepsites
jetty-util-xxx.jar: LifeCycle (base class for stuff), URIUtil (used in i2psnark)
jetty-sslengine-xxx.jar: SSL NIO Connector for console
jetty-java5-threadpool-xxx.jar: Concurrent thread pool for eepsite
jetty-deploy, -http, -io, -security, -servlet, -webapp: All split out from main server jar in Jetty 7
jetty-continuation-xxx.jar: Needed? Useful?
jetty-servlets-xxx.jar: Needed for CGI for eepsite
jetty-sslengine-xxx.jar: Old Jetty 6, now a dummy
jetty-java5-threadpool-xxx.jar: Old Jetty 6, now a dummy
glassfish 2.1: Not used, too old, see Tomcat below.
jetty-rewrite-handler: Not used by I2P, but only 20KB and could be useful for eepsites
jetty-management: Not used by I2P, but only 34KB and could be useful for eepsites, and we bundled it with Jetty 5

View File

@ -38,15 +38,15 @@ import org.eclipse.jetty.webapp.WebAppContext;
* @author zzz
*/
public class WebAppConfiguration implements Configuration {
private WebAppContext _wac;
private static final String CLASSPATH = ".classpath";
/**
* 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;
@ -102,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());
@ -110,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());
}
}
@ -130,13 +130,12 @@ public class WebAppConfiguration implements Configuration {
/** @since Jetty 7 */
public void configure(WebAppContext context) throws Exception {
_wac = context;
configureClassPath();
configureClassPath(context);
}
/** @since Jetty 7 */
public void cloneConfigure(WebAppContext template, WebAppContext context) {
throw new UnsupportedOperationException();
// no state, nothing to be done
}
/** @since Jetty 7 */

View File

@ -1102,13 +1102,13 @@
<!-- We have to package the new eepsite files for MigrateJetty.java, but we
can't overwrite an existing eepsite dir in a non-split configuration.
-->
<copy todir="pkg-temp/eepsite-jetty6" >
<copy todir="pkg-temp/eepsite-jetty7" >
<fileset dir="installer/resources/eepsite" includes="*.xml contexts/* etc/*" />
</copy>
</target>
<target name="delete-j6-update">
<delete dir="pkg-temp/eepsite-jetty6" />
<delete dir="pkg-temp/eepsite-jetty7" />
</target>
<!-- Jetty 6 I2P logging addons, not really fixes -->

View File

@ -4,26 +4,20 @@
<!--
Configure a custom context for the eepsite.
This context contains only a Context with a default servlet
This context contains only a ServletContextHandler with a default servlet
to serve static html files and images.
-->
<Configure class="org.mortbay.jetty.servlet.Context">
<Configure class="org.eclipse.jetty.servlet.ServletContextHandler">
<Set name="contextPath">/</Set>
<Set name="resourceBase">./eepsite/docroot/</Set>
<Call name="setInitParams">
<Arg>
<Map>
<Entry>
<Item>org.mortbay.jetty.servlet.Default.cacheControl</Item>
<Item>max-age=3600,public</Item>
</Entry>
</Map>
</Arg>
<Call name="setInitParameter">
<Arg>cacheControl</Arg>
<Arg>max-age=3600,public</Arg>
</Call>
<Call name="setMimeTypes">
<Arg>
<New class="org.mortbay.jetty.MimeTypes">
<New class="org.eclipse.jetty.http.MimeTypes">
<Call name="addMimeMapping">
<Arg>sud</Arg>
<Arg>application/zip</Arg>
@ -40,7 +34,7 @@ to serve static html files and images.
</Arg>
</Call>
<Call name="addServlet">
<Arg>org.mortbay.jetty.servlet.DefaultServlet</Arg>
<Arg>org.eclipse.jetty.servlet.DefaultServlet</Arg>
<Arg>/</Arg>
</Call>
</Configure>

View File

@ -22,21 +22,15 @@ Configure a custom context for the eepsite.
* parameter value.
-->
<Configure class="org.mortbay.jetty.servlet.Context">
<Configure class="org.eclipse.jetty.servlet.ServletContextHandler">
<Set name="contextPath">/cgi-bin</Set>
<Set name="resourceBase">./eepsite/cgi-bin/</Set>
<Call name="setInitParams">
<Arg>
<Map>
<Entry>
<Item>Path</Item>
<Item>/usr/local/bin:/bin:/usr/bin</Item>
</Entry>
</Map>
</Arg>
<Call name="setInitParameter">
<Arg>Path</Arg>
<Arg>/usr/local/bin:/bin:/usr/bin</Arg>
</Call>
<Call name="addServlet">
<Arg>org.mortbay.servlet.CGI</Arg>
<Arg>org.eclipse.jetty.servlets.CGI</Arg>
<Arg>/</Arg>
</Call>
</Configure>

View File

@ -35,23 +35,23 @@
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<!-- UNCOMMENT TO ACTIVATE
<context-param>
<param-name>org.mortbay.jetty.servlet.SessionDomain</param-name>
<param-name>org.eclipse.jetty.servlet.SessionDomain</param-name>
<param-value>127.0.0.1</param-value>
</context-param>
<context-param>
<param-name>org.mortbay.jetty.servlet.SessionPath</param-name>
<param-name>org.eclipse.jetty.servlet.SessionPath</param-name>
<param-value>/</param-value>
</context-param>
<context-param>
<param-name>org.mortbay.jetty.servlet.MaxAge</param-name>
<param-name>org.eclipse.jetty.servlet.MaxAge</param-name>
<param-value>-1</param-value>
</context-param>
-->
<context-param>
<param-name>org.mortbay.jetty.webapp.NoTLDJarPattern</param-name>
<param-name>org.eclipse.jetty.webapp.NoTLDJarPattern</param-name>
<param-value>start.jar|ant-.*\.jar|dojo-.*\.jar|jetty-.*\.jar|jsp-api-.*\.jar|junit-.*\.jar|servlet-api-.*\.jar|dnsns\.jar|rt\.jar|jsse\.jar|tools\.jar|sunpkcs11\.jar|sunjce_provider\.jar|xerces.*\.jar</param-value>
</context-param>
@ -112,7 +112,7 @@
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<servlet>
<servlet-name>default</servlet-name>
<servlet-class>org.mortbay.jetty.servlet.DefaultServlet</servlet-class>
<servlet-class>org.eclipse.jetty.servlet.DefaultServlet</servlet-class>
<init-param>
<param-name>acceptRanges</param-name>
<param-value>true</param-value>
@ -306,7 +306,7 @@
<!-- Uncomment for dynamic invocation
<servlet>
<servlet-name>invoker</servlet-name>
<servlet-class>org.mortbay.jetty.servlet.Invoker</servlet-class>
<servlet-class>org.eclipse.jetty.servlet.Invoker</servlet-class>
<init-param>
<param-name>verbose</param-name>
<param-value>false</param-value>

View File

@ -18,8 +18,8 @@
<!-- war files placed in the webapps/ dir. -->
<!-- * Uncomment the line to allow Jetty to follow symlinks -->
<!-- -->
<!-- I2P uses Jetty 6.1.26. If you need web server features not found -->
<!-- in Jetty 6, you may install and run Jetty 7 or 8 in a different JVM -->
<!-- I2P uses Jetty 7. If you need web server features not found -->
<!-- in Jetty 7, you may install and run Jetty 7 or 8 in a different JVM -->
<!-- or run any other web server such as Apache. If you do run another web -->
<!-- server instead, be sure and disable the Jetty 6 server for your -->
<!-- eepsite on http://127.0.0.1:7657/configclients.jsp . -->
@ -44,7 +44,7 @@
<!-- =============================================================== -->
<Configure id="Server" class="org.mortbay.jetty.Server">
<Configure id="Server" class="org.eclipse.jetty.server.Server">
<!-- =========================================================== -->
<!-- Server Thread Pool -->
@ -57,7 +57,7 @@
Requests above the max will be queued
-->
<!--
<New class="org.mortbay.thread.QueuedThreadPool">
<New class="org.eclipse.jetty.util.thread.QueuedThreadPool">
<Set name="minThreads">1</Set>
<Set name="maxThreads">16</Set>
<Set name="lowThreads">2</Set>
@ -73,10 +73,13 @@
set the thread name, set daemon, etc.
See RouterConsoleRunner.
-->
<New class="org.mortbay.thread.concurrent.ThreadPool">
<Arg type="int">0</Arg>
<Set name="corePoolSize">1</Set>
<Set name="maximumPoolSize">24</Set>
<New class="org.eclipse.jetty.util.thread.ExecutorThreadPool">
<!-- corePoolSize (must be at least 2) -->
<Arg type="int">2</Arg>
<!-- maximumPoolSize -->
<Arg type="int">16</Arg>
<!-- keepAliveTime (milliseconds) -->
<Arg type="long">60000</Arg>
</New>
</Set>
@ -97,7 +100,7 @@
-->
<Call name="addConnector">
<Arg>
<New class="org.mortbay.jetty.nio.SelectChannelConnector">
<New class="org.eclipse.jetty.server.nio.SelectChannelConnector">
<Set name="host">127.0.0.1</Set>
<Set name="port">7658</Set>
<Set name="maxIdleTime">60000</Set>
@ -106,7 +109,7 @@
<Set name="confidentialPort">8443</Set>
<Set name="lowResourcesConnections">5000</Set>
<Set name="lowResourcesMaxIdleTime">5000</Set>
<Set name="useDirectBuffers">false</Set>
<Set name="useDirectBuffers">false</Set>
</New>
</Arg>
</Call>
@ -117,7 +120,7 @@
<!--
<Call name="addConnector">
<Arg>
<New class="org.mortbay.jetty.bio.SocketConnector">
<New class="org.eclipse.jetty.server.bio.SocketConnector">
<Set name="host">127.0.0.1</Set>
<Set name="port">7658</Set>
<Set name="maxIdleTime">60000</Set>
@ -155,7 +158,7 @@
<!-- =========================================================== -->
<!--
<Set name="sessionIdManager">
<New class="org.mortbay.jetty.servlet.HashSessionIdManager">
<New class="org.eclipse.jetty.server.session.HashSessionIdManager">
<Set name="workerName">node1</Set>
</New>
</Set>
@ -165,23 +168,48 @@
<!-- Set handler Collection Structure -->
<!-- =========================================================== -->
<Set name="handler">
<New id="Handlers" class="org.mortbay.jetty.handler.HandlerCollection">
<New id="Handlers" class="org.eclipse.jetty.server.handler.HandlerCollection">
<Set name="handlers">
<Array type="org.mortbay.jetty.Handler">
<Array type="org.eclipse.jetty.server.Handler">
<Item>
<New id="Contexts" class="org.mortbay.jetty.handler.ContextHandlerCollection"/>
<New id="Contexts" class="org.eclipse.jetty.server.handler.ContextHandlerCollection"/>
</Item>
<Item>
<New id="DefaultHandler" class="org.mortbay.jetty.handler.DefaultHandler"/>
<New id="DefaultHandler" class="org.eclipse.jetty.server.handler.DefaultHandler"/>
</Item>
<Item>
<New id="RequestLog" class="org.mortbay.jetty.handler.RequestLogHandler"/>
<New id="RequestLog" class="org.eclipse.jetty.server.handler.RequestLogHandler"/>
</Item>
</Array>
</Set>
</New>
</Set>
<!-- =============================================================== -->
<!-- Create the deployment manager -->
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<!-- The deplyment manager handles the lifecycle of deploying web -->
<!-- applications. Apps are provided by instances of the -->
<!-- AppProvider interface. Typically these are provided by -->
<!-- one or more of: -->
<!-- jetty-webapps.xml - monitors webapps for wars and dirs -->
<!-- jetty-contexts.xml - monitors contexts for context xml -->
<!-- jetty-templates.xml - monitors contexts and templates -->
<!-- =============================================================== -->
<Call name="addBean">
<Arg>
<New id="DeploymentManager" class="org.eclipse.jetty.deploy.DeploymentManager">
<Set name="contexts">
<Ref id="Contexts" />
</Set>
<Call name="setContextAttribute">
<Arg>org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern</Arg>
<Arg>.*/.*jsp-api-[^/]*\.jar$|.*/.*jsp-[^/]*\.jar$|.*/.*taglibs[^/]*\.jar$</Arg>
</Call>
</New>
</Arg>
</Call>
<!-- =========================================================== -->
<!-- Configure the context deployer -->
<!-- A context deployer will deploy contexts described in -->
@ -193,16 +221,16 @@
<!-- in the $JETTY_HOME/contexts directory -->
<!-- -->
<!-- =========================================================== -->
<Call name="addLifeCycle">
<Arg>
<New class="org.mortbay.jetty.deployer.ContextDeployer">
<Set name="contexts"><Ref id="Contexts"/></Set>
<Set name="configurationDir">./eepsite/contexts</Set>
<!-- set to 60 to have it check for changes once a minute -->
<Set name="scanInterval">0</Set>
</New>
</Arg>
</Call>
<Ref id="DeploymentManager">
<Call name="addAppProvider">
<Arg>
<New class="org.eclipse.jetty.deploy.providers.ContextProvider">
<Set name="monitoredDirName">./eepsite/contexts</Set>
<Set name="scanInterval">30</Set>
</New>
</Arg>
</Call>
</Ref>
<!-- =========================================================== -->
<!-- Configure the webapp deployer. -->
@ -219,7 +247,7 @@
<!-- =========================================================== -->
<Call name="addLifeCycle">
<Arg>
<New class="org.mortbay.jetty.deployer.WebAppDeployer">
<New class="org.eclipse.jetty.deploy.WebAppDeployer">
<Set name="contexts"><Ref id="Contexts"/></Set>
<Set name="webAppDir">./eepsite/webapps</Set>
<Set name="parentLoaderPriority">false</Set>
@ -231,6 +259,20 @@
</Arg>
</Call>
<!-- FIXME Above is deprecated, but this doesn't work
java.lang.IllegalStateException: No Method: <Call name="addAppProvider"><New class="org.eclipse.jetty.deploy.providers.WebAppProvider"><Set name="monitoredDirName">./eepsite/webapps</Set><Set name="parentLoaderPriority">false</Set><Set name="extractWars">false</Set><Set name="defaultsDescriptor">./eepsite/etc/webdefault.xml</Set></New></Call> on class org.eclipse.jetty.deploy.DeploymentManager
<Ref id="DeploymentManager">
<Call id="webappprovider" name="addAppProvider">
<New class="org.eclipse.jetty.deploy.providers.WebAppProvider">
<Set name="monitoredDirName">./eepsite/webapps</Set>
<Set name="parentLoaderPriority">false</Set>
<Set name="extractWars">false</Set>
<Set name="defaultsDescriptor">./eepsite/etc/webdefault.xml</Set>
</New>
</Call>
</Ref>
-->
<!-- =========================================================== -->
<!-- Configure Authentication Realms -->
<!-- Realms may be configured for the entire server here, or -->
@ -240,9 +282,9 @@
<!-- =========================================================== -->
<!-- UNCOMMENT TO ACTIVATE
<Set name="UserRealms">
<Array type="org.mortbay.jetty.security.UserRealm">
<Array type="org.eclipse.jetty.security.LoginService">
<Item>
<New class="org.mortbay.jetty.security.HashUserRealm">
<New class="org.eclipse.jetty.security.HashLoginService">
<Set name="name">Test Realm</Set>
<Set name="config">./eepsite/etc/realm.properties</Set>
<Set name="refreshInterval">0</Set>

View File

@ -35,13 +35,15 @@ import net.i2p.router.RouterContext;
*/
abstract class MigrateJetty {
private static boolean _wasChecked;
private static boolean _hasJetty6;
private static boolean _hasLatestJetty;
private static final String OLD_CLASS = "org.mortbay.jetty.Server";
private static final String NEW_CLASS = "org.mortbay.start.Main";
private static final String BACKUP = "jetty5.xml";
private static final String JETTY6_TEMPLATE_DIR = "eepsite-jetty6";
private static final String JETTY6_TEMPLATE_PKGDIR = "eepsite";
private static final String OLD_CLASS_6 = "org.mortbay.start.Main";
private static final String NEW_CLASS = "net.i2p.jetty.JettyStart";
private static final String TEST_CLASS = "org.eclipse.jetty.server.Server";
private static final String BACKUP = "jetty6.xml";
private static final String JETTY_TEMPLATE_DIR = "eepsite-jetty7";
private static final String JETTY_TEMPLATE_PKGDIR = "eepsite";
private static final String BASE_CONTEXT = "contexts/base-context.xml";
private static final String CGI_CONTEXT = "contexts/cgi-context.xml";
@ -49,13 +51,13 @@ abstract class MigrateJetty {
boolean shouldSave = false;
for (int i = 0; i < apps.size(); i++) {
ClientAppConfig app = apps.get(i);
if (!app.className.equals(OLD_CLASS))
if (!(app.className.equals(OLD_CLASS) || app.className.equals(OLD_CLASS_6)))
continue;
String client = "client application " + i + " [" + app.clientName +
"] from Jetty 5 " + OLD_CLASS +
" to Jetty 6 " + NEW_CLASS;
if (!hasJetty6()) {
System.err.println("WARNING: Jetty 6 unavailable, cannot migrate " + client);
"] from Jetty 5/6 " + app.className +
" to Jetty 7 " + NEW_CLASS;
if (!hasLatestJetty()) {
System.err.println("WARNING: Jetty 7 unavailable, cannot migrate " + client);
continue;
}
if (app.args == null)
@ -83,10 +85,10 @@ abstract class MigrateJetty {
", cannot migrate " + client);
continue;
}
File baseEep = new File(ctx.getBaseDir(), JETTY6_TEMPLATE_DIR);
File baseEep = new File(ctx.getBaseDir(), JETTY_TEMPLATE_DIR);
// in packages, or perhaps on an uninstall/reinstall, the files are in eepsite/
if (!baseEep.exists())
baseEep = new File(ctx.getBaseDir(), JETTY6_TEMPLATE_PKGDIR);
baseEep = new File(ctx.getBaseDir(), JETTY_TEMPLATE_PKGDIR);
if (baseEep.equals(eepsite)) {
// non-split directory yet not an upgrade? shouldn't happen
System.err.println("Eepsite in non-split directory " + eepsite +
@ -132,28 +134,29 @@ abstract class MigrateJetty {
}
if (shouldSave) {
File cfgFile = ClientAppConfig.configFile(ctx);
File backup = new File(cfgFile.getAbsolutePath() + ".jetty5");
File backup = new File(cfgFile.getAbsolutePath() + ".jetty6");
if (backup.exists())
backup = new File(cfgFile.getAbsolutePath() + ctx.random().nextInt());
boolean ok = WorkingDir.copyFile(cfgFile, backup);
if (ok) {
ClientAppConfig.writeClientAppConfig(ctx, apps);
System.err.println("WARNING: Migrated clients config file " + cfgFile +
" from Jetty 5 " + OLD_CLASS +
" to Jetty 6 " + NEW_CLASS + "\n" +
" from Jetty 5/6 " + OLD_CLASS + '/' + OLD_CLASS_6 +
" to Jetty 7 " + NEW_CLASS + "\n" +
"Your old clients config file was saved as " + backup);
}
}
}
private static boolean hasJetty6() {
/** do we have Jetty 7? */
private static boolean hasLatestJetty() {
if (!_wasChecked) {
try {
LoadClientAppsJob.testClient(NEW_CLASS, null);
_hasJetty6 = true;
LoadClientAppsJob.testClient(TEST_CLASS, null);
_hasLatestJetty = true;
} catch (ClassNotFoundException cnfe) {}
_wasChecked = true;
}
return _hasJetty6;
return _hasLatestJetty;
}
}