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 2017/07/27 08:25:46 UTC
svn commit: r1803135 - in /tomcat/trunk:
java/org/apache/catalina/util/SystemPropertyReplacerListener.java
java/org/apache/tomcat/util/digester/Digester.java
webapps/docs/config/listeners.xml webapps/docs/config/systemprops.xml
Author: remm
Date: Thu Jul 27 08:25:46 2017
New Revision: 1803135
URL: http://svn.apache.org/viewvc?rev=1803135&view=rev
Log:
Avoid circular dependency.
Added:
tomcat/trunk/java/org/apache/catalina/util/SystemPropertyReplacerListener.java (with props)
Modified:
tomcat/trunk/java/org/apache/tomcat/util/digester/Digester.java
tomcat/trunk/webapps/docs/config/listeners.xml
tomcat/trunk/webapps/docs/config/systemprops.xml
Added: tomcat/trunk/java/org/apache/catalina/util/SystemPropertyReplacerListener.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/util/SystemPropertyReplacerListener.java?rev=1803135&view=auto
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/util/SystemPropertyReplacerListener.java (added)
+++ tomcat/trunk/java/org/apache/catalina/util/SystemPropertyReplacerListener.java Thu Jul 27 08:25:46 2017
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package org.apache.catalina.util;
+
+
+import org.apache.catalina.Lifecycle;
+import org.apache.catalina.LifecycleEvent;
+import org.apache.catalina.LifecycleListener;
+import org.apache.tomcat.util.digester.Digester;
+
+
+/**
+ * Helper class used to do property replacement on system properties.
+ */
+public class SystemPropertyReplacerListener
+ implements LifecycleListener {
+
+
+ // ---------------------------------------------- LifecycleListener Methods
+
+
+ @Override
+ public void lifecycleEvent(LifecycleEvent event) {
+ if (Lifecycle.BEFORE_INIT_EVENT.equals(event.getType())) {
+ Digester.replace();
+ }
+ }
+
+
+}
Propchange: tomcat/trunk/java/org/apache/catalina/util/SystemPropertyReplacerListener.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: tomcat/trunk/java/org/apache/tomcat/util/digester/Digester.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/digester/Digester.java?rev=1803135&r1=1803134&r2=1803135&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/digester/Digester.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/digester/Digester.java Thu Jul 27 08:25:46 2017
@@ -37,9 +37,6 @@ import javax.xml.parsers.ParserConfigura
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
-import org.apache.catalina.Lifecycle;
-import org.apache.catalina.LifecycleEvent;
-import org.apache.catalina.LifecycleListener;
import org.apache.juli.logging.Log;
import org.apache.juli.logging.LogFactory;
import org.apache.tomcat.util.ExceptionUtils;
@@ -298,7 +295,7 @@ public class Digester extends DefaultHan
* The Log to which most logging calls will be made.
*/
protected Log log = LogFactory.getLog(Digester.class);
- protected StringManager sm = StringManager.getManager(Digester.class);
+ protected static StringManager sm = StringManager.getManager(Digester.class);
/**
* The Log to which all SAX event related logging calls will be made.
@@ -313,28 +310,23 @@ public class Digester extends DefaultHan
}
- public static class SystemPropertyReplacementListener
- implements LifecycleListener {
- protected Log log = LogFactory.getLog(Digester.class);
- protected StringManager sm = StringManager.getManager(Digester.class);
- @Override
- public void lifecycleEvent(LifecycleEvent event) {
- if (propertySource != null && Lifecycle.BEFORE_INIT_EVENT.equals(event.getType())) {
- IntrospectionUtils.PropertySource[] propertySources =
- new IntrospectionUtils.PropertySource[] { propertySource };
- Properties properties = System.getProperties();
- Set<String> names = properties.stringPropertyNames();
- for (String name : names) {
- String value = System.getProperty(name);
- if (value != null) {
- try {
- String newValue = IntrospectionUtils.replaceProperties(value, null, propertySources);
- if (value != newValue) {
- System.setProperty(name, newValue);
- }
- } catch (Exception e) {
- log.warn(sm.getString("digester.failedToUpdateSystemProperty", name, value), e);
+ public static void replace() {
+ Log log = LogFactory.getLog(Digester.class);
+ if (propertySource != null) {
+ IntrospectionUtils.PropertySource[] propertySources =
+ new IntrospectionUtils.PropertySource[] { propertySource };
+ Properties properties = System.getProperties();
+ Set<String> names = properties.stringPropertyNames();
+ for (String name : names) {
+ String value = System.getProperty(name);
+ if (value != null) {
+ try {
+ String newValue = IntrospectionUtils.replaceProperties(value, null, propertySources);
+ if (value != newValue) {
+ System.setProperty(name, newValue);
}
+ } catch (Exception e) {
+ log.warn(sm.getString("digester.failedToUpdateSystemProperty", name, value), e);
}
}
}
Modified: tomcat/trunk/webapps/docs/config/listeners.xml
URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/config/listeners.xml?rev=1803135&r1=1803134&r2=1803135&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/config/listeners.xml (original)
+++ tomcat/trunk/webapps/docs/config/listeners.xml Thu Jul 27 08:25:46 2017
@@ -571,6 +571,15 @@
</subsection>
+ <subsection name="System property replacement - org.apache.catalina.util.SystemPropertyReplacerListener">
+
+ <p>This listener performs system property replacement using the property
+ source configured on the digester. When <code>${parameter}</code>
+ denoted parameters are found in the values of system properties,
+ the property source will be invoked to attempt to replace it.</p>
+
+ </subsection>
+
</section>
</body>
Modified: tomcat/trunk/webapps/docs/config/systemprops.xml
URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/config/systemprops.xml?rev=1803135&r1=1803134&r2=1803135&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/config/systemprops.xml (original)
+++ tomcat/trunk/webapps/docs/config/systemprops.xml Thu Jul 27 08:25:46 2017
@@ -47,7 +47,7 @@
denoted parameters are found in the XML files that Tomcat parses.</p>
<p>Property replacement from the specified property source on the JVM
system properties can also be done by adding the
- <code>org.apache.tomcat.util.digester.Digester$SystemPropertyReplacementListener</code>
+ <code>org.apache.catalina.util.SystemPropertyReplacerListener</code>
listener as a Server listener in the container.</p>
</property>
</properties>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org
Re: svn commit: r1803135 - in /tomcat/trunk: java/org/apache/catalina/util/SystemPropertyReplacerListener.java
java/org/apache/tomcat/util/digester/Digester.java webapps/docs/config/listeners.xml
webapps/docs/config/systemprops.xml
Posted by Konstantin Kolinko <kn...@gmail.com>.
2017-07-27 11:25 GMT+03:00 <re...@apache.org>:
> Author: remm
> Date: Thu Jul 27 08:25:46 2017
> New Revision: 1803135
>
> URL: http://svn.apache.org/viewvc?rev=1803135&view=rev
> Log:
> Avoid circular dependency.
>
> Added:
> tomcat/trunk/java/org/apache/catalina/util/SystemPropertyReplacerListener.java (with props)
> Modified:
> tomcat/trunk/java/org/apache/tomcat/util/digester/Digester.java
> tomcat/trunk/webapps/docs/config/listeners.xml
> tomcat/trunk/webapps/docs/config/systemprops.xml
>
> Modified: tomcat/trunk/java/org/apache/tomcat/util/digester/Digester.java
> URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/digester/Digester.java?rev=1803135&r1=1803134&r2=1803135&view=diff
> ==============================================================================
> --- tomcat/trunk/java/org/apache/tomcat/util/digester/Digester.java (original)
> +++ tomcat/trunk/java/org/apache/tomcat/util/digester/Digester.java Thu Jul 27 08:25:46 2017
> @@ -37,9 +37,6 @@ import javax.xml.parsers.ParserConfigura
> [...]
> + public static void replace() {
I do not like this method name. It is too generic.
And there is no way to customize its behaviour (no parameters).
> + Log log = LogFactory.getLog(Digester.class);
> + if (propertySource != null) {
> + IntrospectionUtils.PropertySource[] propertySources =
> + new IntrospectionUtils.PropertySource[] { propertySource };
> + Properties properties = System.getProperties();
> + Set<String> names = properties.stringPropertyNames();
> + for (String name : names) {
> + String value = System.getProperty(name);
> + if (value != null) {
> + try {
> + String newValue = IntrospectionUtils.replaceProperties(value, null, propertySources);
> + if (value != newValue) {
> + System.setProperty(name, newValue);
> }
> + } catch (Exception e) {
> + log.warn(sm.getString("digester.failedToUpdateSystemProperty", name, value), e);
> }
> }
> }
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org