You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by gt...@apache.org on 2013/10/24 14:01:16 UTC
git commit: https://issues.apache.org/jira/browse/AMQ-4820 - find
elements by ns and local name to deal with namespace prefix. Ensure we trap
all errors on plugin start so we don't cause a failed broker start,
and trap no broker element with a better err
Updated Branches:
refs/heads/trunk 0f09f78f3 -> 043a4ad4f
https://issues.apache.org/jira/browse/AMQ-4820 - find elements by ns and local name to deal with namespace prefix. Ensure we trap all errors on plugin start so we don't cause a failed broker start, and trap no broker element with a better error
Project: http://git-wip-us.apache.org/repos/asf/activemq/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq/commit/043a4ad4
Tree: http://git-wip-us.apache.org/repos/asf/activemq/tree/043a4ad4
Diff: http://git-wip-us.apache.org/repos/asf/activemq/diff/043a4ad4
Branch: refs/heads/trunk
Commit: 043a4ad4ff235ce28bc1bcbd594c50a262caf373
Parents: 0f09f78
Author: gtully <ga...@gmail.com>
Authored: Thu Oct 24 12:59:15 2013 +0100
Committer: gtully <ga...@gmail.com>
Committed: Thu Oct 24 13:00:04 2013 +0100
----------------------------------------------------------------------
.../plugin/RuntimeConfigurationBroker.java | 22 ++++---
.../apache/activemq/CustomPropertiesBean.java | 37 +++++++++++
.../apache/activemq/NameSpaceXmlLoadTest.java | 58 ++++++++++++++++++
.../org/apache/activemq/namespace-prefix.xml | 64 ++++++++++++++++++++
4 files changed, 174 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/activemq/blob/043a4ad4/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 5c38d94..58a11e1 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
@@ -657,16 +657,22 @@ public class RuntimeConfigurationBroker extends BrokerFilter {
dbf.setNamespaceAware(true);
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(configToMonitor.getInputStream());
- Node brokerRootNode = doc.getElementsByTagName("broker").item(0);
+ Node brokerRootNode = doc.getElementsByTagNameNS("*","broker").item(0);
- JAXBElement<DtoBroker> brokerJAXBElement =
- unMarshaller.unmarshal(brokerRootNode, DtoBroker.class);
- jaxbConfig = brokerJAXBElement.getValue();
+ if (brokerRootNode != null) {
- // if we can parse we can track mods
- lastModified = configToMonitor.lastModified();
+ JAXBElement<DtoBroker> brokerJAXBElement =
+ unMarshaller.unmarshal(brokerRootNode, DtoBroker.class);
+ jaxbConfig = brokerJAXBElement.getValue();
- loadPropertiesPlaceHolderSupport(doc);
+ // if we can parse we can track mods
+ lastModified = configToMonitor.lastModified();
+
+ loadPropertiesPlaceHolderSupport(doc);
+
+ } else {
+ info("Failed to find 'broker' element by tag in: " + configToMonitor);
+ }
} catch (IOException e) {
info("Failed to access: " + configToMonitor, e);
@@ -676,6 +682,8 @@ public class RuntimeConfigurationBroker extends BrokerFilter {
info("Failed to document parse: " + configToMonitor, e);
} catch (SAXException e) {
info("Failed to find broker element in: " + configToMonitor, e);
+ } catch (Exception e) {
+ info("Unexpected exception during load of: " + configToMonitor, e);
}
}
return jaxbConfig;
http://git-wip-us.apache.org/repos/asf/activemq/blob/043a4ad4/activemq-runtime-config/src/test/java/org/apache/activemq/CustomPropertiesBean.java
----------------------------------------------------------------------
diff --git a/activemq-runtime-config/src/test/java/org/apache/activemq/CustomPropertiesBean.java b/activemq-runtime-config/src/test/java/org/apache/activemq/CustomPropertiesBean.java
new file mode 100644
index 0000000..97aebf4
--- /dev/null
+++ b/activemq-runtime-config/src/test/java/org/apache/activemq/CustomPropertiesBean.java
@@ -0,0 +1,37 @@
+/**
+ * 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.activemq;
+
+import java.util.Properties;
+import org.springframework.beans.factory.FactoryBean;
+
+public class CustomPropertiesBean implements FactoryBean<Properties> {
+ @Override
+ public Properties getObject() throws Exception {
+ return System.getProperties();
+ }
+
+ @Override
+ public Class<?> getObjectType() {
+ return Properties.class;
+ }
+
+ @Override
+ public boolean isSingleton() {
+ return false;
+ }
+}
http://git-wip-us.apache.org/repos/asf/activemq/blob/043a4ad4/activemq-runtime-config/src/test/java/org/apache/activemq/NameSpaceXmlLoadTest.java
----------------------------------------------------------------------
diff --git a/activemq-runtime-config/src/test/java/org/apache/activemq/NameSpaceXmlLoadTest.java b/activemq-runtime-config/src/test/java/org/apache/activemq/NameSpaceXmlLoadTest.java
new file mode 100644
index 0000000..f66918c
--- /dev/null
+++ b/activemq-runtime-config/src/test/java/org/apache/activemq/NameSpaceXmlLoadTest.java
@@ -0,0 +1,58 @@
+/**
+ * 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.activemq;
+
+import java.util.HashMap;
+import javax.management.ObjectName;
+import org.apache.activemq.plugin.RuntimeConfigurationBroker;
+import org.apache.activemq.plugin.jmx.RuntimeConfigurationViewMBean;
+import org.apache.activemq.util.IOHelper;
+import org.apache.activemq.util.IntrospectionSupport;
+import org.junit.Test;
+
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertTrue;
+
+public class NameSpaceXmlLoadTest extends RuntimeConfigTestSupport {
+
+ @Test
+ public void testCanLoad() throws Exception {
+ final String brokerConfig = "namespace-prefix";
+ System.setProperty("data", IOHelper.getDefaultDataDirectory());
+ System.setProperty("broker-name", brokerConfig);
+ startBroker(brokerConfig);
+ assertTrue("broker alive", brokerService.isStarted());
+ assertEquals("nameMatch", brokerConfig, brokerService.getBrokerName());
+
+ // verify runtimeConfig active
+ ObjectName objectName =
+ new ObjectName(brokerService.getBrokerObjectName().toString() +
+ RuntimeConfigurationBroker.objectNamePropsAppendage);
+ RuntimeConfigurationViewMBean runtimeConfigurationView =
+ (RuntimeConfigurationViewMBean) brokerService.getManagementContext().newProxyInstance(objectName,
+ RuntimeConfigurationViewMBean.class, false);
+
+ HashMap<String, String> props = new HashMap<String, String>();
+ IntrospectionSupport.getProperties(runtimeConfigurationView, props, null);
+ LOG.info("mbean attributes before: " + props);
+ String propOfInterest = "modified";
+ assertNotEquals("modified is valid", "unknown", props.get(propOfInterest));
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/activemq/blob/043a4ad4/activemq-runtime-config/src/test/resources/org/apache/activemq/namespace-prefix.xml
----------------------------------------------------------------------
diff --git a/activemq-runtime-config/src/test/resources/org/apache/activemq/namespace-prefix.xml b/activemq-runtime-config/src/test/resources/org/apache/activemq/namespace-prefix.xml
new file mode 100644
index 0000000..40ae71e
--- /dev/null
+++ b/activemq-runtime-config/src/test/resources/org/apache/activemq/namespace-prefix.xml
@@ -0,0 +1,64 @@
+<?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.
+-->
+<tag0:beans xmlns:tag0="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">
+ <tag0:bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
+ <tag0:property name="properties">
+ <tag0:bean class="org.apache.activemq.CustomPropertiesBean"/>
+ </tag0:property>
+ </tag0:bean>
+ <amq:broker xmlns:amq="http://activemq.apache.org/schema/core" start="false" dataDirectory="${data}" persistent="false"
+ brokerName="${broker-name}">
+ <amq:destinationPolicy>
+ <amq:policyMap>
+ <amq:policyEntries>
+ <amq:policyEntry topic=">" producerFlowControl="true">
+ <amq:pendingMessageLimitStrategy>
+ <amq:constantPendingMessageLimitStrategy limit="1000"/>
+ </amq:pendingMessageLimitStrategy>
+ </amq:policyEntry>
+ <amq:policyEntry queue=">" producerFlowControl="true" memoryLimit="1mb"/>
+ </amq:policyEntries>
+ </amq:policyMap>
+ </amq:destinationPolicy>
+ <amq:managementContext>
+ <amq:managementContext createConnector="false"/>
+ </amq:managementContext>
+ <amq:plugins>
+ <amq:jaasAuthenticationPlugin configuration="karaf"/>
+ <amq:runtimeConfigurationPlugin checkPeriod="1000"/>
+ </amq:plugins>
+ <amq:systemUsage>
+ <amq:systemUsage>
+ <amq:memoryUsage>
+ <amq:memoryUsage limit="64 mb"/>
+ </amq:memoryUsage>
+ <amq:storeUsage>
+ <amq:storeUsage limit="100 gb"/>
+ </amq:storeUsage>
+ <amq:tempUsage>
+ <amq:tempUsage limit="50 gb"/>
+ </amq:tempUsage>
+ </amq:systemUsage>
+ </amq:systemUsage>
+ <amq:transportConnectors>
+ <amq:transportConnector name="openwire" uri="tcp://0.0.0.0:0?maximumConnections=1000"/>
+ </amq:transportConnectors>
+ </amq:broker>
+</tag0:beans>
\ No newline at end of file