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

This commit is contained in:
gtully 2013-10-24 12:59:15 +01:00
parent 0f09f78f3e
commit 043a4ad4ff
4 changed files with 174 additions and 7 deletions

View File

@ -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;

View File

@ -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;
}
}

View File

@ -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));
}
}

View File

@ -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>