From 04804de5a167a6addeff6c1c874bd06ef84e1330 Mon Sep 17 00:00:00 2001 From: Martin Ritchie Date: Thu, 10 Sep 2009 14:38:25 +0000 Subject: QPID-2091 : Updated ServerConfiguration and added test to ServerConfigurationTest. Merged virtualhost.xml with config.xml git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@813459 13f79535-47bb-0310-9956-ffa450edef68 --- java/broker/etc/config.xml | 132 +++++++++++++++++++-- java/broker/etc/virtualhosts.xml | 123 ------------------- .../server/configuration/ServerConfiguration.java | 35 +++--- .../configuration/ServerConfigurationTest.java | 55 +++++---- 4 files changed, 170 insertions(+), 175 deletions(-) delete mode 100644 java/broker/etc/virtualhosts.xml (limited to 'java/broker') diff --git a/java/broker/etc/config.xml b/java/broker/etc/config.xml index 928b773606..8fb3a8cf5a 100644 --- a/java/broker/etc/config.xml +++ b/java/broker/etc/config.xml @@ -24,17 +24,20 @@ ${QPID_WORK} ${prefix}/etc - - true - true + false + false /path/to/keystore.ks keystorepass - --> + false false + 262144 + 262144 nio 5672 @@ -59,6 +62,7 @@ 65535 false false + en_US @@ -89,40 +93,143 @@ - ${conf}/virtualhosts + test localhost - org.apache.qpid.server.store.MemoryMessageStore + org.apache.qpid.server.store.MemoryMessageStore + 20000 + + + direct + test.direct + true + + + topic + test.topic + + + + amq.direct + 4235264 + + 2117632 + + 600000 + + 50 + + + + queue + + + ping + + + test-queue + + test.direct + true + + + + test-ping + + test.direct + + + + + development - org.apache.qpid.server.store.MemoryMessageStore + org.apache.qpid.server.store.MemoryMessageStore + + + + 30000 + 50 + + queue + + amq.direct + 4235264 + + 2117632 + + 600000 + + + + + ping + + amq.direct + 4235264 + + 2117632 + + 600000 + + + + - test - org.apache.qpid.server.store.MemoryMessageStore + org.apache.qpid.server.store.MemoryMessageStore + + + + 30000 + 50 + + queue + + amq.direct + 4235264 + + 2117632 + + 600000 + + + + + ping + + amq.direct + 4235264 + + 2117632 + + 600000 + + + + - 0 @@ -132,7 +239,8 @@ true - ${conf}/virtualhosts.xml + ON + diff --git a/java/broker/etc/virtualhosts.xml b/java/broker/etc/virtualhosts.xml deleted file mode 100644 index f62ec3f5d7..0000000000 --- a/java/broker/etc/virtualhosts.xml +++ /dev/null @@ -1,123 +0,0 @@ - - - - test - - localhost - - - - direct - test.direct - true - - - topic - test.topic - - - - amq.direct - 4235264 - 2117632 - 600000 - - - queue - - - ping - - - test-queue - - test.direct - true - - - - test-ping - - test.direct - - - - - - - - - - development - - - 30000 - 5000 - - queue - - amq.direct - 4235264 - 2117632 - 600000 - - - - ping - - amq.direct - 4235264 - 2117632 - 600000 - - - - - - - test - - - 30000 - 5000 - - queue - - amq.direct - 4235264 - 2117632 - 600000 - - - - ping - - amq.direct - 4235264 - 2117632 - 600000 - - - - - - diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/ServerConfiguration.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/ServerConfiguration.java index 7ea7738189..ed9d8acc08 100644 --- a/java/broker/src/main/java/org/apache/qpid/server/configuration/ServerConfiguration.java +++ b/java/broker/src/main/java/org/apache/qpid/server/configuration/ServerConfiguration.java @@ -147,32 +147,27 @@ public class ServerConfiguration implements SignalHandler Object thing = i.next(); if (thing instanceof String) { + //Open the Virtualhost.xml file and copy values in to main config XMLConfiguration vhostConfiguration = new XMLConfiguration((String) thing); - List hosts = vhostConfiguration.getList("virtualhost.name"); - for (int j = 0; j < hosts.size(); j++) - { - String name = (String) hosts.get(j); - // Add the keys of the virtual host to the main config then bail out - - Configuration myConf = vhostConfiguration.subset("virtualhost." + name); - Iterator k = myConf.getKeys(); - while (k.hasNext()) - { - String key = (String) k.next(); - conf.setProperty("virtualhosts.virtualhost."+name+"."+key, myConf.getProperty(key)); - } - VirtualHostConfiguration vhostConfig = new VirtualHostConfiguration(name, conf.subset("virtualhosts.virtualhost."+name)); - _virtualHosts.put(vhostConfig.getName(), vhostConfig); - } - // Grab things other than the virtualhosts themselves Iterator keys = vhostConfiguration.getKeys(); while (keys.hasNext()) { String key = (String) keys.next(); - conf.setProperty("virtualhosts."+key, vhostConfiguration.getProperty(key)); + conf.setProperty("virtualhosts." + key, vhostConfiguration.getProperty(key)); } } } + + List hosts = conf.getList("virtualhosts.virtualhost.name"); + for (int j = 0; j < hosts.size(); j++) + { + String name = (String) hosts.get(j); + // Add the keys of the virtual host to the main config then bail out + + VirtualHostConfiguration vhostConfig = new VirtualHostConfiguration(name, conf.subset("virtualhosts.virtualhost." + name)); + _virtualHosts.put(vhostConfig.getName(), vhostConfig); + } + } private void substituteEnvironmentVariables() @@ -202,7 +197,7 @@ public class ServerConfiguration implements SignalHandler } /** - * Check the configuration file to see if status updates are enabled. + * Check the configuration file to see if status updates are enabled. * @return true if status updates are enabled */ public boolean getStatusUpdatesEnabled() @@ -466,7 +461,7 @@ public class ServerConfiguration implements SignalHandler { return getConfig().getBoolean("management.enabled", true); } - + public void setManagementEnabled(boolean enabled) { getConfig().setProperty("management.enabled", enabled); diff --git a/java/broker/src/test/java/org/apache/qpid/server/configuration/ServerConfigurationTest.java b/java/broker/src/test/java/org/apache/qpid/server/configuration/ServerConfigurationTest.java index 8cb0837b39..ebfa80d139 100644 --- a/java/broker/src/test/java/org/apache/qpid/server/configuration/ServerConfigurationTest.java +++ b/java/broker/src/test/java/org/apache/qpid/server/configuration/ServerConfigurationTest.java @@ -54,7 +54,7 @@ public class ServerConfigurationTest extends TestCase _config = new XMLConfiguration(); } - + @Override public void tearDown() throws Exception { @@ -727,7 +727,7 @@ public class ServerConfigurationTest extends TestCase assertEquals(true, config.getQpidNIO()); // From the second file, not // present in the first } - + public void testVariableInterpolation() throws Exception { File mainFile = File.createTempFile(getClass().getName(), null); @@ -742,7 +742,7 @@ public class ServerConfigurationTest extends TestCase out.close(); ServerConfiguration config = new ServerConfiguration(mainFile.getAbsoluteFile()); - assertEquals("Did not get correct interpolated value", + assertEquals("Did not get correct interpolated value", "foo", config.getManagementKeyStorePath()); } @@ -783,7 +783,7 @@ public class ServerConfigurationTest extends TestCase out.write("\t\n"); out.write("\n"); out.close(); - + // Load config ApplicationRegistry reg = new ConfigurationFileApplicationRegistry(mainFile); ApplicationRegistry.initialise(reg, 1); @@ -795,15 +795,15 @@ public class ServerConfigurationTest extends TestCase TestIoSession iosession = new TestIoSession(); iosession.setAddress("127.0.0.1"); - + AMQProtocolSession session = new AMQMinaProtocolSession(iosession, virtualHostRegistry, codecFactory); assertFalse(reg.getAccessManager().authoriseConnect(session, virtualHost)); - + iosession.setAddress("127.1.2.3"); session = new AMQMinaProtocolSession(iosession, virtualHostRegistry, codecFactory); assertTrue(reg.getAccessManager().authoriseConnect(session, virtualHost)); } - + public void testCombinedConfigurationFirewall() throws Exception { // Write out config @@ -870,7 +870,7 @@ public class ServerConfigurationTest extends TestCase TestIoSession iosession = new TestIoSession(); iosession.setAddress("127.0.0.1"); - + AMQProtocolSession session = new AMQMinaProtocolSession(iosession, virtualHostRegistry, codecFactory); assertFalse(reg.getAccessManager().authoriseConnect(session, virtualHost)); } @@ -947,22 +947,22 @@ public class ServerConfigurationTest extends TestCase fileBRandom.setLength(0); fileBRandom.seek(0); fileBRandom.close(); - + out = new FileWriter(fileB); out.write("\n"); out.write("\t"); out.write("\n"); out.close(); - + reg.getConfiguration().reparseConfigFile(); - + assertTrue(reg.getAccessManager().authoriseConnect(session, virtualHost)); - + fileBRandom = new RandomAccessFile(fileB, "rw"); fileBRandom.setLength(0); fileBRandom.seek(0); fileBRandom.close(); - + out = new FileWriter(fileB); out.write("\n"); out.write("\t"); @@ -970,17 +970,17 @@ public class ServerConfigurationTest extends TestCase out.close(); reg.getConfiguration().reparseConfigFile(); - + assertFalse(reg.getAccessManager().authoriseConnect(session, virtualHost)); } public void testnewParserOutputVsOldParserOutput() throws ConfigurationException { String configDir = System.getProperty("QPID_HOME")+"/etc"; - - XMLConfiguration oldConfig = new XMLConfiguration(configDir +"/sample-parsed-config.xml"); - Configuration newConfig = new ServerConfiguration(new File(configDir+"/persistent_config-config-test.xml")).getConfig(); - + + XMLConfiguration oldConfig = new XMLConfiguration(configDir +"/config-systests-ServerConfigurationTest-Old.xml"); + Configuration newConfig = new ServerConfiguration(new File(configDir+"/config-systests-ServerConfigurationTest-New.xml")).getConfig(); + Iterator xmlKeys = oldConfig.getKeys(); while (xmlKeys.hasNext()) { @@ -988,6 +988,21 @@ public class ServerConfigurationTest extends TestCase assertEquals("Incorrect value for "+key, oldConfig.getProperty(key), newConfig.getProperty(key)); } } - - + + + public void testNoVirtualhostXMLFile() throws Exception + { + int REGISTRY=1; + + File configFile = new File(System.getProperty("QPID_HOME")+"/etc/config.xml"); + assertTrue(configFile.exists()); + + ApplicationRegistry.initialise(new ConfigurationFileApplicationRegistry(configFile), REGISTRY); + + VirtualHostRegistry virtualHostRegistry = ApplicationRegistry.getInstance(REGISTRY).getVirtualHostRegistry(); + + assertEquals("Incorrect virtualhost count", 3 , virtualHostRegistry.getVirtualHosts().size()); + } + + } -- cgit v1.2.1