Bug 345729 remove previous solution in lew of more general approach allowing for the application of a jetty-web.xml type file to all contexts in the binding phase

git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@3208 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
Jesse McConnell 2011-05-18 20:01:09 +00:00
parent d722830f0b
commit a85e00f3ff
6 changed files with 110 additions and 204 deletions

View File

@ -0,0 +1,72 @@
package org.eclipse.jetty.deploy.bindings;
import java.net.URL;
import org.eclipse.jetty.deploy.App;
import org.eclipse.jetty.deploy.AppLifeCycle;
import org.eclipse.jetty.deploy.graph.Node;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.resource.FileResource;
import org.eclipse.jetty.util.resource.Resource;
import org.eclipse.jetty.webapp.WebAppContext;
import org.eclipse.jetty.xml.XmlConfiguration;
public class GlobalJettyXmlBinding implements AppLifeCycle.Binding
{
private String _jettyXml;
public String getJettyXml()
{
return _jettyXml;
}
public void setJettyXml(String jettyXml)
{
this._jettyXml = jettyXml;
}
public String[] getBindingTargets()
{
return new String[] { "deploying" };
}
public void processBinding(Node node, App app) throws Exception
{
ContextHandler handler = app.getContextHandler();
if (handler == null)
{
throw new NullPointerException("No Handler created for App: " + app);
}
if (handler instanceof WebAppContext)
{
WebAppContext context = (WebAppContext)handler;
if (Log.isDebugEnabled())
{
Log.debug("Binding: Configuring webapp context with global settings from: " + _jettyXml);
}
if ( _jettyXml == null )
{
Log.warn("Binding: global context binding is enabled but no jetty-web.xml file has been registered");
}
Resource globalContextSettings = new FileResource(new URL(_jettyXml));
if (globalContextSettings.exists())
{
XmlConfiguration jettyXmlConfig = new XmlConfiguration(globalContextSettings.getInputStream());
jettyXmlConfig.configure(context);
}
else
{
Log.info("Binding: Unable to locate global webapp context settings: " + _jettyXml);
}
}
}
}

View File

@ -1,86 +0,0 @@
package org.eclipse.jetty.deploy.bindings;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.jetty.deploy.App;
import org.eclipse.jetty.deploy.AppLifeCycle;
import org.eclipse.jetty.deploy.graph.Node;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.webapp.WebAppContext;
/**
* This binding allows a user to manage a server wide policy of server
* and system classes as they exist for the webapp context. These settings
* can alter and override any that might have been set during context handler
* creation.
*
*/
public class WebappClasspathPatternBinding implements AppLifeCycle.Binding
{
private List<String> _serverClasses = new ArrayList<String>();
private List<String> _systemClasses = new ArrayList<String>();
/**
* if true, this binding will replace server and system classes instead
* of merging with whatever is in the ContextHandler when processBinding
* is invoked.
*/
private boolean _override = false;
public void setOverride( boolean override )
{
_override = override;
}
public void setServerClasses(String[] serverClasses)
{
for ( String entry : serverClasses )
{
_serverClasses.add(entry);
}
}
public void setSystemClasses(String[] systemClasses)
{
for (String entry : systemClasses)
{
_systemClasses.add(entry);
}
}
public String[] getBindingTargets()
{
return new String[] { "deploying" };
}
public void processBinding(Node node, App app) throws Exception
{
ContextHandler handler = app.getContextHandler();
if (handler == null)
{
throw new NullPointerException("No Handler created for App: " + app);
}
if (handler instanceof WebAppContext)
{
WebAppContext webapp = (WebAppContext)handler;
if ( !_override )
{
for ( String entry : webapp.getServerClasses() )
{
_serverClasses.add(entry);
}
for ( String entry : webapp.getSystemClasses() )
{
_systemClasses.add(entry);
}
}
webapp.setServerClasses( _serverClasses.toArray(new String[_serverClasses.size()]) );
webapp.setSystemClasses( _systemClasses.toArray(new String[_systemClasses.size()]) );
}
}
}

View File

@ -15,21 +15,26 @@
// ========================================================================
package org.eclipse.jetty.deploy.bindings;
import java.io.File;
import junit.framework.Assert;
import org.eclipse.jetty.deploy.providers.ScanningAppProvider;
import org.eclipse.jetty.deploy.test.XmlConfiguredJetty;
import org.eclipse.jetty.toolchain.test.IO;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
import org.eclipse.jetty.toolchain.test.TestingDir;
import org.eclipse.jetty.webapp.WebAppContext;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
/**
* Tests {@link ScanningAppProvider} as it starts up for the first time.
*/
public class WebappClasspathPatternBindingTest
public class GlobalJettyXmlBindingTest
{
@Rule
public TestingDir testdir = new TestingDir();
@ -40,17 +45,11 @@ public class WebappClasspathPatternBindingTest
{
jetty = new XmlConfiguredJetty(testdir);
jetty.addConfiguration("jetty.xml");
// jetty.addConfiguration("jetty-deploymgr-contexts.xml");
// Setup initial context
jetty.copyContext("foo.xml","foo.xml");
jetty.copyWebapp("foo-webapp-1.war","foo.war");
// Should not throw an Exception
// jetty.load();
// Start it
// jetty.start();
}
@After
@ -63,6 +62,8 @@ public class WebappClasspathPatternBindingTest
@Test
public void testServerAndSystemClassesOverride() throws Exception
{
IO.copy(MavenTestingUtils.getTestResourceFile("context-binding-test-1.xml"), new File(jetty.getJettyHome(), "context-binding-test-1.xml"));
jetty.addConfiguration("binding-test-contexts-1.xml");
jetty.load();
jetty.start();
@ -100,46 +101,5 @@ public class WebappClasspathPatternBindingTest
Assert.assertFalse(jndiPackage);
}
@Test
public void testServerAndSystemClassesModification() throws Exception
{
jetty.addConfiguration("binding-test-contexts-2.xml");
jetty.load();
jetty.start();
WebAppContext context = jetty.getWebAppContexts().get(0);
Assert.assertNotNull(context);
Assert.assertEquals(context.getDefaultServerClasses().length,context.getServerClasses().length - 1); // added a pattern
Assert.assertEquals(context.getDefaultSystemClasses().length,context.getSystemClasses().length - 1); // added a pattern
boolean testPackageServer = false;
for (String entry : context.getSystemClasses())
{
if ("com.foo.test.".equals(entry))
{
testPackageServer = true;
}
}
Assert.assertTrue(testPackageServer);
boolean testPackageSystem = false;
for (String entry : context.getSystemClasses())
{
if ("com.foo.test.".equals(entry))
{
testPackageSystem = true;
}
}
Assert.assertTrue(testPackageSystem);
}
}

View File

@ -30,17 +30,13 @@
<New id="DeploymentManager" class="org.eclipse.jetty.deploy.DeploymentManager">
<Set name="contexts">
<Ref id="Contexts" />
</Set>
</Set>
<Ref id="DeploymentManager">
<Call name="addLifeCycleBinding">
<Arg>
<New class="org.eclipse.jetty.deploy.bindings.WebappClasspathPatternBinding">
<Set name="override">true</Set>
<Set name="serverClasses"><Ref id="serverClasses"/></Set>
<Set name="systemClasses"><Ref id="systemClasses"/></Set>
<New class="org.eclipse.jetty.deploy.bindings.GlobalJettyXmlBinding">
<Set name="jettyXml">file://<SystemProperty name="jetty.home" />/context-binding-test-1.xml</Set>
</New>
</Arg>
</Call>

View File

@ -1,63 +0,0 @@
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
<Configure id="Server" class="org.eclipse.jetty.server.Server">
<Array id="serverClasses" type="java.lang.String">
<Item>org.foo.test.</Item>
</Array>
<Array id="systemClasses" type="java.lang.String">
<Item>com.foo.test.</Item>
</Array>
<Call name="addLifeCycle">
<Arg>
<New id="DeploymentManager" class="org.eclipse.jetty.deploy.DeploymentManager">
<Set name="contexts">
<Ref id="Contexts" />
</Set>
<Ref id="DeploymentManager">
<Call name="addLifeCycleBinding">
<Arg>
<New class="org.eclipse.jetty.deploy.bindings.WebappClasspathPatternBinding">
<Set name="serverClasses"><Ref id="serverClasses"/></Set>
<Set name="systemClasses"><Ref id="systemClasses"/></Set>
</New>
</Arg>
</Call>
</Ref>
<!-- Providers of Apps -->
<Set name="appProviders">
<Array type="org.eclipse.jetty.deploy.AppProvider">
<Item>
<New class="org.eclipse.jetty.deploy.providers.ContextProvider">
<Set name="monitoredDirName"><SystemProperty name="jetty.home" />/contexts</Set>
<Set name="scanInterval">1</Set>
<Set name="configurationManager">
<New class="org.eclipse.jetty.deploy.FileConfigurationManager">
<Set name="file">
<Property name="test.targetdir" default="target" />/xml-configured-jetty.properties
</Set>
</New>
</Set>
</New>
</Item>
<Item>
<New class="org.eclipse.jetty.deploy.providers.WebAppProvider">
<Set name="monitoredDirName"><SystemProperty name="jetty.home" />/webapps</Set>
<Set name="scanInterval">1</Set>
<Set name="contextXmlDir"><SystemProperty name="jetty.home" />/contexts</Set>
</New>
</Item>
</Array>
</Set>
</New>
</Arg>
</Call>
</Configure>

View File

@ -0,0 +1,27 @@
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
<Array id="serverClasses" type="java.lang.String">
<Item>-org.eclipse.jetty.continuation.</Item>
<Item>-org.eclipse.jetty.jndi.</Item>
<Item>-org.eclipse.jetty.plus.jaas.</Item>
<Item>-org.eclipse.jetty.websocket.</Item>
<Item>-org.eclipse.jetty.servlet.DefaultServlet</Item>
<Item>org.eclipse.jetty.</Item>
<Item>org.eclipse.foo.</Item>
</Array>
<Array id="systemClasses" type="java.lang.String">
<Item>java.</Item>
<Item>javax.</Item>
<Item>org.xml.</Item>
<Item>org.w3c.</Item>
<Item>org.apache.commons.logging</Item>
<Item>org.eclipse.jetty.continuation</Item>
<Item>org.eclipse.jetty.plus.jaas.</Item>
<Item>org.eclipse.jetty.websocket</Item>
<Item>org.eclipse.jetty.servlet.DefaultServlet</Item>
</Array>
<Set name="serverClasses"><Ref id="serverClasses"/></Set>
<Set name="systemClasses"><Ref id="systemClasses"/></Set>
</Configure>