From 543118f837516fc5801e27ff4aaefb03647a9582 Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Thu, 4 Nov 2010 02:08:49 +0000 Subject: [PATCH] 329410 Enforce XmlConfiguration properties as Map git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@2469 7e9141cc-0065-0410-87d8-b60c137991c4 --- VERSION.txt | 1 + .../jetty/deploy/ConfigurationManager.java | 2 +- .../deploy/FileConfigurationManager.java | 6 +- .../deploy/providers/ContextProvider.java | 5 +- .../deploy/providers/ScanningAppProvider.java | 8 +- .../jetty/deploy/test/XmlConfiguredJetty.java | 108 +++++++++--------- .../serverfactory/ServerInstanceWrapper.java | 18 +-- .../eclipse/jetty/server/ResourceCache.java | 6 + .../webapp/JettyWebXmlConfiguration.java | 8 +- .../jetty/webapp/WebAppClassLoader.java | 42 +++---- .../eclipse/jetty/webapp/WebAppContext.java | 12 +- .../eclipse/jetty/xml/XmlConfiguration.java | 38 +++--- .../test/support/TestableJettyServer.java | 63 +++++----- 13 files changed, 175 insertions(+), 142 deletions(-) diff --git a/VERSION.txt b/VERSION.txt index f382ba0186a..876cdab5cf7 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -11,6 +11,7 @@ jetty-7.2.1-SNAPSHOT + 328885 web overrides do not override + 328988 Idle saving of session values + 329180 Spin check for Selector to stop + + 329410 Enforce XmlConfiguration properties as Map + JETTY-748 Prevent race close of socket by old acceptor threads + JETTY-1291 Extract query parameters even if POST content consumed + JETTY-1295 Contexts mixed up when hot-deploying on virtual hosts diff --git a/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/ConfigurationManager.java b/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/ConfigurationManager.java index 7584ffb7f61..9016e22ccf7 100644 --- a/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/ConfigurationManager.java +++ b/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/ConfigurationManager.java @@ -22,5 +22,5 @@ import java.util.Map; */ public interface ConfigurationManager { - public Map getProperties(); + public Map getProperties(); } diff --git a/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/FileConfigurationManager.java b/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/FileConfigurationManager.java index e5ffaa7e123..7cd67d1bad9 100644 --- a/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/FileConfigurationManager.java +++ b/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/FileConfigurationManager.java @@ -30,7 +30,7 @@ import org.eclipse.jetty.util.resource.Resource; public class FileConfigurationManager implements ConfigurationManager { private Resource _file; - private Map _map = new HashMap(); + private Map _map = new HashMap(); public FileConfigurationManager() { @@ -44,7 +44,7 @@ public class FileConfigurationManager implements ConfigurationManager /** * @see org.eclipse.jetty.deploy.ConfigurationManager#getProperties() */ - public Map getProperties() + public Map getProperties() { try { @@ -64,7 +64,7 @@ public class FileConfigurationManager implements ConfigurationManager Properties properties = new Properties(); properties.load(_file.getInputStream()); for (Map.Entry entry : properties.entrySet()) - _map.put(entry.getKey().toString(),entry.getValue()); + _map.put(entry.getKey().toString(),String.valueOf(entry.getValue())); } } } diff --git a/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/providers/ContextProvider.java b/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/providers/ContextProvider.java index 92940acee7a..3191f14405b 100644 --- a/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/providers/ContextProvider.java +++ b/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/providers/ContextProvider.java @@ -64,8 +64,9 @@ public class ContextProvider extends ScanningAppProvider if (resource.exists() && FileID.isXmlFile(file)) { XmlConfiguration xmlc = new XmlConfiguration(resource.getURL()); - Map props = new HashMap(); - props.put("Server",getDeploymentManager().getServer()); + Map props = new HashMap(); + + xmlc.getIdMap().put("Server",getDeploymentManager().getServer()); if (getConfigurationManager() != null) props.putAll(getConfigurationManager().getProperties()); xmlc.setProperties(props); diff --git a/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/providers/ScanningAppProvider.java b/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/providers/ScanningAppProvider.java index 09cce7cf14a..ab92209f69f 100644 --- a/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/providers/ScanningAppProvider.java +++ b/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/providers/ScanningAppProvider.java @@ -213,14 +213,18 @@ public abstract class ScanningAppProvider extends AbstractLifeCycle implements A } /* ------------------------------------------------------------ */ - @Deprecated + /** + * @deprecated use {@link #setMonitoredDirResource(Resource)} + */ public void setMonitoredDir(Resource dir) { setMonitoredDirResource(dir); } /* ------------------------------------------------------------ */ - @Deprecated + /** + * @deprecated use {@link #setMonitoredDirName(String)} + */ public void setMonitoredDir(String dir) { setMonitoredDirName(dir); diff --git a/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/test/XmlConfiguredJetty.java b/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/test/XmlConfiguredJetty.java index 52704a4b1e3..09271dcc12a 100644 --- a/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/test/XmlConfiguredJetty.java +++ b/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/test/XmlConfiguredJetty.java @@ -28,7 +28,9 @@ import java.net.URL; import java.net.URLConnection; import java.net.UnknownHostException; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Properties; import org.eclipse.jetty.deploy.DeploymentManager; @@ -48,12 +50,12 @@ import org.junit.Assert; */ public class XmlConfiguredJetty { - private List xmlConfigurations; - private Properties properties = new Properties(); - private Server server; - private int serverPort; - private String scheme = HttpSchemes.HTTP; - private File jettyHome; + private List _xmlConfigurations; + private Map _properties = new HashMap(); + private Server _server; + private int _serverPort; + private String _scheme = HttpSchemes.HTTP; + private File _jettyHome; public XmlConfiguredJetty() throws IOException { @@ -62,52 +64,52 @@ public class XmlConfiguredJetty public XmlConfiguredJetty(String testname) throws IOException { - xmlConfigurations = new ArrayList(); - properties = new Properties(); + _xmlConfigurations = new ArrayList(); + Properties properties = new Properties(); String jettyHomeBase = MavenTestingUtils.getTargetTestingDir(testname).getAbsolutePath(); // Ensure we have a new (pristene) directory to work with. int idx = 0; - jettyHome = new File(jettyHomeBase + "#" + idx); - while (jettyHome.exists()) + _jettyHome = new File(jettyHomeBase + "#" + idx); + while (_jettyHome.exists()) { idx++; - jettyHome = new File(jettyHomeBase + "#" + idx); + _jettyHome = new File(jettyHomeBase + "#" + idx); } - deleteContents(jettyHome); + deleteContents(_jettyHome); // Prepare Jetty.Home (Test) dir - jettyHome.mkdirs(); + _jettyHome.mkdirs(); - File logsDir = new File(jettyHome,"logs"); + File logsDir = new File(_jettyHome,"logs"); logsDir.mkdirs(); - File etcDir = new File(jettyHome,"etc"); + File etcDir = new File(_jettyHome,"etc"); etcDir.mkdirs(); IO.copyFile(MavenTestingUtils.getTestResourceFile("etc/realm.properties"),new File(etcDir,"realm.properties")); IO.copyFile(MavenTestingUtils.getTestResourceFile("etc/webdefault.xml"),new File(etcDir,"webdefault.xml")); - File contextsDir = new File(jettyHome,"contexts"); + File contextsDir = new File(_jettyHome,"contexts"); if (contextsDir.exists()) { deleteContents(contextsDir); } contextsDir.mkdirs(); - File webappsDir = new File(jettyHome,"webapps"); + File webappsDir = new File(_jettyHome,"webapps"); if (webappsDir.exists()) { deleteContents(webappsDir); } webappsDir.mkdirs(); - File tmpDir = new File(jettyHome,"tmp"); + File tmpDir = new File(_jettyHome,"tmp"); if (tmpDir.exists()) { deleteContents(tmpDir); } tmpDir.mkdirs(); - File workishDir = new File(jettyHome,"workish"); + File workishDir = new File(_jettyHome,"workish"); if (workishDir.exists()) { deleteContents(workishDir); @@ -116,8 +118,8 @@ public class XmlConfiguredJetty // Setup properties System.setProperty("java.io.tmpdir",tmpDir.getAbsolutePath()); - properties.setProperty("jetty.home",jettyHome.getAbsolutePath()); - System.setProperty("jetty.home",jettyHome.getAbsolutePath()); + properties.setProperty("jetty.home",_jettyHome.getAbsolutePath()); + System.setProperty("jetty.home",_jettyHome.getAbsolutePath()); properties.setProperty("test.basedir",MavenTestingUtils.getBasedir().getAbsolutePath()); properties.setProperty("test.resourcesdir",MavenTestingUtils.getTestResourcesDir().getAbsolutePath()); properties.setProperty("test.webapps",webappsDir.getAbsolutePath()); @@ -128,11 +130,13 @@ public class XmlConfiguredJetty File testConfig = MavenTestingUtils.getTargetFile("xml-configured-jetty.properties"); FileOutputStream out = new FileOutputStream(testConfig); properties.store(out,"Generated by " + XmlConfiguredJetty.class.getName()); + for (Object key:properties.keySet()) + _properties.put(String.valueOf(key),String.valueOf(properties.get(key))); } public void addConfiguration(File xmlConfigFile) throws MalformedURLException { - xmlConfigurations.add(xmlConfigFile.toURI().toURL()); + _xmlConfigurations.add(xmlConfigFile.toURI().toURL()); } public void addConfiguration(String testConfigName) throws MalformedURLException @@ -142,7 +146,7 @@ public class XmlConfiguredJetty public void addConfiguration(URL xmlConfig) { - xmlConfigurations.add(xmlConfig); + _xmlConfigurations.add(xmlConfig); } public void assertNoWebAppContexts() @@ -221,7 +225,7 @@ public class XmlConfiguredJetty { System.out.printf("Copying Context: %s -> %s%n",srcName,destName); File srcDir = MavenTestingUtils.getTestResourceDir("contexts"); - File destDir = new File(jettyHome,"contexts"); + File destDir = new File(_jettyHome,"contexts"); File srcFile = new File(srcDir,srcName); File destFile = new File(destDir,destName); @@ -242,7 +246,7 @@ public class XmlConfiguredJetty { System.out.printf("Copying Webapp: %s -> %s%n",srcName,destName); File srcDir = MavenTestingUtils.getTestResourceDir("webapps"); - File destDir = new File(jettyHome,"webapps"); + File destDir = new File(_jettyHome,"webapps"); File srcFile = new File(srcDir,srcName); File destFile = new File(destDir,destName); @@ -276,48 +280,48 @@ public class XmlConfiguredJetty public DeploymentManager getActiveDeploymentManager() { - return server.getBean(DeploymentManager.class); + return _server.getBean(DeploymentManager.class); } public File getJettyDir(String name) { - return new File(jettyHome,name); + return new File(_jettyHome,name); } public File getJettyHome() { - return jettyHome; + return _jettyHome; } public String getScheme() { - return scheme; + return _scheme; } public Server getServer() { - return server; + return _server; } public int getServerPort() { - return serverPort; + return _serverPort; } public URI getServerURI() throws UnknownHostException { StringBuffer uri = new StringBuffer(); - uri.append(this.scheme).append("://"); + uri.append(this._scheme).append("://"); uri.append(InetAddress.getLocalHost().getHostAddress()); - uri.append(":").append(this.serverPort); + uri.append(":").append(this._serverPort); return URI.create(uri.toString()); } public List getWebAppContexts() { List contexts = new ArrayList(); - HandlerCollection handlers = (HandlerCollection)server.getHandler(); - System.out.println(server.dump()); + HandlerCollection handlers = (HandlerCollection)_server.getHandler(); + System.out.println(_server.dump()); Handler children[] = handlers.getChildHandlers(); for (Handler handler : children) @@ -336,18 +340,18 @@ public class XmlConfiguredJetty public void load() throws Exception { XmlConfiguration last = null; - Object[] obj = new Object[this.xmlConfigurations.size()]; + Object[] obj = new Object[this._xmlConfigurations.size()]; // Configure everything - for (int i = 0; i < this.xmlConfigurations.size(); i++) + for (int i = 0; i < this._xmlConfigurations.size(); i++) { - URL configURL = this.xmlConfigurations.get(i); + URL configURL = this._xmlConfigurations.get(i); XmlConfiguration configuration = new XmlConfiguration(configURL); if (last != null) { configuration.getIdMap().putAll(last.getIdMap()); } - configuration.setProperties(properties); + configuration.setProperties(_properties); obj[i] = configuration.configure(); last = configuration; } @@ -355,7 +359,7 @@ public class XmlConfiguredJetty // Test for Server Instance. Server foundServer = null; int serverCount = 0; - for (int i = 0; i < this.xmlConfigurations.size(); i++) + for (int i = 0; i < this._xmlConfigurations.size(); i++) { if (obj[i] instanceof Server) { @@ -376,14 +380,14 @@ public class XmlConfiguredJetty Assert.assertEquals("Server load count",1,serverCount); - this.server = foundServer; - this.server.setGracefulShutdown(10); + this._server = foundServer; + this._server.setGracefulShutdown(10); } public void removeContext(String name) { - File destDir = new File(jettyHome,"contexts"); + File destDir = new File(_jettyHome,"contexts"); File contextFile = new File(destDir,name); if (contextFile.exists()) { @@ -393,34 +397,34 @@ public class XmlConfiguredJetty public void setProperty(String key, String value) { - properties.setProperty(key,value); + _properties.put(key,value); } public void setScheme(String scheme) { - this.scheme = scheme; + this._scheme = scheme; } public void start() throws Exception { - Assert.assertNotNull("Server should not be null (failed load?)",server); + Assert.assertNotNull("Server should not be null (failed load?)",_server); - server.start(); + _server.start(); // Find the active server port. - this.serverPort = (-1); - Connector connectors[] = server.getConnectors(); + this._serverPort = (-1); + Connector connectors[] = _server.getConnectors(); for (int i = 0; i < connectors.length; i++) { Connector connector = connectors[i]; if (connector.getLocalPort() > 0) { - this.serverPort = connector.getLocalPort(); + this._serverPort = connector.getLocalPort(); break; } } - Assert.assertTrue("Server Port is between 1 and 65535. Actually <" + serverPort + ">",(1 <= this.serverPort) && (this.serverPort <= 65535)); + Assert.assertTrue("Server Port is between 1 and 65535. Actually <" + _serverPort + ">",(1 <= this._serverPort) && (this._serverPort <= 65535)); // Uncomment to have server start and continue to run (without exiting) // System.out.printf("Listening to port %d%n",this.serverPort); @@ -429,7 +433,7 @@ public class XmlConfiguredJetty public void stop() throws Exception { - server.stop(); + _server.stop(); } diff --git a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/internal/serverfactory/ServerInstanceWrapper.java b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/internal/serverfactory/ServerInstanceWrapper.java index 7e4afc5b295..a381e616d52 100644 --- a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/internal/serverfactory/ServerInstanceWrapper.java +++ b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/internal/serverfactory/ServerInstanceWrapper.java @@ -248,27 +248,27 @@ public class ServerInstanceWrapper { { return; } - Map id_map = new HashMap(); + Map id_map = new HashMap(); id_map.put("Server",server); - Map properties = new HashMap(); - Enumeration en = props.keys(); + Map properties = new HashMap(); + Enumeration en = props.keys(); while (en.hasMoreElements()) { - Object key = en.nextElement(); - Object value = props.get(key); - properties.put(key, value); + Object key = en.nextElement(); + Object value = props.get(key); + properties.put(String.valueOf(key), String.valueOf(value)); } for (URL jettyConfiguration : jettyConfigurations) { - InputStream is = null; + InputStream is = null; try { // Execute a Jetty configuration file is = jettyConfiguration.openStream(); XmlConfiguration config = new XmlConfiguration(is); - config.setIdMap(id_map); - config.setProperties(properties); + config.getIdMap().putAll(id_map); + config.getProperties().putAll(properties); config.configure(); id_map=config.getIdMap(); } diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/ResourceCache.java b/jetty-server/src/main/java/org/eclipse/jetty/server/ResourceCache.java index 4f107dfd7ae..25f1eae3d3f 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/ResourceCache.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/ResourceCache.java @@ -305,6 +305,12 @@ public class ResourceCache return null; } } + + /* ------------------------------------------------------------ */ + public String toString() + { + return "ResourceCache["+_parent+","+_factory+"]@"+hashCode(); + } /* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */ diff --git a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/JettyWebXmlConfiguration.java b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/JettyWebXmlConfiguration.java index 3acf9b5199c..57701d01f28 100644 --- a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/JettyWebXmlConfiguration.java +++ b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/JettyWebXmlConfiguration.java @@ -97,13 +97,15 @@ public class JettyWebXmlConfiguration extends AbstractConfiguration */ private void setupXmlConfiguration(XmlConfiguration jetty_config, Resource web_inf) { - Map props = jetty_config.getProperties(); + Map props = jetty_config.getProperties(); if (props == null) { - props = new HashMap(); + props = new HashMap(); jetty_config.setProperties(props); } - props.put(PROPERTY_THIS_WEB_INF_URL, web_inf.getURL()); + + // TODO - should this be an id rather than a property? + props.put(PROPERTY_THIS_WEB_INF_URL, String.valueOf(web_inf.getURL())); } } diff --git a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebAppClassLoader.java b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebAppClassLoader.java index 28c4baa6d6f..ded248c8235 100644 --- a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebAppClassLoader.java +++ b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebAppClassLoader.java @@ -25,6 +25,7 @@ import java.util.Collections; import java.util.Enumeration; import java.util.HashSet; import java.util.List; +import java.util.Set; import java.util.StringTokenizer; import org.eclipse.jetty.server.handler.ContextHandler; @@ -52,15 +53,13 @@ import org.eclipse.jetty.util.resource.ResourceCollection; * context classloader will be used. If that is null then the * classloader that loaded this class is used as the parent. * - * */ public class WebAppClassLoader extends URLClassLoader { + private final Context _context; + private final ClassLoader _parent; + private final Set _extensions=new HashSet(); private String _name=String.valueOf(hashCode()); - private Context _context; - private ClassLoader _parent; - private HashSet _extensions; - /* ------------------------------------------------------------ */ /** The Context in which the classloader operates. @@ -142,10 +141,10 @@ public class WebAppClassLoader extends URLClassLoader if (_parent==null) throw new IllegalArgumentException("no parent classloader!"); - _extensions = new HashSet(); _extensions.add(".jar"); _extensions.add(".zip"); + // TODO remove this system property String extensions = System.getProperty(WebAppClassLoader.class.getName() + ".extensions"); if(extensions!=null) { @@ -222,25 +221,22 @@ public class WebAppClassLoader extends URLClassLoader if (Log.isDebugEnabled()) Log.debug("Path resource=" + resource); - // Resolve file path if possible - File file= resource.getFile(); - if (file != null) - { - URL url= resource.getURL(); - addURL(url); - } + // Add the resource + if (resource.isDirectory() && resource instanceof ResourceCollection) + addClassPath(resource); else { - // Add resource or expand jar/ - if (!resource.isDirectory() && file == null) - { - throw new IllegalArgumentException("!file: "+resource); - } - else + // Resolve file path if possible + File file= resource.getFile(); + if (file != null) { URL url= resource.getURL(); addURL(url); } + else if (resource.isDirectory()) + addURL(resource.getURL()); + else + throw new IllegalArgumentException("!file: "+resource); } } } @@ -286,12 +282,6 @@ public class WebAppClassLoader extends URLClassLoader } } } - /* ------------------------------------------------------------ */ - public void destroy() - { - this._parent=null; - } - /* ------------------------------------------------------------ */ public PermissionCollection getPermissions(CodeSource cs) @@ -308,7 +298,6 @@ public class WebAppClassLoader extends URLClassLoader boolean system_class=_context.isSystemClass(name); boolean server_class=_context.isServerClass(name); - List from_parent = toList(server_class?null:_parent.getResources(name)); List from_webapp = toList((system_class&&!from_parent.isEmpty())?null:this.findResources(name)); @@ -446,5 +435,4 @@ public class WebAppClassLoader extends URLClassLoader return "WebAppClassLoader@" + _name + "(" + LazyList.array2List(getURLs()) + ") / " + _parent; return "WebAppClassLoader@" + _name; } - } diff --git a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebAppContext.java b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebAppContext.java index aacf3031c68..4f311c99084 100644 --- a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebAppContext.java +++ b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebAppContext.java @@ -867,13 +867,23 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL /* ------------------------------------------------------------ */ /** * The override descriptor is a web.xml format file that is applied to the context after the standard WEB-INF/web.xml - * @param overrideDescriptor The overrideDescritpor to set. + * @param overrideDescriptor The overrideDescriptors (file or URL) to set. */ public void setOverrideDescriptors(List overrideDescriptors) { _overrideDescriptors.clear(); _overrideDescriptors.addAll(overrideDescriptors); } + + /* ------------------------------------------------------------ */ + /** + * The override descriptor is a web.xml format file that is applied to the context after the standard WEB-INF/web.xml + * @param overrideDescriptor The overrideDescriptor (file or URL) to add. + */ + public void addOverrideDescriptor(String overrideDescriptor) + { + _overrideDescriptors.add(overrideDescriptor); + } /* ------------------------------------------------------------ */ /** diff --git a/jetty-xml/src/main/java/org/eclipse/jetty/xml/XmlConfiguration.java b/jetty-xml/src/main/java/org/eclipse/jetty/xml/XmlConfiguration.java index fe01668c496..054c257fe12 100644 --- a/jetty-xml/src/main/java/org/eclipse/jetty/xml/XmlConfiguration.java +++ b/jetty-xml/src/main/java/org/eclipse/jetty/xml/XmlConfiguration.java @@ -68,8 +68,8 @@ public class XmlConfiguration /* ------------------------------------------------------------ */ private static XmlParser __parser; private XmlParser.Node _config; - private Map _idMap = new HashMap(); - private Map _propertyMap = new HashMap(); + private final Map _idMap = new HashMap(); + private final Map _propertyMap = new HashMap(); /* ------------------------------------------------------------ */ private synchronized static void initParser() throws IOException @@ -156,25 +156,33 @@ public class XmlConfiguration } /* ------------------------------------------------------------ */ - public Map getIdMap() + public Map getIdMap() { return _idMap; } /* ------------------------------------------------------------ */ - public void setIdMap(Map map) + /** + * @deprecated use {@link #getIdMap()}.put(...) + */ + public void setIdMap(Map map) { - _idMap=map; + _idMap.clear(); + _idMap.putAll(map); } /* ------------------------------------------------------------ */ - public void setProperties (Map map) + /** + * @deprecated use {@link #getProperties()}.put(...) + */ + public void setProperties (Map map) { - _propertyMap = map; + _propertyMap.clear(); + _propertyMap.putAll(map); } /* ------------------------------------------------------------ */ - public Map getProperties () + public Map getProperties () { return _propertyMap; } @@ -465,7 +473,7 @@ public class XmlConfiguration { if (!(obj instanceof Map)) throw new IllegalArgumentException("Object for put is not a Map: " + obj); - Map map = (Map) obj; + Map map = (Map) obj; String name = node.getAttribute("name"); Object value = value(obj, node); @@ -735,7 +743,7 @@ public class XmlConfiguration { String id = node.getAttribute("id"); - Map map = new HashMap(); + Map map = new HashMap(); if (id != null) _idMap.put(id, map); for (int i = 0; i < node.size(); i++) @@ -892,7 +900,7 @@ public class XmlConfiguration if ("String".equals(type) || "java.lang.String".equals(type)) return value.toString(); - Class pClass = TypeUtil.fromName(type); + Class pClass = TypeUtil.fromName(type); if (pClass != null) return TypeUtil.valueOf(pClass, value.toString()); if ("URL".equals(type) || "java.net.URL".equals(type)) @@ -1009,7 +1017,6 @@ public class XmlConfiguration Log.warn(e); } - // If no start.config properties, use clean slate if (properties==null) properties = new Properties(); @@ -1030,7 +1037,12 @@ public class XmlConfiguration if ( last != null ) configuration.getIdMap().putAll( last.getIdMap() ); if ( properties.size() > 0 ) - configuration.setProperties( properties ); + { + Map props = new HashMap(); + for (Object key:properties.keySet()) + props.put(key.toString(),String.valueOf(properties.get(key))); + configuration.setProperties( props ); + } obj[i] = configuration.configure(); last = configuration; } diff --git a/tests/test-integration/src/test/java/org/eclipse/jetty/test/support/TestableJettyServer.java b/tests/test-integration/src/test/java/org/eclipse/jetty/test/support/TestableJettyServer.java index b4b377e61d9..adc89697a4f 100644 --- a/tests/test-integration/src/test/java/org/eclipse/jetty/test/support/TestableJettyServer.java +++ b/tests/test-integration/src/test/java/org/eclipse/jetty/test/support/TestableJettyServer.java @@ -25,7 +25,9 @@ import java.net.URI; import java.net.URL; import java.net.UnknownHostException; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Properties; import org.eclipse.jetty.http.HttpSchemes; @@ -41,11 +43,11 @@ import org.junit.Ignore; @Ignore public class TestableJettyServer { - private List xmlConfigurations; - private Properties properties = new Properties(); - private Server server; - private int serverPort; - private String scheme = HttpSchemes.HTTP; + private List _xmlConfigurations; + private final Map _properties = new HashMap(); + private Server _server; + private int _serverPort; + private String _scheme = HttpSchemes.HTTP; /* Popular Directories */ private File baseDir; @@ -53,8 +55,8 @@ public class TestableJettyServer public TestableJettyServer() throws IOException { - xmlConfigurations = new ArrayList(); - properties = new Properties(); + _xmlConfigurations = new ArrayList(); + Properties properties = new Properties(); /* Establish Popular Directories */ String baseDirPath = System.getProperty("basedir"); @@ -81,16 +83,19 @@ public class TestableJettyServer File testConfig = new File(targetDir,"testable-jetty-server-config.properties"); FileOutputStream out = new FileOutputStream(testConfig); properties.store(out,"Generated by " + TestableJettyServer.class.getName()); + + for (Object key:properties.keySet()) + _properties.put(String.valueOf(key),String.valueOf(properties.get(key))); } public void addConfiguration(URL xmlConfig) { - xmlConfigurations.add(xmlConfig); + _xmlConfigurations.add(xmlConfig); } public void addConfiguration(File xmlConfigFile) throws MalformedURLException { - xmlConfigurations.add(xmlConfigFile.toURI().toURL()); + _xmlConfigurations.add(xmlConfigFile.toURI().toURL()); } public void addConfiguration(String testConfigName) throws MalformedURLException @@ -100,25 +105,25 @@ public class TestableJettyServer public void setProperty(String key, String value) { - properties.setProperty(key,value); + _properties.put(key,value); } @SuppressWarnings("unchecked") public void load() throws Exception { XmlConfiguration last = null; - Object[] obj = new Object[this.xmlConfigurations.size()]; + Object[] obj = new Object[this._xmlConfigurations.size()]; // Configure everything - for (int i = 0; i < this.xmlConfigurations.size(); i++) + for (int i = 0; i < this._xmlConfigurations.size(); i++) { - URL configURL = this.xmlConfigurations.get(i); + URL configURL = this._xmlConfigurations.get(i); XmlConfiguration configuration = new XmlConfiguration(configURL); if (last != null) { configuration.getIdMap().putAll(last.getIdMap()); } - configuration.setProperties(properties); + configuration.setProperties(_properties); obj[i] = configuration.configure(); last = configuration; } @@ -126,7 +131,7 @@ public class TestableJettyServer // Test for Server Instance. Server foundServer = null; int serverCount = 0; - for (int i = 0; i < this.xmlConfigurations.size(); i++) + for (int i = 0; i < this._xmlConfigurations.size(); i++) { if (obj[i] instanceof Server) { @@ -147,59 +152,59 @@ public class TestableJettyServer Assert.assertEquals("Server load count",1,serverCount); - this.server = foundServer; - this.server.setGracefulShutdown(10); + this._server = foundServer; + this._server.setGracefulShutdown(10); } public String getScheme() { - return scheme; + return _scheme; } public void setScheme(String scheme) { - this.scheme = scheme; + this._scheme = scheme; } public void start() throws Exception { - Assert.assertNotNull("Server should not be null (failed load?)",server); + Assert.assertNotNull("Server should not be null (failed load?)",_server); - server.start(); + _server.start(); // Find the active server port. - this.serverPort = (-1); - Connector connectors[] = server.getConnectors(); + this._serverPort = (-1); + Connector connectors[] = _server.getConnectors(); for (int i = 0; i < connectors.length; i++) { Connector connector = connectors[i]; if (connector.getLocalPort() > 0) { - this.serverPort = connector.getLocalPort(); + this._serverPort = connector.getLocalPort(); break; } } - Assert.assertTrue("Server Port is between 1 and 65535. Actually <" + serverPort + ">",(1 <= this.serverPort) && (this.serverPort <= 65535)); + Assert.assertTrue("Server Port is between 1 and 65535. Actually <" + _serverPort + ">",(1 <= this._serverPort) && (this._serverPort <= 65535)); } public int getServerPort() { - return serverPort; + return _serverPort; } public void stop() throws Exception { - server.stop(); + _server.stop(); } public URI getServerURI() throws UnknownHostException { StringBuffer uri = new StringBuffer(); - uri.append(this.scheme).append("://"); + uri.append(this._scheme).append("://"); uri.append(InetAddress.getLocalHost().getHostAddress()); - uri.append(":").append(this.serverPort); + uri.append(":").append(this._serverPort); return URI.create(uri.toString()); } }