mirror of https://github.com/apache/activemq.git
https://issues.apache.org/jira/browse/AMQ-4682 - support values and list/values for PropertyPlaceholderConfigurer locations
This commit is contained in:
parent
a0c1781c4e
commit
8d4fef8af2
|
@ -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) {
|
||||
|
|
|
@ -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));
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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>
|
Loading…
Reference in New Issue