From 736e95c28722667f15ade16bbc3d13f9b6981ff3 Mon Sep 17 00:00:00 2001 From: Stanislav Knot Date: Tue, 5 Dec 2017 17:01:20 +0100 Subject: [PATCH] ARTEMIS-1537 broker was less strict while reloading configuration --- .../activemq/artemis/utils/XMLUtil.java | 2 +- .../impl/FileConfigurationParser.java | 17 +- ...gurationTest-full-config-wrong-address.xml | 212 ++++++++++++++++++ .../impl/ConfigurationValidationTest.java | 16 ++ 4 files changed, 243 insertions(+), 4 deletions(-) create mode 100644 artemis-server/src/test/resources/ConfigurationTest-full-config-wrong-address.xml diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/XMLUtil.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/XMLUtil.java index ac57a15b66..017832b0a6 100644 --- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/XMLUtil.java +++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/XMLUtil.java @@ -352,7 +352,7 @@ public final class XMLUtil { return nodes; } - private static URL findResource(final String resourceName) { + public static URL findResource(final String resourceName) { return AccessController.doPrivileged(new PrivilegedAction() { @Override public URL run() { diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/deployers/impl/FileConfigurationParser.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/deployers/impl/FileConfigurationParser.java index e8eee49e3c..6c64a3bd87 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/deployers/impl/FileConfigurationParser.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/deployers/impl/FileConfigurationParser.java @@ -89,6 +89,12 @@ import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; import org.w3c.dom.NodeList; +import javax.xml.XMLConstants; +import javax.xml.transform.dom.DOMSource; +import javax.xml.validation.Schema; +import javax.xml.validation.SchemaFactory; +import javax.xml.validation.Validator; + /** * Parses an XML document according to the {@literal artemis-configuration.xsd} schema. */ @@ -248,14 +254,19 @@ public final class FileConfigurationParser extends XMLConfigurationUtil { } public Configuration parseMainConfig(final InputStream input) throws Exception { - Reader reader = new InputStreamReader(input); String xml = XMLUtil.readerToString(reader); xml = XMLUtil.replaceSystemProps(xml); Element e = XMLUtil.stringToElement(xml); - + SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); + Schema schema = schemaFactory.newSchema(XMLUtil.findResource("schema/artemis-server.xsd")); + Validator validator = schema.newValidator(); + try { + validator.validate(new DOMSource(e)); + } catch (Exception ex) { + ActiveMQServerLogger.LOGGER.error(ex.getMessage()); + } Configuration config = new ConfigurationImpl(); - parseMainConfig(e, config); return config; diff --git a/artemis-server/src/test/resources/ConfigurationTest-full-config-wrong-address.xml b/artemis-server/src/test/resources/ConfigurationTest-full-config-wrong-address.xml new file mode 100644 index 0000000000..202dbba691 --- /dev/null +++ b/artemis-server/src/test/resources/ConfigurationTest-full-config-wrong-address.xml @@ -0,0 +1,212 @@ + + + + + + + + 0.0.0.0 + + true + + + ASYNCIO + + ./data/paging + + ./data/bindings + + ./data/journal + + ./data/large-messages + + true + + 2 + + -1 + + 10M + + + 32000 + + + + 4096 + + + + + + + + + + + + + + + + + + + + + 5000 + + + 90 + + + true + + 120000 + + 60000 + + HALT + + + + + + + + + + + tcp://0.0.0.0:61616?tcpSendBufferSize=1048576;tcpReceiveBufferSize=1048576;protocols=CORE,AMQP,STOMP,HORNETQ,MQTT,OPENWIRE;useEpoll=true;amqpCredits=1000;amqpLowCredits=300 + + + tcp://0.0.0.0:5672?tcpSendBufferSize=1048576;tcpReceiveBufferSize=1048576;protocols=AMQP;useEpoll=true;amqpCredits=1000;amqpMinCredits=300 + + + tcp://0.0.0.0:61613?tcpSendBufferSize=1048576;tcpReceiveBufferSize=1048576;protocols=STOMP;useEpoll=true + + + tcp://0.0.0.0:5445?protocols=HORNETQ,STOMP;useEpoll=true + + + tcp://0.0.0.0:1883?tcpSendBufferSize=1048576;tcpReceiveBufferSize=1048576;protocols=MQTT;useEpoll=true + + + + + + + + + + + + + + + + + + + + + + + + DLQ + ExpiryQueue + 0 + + -1 + 10 + PAGE + true + true + true + true + + + + DLQ + ExpiryQueue + 0 + + -1 + 10 + PAGE + true + true + true + true + + + + +
+ + + +
+
+ + + +
+ fail +
+ +
+
\ No newline at end of file diff --git a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/config/impl/ConfigurationValidationTest.java b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/config/impl/ConfigurationValidationTest.java index ac6e4bea12..c6b7c1603e 100644 --- a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/config/impl/ConfigurationValidationTest.java +++ b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/config/impl/ConfigurationValidationTest.java @@ -57,4 +57,20 @@ public class ConfigurationValidationTest extends ActiveMQTestBase { Assert.assertEquals(true, fc.isPersistDeliveryCountBeforeDelivery()); } + + @Test + public void testChangeConfiguration() throws Exception { + FileConfiguration fc = new FileConfiguration(); + FileDeploymentManager deploymentManager = new FileDeploymentManager("ConfigurationTest-full-config.xml"); + deploymentManager.addDeployable(fc); + deploymentManager.readConfiguration(); + deploymentManager = new FileDeploymentManager("ConfigurationTest-full-config-wrong-address.xml"); + deploymentManager.addDeployable(fc); + + try { + deploymentManager.readConfiguration(); + fail("Exception expected"); + } catch (Exception ignored) { + } + } }