You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by re...@apache.org on 2020/03/19 17:58:04 UTC
[tomcat] branch 9.0.x updated: Allow multiple property sources
This is an automated email from the ASF dual-hosted git repository.
remm pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/9.0.x by this push:
new 7ecda7d Allow multiple property sources
7ecda7d is described below
commit 7ecda7d462bcebba0c07a088af5cd5bcf46978b0
Author: remm <re...@apache.org>
AuthorDate: Thu Mar 19 18:31:33 2020 +0100
Allow multiple property sources
The problem appears with the introduction of EnvironmentPropertySource,
where people could use it but prevent use of a custom property source.
---
java/org/apache/tomcat/util/digester/Digester.java | 76 +++++++++++++---------
webapps/docs/changelog.xml | 5 ++
webapps/docs/config/systemprops.xml | 3 +-
3 files changed, 54 insertions(+), 30 deletions(-)
diff --git a/java/org/apache/tomcat/util/digester/Digester.java b/java/org/apache/tomcat/util/digester/Digester.java
index fcf32c7..9fd4a15 100644
--- a/java/org/apache/tomcat/util/digester/Digester.java
+++ b/java/org/apache/tomcat/util/digester/Digester.java
@@ -25,6 +25,7 @@ import java.lang.reflect.InvocationTargetException;
import java.net.URI;
import java.net.URISyntaxException;
import java.security.Permission;
+import java.util.ArrayList;
import java.util.EmptyStackException;
import java.util.HashMap;
import java.util.List;
@@ -32,6 +33,7 @@ import java.util.Map;
import java.util.Properties;
import java.util.PropertyPermission;
import java.util.Set;
+import java.util.StringTokenizer;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
@@ -84,31 +86,36 @@ public class Digester extends DefaultHandler2 {
// ---------------------------------------------------------- Static Fields
- protected static IntrospectionUtils.PropertySource propertySource;
- private static boolean propertySourceSet = false;
+ protected static IntrospectionUtils.PropertySource[] propertySources;
+ private static boolean propertySourcesSet = false;
protected static final StringManager sm = StringManager.getManager(Digester.class);
static {
- String className = System.getProperty("org.apache.tomcat.util.digester.PROPERTY_SOURCE");
- IntrospectionUtils.PropertySource source = null;
- if (className != null) {
- ClassLoader[] cls = new ClassLoader[] { Digester.class.getClassLoader(),
- Thread.currentThread().getContextClassLoader() };
- for (int i = 0; i < cls.length; i++) {
- try {
- Class<?> clazz = Class.forName(className, true, cls[i]);
- source = (IntrospectionUtils.PropertySource)
- clazz.getConstructor().newInstance();
- break;
- } catch (Throwable t) {
- ExceptionUtils.handleThrowable(t);
- LogFactory.getLog(Digester.class).error(sm.getString("digester.propertySourceLoadError", className), t);
+ String classNames = System.getProperty("org.apache.tomcat.util.digester.PROPERTY_SOURCE");
+ ArrayList<IntrospectionUtils.PropertySource> sourcesList = new ArrayList<>();
+ IntrospectionUtils.PropertySource[] sources = null;
+ if (classNames != null) {
+ StringTokenizer classNamesTokenizer = new StringTokenizer(classNames, ",");
+ while (classNamesTokenizer.hasMoreTokens()) {
+ String className = classNamesTokenizer.nextToken().trim();
+ ClassLoader[] cls = new ClassLoader[] { Digester.class.getClassLoader(),
+ Thread.currentThread().getContextClassLoader() };
+ for (int i = 0; i < cls.length; i++) {
+ try {
+ Class<?> clazz = Class.forName(className, true, cls[i]);
+ sourcesList.add((IntrospectionUtils.PropertySource) clazz.getConstructor().newInstance());
+ break;
+ } catch (Throwable t) {
+ ExceptionUtils.handleThrowable(t);
+ LogFactory.getLog(Digester.class).error(sm.getString("digester.propertySourceLoadError", className), t);
+ }
}
}
+ sources = sourcesList.toArray(new IntrospectionUtils.PropertySource[0]);
}
- if (source != null) {
- propertySource = source;
- propertySourceSet = true;
+ if (sources != null) {
+ propertySources = sources;
+ propertySourcesSet = true;
}
if (Boolean.getBoolean("org.apache.tomcat.util.digester.REPLACE_SYSTEM_PROPERTIES")) {
replaceSystemProperties();
@@ -116,9 +123,17 @@ public class Digester extends DefaultHandler2 {
}
public static void setPropertySource(IntrospectionUtils.PropertySource propertySource) {
- if (!propertySourceSet) {
- Digester.propertySource = propertySource;
- propertySourceSet = true;
+ if (!propertySourcesSet) {
+ propertySources = new IntrospectionUtils.PropertySource[1];
+ propertySources[0] = propertySource;
+ propertySourcesSet = true;
+ }
+ }
+
+ public static void setPropertySource(IntrospectionUtils.PropertySource[] propertySources) {
+ if (!propertySourcesSet) {
+ Digester.propertySources = propertySources;
+ propertySourcesSet = true;
}
}
@@ -158,7 +173,7 @@ public class Digester extends DefaultHandler2 {
}
- protected IntrospectionUtils.PropertySource source[] = new IntrospectionUtils.PropertySource[] {
+ protected IntrospectionUtils.PropertySource[] source = new IntrospectionUtils.PropertySource[] {
new SystemPropertySource() };
@@ -338,18 +353,21 @@ public class Digester extends DefaultHandler2 {
public Digester() {
- propertySourceSet = true;
- if (propertySource != null) {
- source = new IntrospectionUtils.PropertySource[] { propertySource, source[0] };
+ propertySourcesSet = true;
+ if (propertySources != null) {
+ ArrayList<IntrospectionUtils.PropertySource> sourcesList = new ArrayList<>();
+ for (IntrospectionUtils.PropertySource cur : propertySources) {
+ sourcesList.add(cur);
+ }
+ sourcesList.add(source[0]);
+ source = sourcesList.toArray(new IntrospectionUtils.PropertySource[0]);
}
}
public static void replaceSystemProperties() {
Log log = LogFactory.getLog(Digester.class);
- if (propertySource != null) {
- IntrospectionUtils.PropertySource[] propertySources =
- new IntrospectionUtils.PropertySource[] { propertySource };
+ if (propertySources != null) {
Properties properties = System.getProperties();
Set<String> names = properties.stringPropertyNames();
for (String name : names) {
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index a51161a..3650d95 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -52,6 +52,11 @@
consistently using the encoding of the web.xml file where specified and
UTF-8 where no explicit encoding is specified. (markt)
</fix>
+ <update>
+ Allow a comma separated list of class names for the
+ <code>org.apache.tomcat.util.digester.PROPERTY_SOURCE</code>
+ system property. (remm)
+ </update>
</changelog>
</subsection>
<subsection name="Coyote">
diff --git a/webapps/docs/config/systemprops.xml b/webapps/docs/config/systemprops.xml
index b4b57be..6c51c81 100644
--- a/webapps/docs/config/systemprops.xml
+++ b/webapps/docs/config/systemprops.xml
@@ -40,7 +40,8 @@
<section name="Property replacements">
<properties>
<property name="org.apache.tomcat.util.digester. PROPERTY_SOURCE">
- <p>Set this to a fully qualified name of a class that implements
+ <p>Set this to a comma separated list of fully qualified name of classes
+ that implement
<code>org.apache.tomcat.util.IntrospectionUtils.PropertySource</code>.
Required to have a public constructor with no arguments.</p>
<p>Use this to add a property source, that will be invoked when
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org