Bug 333771 - System properties are not available inside XML configuration

file by using the 'property' tag.

* Made lookups of Properties by the Start Config use Jetty Property then
  System Properties, and lastly default values when requested.
* Made XmlConfiguration use layered property lookup from Start Config,
  benefitting XmlConfiguration of the same logic.
* Made all use of Start Config.getProperty() use static references
  per the method signature.

git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@2646 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
Joakim Erdfelt 2011-01-10 18:10:15 +00:00
parent 9cd55e8ba5
commit 892bd690e0
6 changed files with 49 additions and 34 deletions

View File

@ -6,14 +6,15 @@ jetty-7.3.0-SNAPSHOT
+ 332432 Scanner.java now always scanning the canonical form of File + 332432 Scanner.java now always scanning the canonical form of File
+ 332517 Improved DefaultServlet debug + 332517 Improved DefaultServlet debug
+ 332703 Cleanup context scope JNDI at stop + 332703 Cleanup context scope JNDI at stop
+ 332796 Annotations inheritance does not work with jetty7 + 332796 Annotations inheritance does not work with jetty7
+ 332799 100% CPU on redeploy session invalidation + 332799 100% CPU on redeploy session invalidation
+ 332937 Added Destroyable interface and reworked dependent lifecycles, specially of JNDI + 332937 Added Destroyable interface and reworked dependent lifecycles, specially of JNDI
+ 333247 fix api compat issue in ConstraintSecurityHandler + 333247 fix api compat issue in ConstraintSecurityHandler
+ 333415 wired up HttpInput.available and added test harnesses + 333415 wired up HttpInput.available and added test harnesses
+ 333481 Handle UTF-32 codepoints + 333481 Handle UTF-32 codepoints
+ 333608 tlds defined in web.xml are not picked up + 333608 tlds defined in web.xml are not picked up
+ 333679 Refactored jetty-jmx. Moved mbeans to modules. + 333679 Refactored jetty-jmx. Moved mbeans to modules
+ 333771 System properties are not available inside XML configuration file by using the 'property' tag
+ 333875 Monitor public constructor + 333875 Monitor public constructor
jetty-7.2.2.v20101205 5 December 2010 jetty-7.2.2.v20101205 5 December 2010

View File

@ -50,7 +50,7 @@
# and /opt/jetty. The java system property "jetty.home" will be # and /opt/jetty. The java system property "jetty.home" will be
# set to this value for use by configure.xml files, f.e.: # set to this value for use by configure.xml files, f.e.:
# #
# <Arg><SystemProperty name="jetty.home" default="."/>/webapps/jetty.war</Arg> # <Arg><Property name="jetty.home" default="."/>/webapps/jetty.war</Arg>
# #
# JETTY_PORT # JETTY_PORT
# Override the default port for Jetty servers. If not set then the # Override the default port for Jetty servers. If not set then the
@ -60,7 +60,7 @@
# used in the demo config files to respect this property in Listener # used in the demo config files to respect this property in Listener
# configuration elements: # configuration elements:
# #
# <Set name="Port"><SystemProperty name="jetty.port" default="8080"/></Set> # <Set name="Port"><Property name="jetty.port" default="8080"/></Set>
# #
# Note: that the config file could ignore this property simply by saying: # Note: that the config file could ignore this property simply by saying:
# #

View File

@ -35,6 +35,7 @@ import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.Enumeration;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
@ -334,7 +335,7 @@ public class Config
if (i2 < 0) if (i2 < 0)
break; break;
String name = s.substring(i1 + 2,i2); String name = s.substring(i1 + 2,i2);
String property = getSystemProperty(name); String property = getProperty(name);
s = s.substring(0,i1) + property + s.substring(i2 + 1); s = s.substring(0,i1) + property + s.substring(i2 + 1);
} }
@ -418,24 +419,39 @@ public class Config
public static Properties getProperties() public static Properties getProperties()
{ {
Properties properties = new Properties(); Properties properties = new Properties();
for (String key : __properties.keySet()) // Add System Properties First
Enumeration<?> ensysprop = System.getProperties().propertyNames();
while(ensysprop.hasMoreElements()) {
String name = (String)ensysprop.nextElement();
properties.put(name, System.getProperty(name));
}
// Add Config Properties Next (overwriting any System Properties that exist)
for (String key : __properties.keySet()) {
properties.put(key,__properties.get(key)); properties.put(key,__properties.get(key));
}
return properties; return properties;
} }
public static String getProperty(String name) public static String getProperty(String name)
{ {
if ("version".equalsIgnoreCase(name)) if ("version".equalsIgnoreCase(name)) {
return _version; return _version;
}
return __properties.get(name); // Search Config Properties First
if (__properties.containsKey(name)) {
return __properties.get(name);
}
// Return what exists in System.Properties otherwise.
return System.getProperty(name);
} }
public static String getProperty(String name, String dftValue) public static String getProperty(String name, String defaultValue)
{ {
// Search Config Properties First
if (__properties.containsKey(name)) if (__properties.containsKey(name))
return __properties.get(name); return __properties.get(name);
return dftValue; // Return what exists in System.Properties otherwise.
return System.getProperty(name, defaultValue);
} }
/** /**
@ -461,15 +477,6 @@ public class Config
return ids; return ids;
} }
private String getSystemProperty(String name)
{
if ("version".equalsIgnoreCase(name))
return _version;
if (__properties.containsKey(name))
return __properties.get(name);
return System.getProperty(name);
}
public List<String> getXmlConfigs() public List<String> getXmlConfigs()
{ {
return _xml; return _xml;

View File

@ -131,8 +131,8 @@ public class Main
if ("--stop".equals(arg)) if ("--stop".equals(arg))
{ {
int port = Integer.parseInt(_config.getProperty("STOP.PORT",System.getProperty("STOP.PORT","-1"))); int port = Integer.parseInt(Config.getProperty("STOP.PORT","-1"));
String key = _config.getProperty("STOP.KEY",System.getProperty("STOP.KEY",null)); String key = Config.getProperty("STOP.KEY",null);
stop(port,key); stop(port,key);
return; return;
} }
@ -498,8 +498,8 @@ public class Main
public void start(List<String> xmls) throws FileNotFoundException, IOException, InterruptedException public void start(List<String> xmls) throws FileNotFoundException, IOException, InterruptedException
{ {
// Setup Start / Stop Monitoring // Setup Start / Stop Monitoring
int port = Integer.parseInt(_config.getProperty("STOP.PORT",System.getProperty("STOP.PORT","-1"))); int port = Integer.parseInt(Config.getProperty("STOP.PORT","-1"));
String key = _config.getProperty("STOP.KEY",System.getProperty("STOP.KEY",null)); String key = Config.getProperty("STOP.KEY",null);
Monitor monitor=new Monitor(port,key); Monitor monitor=new Monitor(port,key);
@ -536,7 +536,7 @@ public class Main
System.err.println("java.class.path=" + classpath); System.err.println("java.class.path=" + classpath);
System.err.println("classloader=" + cl); System.err.println("classloader=" + cl);
System.err.println("classloader.parent=" + cl.getParent()); System.err.println("classloader.parent=" + cl.getParent());
System.err.println("properties="+_config.getProperties()); System.err.println("properties=" + Config.getProperties());
} }
// Show the usage information and return // Show the usage information and return
@ -1017,7 +1017,7 @@ public class Main
// parse the config // parse the config
_config.parse(cfgstream); _config.parse(cfgstream);
_jettyHome = _config.getProperty("jetty.home"); _jettyHome = Config.getProperty("jetty.home");
if (_jettyHome != null) if (_jettyHome != null)
{ {
_jettyHome = new File(_jettyHome).getCanonicalPath(); _jettyHome = new File(_jettyHome).getCanonicalPath();

View File

@ -113,7 +113,7 @@ public class ConfigTest
Config cfg = new Config(); Config cfg = new Config();
cfg.parse(buf); cfg.parse(buf);
Assert.assertEquals(getTestResourcesDir().getCanonicalPath(),cfg.getProperty("test.resources.dir")); Assert.assertEquals(getTestResourcesDir().getCanonicalPath(),Config.getProperty("test.resources.dir"));
} }
/* /*
@ -129,8 +129,8 @@ public class ConfigTest
Config options = new Config(); Config options = new Config();
options.parse(buf); options.parse(buf);
Assert.assertEquals("foo",options.getProperty("test.jetty.start.text")); Assert.assertEquals("foo",Config.getProperty("test.jetty.start.text"));
Assert.assertEquals("Eatagramovabits",options.getProperty("test.jetty.start.quote")); Assert.assertEquals("Eatagramovabits",Config.getProperty("test.jetty.start.quote"));
} }
/* /*

View File

@ -28,13 +28,12 @@ import java.net.UnknownHostException;
import java.security.AccessControlException; import java.security.AccessControlException;
import java.security.AccessController; import java.security.AccessController;
import java.security.PrivilegedAction; import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Enumeration;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
import java.util.Set; import java.util.Set;
@ -174,7 +173,7 @@ public class XmlConfiguration
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
/** /**
* @deprecated use {@link #getProperties()}.put(...) * @deprecated use {@link #getProperties()}.putAll(...)
*/ */
public void setProperties (Map<String,String> map) public void setProperties (Map<String,String> map)
{ {
@ -1021,8 +1020,15 @@ public class XmlConfiguration
} }
// If no start.config properties, use clean slate // If no start.config properties, use clean slate
if (properties==null) if (properties==null) {
properties = new Properties(); properties = new Properties();
// Add System Properties
Enumeration<?> ensysprop = System.getProperties().propertyNames();
while(ensysprop.hasMoreElements()) {
String name = (String)ensysprop.nextElement();
properties.put(name, System.getProperty(name));
}
}
// For all arguments, load properties or parse XMLs // For all arguments, load properties or parse XMLs
XmlConfiguration last = null; XmlConfiguration last = null;
@ -1042,8 +1048,9 @@ public class XmlConfiguration
if ( properties.size() > 0 ) if ( properties.size() > 0 )
{ {
Map<String,String> props = new HashMap<String,String>(); Map<String,String> props = new HashMap<String,String>();
for (Object key:properties.keySet()) for (Object key:properties.keySet()) {
props.put(key.toString(),String.valueOf(properties.get(key))); props.put(key.toString(),String.valueOf(properties.get(key)));
}
configuration.setProperties( props ); configuration.setProperties( props );
} }
obj[i] = configuration.configure(); obj[i] = configuration.configure();