activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gtu...@apache.org
Subject git commit: https://issues.apache.org/jira/browse/AMQ-4682 - support values and list/values for PropertyPlaceholderConfigurer locations
Date Tue, 03 Sep 2013 11:22:10 GMT
Updated Branches:
  refs/heads/trunk a0c1781c4 -> 8d4fef8af


https://issues.apache.org/jira/browse/AMQ-4682 - support values and list/values for PropertyPlaceholderConfigurer
locations


Project: http://git-wip-us.apache.org/repos/asf/activemq/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq/commit/8d4fef8a
Tree: http://git-wip-us.apache.org/repos/asf/activemq/tree/8d4fef8a
Diff: http://git-wip-us.apache.org/repos/asf/activemq/diff/8d4fef8a

Branch: refs/heads/trunk
Commit: 8d4fef8af2a29e1f81e39f088b6ceb893e131f01
Parents: a0c1781
Author: gtully <gary.tully@gmail.com>
Authored: Tue Sep 3 12:18:10 2013 +0100
Committer: gtully <gary.tully@gmail.com>
Committed: Tue Sep 3 12:21:48 2013 +0100

----------------------------------------------------------------------
 .../plugin/RuntimeConfigurationBroker.java      | 35 +++++++++---------
 .../org/apache/activemq/SpringBeanTest.java     | 27 ++++++++++++++
 ...ableConfig1000-spring-property-file-list.xml | 38 ++++++++++++++++++++
 3 files changed, 84 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq/blob/8d4fef8a/activemq-runtime-config/src/main/java/org/apache/activemq/plugin/RuntimeConfigurationBroker.java
----------------------------------------------------------------------
diff --git a/activemq-runtime-config/src/main/java/org/apache/activemq/plugin/RuntimeConfigurationBroker.java
b/activemq-runtime-config/src/main/java/org/apache/activemq/plugin/RuntimeConfigurationBroker.java
index 7693692..bd2d652 100644
--- a/activemq-runtime-config/src/main/java/org/apache/activemq/plugin/RuntimeConfigurationBroker.java
+++ b/activemq-runtime-config/src/main/java/org/apache/activemq/plugin/RuntimeConfigurationBroker.java
@@ -99,6 +99,7 @@ import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
 import org.springframework.beans.factory.xml.PluggableSchemaResolver;
 import org.springframework.core.io.Resource;
 import org.w3c.dom.Document;
+import org.w3c.dom.Element;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
 import org.xml.sax.InputSource;
@@ -692,10 +693,10 @@ public class RuntimeConfigurationBroker extends BrokerFilter {
         // find resources
         //        <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
         //            <property name="locations">
-        //              <value>${props.base}users.properties</value>
+        //              ...
         //            </property>
         //          </bean>
-        String resourcesString = null;
+        String resourcesString = "";
         NodeList beans = doc.getElementsByTagName("bean");
         for (int i = 0; i < beans.getLength(); i++) {
             Node bean = beans.item(0);
@@ -704,14 +705,18 @@ public class RuntimeConfigurationBroker extends BrokerFilter {
                     NodeList beanProps = bean.getChildNodes();
                     for (int j = 0; j < beanProps.getLength(); j++) {
                         Node beanProp = beanProps.item(j);
-                        if (beanProp.hasAttributes() && beanProp.getAttributes().getNamedItem("name").getTextContent().equals("locations"))
{
-                            NodeList locationsPropNodes = beanProp.getChildNodes();
-                            for (int k = 0; k < locationsPropNodes.getLength(); k++) {
-                                Node location = locationsPropNodes.item(k);
-                                if (Node.ELEMENT_NODE == location.getNodeType() &&
location.getLocalName().equals("value")) {
-                                    resourcesString = location.getFirstChild().getTextContent();
-                                    break;
+                        if (Node.ELEMENT_NODE == beanProp.getNodeType() &&
+                                beanProp.hasAttributes() && beanProp.getAttributes().getNamedItem("name").getTextContent().equals("locations"))
{
+
+                            // interested in value or list/value of locations property
+                            Element beanPropElement = (Element) beanProp;
+                            NodeList values = beanPropElement.getElementsByTagName("value");
+                            for (int k = 0; k < values.getLength(); k++) {
+                                Node value = values.item(k);
+                                if (!resourcesString.isEmpty()) {
+                                    resourcesString += ",";
                                 }
+                                resourcesString += value.getFirstChild().getTextContent();
                             }
                         }
                     }
@@ -719,13 +724,11 @@ public class RuntimeConfigurationBroker extends BrokerFilter {
             }
         }
         List<Resource> propResources = new LinkedList<Resource>();
-        if (resourcesString != null) {
-            for (String value : resourcesString.split(",")) {
-                try {
-                    propResources.add(Utils.resourceFromString(replacePlaceHolders(value)));
-                } catch (MalformedURLException e) {
-                    info("failed to resolve resource: " + value, e);
-                }
+        for (String value : resourcesString.split(",")) {
+            try {
+                propResources.add(Utils.resourceFromString(replacePlaceHolders(value)));
+            } catch (MalformedURLException e) {
+                info("failed to resolve resource: " + value, e);
             }
         }
         for (Resource resource : propResources) {

http://git-wip-us.apache.org/repos/asf/activemq/blob/8d4fef8a/activemq-runtime-config/src/test/java/org/apache/activemq/SpringBeanTest.java
----------------------------------------------------------------------
diff --git a/activemq-runtime-config/src/test/java/org/apache/activemq/SpringBeanTest.java
b/activemq-runtime-config/src/test/java/org/apache/activemq/SpringBeanTest.java
index 9455774..6d13746 100644
--- a/activemq-runtime-config/src/test/java/org/apache/activemq/SpringBeanTest.java
+++ b/activemq-runtime-config/src/test/java/org/apache/activemq/SpringBeanTest.java
@@ -116,4 +116,31 @@ public class SpringBeanTest extends RuntimeConfigTestSupport {
         assertEquals("name is replaced", "guest", discoveryNetworkConnector.getName());
     }
 
+    @Test
+    public void testAddPropertyRefFromFileAsList() throws Exception {
+
+        System.setProperty("network.uri", "static:(tcp://localhost:8888)");
+        System.setProperty("props.base", "classpath:");
+        final String brokerConfig = "SpringPropertyTestFileList-broker";
+        applyNewConfig(brokerConfig, "emptyUpdatableConfig1000-spring-property-file-list");
+        startBroker(brokerConfig);
+        assertTrue("broker alive", brokerService.isStarted());
+
+        ObjectName objectName =
+                        new ObjectName(brokerService.getBrokerObjectName().toString() +
+                                RuntimeConfigurationBroker.objectNamePropsAppendage);
+                RuntimeConfigurationViewMBean runtimeConfigurationView =
+                        (RuntimeConfigurationViewMBean) brokerService.getManagementContext().newProxyInstance(objectName,
+                                RuntimeConfigurationViewMBean.class, false);
+
+                String propOfInterest = "modified";
+                HashMap<String, String> props = new HashMap<String, String>();
+                IntrospectionSupport.getProperties(runtimeConfigurationView, props, null);
+                LOG.info("mbean attributes before: " + props);
+
+        assertNotEquals("unknown", props.get(propOfInterest));
+
+
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/activemq/blob/8d4fef8a/activemq-runtime-config/src/test/resources/org/apache/activemq/emptyUpdatableConfig1000-spring-property-file-list.xml
----------------------------------------------------------------------
diff --git a/activemq-runtime-config/src/test/resources/org/apache/activemq/emptyUpdatableConfig1000-spring-property-file-list.xml
b/activemq-runtime-config/src/test/resources/org/apache/activemq/emptyUpdatableConfig1000-spring-property-file-list.xml
new file mode 100644
index 0000000..8ffdf02
--- /dev/null
+++ b/activemq-runtime-config/src/test/resources/org/apache/activemq/emptyUpdatableConfig1000-spring-property-file-list.xml
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    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.
+-->
+<beans
+  xmlns="http://www.springframework.org/schema/beans"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
+  http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd">
+
+  <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
+    <property name="locations">
+      <list>
+        <value>${props.base}users.properties</value>
+        <value>${props.base}users.properties</value>
+      </list>
+    </property>
+  </bean>
+
+  <broker xmlns="http://activemq.apache.org/schema/core" start="false" persistent="false"
>
+    <plugins>
+      <runtimeConfigurationPlugin checkPeriod="1000" />
+    </plugins>
+  </broker>
+</beans>


Mime
View raw message