310051 - _configurationClasses now defaults to null in WebAppContext

git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@1547 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
Jan Bartel 2010-04-22 11:01:01 +00:00
parent fb284cb2a8
commit 5731200946
3 changed files with 113 additions and 10 deletions

View File

@ -11,6 +11,7 @@ jetty-7.1-SNAPSHOT
+ 308925 Protect the test webapp from remote access
+ 309466 Removed synchronization from StdErrLog
+ 309765 Added JSP module
+ 310051 _configurationClasses now defaults to null in WebAppContext
+ JETTY-903 Stop both caches
+ JETTY-1200 SSL NIO Endpoint wraps non NIO buffers
+ JETTY-1202 Use platform default algorithm for SecureRandom

View File

@ -19,7 +19,6 @@ import java.net.MalformedURLException;
import java.security.PermissionCollection;
import java.util.EventListener;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpSessionActivationListener;
@ -30,6 +29,7 @@ import javax.servlet.http.HttpSessionListener;
import org.eclipse.jetty.security.SecurityHandler;
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.HandlerContainer;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.server.handler.ErrorHandler;
import org.eclipse.jetty.server.session.SessionHandler;
@ -74,7 +74,7 @@ public class WebAppContext extends ServletContextHandler
"org.eclipse.jetty.webapp.JettyWebXmlConfiguration",
"org.eclipse.jetty.webapp.TagLibConfiguration"
} ;
private String[] _configurationClasses=null;
private String[] _configurationClasses=__dftConfigurationClasses;
private Configuration[] _configurations;
private String _defaultsDescriptor=WEB_DEFAULTS_XML;
private String _descriptor=null;
@ -113,6 +113,8 @@ public class WebAppContext extends ServletContextHandler
private Map _resourceAliases;
private boolean _ownClassLoader=false;
private boolean _configurationDiscovered=true;
private boolean _configurationClassesSet=false;
private boolean _configurationsSet=false;
public static ContextHandler getCurrentWebAppContext()
{
@ -644,21 +646,27 @@ public class WebAppContext extends ServletContextHandler
return _parentLoaderPriority;
}
/* ------------------------------------------------------------ */
public String[] getDefaultConfigurationClasses ()
{
return __dftConfigurationClasses;
}
/* ------------------------------------------------------------ */
protected void loadConfigurations()
throws Exception
{
//if the configuration instances have been set explicitly, use them
if (_configurations!=null)
return;
//look for a Server attribute with the list of names of Configuration classes
//to apply to every web app. If not present, use our defaults.
String[] serverConfigs = (String[])getServer().getAttribute(SERVER_CONFIG);
if (serverConfigs != null)
_configurationClasses = serverConfigs;
if (_configurationClasses == null)
_configurationClasses=__dftConfigurationClasses;
//if the configuration classnames have been set explicitly use them
if (!_configurationClassesSet){
System.err.println("DEFAULTS");
_configurationClasses=__dftConfigurationClasses;}
_configurations = new Configuration[_configurationClasses.length];
for (int i = 0; i < _configurationClasses.length; i++)
{
@ -695,6 +703,7 @@ public class WebAppContext extends ServletContextHandler
public void setConfigurationClasses(String[] configurations)
{
_configurationClasses = configurations==null?null:(String[])configurations.clone();
_configurationClassesSet = true;
}
/* ------------------------------------------------------------ */
@ -704,6 +713,7 @@ public class WebAppContext extends ServletContextHandler
public void setConfigurations(Configuration[] configurations)
{
_configurations = configurations==null?null:(Configuration[])configurations.clone();
_configurationsSet = true;
}
/* ------------------------------------------------------------ */
@ -950,6 +960,24 @@ public class WebAppContext extends ServletContextHandler
{
this._logUrlOnStart = logOnStart;
}
/* ------------------------------------------------------------ */
@Override
public void setServer(Server server)
{
super.setServer(server);
//if we haven't been given a set of configuration instances to
//use, and we haven't been given a set of configuration classes
//to use, use the configuration classes that came from the
//Server (if there are any)
if (!_configurationsSet && !_configurationClassesSet && server != null)
{
String[] serverConfigs = (String[])server.getAttribute(SERVER_CONFIG);
if (serverConfigs != null)
setConfigurationClasses(serverConfigs);
}
}
/* ------------------------------------------------------------ */
@Override

View File

@ -0,0 +1,74 @@
// ========================================================================
// Copyright (c) 2010 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
package org.eclipse.jetty.webapp;
import java.util.Arrays;
import org.eclipse.jetty.server.Server;
import junit.framework.TestCase;
public class WebAppContextTest extends TestCase
{
public void testConfigurationClassesFromDefault ()
{
Server server = new Server();
//test if no classnames set, its the defaults
WebAppContext wac = new WebAppContext();
assertNull(wac.getConfigurations());
String[] classNames = wac.getConfigurationClasses();
assertNotNull(classNames);
//test if no classname set, and none from server its the defaults
wac.setServer(server);
assertEquals(classNames, wac.getConfigurationClasses());
}
public void testConfigurationClassesExplicit ()
{
String[] classNames = {"x.y.z"};
Server server = new Server();
server.setAttribute(WebAppContext.SERVER_CONFIG, classNames);
//test an explicitly set classnames list overrides that from the server
WebAppContext wac = new WebAppContext();
String[] myClassNames = {"a.b.c", "d.e.f"};
wac.setConfigurationClasses(myClassNames);
wac.setServer(server);
String[] names = wac.getConfigurationClasses();
assertTrue(Arrays.equals(myClassNames, names));
//test if no explicit classnames, they come from the server
WebAppContext wac2 = new WebAppContext();
wac2.setServer(server);
assertTrue(Arrays.equals(classNames, wac2.getConfigurationClasses()));
}
public void testConfigurationInstances ()
{
Configuration[] configs = {new WebInfConfiguration()};
WebAppContext wac = new WebAppContext();
wac.setConfigurations(configs);
assertTrue(Arrays.equals(configs, wac.getConfigurations()));
//test that explicit config instances override any from server
String[] classNames = {"x.y.z"};
Server server = new Server();
server.setAttribute(WebAppContext.SERVER_CONFIG, classNames);
wac.setServer(server);
assertTrue(Arrays.equals(configs,wac.getConfigurations()));
}
}