diff --git a/activemq-core/src/main/java/org/apache/activemq/xbean/XBeanBrokerFactory.java b/activemq-core/src/main/java/org/apache/activemq/xbean/XBeanBrokerFactory.java index 5ca5c86846..8139bd624f 100644 --- a/activemq-core/src/main/java/org/apache/activemq/xbean/XBeanBrokerFactory.java +++ b/activemq-core/src/main/java/org/apache/activemq/xbean/XBeanBrokerFactory.java @@ -20,14 +20,18 @@ import java.beans.PropertyEditorManager; import java.io.File; import java.net.MalformedURLException; import java.net.URI; +import java.util.Map; import org.apache.activemq.broker.BrokerFactoryHandler; import org.apache.activemq.broker.BrokerService; +import org.apache.activemq.util.IntrospectionSupport; +import org.apache.activemq.util.URISupport; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.xbean.spring.context.ResourceXmlApplicationContext; import org.apache.xbean.spring.context.impl.URIEditor; import org.springframework.beans.BeansException; +import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.core.io.ClassPathResource; @@ -46,7 +50,22 @@ public class XBeanBrokerFactory implements BrokerFactoryHandler { PropertyEditorManager.registerEditor(URI.class, URIEditor.class); } + private boolean validate = true; + public boolean isValidate() { + return validate; + } + + public void setValidate(boolean validate) { + this.validate = validate; + } + public BrokerService createBroker(URI config) throws Exception { + + Map map = URISupport.parseParameters(config); + if (!map.isEmpty()) { + IntrospectionSupport.setProperties(this, map); + config = URISupport.removeQuery(config); + } String uri = config.getSchemeSpecificPart(); ApplicationContext context = createApplicationContext(uri); @@ -93,6 +112,11 @@ public class XBeanBrokerFactory implements BrokerFactoryHandler { } else { resource = new ClassPathResource(uri); } - return new ResourceXmlApplicationContext(resource); + return new ResourceXmlApplicationContext(resource) { + @Override + protected void initBeanDefinitionReader(XmlBeanDefinitionReader reader) { + reader.setValidating(isValidate()); + } + }; } } diff --git a/activemq-core/src/test/java/org/apache/activemq/broker/OutOfOrderXMLTest.java b/activemq-core/src/test/java/org/apache/activemq/broker/OutOfOrderXMLTest.java new file mode 100644 index 0000000000..11fbb56902 --- /dev/null +++ b/activemq-core/src/test/java/org/apache/activemq/broker/OutOfOrderXMLTest.java @@ -0,0 +1,33 @@ +/** + * 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.broker; + +import java.net.URI; +import org.apache.activemq.xbean.XBeanBrokerFactory; +import org.junit.Test; + +// https://issues.apache.org/activemq/browse/AMQ-2939 +public class OutOfOrderXMLTest { + + @Test + public void verifyBrokerCreationWhenXmlOutOfOrderValidationFalse() throws Exception { + BrokerService answer = + BrokerFactory.createBroker(new URI("xbean:org/apache/activemq/broker/out-of-order-broker-elements.xml?validate=false")); + answer.stop(); + + } +} diff --git a/activemq-core/src/test/resources/org/apache/activemq/broker/out-of-order-broker-elements.xml b/activemq-core/src/test/resources/org/apache/activemq/broker/out-of-order-broker-elements.xml new file mode 100644 index 0000000000..245d946f50 --- /dev/null +++ b/activemq-core/src/test/resources/org/apache/activemq/broker/out-of-order-broker-elements.xml @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +