summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Rudyy <orudyy@apache.org>2013-02-19 09:35:28 +0000
committerAlex Rudyy <orudyy@apache.org>2013-02-19 09:35:28 +0000
commita973713561140fe7395368ae53def8f7edfa18a3 (patch)
tree7bda80afada592df681fb73908400e7a189f015f
parent1b0f1d06188e73e9440dc1789c28ee65e24d539d (diff)
downloadqpid-python-a973713561140fe7395368ae53def8f7edfa18a3.tar.gz
QPID-4390: Introduce a configuration store in java broker allowing runtime modifications and replace existing xml file configuration with json configuration store
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1447646 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--qpid/java/bdbstore/build.xml15
-rw-r--r--qpid/java/bdbstore/jmx/src/main/java/org/apache/qpid/server/store/berkeleydb/jmx/BDBHAMessageStoreManagerMBeanProvider.java11
-rw-r--r--qpid/java/bdbstore/jmx/src/test/java/org/apache/qpid/server/store/berkeleydb/HAClusterManagementTest.java1
-rw-r--r--qpid/java/bdbstore/jmx/src/test/java/org/apache/qpid/server/store/berkeleydb/HAClusterTwoNodeTest.java9
-rw-r--r--qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBHAMessageStore.java4
-rw-r--r--qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBHAMessageStoreFactory.java41
-rw-r--r--qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBMessageStore.java4
-rw-r--r--qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBMessageStoreFactory.java41
-rw-r--r--qpid/java/bdbstore/src/main/resources/META-INF/services/org.apache.qpid.server.store.MessageStoreFactory20
-rw-r--r--qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBHAMessageStoreTest.java74
-rw-r--r--qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBMessageStoreTest.java2
-rw-r--r--qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBUpgradeTest.java11
-rw-r--r--qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/HATestClusterCreator.java34
-rw-r--r--qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/MessageStoreCreatorTest.java44
-rw-r--r--qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/upgrade/AbstractUpgradeTestCase.java19
-rw-r--r--qpid/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/config/AbstractConfiguration.java4
-rw-r--r--qpid/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/config/ConfigurationFile.java12
-rw-r--r--qpid/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/config/PlainConfiguration.java50
-rw-r--r--qpid/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/plugins/DefaultAccessControl.java2
-rw-r--r--qpid/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/plugins/DefaultAccessControlFactory.java42
-rw-r--r--qpid/java/broker-plugins/access-control/src/test/java/org/apache/qpid/server/security/access/config/PlainConfigurationTest.java22
-rw-r--r--qpid/java/broker-plugins/access-control/src/test/java/org/apache/qpid/server/security/access/plugins/DefaultAccessControlFactoryTest.java69
-rw-r--r--qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/HttpManagement.java328
-rw-r--r--qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/HttpManagementFactory.java31
-rw-r--r--qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/AbstractServlet.java52
-rw-r--r--qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/LogRecordsServlet.java13
-rw-r--r--qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/MessageContentServlet.java6
-rw-r--r--qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/MessageServlet.java31
-rw-r--r--qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/RestServlet.java14
-rw-r--r--qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/SaslServlet.java19
-rw-r--r--qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/StructureServlet.java5
-rw-r--r--qpid/java/broker-plugins/management-http/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.PluginFactory (renamed from qpid/java/broker-plugins/management-http/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.ManagementFactory)0
-rw-r--r--qpid/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/HttpManagementFactoryTest.java56
-rw-r--r--qpid/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/CustomRMIServerSocketFactory.java68
-rw-r--r--qpid/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/JMXManagedObjectRegistry.java380
-rw-r--r--qpid/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/JMXManagement.java188
-rw-r--r--qpid/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/JMXManagementFactory.java21
-rw-r--r--qpid/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/MBeanInvocationHandlerImpl.java87
-rw-r--r--qpid/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/ManagementLogonLogoffReporter.java95
-rw-r--r--qpid/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/UsernameAccessor.java (renamed from qpid/java/broker/src/main/java/org/apache/qpid/server/management/plugin/ManagementPlugin.java)11
-rw-r--r--qpid/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/UsernameCachingRMIJRMPServer.java100
-rw-r--r--qpid/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/mbeans/VirtualHostMBean.java66
-rw-r--r--qpid/java/broker-plugins/management-jmx/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.PluginFactory (renamed from qpid/java/broker-plugins/management-jmx/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.ManagementFactory)0
-rw-r--r--qpid/java/broker-plugins/management-jmx/src/test/java/org/apache/qpid/server/jmx/JMXManagementFactoryTest.java29
-rw-r--r--qpid/java/broker-plugins/management-jmx/src/test/java/org/apache/qpid/server/jmx/ManagementLogActorTest.java173
-rw-r--r--qpid/java/broker-plugins/management-jmx/src/test/java/org/apache/qpid/server/jmx/ManagementLogonLogoffReporterTest.java101
-rw-r--r--qpid/java/broker/etc/config.xml119
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/AMQChannel.java9
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/Broker.java344
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/BrokerOptions.java132
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/Main.java227
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/ProtocolExclusion.java74
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/ProtocolInclusion.java74
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/BrokerConfigurationStoreCreator.java58
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/BrokerProperties.java54
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigurationEntry.java213
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigurationEntryStore.java37
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigurationStoreFactory.java35
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfiguredObjectRecoverer.java28
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/IllegalConfigurationException.java37
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/RecovererProvider.java28
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ServerConfiguration.java994
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ServerNetworkTransportConfiguration.java90
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/VirtualHostConfiguration.java80
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/XmlConfigurationUtilities.java111
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/plugins/AbstractConfiguration.java2
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/AuthenticationProviderRecoverer.java55
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/BrokerRecoverer.java139
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/DefaultRecovererProvider.java112
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/GroupProviderRecoverer.java74
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/KeyStoreRecoverer.java40
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/PluginRecoverer.java66
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/PortRecoverer.java52
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/RecovererHelper.java44
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/TrustStoreRecoverer.java40
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/VirtualHostRecoverer.java51
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/JsonConfigurationEntryStore.java528
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/StoreConfigurationChangeListener.java205
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/factory/JsonConfigurationStoreFactory.java43
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/updater/ChangeStateTask.java67
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/updater/CreateChildTask.java78
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/updater/SetAttributeTask.java74
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/updater/TaskExecutor.java324
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/handler/ConnectionSecureOkMethodHandler.java10
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/handler/ConnectionStartOkMethodHandler.java18
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/handler/QueueDeclareHandler.java13
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/logging/AbstractRootMessageLogger.java5
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/logging/Log4jMessageLogger.java5
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/model/AuthenticationProvider.java14
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/model/Broker.java124
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/model/ConfigurationChangeListener.java1
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/model/ConfiguredObject.java22
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/model/GroupProvider.java4
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/model/KeyStore.java51
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/model/Model.java3
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/model/Plugin.java52
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/model/Port.java22
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/model/Protocol.java97
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/model/Transport.java26
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/model/TrustStore.java65
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/model/UUIDGenerator.java5
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/model/VirtualHost.java20
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/AbstractAdapter.java271
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/AbstractKeyStoreAdapter.java198
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/AbstractPluginAdapter.java152
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/AmqpPortAdapter.java251
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/AuthenticationProviderAdapter.java147
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/AuthenticationProviderFactory.java77
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/BindingAdapter.java15
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/BrokerAdapter.java802
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/ConnectionAdapter.java63
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/ConsumerAdapter.java16
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/ExchangeAdapter.java25
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/GroupProviderAdapter.java98
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/HTTPPortAdapter.java273
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/KeyStoreAdapter.java48
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/PortAdapter.java162
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/PortFactory.java215
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/QueueAdapter.java41
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/SessionAdapter.java19
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/TrustStoreAdapter.java43
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/VirtualHostAdapter.java309
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/VirtualHostAliasAdapter.java9
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/AccessControlFactory.java5
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/AuthenticationManagerFactory.java7
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/GroupManagerFactory.java5
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/PluginFactory.java (renamed from qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/ManagementFactory.java)12
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQProtocolEngine.java19
-rwxr-xr-xqpid/java/broker/src/main/java/org/apache/qpid/server/protocol/MultiVersionProtocolEngine.java28
-rwxr-xr-xqpid/java/broker/src/main/java/org/apache/qpid/server/protocol/MultiVersionProtocolEngineFactory.java12
-rwxr-xr-xqpid/java/broker/src/main/java/org/apache/qpid/server/protocol/ProtocolEngine_0_10.java9
-rwxr-xr-xqpid/java/broker/src/main/java/org/apache/qpid/server/protocol/ProtocolEngine_1_0_0.java19
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/ProtocolEngine_1_0_0_SASL.java23
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/v1_0/Connection_1_0.java9
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/v1_0/Session_1_0.java7
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/queue/AMQQueueFactory.java12
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/queue/IncomingMessage.java32
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/queue/SimpleAMQQueue.java17
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/registry/ApplicationRegistry.java592
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/registry/IApplicationRegistry.java85
-rwxr-xr-xqpid/java/broker/src/main/java/org/apache/qpid/server/security/SecurityManager.java14
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/AbstractPrincipalDatabaseAuthManagerFactory.java71
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/AnonymousAuthenticationManagerFactory.java14
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/AuthenticationManagerRegistry.java208
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/Base64MD5PasswordFileAuthenticationManagerFactory.java42
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/ExternalAuthenticationManagerFactory.java14
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/IAuthenticationManagerRegistry.java53
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/KerberosAuthenticationManagerFactory.java14
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/PlainPasswordFileAuthenticationManagerFactory.java42
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthManagerFactory.java92
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthenticationManager.java2
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/SimpleLDAPAuthenticationManagerFactory.java47
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/rmi/RMIPasswordAuthenticator.java18
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/security/group/FileGroupManager.java6
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/security/group/FileGroupManagerFactory.java44
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/security/group/GroupPrincipalAccessor.java15
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/state/AMQStateManager.java24
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/store/MemoryMessageStore.java3
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/store/MemoryMessageStoreFactory.java39
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/store/MessageStoreCreator.java66
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/store/MessageStoreFactory.java28
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/store/derby/DerbyMessageStore.java4
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/store/derby/DerbyMessageStoreFactory.java41
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/transport/QpidAcceptor.java81
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/transport/ServerConnectionDelegate.java29
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/transport/ServerSessionDelegate.java13
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/util/MapValueConverter.java335
-rwxr-xr-xqpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHost.java4
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHostImpl.java50
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHostRegistry.java51
-rw-r--r--qpid/java/broker/src/main/resources/META-INF/services/org.apache.qpid.server.configuration.ConfigurationStoreFactory19
-rw-r--r--qpid/java/broker/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.AuthenticationManagerFactory3
-rw-r--r--qpid/java/broker/src/main/resources/META-INF/services/org.apache.qpid.server.store.MessageStoreFactory20
-rw-r--r--qpid/java/broker/src/main/resources/initial-store.json58
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/AMQChannelTest.java103
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/BrokerOptionsTest.java168
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/MainTest.java115
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/ack/AcknowledgeTest.java71
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/BrokerConfigurationStoreCreatorTest.java107
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/BrokerPropertiesTest.java51
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/QueueConfigurationTest.java157
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/ServerConfigurationTest.java1791
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/VirtualHostConfigurationTest.java129
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/plugins/AbstractConfigurationTest.java4
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/BrokerRecovererTest.java405
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/DefaultRecovererProviderTest.java62
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/GroupProviderRecovererTest.java97
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/KeyStoreRecovererTest.java111
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/PluginRecovererTest.java117
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/TrustStoreRecovererTest.java108
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/VirtualHostRecovererTest.java124
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/store/ConfigurationEntryStoreTestCase.java392
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/store/JsonConfigurationEntryStoreTest.java77
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/store/StoreConfigurationChangeListenerTest.java83
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/updater/TaskExecutorTest.java296
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/exchange/AbstractHeadersExchangeTestBase.java49
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/exchange/HeadersExchangeTest.java16
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/exchange/TopicExchangeTest.java31
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/logging/UnitTestMessageLogger.java5
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/logging/actors/AMQPChannelActorTest.java150
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/logging/actors/AMQPConnectionActorTest.java26
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/logging/actors/BaseActorTestCase.java66
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/logging/actors/BaseConnectionActorTestCase.java35
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/logging/actors/CurrentActorTest.java7
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/logging/actors/HttpManagementActorTest.java14
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/logging/actors/ManagementActorTest.java28
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/logging/actors/QueueActorTest.java12
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/logging/actors/SubscriptionActorTest.java13
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/logging/messages/AbstractTestMessages.java13
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/logging/messages/ExchangeMessagesTest.java23
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/AbstractTestLogSubject.java47
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/BindingLogSubjectTest.java17
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/ChannelLogSubjectTest.java1
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/ConnectionLogSubjectTest.java26
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/ExchangeLogSubjectTest.java16
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/MessageStoreLogSubjectTest.java16
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/QueueLogSubjectTest.java15
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/SubscriptionLogSubjectTest.java24
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/model/BrokerShutdownTest.java216
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/model/adapter/AuthenticationProviderFactoryTest.java85
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/model/adapter/PortFactoryTest.java212
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/model/configuration/ConfigurationEntryTest.java129
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/protocol/InternalTestProtocolSession.java6
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/protocol/MaxChannelsTest.java42
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/protocol/MultiVersionProtocolEngineFactoryTest.java68
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/queue/AMQPriorityQueueTest.java28
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/queue/AMQQueueFactoryTest.java68
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/queue/AckTest.java28
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/queue/SimpleAMQQueueTest.java72
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/queue/SimpleAMQQueueThreadPoolTest.java27
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/registry/ApplicationRegistryShutdownTest.java104
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/AuthenticationManagerRegistryTest.java355
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/Base64MD5PasswordFileAuthenticationManagerFactoryTest.java111
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/PlainPasswordFileAuthenticationManagerFactoryTest.java111
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthManagerFactoryTest.java139
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/SimpleLDAPAuthenticationManagerFactoryTest.java12
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/rmi/RMIPasswordAuthenticatorTest.java26
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/security/group/FileGroupManagerFactoryTest.java35
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/security/group/FileGroupManagerTest.java4
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/security/group/GroupPrincipalAccessorTest.java7
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/store/MessageStoreCreatorTest.java39
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/store/MessageStoreTest.java49
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/subscription/QueueBrowserUsesNoAckTest.java79
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/subscription/SubscriptionFactoryImplTest.java53
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/transport/ServerSessionTest.java29
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/util/BrokerTestHelper.java209
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/util/InternalBrokerBaseCase.java372
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/util/TestApplicationRegistry.java105
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/virtualhost/MockVirtualHost.java10
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/virtualhost/VirtualHostImplTest.java107
-rw-r--r--qpid/java/broker/src/velocity/templates/org/apache/qpid/server/logging/messages/LogMessages.vm19
-rw-r--r--qpid/java/common/src/main/java/org/apache/qpid/transport/NetworkTransportConfiguration.java8
-rw-r--r--qpid/java/common/src/main/java/org/apache/qpid/transport/network/io/IoNetworkTransport.java6
-rw-r--r--qpid/java/common/src/test/java/org/apache/qpid/test/utils/QpidTestCase.java7
-rw-r--r--qpid/java/common/src/test/java/org/apache/qpid/test/utils/TestFileUtils.java40
-rw-r--r--qpid/java/module.xml34
-rw-r--r--qpid/java/systests/etc/config-systests-bdb-settings.xml26
-rw-r--r--qpid/java/systests/etc/config-systests-bdb.xml29
-rw-r--r--qpid/java/systests/etc/config-systests-derby-mem-settings.xml26
-rw-r--r--qpid/java/systests/etc/config-systests-derby-mem.xml29
-rw-r--r--qpid/java/systests/etc/config-systests-derby-settings.xml26
-rw-r--r--qpid/java/systests/etc/config-systests-derby.xml29
-rw-r--r--qpid/java/systests/etc/config-systests-settings.xml102
-rw-r--r--qpid/java/systests/etc/config-systests.json64
-rw-r--r--qpid/java/systests/src/main/java/org/apache/qpid/client/failover/MultipleBrokersFailoverTest.java27
-rw-r--r--qpid/java/systests/src/main/java/org/apache/qpid/client/ssl/SSLTest.java24
-rw-r--r--qpid/java/systests/src/main/java/org/apache/qpid/server/SupportedProtocolVersionsTest.java124
-rw-r--r--qpid/java/systests/src/main/java/org/apache/qpid/server/configuration/ServerConfigurationFileTest.java75
-rw-r--r--qpid/java/systests/src/main/java/org/apache/qpid/server/logging/AbstractTestLogging.java39
-rw-r--r--qpid/java/systests/src/main/java/org/apache/qpid/server/logging/AlertingTest.java6
-rw-r--r--qpid/java/systests/src/main/java/org/apache/qpid/server/logging/BrokerLoggingTest.java95
-rw-r--r--qpid/java/systests/src/main/java/org/apache/qpid/server/logging/VirtualHostLoggingTest.java15
-rw-r--r--qpid/java/systests/src/main/java/org/apache/qpid/server/persistent/NoLocalAfterRecoveryTest.java2
-rw-r--r--qpid/java/systests/src/main/java/org/apache/qpid/server/queue/MultipleTransactedBatchProducerTest.java5
-rw-r--r--qpid/java/systests/src/main/java/org/apache/qpid/server/security/acl/AbstractACLTestCase.java21
-rw-r--r--qpid/java/systests/src/main/java/org/apache/qpid/server/security/acl/ExternalACLJMXTest.java4
-rw-r--r--qpid/java/systests/src/main/java/org/apache/qpid/server/security/auth/manager/ExternalAuthenticationTest.java47
-rw-r--r--qpid/java/systests/src/main/java/org/apache/qpid/server/security/auth/manager/MultipleAuthenticationManagersTest.java28
-rw-r--r--qpid/java/systests/src/main/java/org/apache/qpid/server/stats/StatisticsReportingTest.java50
-rw-r--r--qpid/java/systests/src/main/java/org/apache/qpid/server/store/StoreOverfullTest.java6
-rw-r--r--qpid/java/systests/src/main/java/org/apache/qpid/systest/management/jmx/BrokerManagementTest.java4
-rw-r--r--qpid/java/systests/src/main/java/org/apache/qpid/systest/management/jmx/ManagementLoggingTest.java26
-rw-r--r--qpid/java/systests/src/main/java/org/apache/qpid/systest/management/jmx/StatisticsTest.java4
-rw-r--r--qpid/java/systests/src/main/java/org/apache/qpid/systest/management/jmx/UserManagementTest.java23
-rw-r--r--qpid/java/systests/src/main/java/org/apache/qpid/systest/management/jmx/UserManagementWithBase64MD5PasswordsTest.java8
-rw-r--r--qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/Asserts.java31
-rw-r--r--qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/BasicAuthRestTest.java19
-rw-r--r--qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/BindingRestTest.java3
-rw-r--r--qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/BrokerRestHttpsTest.java19
-rw-r--r--qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/BrokerRestTest.java16
-rw-r--r--qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/GroupProviderRestTest.java4
-rw-r--r--qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/GroupRestTest.java4
-rw-r--r--qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/PortRestTest.java23
-rw-r--r--qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/QpidRestTestCase.java15
-rw-r--r--qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/RestTestHelper.java17
-rw-r--r--qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/SaslRestTest.java13
-rw-r--r--qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/StructureRestTest.java31
-rw-r--r--qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/UserRestTest.java16
-rw-r--r--qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/VirtualHostRestTest.java142
-rw-r--r--qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/acl/GroupRestACLTest.java15
-rw-r--r--qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/acl/UserRestACLTest.java22
-rw-r--r--qpid/java/systests/src/main/java/org/apache/qpid/test/client/message/JMSDestinationTest.java3
-rw-r--r--qpid/java/systests/src/main/java/org/apache/qpid/test/client/timeouts/SyncWaitDelayTest.java6
-rw-r--r--qpid/java/systests/src/main/java/org/apache/qpid/test/unit/client/MaxDeliveryCountTest.java7
-rw-r--r--qpid/java/systests/src/main/java/org/apache/qpid/test/unit/topic/DurableSubscriptionTest.java2
-rw-r--r--qpid/java/systests/src/main/java/org/apache/qpid/test/unit/transacted/TransactionTimeoutDisabledTest.java2
-rw-r--r--qpid/java/systests/src/main/java/org/apache/qpid/test/unit/transacted/TransactionTimeoutTest.java26
-rw-r--r--qpid/java/systests/src/main/java/org/apache/qpid/test/utils/BrokerCommandHelper.java71
-rw-r--r--qpid/java/systests/src/main/java/org/apache/qpid/test/utils/BrokerCommandHelperTest.java39
-rw-r--r--qpid/java/systests/src/main/java/org/apache/qpid/test/utils/InternalBrokerHolder.java3
-rw-r--r--qpid/java/systests/src/main/java/org/apache/qpid/test/utils/JMXTestUtils.java6
-rwxr-xr-xqpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidBrokerTestCase.java330
-rw-r--r--qpid/java/systests/src/main/java/org/apache/qpid/test/utils/TestBrokerConfiguration.java229
-rw-r--r--qpid/java/systests/src/main/java/org/apache/qpid/test/utils/TestSSLConstants.java3
-rw-r--r--qpid/java/systests/src/main/java/org/apache/qpid/util/LogMonitor.java35
-rw-r--r--qpid/java/test-profiles/java-bdb-spawn.0-10.testprofile6
-rw-r--r--qpid/java/test-profiles/java-bdb-spawn.0-8.testprofile6
-rw-r--r--qpid/java/test-profiles/java-bdb-spawn.0-9-1.testprofile6
-rw-r--r--qpid/java/test-profiles/java-bdb-spawn.0-9.testprofile6
-rw-r--r--qpid/java/test-profiles/java-bdb.0-10.testprofile6
-rw-r--r--qpid/java/test-profiles/java-bdb.0-8.testprofile6
-rw-r--r--qpid/java/test-profiles/java-bdb.0-9-1.testprofile6
-rw-r--r--qpid/java/test-profiles/java-bdb.0-9.testprofile6
-rw-r--r--qpid/java/test-profiles/java-dby-mem.0-10.testprofile8
-rw-r--r--qpid/java/test-profiles/java-dby-mem.0-8.testprofile8
-rw-r--r--qpid/java/test-profiles/java-dby-mem.0-9-1.testprofile8
-rw-r--r--qpid/java/test-profiles/java-dby-mem.0-9.testprofile8
-rw-r--r--qpid/java/test-profiles/java-dby-spawn.0-10.testprofile6
-rw-r--r--qpid/java/test-profiles/java-dby-spawn.0-8.testprofile6
-rw-r--r--qpid/java/test-profiles/java-dby-spawn.0-9-1.testprofile6
-rw-r--r--qpid/java/test-profiles/java-dby-spawn.0-9.testprofile6
-rw-r--r--qpid/java/test-profiles/java-dby.0-10.testprofile6
-rw-r--r--qpid/java/test-profiles/java-dby.0-8.testprofile6
-rw-r--r--qpid/java/test-profiles/java-dby.0-9-1.testprofile6
-rw-r--r--qpid/java/test-profiles/java-dby.0-9.testprofile6
-rw-r--r--qpid/java/test-profiles/java-mms-spawn.0-10.testprofile5
-rw-r--r--qpid/java/test-profiles/java-mms-spawn.0-8.testprofile5
-rw-r--r--qpid/java/test-profiles/java-mms-spawn.0-9-1.testprofile5
-rw-r--r--qpid/java/test-profiles/java-mms-spawn.0-9.testprofile5
-rw-r--r--qpid/java/test-profiles/java-mms.0-10.testprofile5
-rw-r--r--qpid/java/test-profiles/java-mms.0-8.testprofile5
-rw-r--r--qpid/java/test-profiles/java-mms.0-9-1.testprofile5
-rw-r--r--qpid/java/test-profiles/java-mms.0-9.testprofile5
-rw-r--r--qpid/java/test-profiles/testprofile.defaults6
344 files changed, 13614 insertions, 10336 deletions
diff --git a/qpid/java/bdbstore/build.xml b/qpid/java/bdbstore/build.xml
index 8f3123193a..46809f6a90 100644
--- a/qpid/java/bdbstore/build.xml
+++ b/qpid/java/bdbstore/build.xml
@@ -78,19 +78,4 @@ http://www.oracle.com/technetwork/database/berkeleydb/downloads/jeoslicense-0868
<target name="build" depends="check-request-props, bdb-jar-required, module.build" />
- <target name="postbuild" depends="copy-store-to-upgrade" />
-
- <target name="copy-store-to-upgrade" description="copy the upgrade tool resource folder contents into the build tree">
- <copy todir="${qpid.home}" failonerror="true">
- <fileset dir="src/test/resources/upgrade"/>
- </copy>
- </target>
-
- <target name="precompile-tests">
- <mkdir dir="${module.test.resources}"/>
- <copy todir="${module.test.resources}">
- <fileset dir="src/test/resources"/>
- </copy>
- </target>
-
</project>
diff --git a/qpid/java/bdbstore/jmx/src/main/java/org/apache/qpid/server/store/berkeleydb/jmx/BDBHAMessageStoreManagerMBeanProvider.java b/qpid/java/bdbstore/jmx/src/main/java/org/apache/qpid/server/store/berkeleydb/jmx/BDBHAMessageStoreManagerMBeanProvider.java
index 837da1eef3..14cdec1669 100644
--- a/qpid/java/bdbstore/jmx/src/main/java/org/apache/qpid/server/store/berkeleydb/jmx/BDBHAMessageStoreManagerMBeanProvider.java
+++ b/qpid/java/bdbstore/jmx/src/main/java/org/apache/qpid/server/store/berkeleydb/jmx/BDBHAMessageStoreManagerMBeanProvider.java
@@ -28,13 +28,11 @@ import org.apache.qpid.server.jmx.MBeanProvider;
import org.apache.qpid.server.jmx.ManagedObject;
import org.apache.qpid.server.model.ConfiguredObject;
import org.apache.qpid.server.model.VirtualHost;
-import org.apache.qpid.server.registry.ApplicationRegistry;
import org.apache.qpid.server.store.berkeleydb.BDBHAMessageStore;
-import org.apache.qpid.server.virtualhost.VirtualHostRegistry;
/**
* This provide will create a {@link BDBHAMessageStoreManagerMBean} if the child is a virtual
- * host and of type {@link BDBHAMessageStore#BDB_HA_STORE_TYPE}.
+ * host and of type {@link BDBHAMessageStore#TYPE}.
*
*/
public class BDBHAMessageStoreManagerMBeanProvider implements MBeanProvider
@@ -50,7 +48,7 @@ public class BDBHAMessageStoreManagerMBeanProvider implements MBeanProvider
public boolean isChildManageableByMBean(ConfiguredObject child)
{
return (child instanceof VirtualHost
- && BDBHAMessageStore.BDB_HA_STORE_TYPE.equals(child.getAttribute(VirtualHost.STORE_TYPE)));
+ && BDBHAMessageStore.TYPE.equals(child.getAttribute(VirtualHost.STORE_TYPE)));
}
@Override
@@ -58,10 +56,7 @@ public class BDBHAMessageStoreManagerMBeanProvider implements MBeanProvider
{
VirtualHost virtualHostChild = (VirtualHost) child;
- VirtualHostRegistry virtualHostRegistry = ApplicationRegistry.getInstance().getVirtualHostRegistry();
- org.apache.qpid.server.virtualhost.VirtualHost vhost = virtualHostRegistry.getVirtualHost(virtualHostChild.getName());
-
- BDBHAMessageStore messageStore = (BDBHAMessageStore) vhost.getMessageStore();
+ BDBHAMessageStore messageStore = (BDBHAMessageStore) virtualHostChild.getMessageStore();
if (LOGGER.isDebugEnabled())
{
diff --git a/qpid/java/bdbstore/jmx/src/test/java/org/apache/qpid/server/store/berkeleydb/HAClusterManagementTest.java b/qpid/java/bdbstore/jmx/src/test/java/org/apache/qpid/server/store/berkeleydb/HAClusterManagementTest.java
index bf1381bb02..ff47ed958d 100644
--- a/qpid/java/bdbstore/jmx/src/test/java/org/apache/qpid/server/store/berkeleydb/HAClusterManagementTest.java
+++ b/qpid/java/bdbstore/jmx/src/test/java/org/apache/qpid/server/store/berkeleydb/HAClusterManagementTest.java
@@ -67,7 +67,6 @@ public class HAClusterManagementTest extends QpidBrokerTestCase
protected void setUp() throws Exception
{
_brokerType = BrokerType.SPAWNED;
- _jmxUtils.setUp();
_clusterCreator.configureClusterNodes();
_brokerFailoverUrl = _clusterCreator.getConnectionUrlForAllClusterNodes();
diff --git a/qpid/java/bdbstore/jmx/src/test/java/org/apache/qpid/server/store/berkeleydb/HAClusterTwoNodeTest.java b/qpid/java/bdbstore/jmx/src/test/java/org/apache/qpid/server/store/berkeleydb/HAClusterTwoNodeTest.java
index b8f5a11fbd..95626f7fa5 100644
--- a/qpid/java/bdbstore/jmx/src/test/java/org/apache/qpid/server/store/berkeleydb/HAClusterTwoNodeTest.java
+++ b/qpid/java/bdbstore/jmx/src/test/java/org/apache/qpid/server/store/berkeleydb/HAClusterTwoNodeTest.java
@@ -57,7 +57,6 @@ public class HAClusterTwoNodeTest extends QpidBrokerTestCase
assertTrue(isJavaBroker());
assertTrue(isBrokerStorePersistent());
- _jmxUtils.setUp();
super.setUp();
}
@@ -87,11 +86,11 @@ public class HAClusterTwoNodeTest extends QpidBrokerTestCase
String storeConfigKeyPrefix = _clusterCreator.getStoreConfigKeyPrefix();
- setConfigurationProperty(storeConfigKeyPrefix + ".repConfig(0).name", ReplicationConfig.INSUFFICIENT_REPLICAS_TIMEOUT);
- setConfigurationProperty(storeConfigKeyPrefix + ".repConfig(0).value", "2 s");
+ setVirtualHostConfigurationProperty(storeConfigKeyPrefix + ".repConfig(0).name", ReplicationConfig.INSUFFICIENT_REPLICAS_TIMEOUT);
+ setVirtualHostConfigurationProperty(storeConfigKeyPrefix + ".repConfig(0).value", "2 s");
- setConfigurationProperty(storeConfigKeyPrefix + ".repConfig(1).name", ReplicationConfig.ELECTIONS_PRIMARY_RETRIES);
- setConfigurationProperty(storeConfigKeyPrefix + ".repConfig(1).value", "0");
+ setVirtualHostConfigurationProperty(storeConfigKeyPrefix + ".repConfig(1).name", ReplicationConfig.ELECTIONS_PRIMARY_RETRIES);
+ setVirtualHostConfigurationProperty(storeConfigKeyPrefix + ".repConfig(1).value", "0");
_clusterCreator.configureClusterNodes();
_clusterCreator.setDesignatedPrimaryOnFirstBroker(designedPrimary);
diff --git a/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBHAMessageStore.java b/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBHAMessageStore.java
index c40f24dbc3..ba111e8091 100644
--- a/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBHAMessageStore.java
+++ b/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBHAMessageStore.java
@@ -105,7 +105,7 @@ public class BDBHAMessageStore extends AbstractBDBMessageStore implements HAMess
put(ReplicationConfig.LOG_FLUSH_TASK_INTERVAL, "1 min");
}});
- public static final String BDB_HA_STORE_TYPE = "BDB-HA";
+ public static final String TYPE = "BDB-HA";
private String _groupName;
private String _nodeName;
@@ -602,6 +602,6 @@ public class BDBHAMessageStore extends AbstractBDBMessageStore implements HAMess
@Override
public String getStoreType()
{
- return BDB_HA_STORE_TYPE;
+ return TYPE;
}
}
diff --git a/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBHAMessageStoreFactory.java b/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBHAMessageStoreFactory.java
new file mode 100644
index 0000000000..20dce2628d
--- /dev/null
+++ b/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBHAMessageStoreFactory.java
@@ -0,0 +1,41 @@
+/*
+ *
+ * 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.qpid.server.store.berkeleydb;
+
+import org.apache.qpid.server.store.MessageStore;
+import org.apache.qpid.server.store.MessageStoreFactory;
+
+public class BDBHAMessageStoreFactory implements MessageStoreFactory
+{
+
+ @Override
+ public String getType()
+ {
+ return BDBHAMessageStore.TYPE;
+ }
+
+ @Override
+ public MessageStore createMessageStore()
+ {
+ return new BDBHAMessageStore();
+ }
+
+}
diff --git a/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBMessageStore.java b/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBMessageStore.java
index 82bc3d8564..4028de4b80 100644
--- a/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBMessageStore.java
+++ b/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBMessageStore.java
@@ -42,7 +42,7 @@ import com.sleepycat.je.EnvironmentConfig;
public class BDBMessageStore extends AbstractBDBMessageStore
{
private static final Logger LOGGER = Logger.getLogger(BDBMessageStore.class);
- private static final String BDB_STORE_TYPE = "BDB";
+ public static final String TYPE = "BDB";
private CommitThreadWrapper _commitThreadWrapper;
@Override
@@ -108,7 +108,7 @@ public class BDBMessageStore extends AbstractBDBMessageStore
@Override
public String getStoreType()
{
- return BDB_STORE_TYPE;
+ return TYPE;
}
}
diff --git a/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBMessageStoreFactory.java b/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBMessageStoreFactory.java
new file mode 100644
index 0000000000..126bf1928a
--- /dev/null
+++ b/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBMessageStoreFactory.java
@@ -0,0 +1,41 @@
+/*
+ *
+ * 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.qpid.server.store.berkeleydb;
+
+import org.apache.qpid.server.store.MessageStore;
+import org.apache.qpid.server.store.MessageStoreFactory;
+
+public class BDBMessageStoreFactory implements MessageStoreFactory
+{
+
+ @Override
+ public String getType()
+ {
+ return BDBMessageStore.TYPE;
+ }
+
+ @Override
+ public MessageStore createMessageStore()
+ {
+ return new BDBMessageStore();
+ }
+
+}
diff --git a/qpid/java/bdbstore/src/main/resources/META-INF/services/org.apache.qpid.server.store.MessageStoreFactory b/qpid/java/bdbstore/src/main/resources/META-INF/services/org.apache.qpid.server.store.MessageStoreFactory
new file mode 100644
index 0000000000..0be7035e2e
--- /dev/null
+++ b/qpid/java/bdbstore/src/main/resources/META-INF/services/org.apache.qpid.server.store.MessageStoreFactory
@@ -0,0 +1,20 @@
+#
+# 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.
+#
+org.apache.qpid.server.store.berkeleydb.BDBMessageStoreFactory
+org.apache.qpid.server.store.berkeleydb.BDBHAMessageStoreFactory \ No newline at end of file
diff --git a/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBHAMessageStoreTest.java b/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBHAMessageStoreTest.java
index a04fb20680..8e32a1d113 100644
--- a/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBHAMessageStoreTest.java
+++ b/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBHAMessageStoreTest.java
@@ -24,12 +24,8 @@ import java.io.File;
import java.net.InetAddress;
import org.apache.commons.configuration.XMLConfiguration;
-import org.apache.qpid.server.configuration.ServerConfiguration;
-import org.apache.qpid.server.logging.SystemOutMessageLogger;
-import org.apache.qpid.server.logging.actors.CurrentActor;
-import org.apache.qpid.server.logging.actors.TestLogActor;
-import org.apache.qpid.server.registry.ApplicationRegistry;
-import org.apache.qpid.server.util.TestApplicationRegistry;
+import org.apache.qpid.server.configuration.VirtualHostConfiguration;
+import org.apache.qpid.server.util.BrokerTestHelper;
import org.apache.qpid.server.virtualhost.VirtualHost;
import org.apache.qpid.test.utils.QpidTestCase;
import org.apache.qpid.util.FileUtils;
@@ -51,6 +47,7 @@ public class BDBHAMessageStoreTest extends QpidTestCase
private int _masterPort;
private String _host;
private XMLConfiguration _configXml;
+ private VirtualHost _virtualHost;
public void setUp() throws Exception
{
@@ -63,41 +60,48 @@ public class BDBHAMessageStoreTest extends QpidTestCase
FileUtils.delete(new File(_workDir), true);
_configXml = new XMLConfiguration();
- }
- public void tearDown() throws Exception
- {
- FileUtils.delete(new File(_workDir), true);
- super.tearDown();
- }
+ BrokerTestHelper.setUp();
+ }
- public void testSetSystemConfiguration() throws Exception
+ public void tearDown() throws Exception
{
- // create virtual host configuration, registry and host instance
- addVirtualHostConfiguration();
- TestApplicationRegistry registry = initialize();
try
{
- VirtualHost virtualhost = registry.getVirtualHostRegistry().getVirtualHost("test" + _masterPort);
- BDBHAMessageStore store = (BDBHAMessageStore) virtualhost.getMessageStore();
-
- // test whether JVM system settings were applied
- Environment env = store.getEnvironment();
- assertEquals("Unexpected number of cleaner threads", TEST_NUMBER_OF_THREADS, env.getConfig().getConfigParam(EnvironmentConfig.CLEANER_THREADS));
- assertEquals("Unexpected log file max", TEST_LOG_FILE_MAX, env.getConfig().getConfigParam(EnvironmentConfig.LOG_FILE_MAX));
-
- ReplicatedEnvironment repEnv = store.getReplicatedEnvironment();
- assertEquals("Unexpected number of elections primary retries", TEST_ELECTION_RETRIES,
- repEnv.getConfig().getConfigParam(ReplicationConfig.ELECTIONS_PRIMARY_RETRIES));
- assertEquals("Unexpected number of elections primary retries", TEST_ENV_CONSISTENCY_TIMEOUT,
- repEnv.getConfig().getConfigParam(ReplicationConfig.ENV_CONSISTENCY_TIMEOUT));
+ FileUtils.delete(new File(_workDir), true);
+ if (_virtualHost != null)
+ {
+ _virtualHost.close();
+ }
}
finally
{
- ApplicationRegistry.remove();
+ BrokerTestHelper.tearDown();
+ super.tearDown();
}
}
+ public void testSetSystemConfiguration() throws Exception
+ {
+ // create virtual host configuration, registry and host instance
+ addVirtualHostConfiguration();
+ String vhostName = "test" + _masterPort;
+ VirtualHostConfiguration configuration = new VirtualHostConfiguration(vhostName, _configXml.subset("virtualhosts.virtualhost." + vhostName), BrokerTestHelper.createBrokerMock());
+ _virtualHost = BrokerTestHelper.createVirtualHost(configuration);
+ BDBHAMessageStore store = (BDBHAMessageStore) _virtualHost.getMessageStore();
+
+ // test whether JVM system settings were applied
+ Environment env = store.getEnvironment();
+ assertEquals("Unexpected number of cleaner threads", TEST_NUMBER_OF_THREADS, env.getConfig().getConfigParam(EnvironmentConfig.CLEANER_THREADS));
+ assertEquals("Unexpected log file max", TEST_LOG_FILE_MAX, env.getConfig().getConfigParam(EnvironmentConfig.LOG_FILE_MAX));
+
+ ReplicatedEnvironment repEnv = store.getReplicatedEnvironment();
+ assertEquals("Unexpected number of elections primary retries", TEST_ELECTION_RETRIES,
+ repEnv.getConfig().getConfigParam(ReplicationConfig.ELECTIONS_PRIMARY_RETRIES));
+ assertEquals("Unexpected number of elections primary retries", TEST_ENV_CONSISTENCY_TIMEOUT,
+ repEnv.getConfig().getConfigParam(ReplicationConfig.ENV_CONSISTENCY_TIMEOUT));
+ }
+
private void addVirtualHostConfiguration() throws Exception
{
int port = findFreePort();
@@ -152,14 +156,4 @@ public class BDBHAMessageStoreTest extends QpidTestCase
}
return _host + ":" + _masterPort;
}
-
- private TestApplicationRegistry initialize() throws Exception
- {
- CurrentActor.set(new TestLogActor(new SystemOutMessageLogger()));
- ServerConfiguration configuration = new ServerConfiguration(_configXml);
- TestApplicationRegistry registry = new TestApplicationRegistry(configuration);
- ApplicationRegistry.initialise(registry);
- registry.getVirtualHostRegistry().setDefaultVirtualHostName("test" + _masterPort);
- return registry;
- }
}
diff --git a/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBMessageStoreTest.java b/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBMessageStoreTest.java
index eef9f7eab4..d18c850ecf 100644
--- a/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBMessageStoreTest.java
+++ b/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBMessageStoreTest.java
@@ -225,7 +225,7 @@ public class BDBMessageStoreTest extends org.apache.qpid.server.store.MessageSto
messageStore.close();
AbstractBDBMessageStore newStore = new BDBMessageStore();
- newStore.configure("", _config.subset("store"));
+ newStore.configure("", getConfig().subset("store"));
newStore.startWithNoRecover();
diff --git a/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBUpgradeTest.java b/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBUpgradeTest.java
index 3c0f72c302..e4837b212e 100644
--- a/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBUpgradeTest.java
+++ b/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBUpgradeTest.java
@@ -31,6 +31,7 @@ import static org.apache.qpid.server.store.berkeleydb.BDBStoreUpgradeTestPrepare
import static org.apache.qpid.server.store.berkeleydb.BDBStoreUpgradeTestPreparer.TOPIC_NAME;
import java.io.File;
+import java.io.InputStream;
import javax.jms.Connection;
import javax.jms.DeliveryMode;
@@ -84,15 +85,13 @@ public class BDBUpgradeTest extends QpidBrokerTestCase
{
FileUtils.delete(directory, true);
}
+ directory.mkdirs();
// copy store files
- String src = getClass().getClassLoader().getResource("upgrade/bdbstore-v4/test-store").toURI().getPath();
- FileUtils.copyRecursive(new File(src), new File(_storeLocation));
-
- //override the broker config used and then start the broker with the updated store
- _configFile = new File("build/etc/config-systests-bdb.xml");
- setConfigurationProperty("management.enabled", "true");
+ InputStream src = getClass().getClassLoader().getResourceAsStream("upgrade/bdbstore-v4/test-store/00000000.jdb");
+ FileUtils.copy(src, new File(_storeLocation, "00000000.jdb"));
+ getBrokerConfiguration().addJmxManagementConfiguration();
super.setUp();
}
diff --git a/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/HATestClusterCreator.java b/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/HATestClusterCreator.java
index 014b93a1ba..4c2fa910f5 100644
--- a/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/HATestClusterCreator.java
+++ b/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/HATestClusterCreator.java
@@ -43,6 +43,7 @@ import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.apache.qpid.client.AMQConnection;
import org.apache.qpid.client.AMQConnectionURL;
+import org.apache.qpid.test.utils.TestBrokerConfiguration;
import org.apache.qpid.test.utils.QpidBrokerTestCase;
import org.apache.qpid.url.URLSyntaxException;
@@ -67,7 +68,7 @@ public class HATestClusterCreator
private final Map<Integer, Integer> _brokerPortToBdbPortMap = new HashMap<Integer, Integer>();
private final Map<Integer, BrokerConfigHolder> _brokerConfigurations = new TreeMap<Integer, BrokerConfigHolder>();
private final String _virtualHostName;
- private final String _storeConfigKeyPrefix;
+ private final String _vhostStoreConfigKeyPrefix;
private final String _ipAddressOfBroker;
private final String _groupName ;
@@ -82,7 +83,7 @@ public class HATestClusterCreator
_groupName = "group" + _testcase.getName();
_ipAddressOfBroker = getIpAddressOfBrokerHost();
_numberOfNodes = numberOfNodes;
- _storeConfigKeyPrefix = "virtualhosts.virtualhost." + _virtualHostName + ".store.";
+ _vhostStoreConfigKeyPrefix = "virtualhosts.virtualhost." + _virtualHostName + ".store.";
_bdbHelperPort = 0;
}
@@ -102,7 +103,9 @@ public class HATestClusterCreator
}
configureClusterNode(brokerPort, bdbPort);
- collectConfig(brokerPort, _testcase.getTestConfiguration(), _testcase.getTestVirtualhosts());
+ TestBrokerConfiguration brokerConfiguration = _testcase.getBrokerConfiguration(brokerPort);
+ brokerConfiguration.addJmxManagementConfiguration();
+ collectConfig(brokerPort, brokerConfiguration, _testcase.getTestVirtualhosts());
brokerPort = _testcase.getNextAvailable(bdbPort + 1);
}
@@ -127,7 +130,7 @@ public class HATestClusterCreator
*/
private String getConfigKey(String configKeySuffix)
{
- final String configKey = StringUtils.substringAfter(_storeConfigKeyPrefix + configKeySuffix, "virtualhosts.");
+ final String configKey = StringUtils.substringAfter(_vhostStoreConfigKeyPrefix + configKeySuffix, "virtualhosts.");
return configKey;
}
@@ -135,7 +138,6 @@ public class HATestClusterCreator
{
final BrokerConfigHolder brokerConfigHolder = _brokerConfigurations.get(brokerPortNumber);
- _testcase.setTestConfiguration(brokerConfigHolder.getTestConfiguration());
_testcase.setTestVirtualhosts(brokerConfigHolder.getTestVirtualhosts());
_testcase.startBroker(brokerPortNumber);
@@ -348,12 +350,12 @@ public class HATestClusterCreator
{
final String nodeName = getNodeNameForNodeAt(bdbPort);
- _testcase.setConfigurationProperty(_storeConfigKeyPrefix + "class", "org.apache.qpid.server.store.berkeleydb.BDBHAMessageStore");
+ _testcase.setVirtualHostConfigurationProperty(_vhostStoreConfigKeyPrefix + "class", "org.apache.qpid.server.store.berkeleydb.BDBHAMessageStore");
- _testcase.setConfigurationProperty(_storeConfigKeyPrefix + "highAvailability.groupName", _groupName);
- _testcase.setConfigurationProperty(_storeConfigKeyPrefix + "highAvailability.nodeName", nodeName);
- _testcase.setConfigurationProperty(_storeConfigKeyPrefix + "highAvailability.nodeHostPort", getNodeHostPortForNodeAt(bdbPort));
- _testcase.setConfigurationProperty(_storeConfigKeyPrefix + "highAvailability.helperHostPort", getHelperHostPort());
+ _testcase.setVirtualHostConfigurationProperty(_vhostStoreConfigKeyPrefix + "highAvailability.groupName", _groupName);
+ _testcase.setVirtualHostConfigurationProperty(_vhostStoreConfigKeyPrefix + "highAvailability.nodeName", nodeName);
+ _testcase.setVirtualHostConfigurationProperty(_vhostStoreConfigKeyPrefix + "highAvailability.nodeHostPort", getNodeHostPortForNodeAt(bdbPort));
+ _testcase.setVirtualHostConfigurationProperty(_vhostStoreConfigKeyPrefix + "highAvailability.helperHostPort", getHelperHostPort());
}
public String getIpAddressOfBrokerHost()
@@ -369,24 +371,24 @@ public class HATestClusterCreator
}
}
- private void collectConfig(final int brokerPortNumber, XMLConfiguration testConfiguration, XMLConfiguration testVirtualhosts)
+ private void collectConfig(final int brokerPortNumber, TestBrokerConfiguration testConfiguration, XMLConfiguration testVirtualhosts)
{
- _brokerConfigurations.put(brokerPortNumber, new BrokerConfigHolder((XMLConfiguration) testConfiguration.clone(),
+ _brokerConfigurations.put(brokerPortNumber, new BrokerConfigHolder(testConfiguration,
(XMLConfiguration) testVirtualhosts.clone()));
}
public class BrokerConfigHolder
{
- private final XMLConfiguration _testConfiguration;
+ private final TestBrokerConfiguration _testConfiguration;
private final XMLConfiguration _testVirtualhosts;
- public BrokerConfigHolder(XMLConfiguration testConfiguration, XMLConfiguration testVirtualhosts)
+ public BrokerConfigHolder(TestBrokerConfiguration testConfiguration, XMLConfiguration testVirtualhosts)
{
_testConfiguration = testConfiguration;
_testVirtualhosts = testVirtualhosts;
}
- public XMLConfiguration getTestConfiguration()
+ public TestBrokerConfiguration getTestConfiguration()
{
return _testConfiguration;
}
@@ -416,7 +418,7 @@ public class HATestClusterCreator
public String getStoreConfigKeyPrefix()
{
- return _storeConfigKeyPrefix;
+ return _vhostStoreConfigKeyPrefix;
}
diff --git a/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/MessageStoreCreatorTest.java b/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/MessageStoreCreatorTest.java
new file mode 100644
index 0000000000..d33eb868c2
--- /dev/null
+++ b/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/MessageStoreCreatorTest.java
@@ -0,0 +1,44 @@
+/*
+ *
+ * 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.qpid.server.store.berkeleydb;
+
+import org.apache.qpid.server.store.MemoryMessageStore;
+import org.apache.qpid.server.store.MessageStore;
+import org.apache.qpid.server.store.MessageStoreCreator;
+import org.apache.qpid.server.store.berkeleydb.BDBHAMessageStore;
+import org.apache.qpid.server.store.berkeleydb.BDBMessageStore;
+import org.apache.qpid.server.store.derby.DerbyMessageStore;
+import org.apache.qpid.test.utils.QpidTestCase;
+
+public class MessageStoreCreatorTest extends QpidTestCase
+{
+ private static final String[] STORE_TYPES = {MemoryMessageStore.TYPE, DerbyMessageStore.TYPE, BDBMessageStore.TYPE, BDBHAMessageStore.TYPE};
+
+ public void testMessageStoreCreator()
+ {
+ MessageStoreCreator messageStoreCreator = new MessageStoreCreator();
+ for (String type : STORE_TYPES)
+ {
+ MessageStore store = messageStoreCreator.createMessageStore(type);
+ assertNotNull("Store of type " + type + " is not created", store);
+ }
+ }
+}
diff --git a/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/upgrade/AbstractUpgradeTestCase.java b/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/upgrade/AbstractUpgradeTestCase.java
index a9995d8267..b2b28b3c2d 100644
--- a/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/upgrade/AbstractUpgradeTestCase.java
+++ b/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/upgrade/AbstractUpgradeTestCase.java
@@ -27,6 +27,7 @@ import static org.apache.qpid.server.store.berkeleydb.BDBStoreUpgradeTestPrepare
import static org.apache.qpid.server.store.berkeleydb.BDBStoreUpgradeTestPreparer.QUEUE_WITH_DLQ_NAME;
import java.io.File;
+import java.io.InputStream;
import org.apache.qpid.server.logging.LogSubject;
import org.apache.qpid.server.logging.subjects.TestBlankSubject;
@@ -111,10 +112,24 @@ public abstract class AbstractUpgradeTestCase extends QpidTestCase
private File copyStore(String storeDirectoryName) throws Exception
{
- String src = getClass().getClassLoader().getResource("upgrade/" + storeDirectoryName).toURI().getPath();
File storeLocation = new File(new File(TMP_FOLDER), "test-store");
deleteDirectoryIfExists(storeLocation);
- FileUtils.copyRecursive(new File(src), new File(TMP_FOLDER));
+ storeLocation.mkdirs();
+ int index = 0;
+ String prefix = "0000000";
+ String extension = ".jdb";
+ InputStream is = null;
+ do
+ {
+ String fileName = prefix + index + extension;
+ is = getClass().getClassLoader().getResourceAsStream("upgrade/" + storeDirectoryName + "/test-store/" + fileName);
+ if (is != null)
+ {
+ FileUtils.copy(is, new File(storeLocation, fileName));
+ }
+ index++;
+ }
+ while (is != null);
return storeLocation;
}
diff --git a/qpid/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/config/AbstractConfiguration.java b/qpid/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/config/AbstractConfiguration.java
index 44c48523e2..f87374ac80 100644
--- a/qpid/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/config/AbstractConfiguration.java
+++ b/qpid/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/config/AbstractConfiguration.java
@@ -22,8 +22,6 @@ package org.apache.qpid.server.security.access.config;
import java.io.File;
-import org.apache.commons.configuration.ConfigurationException;
-
public abstract class AbstractConfiguration implements ConfigurationFile
{
private File _file;
@@ -39,7 +37,7 @@ public abstract class AbstractConfiguration implements ConfigurationFile
return _file;
}
- public RuleSet load() throws ConfigurationException
+ public RuleSet load()
{
_config = new RuleSet();
return _config;
diff --git a/qpid/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/config/ConfigurationFile.java b/qpid/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/config/ConfigurationFile.java
index 8b1a00259b..966c32e24e 100644
--- a/qpid/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/config/ConfigurationFile.java
+++ b/qpid/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/config/ConfigurationFile.java
@@ -22,7 +22,7 @@ package org.apache.qpid.server.security.access.config;
import java.io.File;
-import org.apache.commons.configuration.ConfigurationException;
+import org.apache.qpid.server.configuration.IllegalConfigurationException;
public interface ConfigurationFile
{
@@ -33,19 +33,17 @@ public interface ConfigurationFile
/**
* Load this configuration file's contents into a {@link RuleSet}.
- *
- * @throws ConfigurationException if the configuration file has errors.
+ * @throws IllegalConfigurationException if the configuration file has errors.
* @throws IllegalArgumentException if individual tokens cannot be parsed.
*/
- RuleSet load() throws ConfigurationException;
+ RuleSet load() throws IllegalConfigurationException;
/**
* Reload this configuration file's contents.
- *
- * @throws ConfigurationException if the configuration file has errors.
+ * @throws IllegalConfigurationException if the configuration file has errors.
* @throws IllegalArgumentException if individual tokens cannot be parsed.
*/
- RuleSet reload() throws ConfigurationException;
+ RuleSet reload() throws IllegalConfigurationException;
RuleSet getConfiguration();
diff --git a/qpid/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/config/PlainConfiguration.java b/qpid/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/config/PlainConfiguration.java
index 86f8ca3217..ab309c54ce 100644
--- a/qpid/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/config/PlainConfiguration.java
+++ b/qpid/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/config/PlainConfiguration.java
@@ -32,9 +32,9 @@ import java.util.List;
import java.util.Map;
import java.util.Stack;
-import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
+import org.apache.qpid.server.configuration.IllegalConfigurationException;
import org.apache.qpid.server.security.access.ObjectType;
import org.apache.qpid.server.security.access.Operation;
import org.apache.qpid.server.security.access.Permission;
@@ -73,7 +73,7 @@ public class PlainConfiguration extends AbstractConfiguration
}
@Override
- public RuleSet load() throws ConfigurationException
+ public RuleSet load()
{
RuleSet ruleSet = super.load();
@@ -127,7 +127,7 @@ public class PlainConfiguration extends AbstractConfiguration
stack.removeElementAt(0);
if (stack.isEmpty())
{
- throw new ConfigurationException(String.format(NOT_ENOUGH_TOKENS_MSG, getLine()));
+ throw new IllegalConfigurationException(String.format(NOT_ENOUGH_TOKENS_MSG, getLine()));
}
// check for and parse optional initial number for ACL lines
@@ -148,7 +148,7 @@ public class PlainConfiguration extends AbstractConfiguration
{
if(StringUtils.equalsIgnoreCase("GROUP", first))
{
- throw new ConfigurationException(String.format("GROUP keyword not supported. Groups should defined via a Group Provider, not in the ACL file.", getLine()));
+ throw new IllegalConfigurationException(String.format("GROUP keyword not supported. Groups should defined via a Group Provider, not in the ACL file.", getLine()));
}
else if (StringUtils.equalsIgnoreCase(CONFIG, first))
{
@@ -156,12 +156,12 @@ public class PlainConfiguration extends AbstractConfiguration
}
else
{
- throw new ConfigurationException(String.format(UNRECOGNISED_INITIAL_MSG, first, getLine()));
+ throw new IllegalConfigurationException(String.format(UNRECOGNISED_INITIAL_MSG, first, getLine()));
}
}
else
{
- throw new ConfigurationException(String.format(NUMBER_NOT_ALLOWED_MSG, first, getLine()));
+ throw new IllegalConfigurationException(String.format(NUMBER_NOT_ALLOWED_MSG, first, getLine()));
}
// reset stack, start next line
@@ -183,7 +183,7 @@ public class PlainConfiguration extends AbstractConfiguration
}
// invalid location for continuation character (add one to line beacuse we ate the EOL)
- throw new ConfigurationException(String.format(PREMATURE_CONTINUATION_MSG, getLine() + 1));
+ throw new IllegalConfigurationException(String.format(PREMATURE_CONTINUATION_MSG, getLine() + 1));
}
else if (_st.ttype == '\'' || _st.ttype == '"')
{
@@ -198,20 +198,20 @@ public class PlainConfiguration extends AbstractConfiguration
if (!stack.isEmpty())
{
- throw new ConfigurationException(String.format(PREMATURE_EOF_MSG, getLine()));
+ throw new IllegalConfigurationException(String.format(PREMATURE_EOF_MSG, getLine()));
}
}
catch (IllegalArgumentException iae)
{
- throw new ConfigurationException(String.format(PARSE_TOKEN_FAILED_MSG, getLine()), iae);
+ throw new IllegalConfigurationException(String.format(PARSE_TOKEN_FAILED_MSG, getLine()), iae);
}
catch (FileNotFoundException fnfe)
{
- throw new ConfigurationException(String.format(CONFIG_NOT_FOUND_MSG, file.getName()), fnfe);
+ throw new IllegalConfigurationException(String.format(CONFIG_NOT_FOUND_MSG, file.getName()), fnfe);
}
catch (IOException ioe)
{
- throw new ConfigurationException(String.format(CANNOT_LOAD_MSG, file.getName()), ioe);
+ throw new IllegalConfigurationException(String.format(CANNOT_LOAD_MSG, file.getName()), ioe);
}
finally
{
@@ -223,7 +223,7 @@ public class PlainConfiguration extends AbstractConfiguration
}
catch (IOException e)
{
- throw new ConfigurationException(String.format(CANNOT_CLOSE_MSG, file.getName()), e);
+ throw new IllegalConfigurationException(String.format(CANNOT_CLOSE_MSG, file.getName()), e);
}
}
}
@@ -232,11 +232,11 @@ public class PlainConfiguration extends AbstractConfiguration
return ruleSet;
}
- private void parseAcl(Integer number, List<String> args) throws ConfigurationException
+ private void parseAcl(Integer number, List<String> args)
{
if (args.size() < 3)
{
- throw new ConfigurationException(String.format(NOT_ENOUGH_ACL_MSG, getLine()));
+ throw new IllegalConfigurationException(String.format(NOT_ENOUGH_ACL_MSG, getLine()));
}
Permission permission = Permission.parse(args.get(0));
@@ -245,7 +245,7 @@ public class PlainConfiguration extends AbstractConfiguration
if (number != null && !getConfiguration().isValidNumber(number))
{
- throw new ConfigurationException(String.format(BAD_ACL_RULE_NUMBER_MSG, getLine()));
+ throw new IllegalConfigurationException(String.format(BAD_ACL_RULE_NUMBER_MSG, getLine()));
}
if (args.size() == 3)
@@ -261,11 +261,11 @@ public class PlainConfiguration extends AbstractConfiguration
}
}
- private void parseConfig(List<String> args) throws ConfigurationException
+ private void parseConfig(List<String> args)
{
if (args.size() < 3)
{
- throw new ConfigurationException(String.format(NOT_ENOUGH_CONFIG_MSG, getLine()));
+ throw new IllegalConfigurationException(String.format(NOT_ENOUGH_CONFIG_MSG, getLine()));
}
Map<String, Boolean> properties = toPluginProperties(args);
@@ -273,7 +273,7 @@ public class PlainConfiguration extends AbstractConfiguration
getConfiguration().configure(properties);
}
- private AclRulePredicates toRulePredicates(List<String> args) throws ConfigurationException
+ private AclRulePredicates toRulePredicates(List<String> args)
{
AclRulePredicates predicates = new AclRulePredicates();
Iterator<String> i = args.iterator();
@@ -282,15 +282,15 @@ public class PlainConfiguration extends AbstractConfiguration
String key = i.next();
if (!i.hasNext())
{
- throw new ConfigurationException(String.format(PROPERTY_KEY_ONLY_MSG, getLine()));
+ throw new IllegalConfigurationException(String.format(PROPERTY_KEY_ONLY_MSG, getLine()));
}
if (!"=".equals(i.next()))
{
- throw new ConfigurationException(String.format(PROPERTY_NO_EQUALS_MSG, getLine()));
+ throw new IllegalConfigurationException(String.format(PROPERTY_NO_EQUALS_MSG, getLine()));
}
if (!i.hasNext())
{
- throw new ConfigurationException(String.format(PROPERTY_NO_VALUE_MSG, getLine()));
+ throw new IllegalConfigurationException(String.format(PROPERTY_NO_VALUE_MSG, getLine()));
}
String value = i.next();
@@ -300,7 +300,7 @@ public class PlainConfiguration extends AbstractConfiguration
}
/** Converts a {@link List} of "name", "=", "value" tokens into a {@link Map}. */
- protected Map<String, Boolean> toPluginProperties(List<String> args) throws ConfigurationException
+ protected Map<String, Boolean> toPluginProperties(List<String> args)
{
Map<String, Boolean> properties = new HashMap<String, Boolean>();
Iterator<String> i = args.iterator();
@@ -309,15 +309,15 @@ public class PlainConfiguration extends AbstractConfiguration
String key = i.next().toLowerCase();
if (!i.hasNext())
{
- throw new ConfigurationException(String.format(PROPERTY_KEY_ONLY_MSG, getLine()));
+ throw new IllegalConfigurationException(String.format(PROPERTY_KEY_ONLY_MSG, getLine()));
}
if (!"=".equals(i.next()))
{
- throw new ConfigurationException(String.format(PROPERTY_NO_EQUALS_MSG, getLine()));
+ throw new IllegalConfigurationException(String.format(PROPERTY_NO_EQUALS_MSG, getLine()));
}
if (!i.hasNext())
{
- throw new ConfigurationException(String.format(PROPERTY_NO_VALUE_MSG, getLine()));
+ throw new IllegalConfigurationException(String.format(PROPERTY_NO_VALUE_MSG, getLine()));
}
// parse property value and save
diff --git a/qpid/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/plugins/DefaultAccessControl.java b/qpid/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/plugins/DefaultAccessControl.java
index 19b9135ea6..6f7885da94 100644
--- a/qpid/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/plugins/DefaultAccessControl.java
+++ b/qpid/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/plugins/DefaultAccessControl.java
@@ -45,7 +45,7 @@ public class DefaultAccessControl implements AccessControl
private RuleSet _ruleSet;
- public DefaultAccessControl(String fileName) throws ConfigurationException
+ public DefaultAccessControl(String fileName)
{
if (_logger.isDebugEnabled())
{
diff --git a/qpid/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/plugins/DefaultAccessControlFactory.java b/qpid/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/plugins/DefaultAccessControlFactory.java
index 38ea61357e..a3d7823caf 100644
--- a/qpid/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/plugins/DefaultAccessControlFactory.java
+++ b/qpid/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/plugins/DefaultAccessControlFactory.java
@@ -20,28 +20,40 @@
*/
package org.apache.qpid.server.security.access.plugins;
-import org.apache.commons.configuration.Configuration;
-import org.apache.commons.configuration.ConfigurationException;
+import java.io.File;
+import java.util.Map;
+
+import org.apache.qpid.server.configuration.IllegalConfigurationException;
import org.apache.qpid.server.plugin.AccessControlFactory;
import org.apache.qpid.server.security.AccessControl;
public class DefaultAccessControlFactory implements AccessControlFactory
{
- public AccessControl createInstance(Configuration securityConfiguration)
- {
- String aclConfiguration = securityConfiguration.getString("acl");
- if(aclConfiguration == null)
- {
- return null;
- }
+ public static final String ATTRIBUTE_ACL_FILE = "aclFile";
- try
- {
- return new DefaultAccessControl(aclConfiguration);
- }
- catch (ConfigurationException e)
+ public AccessControl createInstance(Map<String, Object> aclConfiguration)
+ {
+ if (aclConfiguration != null)
{
- throw new RuntimeException("caught exception during instance creation", e);
+ Object aclFile = aclConfiguration.get(ATTRIBUTE_ACL_FILE);
+ if (aclFile != null)
+ {
+ if (aclFile instanceof String)
+ {
+ String aclPath = (String) aclFile;
+ if (!new File(aclPath).exists())
+ {
+ throw new IllegalConfigurationException("ACL file '" + aclPath + "' is not found");
+ }
+ return new DefaultAccessControl(aclPath);
+ }
+ else
+ {
+ throw new IllegalConfigurationException("Expected '" + ATTRIBUTE_ACL_FILE + "' attribute value of type String but was " + aclFile.getClass()
+ + ": " + aclFile);
+ }
+ }
}
+ return null;
}
}
diff --git a/qpid/java/broker-plugins/access-control/src/test/java/org/apache/qpid/server/security/access/config/PlainConfigurationTest.java b/qpid/java/broker-plugins/access-control/src/test/java/org/apache/qpid/server/security/access/config/PlainConfigurationTest.java
index 21d8ff4400..cbfc9003c8 100644
--- a/qpid/java/broker-plugins/access-control/src/test/java/org/apache/qpid/server/security/access/config/PlainConfigurationTest.java
+++ b/qpid/java/broker-plugins/access-control/src/test/java/org/apache/qpid/server/security/access/config/PlainConfigurationTest.java
@@ -26,7 +26,7 @@ import java.util.Map;
import junit.framework.TestCase;
-import org.apache.commons.configuration.ConfigurationException;
+import org.apache.qpid.server.configuration.IllegalConfigurationException;
import org.apache.qpid.server.security.access.ObjectProperties;
import org.apache.qpid.server.security.access.ObjectProperties.Property;
import org.apache.qpid.server.security.access.ObjectType;
@@ -73,7 +73,7 @@ public class PlainConfigurationTest extends TestCase
fail("fail");
}
- catch (ConfigurationException ce)
+ catch (IllegalConfigurationException ce)
{
assertEquals(String.format(PlainConfiguration.CONFIG_NOT_FOUND_MSG, "doesnotexist"), ce.getMessage());
assertTrue(ce.getCause() instanceof FileNotFoundException);
@@ -87,7 +87,7 @@ public class PlainConfigurationTest extends TestCase
writeACLConfig("ACL ALLOW ALL \\ ALL");
fail("fail");
}
- catch (ConfigurationException ce)
+ catch (IllegalConfigurationException ce)
{
assertEquals(String.format(PlainConfiguration.PREMATURE_CONTINUATION_MSG, 1), ce.getMessage());
}
@@ -100,7 +100,7 @@ public class PlainConfigurationTest extends TestCase
writeACLConfig("ACL unparsed ALL ALL");
fail("fail");
}
- catch (ConfigurationException ce)
+ catch (IllegalConfigurationException ce)
{
assertEquals(String.format(PlainConfiguration.PARSE_TOKEN_FAILED_MSG, 1), ce.getMessage());
assertTrue(ce.getCause() instanceof IllegalArgumentException);
@@ -115,7 +115,7 @@ public class PlainConfigurationTest extends TestCase
writeACLConfig("ACL ALLOW");
fail("fail");
}
- catch (ConfigurationException ce)
+ catch (IllegalConfigurationException ce)
{
assertEquals(String.format(PlainConfiguration.NOT_ENOUGH_ACL_MSG, 1), ce.getMessage());
}
@@ -128,7 +128,7 @@ public class PlainConfigurationTest extends TestCase
writeACLConfig("CONFIG");
fail("fail");
}
- catch (ConfigurationException ce)
+ catch (IllegalConfigurationException ce)
{
assertEquals(String.format(PlainConfiguration.NOT_ENOUGH_TOKENS_MSG, 1), ce.getMessage());
}
@@ -141,7 +141,7 @@ public class PlainConfigurationTest extends TestCase
writeACLConfig("INVALID");
fail("fail");
}
- catch (ConfigurationException ce)
+ catch (IllegalConfigurationException ce)
{
assertEquals(String.format(PlainConfiguration.NOT_ENOUGH_TOKENS_MSG, 1), ce.getMessage());
}
@@ -154,7 +154,7 @@ public class PlainConfigurationTest extends TestCase
writeACLConfig("ACL ALLOW adk CREATE QUEUE name");
fail("fail");
}
- catch (ConfigurationException ce)
+ catch (IllegalConfigurationException ce)
{
assertEquals(String.format(PlainConfiguration.PROPERTY_KEY_ONLY_MSG, 1), ce.getMessage());
}
@@ -167,7 +167,7 @@ public class PlainConfigurationTest extends TestCase
writeACLConfig("ACL ALLOW adk CREATE QUEUE name test");
fail("fail");
}
- catch (ConfigurationException ce)
+ catch (IllegalConfigurationException ce)
{
assertEquals(String.format(PlainConfiguration.PROPERTY_NO_EQUALS_MSG, 1), ce.getMessage());
}
@@ -180,7 +180,7 @@ public class PlainConfigurationTest extends TestCase
writeACLConfig("ACL ALLOW adk CREATE QUEUE name =");
fail("fail");
}
- catch (ConfigurationException ce)
+ catch (IllegalConfigurationException ce)
{
assertEquals(String.format(PlainConfiguration.PROPERTY_NO_VALUE_MSG, 1), ce.getMessage());
}
@@ -432,7 +432,7 @@ public class PlainConfigurationTest extends TestCase
writeACLConfig("GROUP group1 bob alice");
fail("Expected exception not thrown");
}
- catch(ConfigurationException e)
+ catch(IllegalConfigurationException e)
{
assertTrue(e.getMessage().contains("GROUP keyword not supported"));
}
diff --git a/qpid/java/broker-plugins/access-control/src/test/java/org/apache/qpid/server/security/access/plugins/DefaultAccessControlFactoryTest.java b/qpid/java/broker-plugins/access-control/src/test/java/org/apache/qpid/server/security/access/plugins/DefaultAccessControlFactoryTest.java
new file mode 100644
index 0000000000..ca1f19098f
--- /dev/null
+++ b/qpid/java/broker-plugins/access-control/src/test/java/org/apache/qpid/server/security/access/plugins/DefaultAccessControlFactoryTest.java
@@ -0,0 +1,69 @@
+package org.apache.qpid.server.security.access.plugins;
+
+import java.io.File;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.regex.Pattern;
+
+import org.apache.qpid.server.configuration.IllegalConfigurationException;
+import org.apache.qpid.server.security.AccessControl;
+import org.apache.qpid.test.utils.QpidTestCase;
+import org.apache.qpid.test.utils.TestFileUtils;
+
+public class DefaultAccessControlFactoryTest extends QpidTestCase
+{
+ public void testCreateInstanceWhenAclFileIsNotPresent()
+ {
+ DefaultAccessControlFactory factory = new DefaultAccessControlFactory();
+ Map<String, Object> attributes = new HashMap<String, Object>();
+ AccessControl acl = factory.createInstance(attributes);
+ assertNull("ACL was created without a configuration file", acl);
+ }
+
+ public void testCreateInstanceWhenAclFileIsSpecified()
+ {
+ File aclFile = TestFileUtils.createTempFile(this, ".acl", "ACL ALLOW all all");
+ DefaultAccessControlFactory factory = new DefaultAccessControlFactory();
+ Map<String, Object> attributes = new HashMap<String, Object>();
+ attributes.put(DefaultAccessControlFactory.ATTRIBUTE_ACL_FILE, aclFile.getAbsolutePath());
+ AccessControl acl = factory.createInstance(attributes);
+
+ assertNotNull("ACL was not created from acl file: " + aclFile.getAbsolutePath(), acl);
+ }
+
+ public void testCreateInstanceWhenAclFileIsSpecifiedButDoesNotExist()
+ {
+ File aclFile = new File(TMP_FOLDER, "my-non-existing-acl-" + System.currentTimeMillis());
+ assertFalse("ACL file " + aclFile.getAbsolutePath() + " actually exists but should not", aclFile.exists());
+ DefaultAccessControlFactory factory = new DefaultAccessControlFactory();
+ Map<String, Object> attributes = new HashMap<String, Object>();
+ attributes.put(DefaultAccessControlFactory.ATTRIBUTE_ACL_FILE, aclFile.getAbsolutePath());
+ try
+ {
+ factory.createInstance(attributes);
+ fail("It should not be possible to create ACL from non existing file");
+ }
+ catch (IllegalConfigurationException e)
+ {
+ assertTrue("Unexpected exception message", Pattern.matches("ACL file '.*' is not found", e.getMessage()));
+ }
+ }
+
+ public void testCreateInstanceWhenAclFileIsSpecifiedAsNonString()
+ {
+ DefaultAccessControlFactory factory = new DefaultAccessControlFactory();
+ Map<String, Object> attributes = new HashMap<String, Object>();
+ Integer aclFile = new Integer(0);
+ attributes.put(DefaultAccessControlFactory.ATTRIBUTE_ACL_FILE, aclFile);
+ try
+ {
+ factory.createInstance(attributes);
+ fail("It should not be possible to create ACL from Integer");
+ }
+ catch (IllegalConfigurationException e)
+ {
+ assertEquals("Unexpected exception message", "Expected '" + DefaultAccessControlFactory.ATTRIBUTE_ACL_FILE
+ + "' attribute value of type String but was " + Integer.class + ": " + aclFile, e.getMessage());
+ }
+ }
+}
diff --git a/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/HttpManagement.java b/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/HttpManagement.java
index f10b308e24..59dbc6e530 100644
--- a/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/HttpManagement.java
+++ b/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/HttpManagement.java
@@ -21,15 +21,20 @@
package org.apache.qpid.server.management.plugin;
import java.io.File;
-import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.UUID;
-import org.apache.commons.configuration.ConfigurationException;
import org.apache.log4j.Logger;
+import org.apache.qpid.server.configuration.IllegalConfigurationException;
import org.apache.qpid.server.logging.actors.CurrentActor;
import org.apache.qpid.server.logging.messages.ManagementConsoleMessages;
import org.apache.qpid.server.management.plugin.servlet.DefinedFileServlet;
import org.apache.qpid.server.management.plugin.servlet.FileServlet;
+import org.apache.qpid.server.management.plugin.servlet.rest.AbstractServlet;
import org.apache.qpid.server.management.plugin.servlet.rest.LogRecordsServlet;
import org.apache.qpid.server.management.plugin.servlet.rest.LogoutServlet;
import org.apache.qpid.server.management.plugin.servlet.rest.MessageContentServlet;
@@ -46,13 +51,18 @@ import org.apache.qpid.server.model.Exchange;
import org.apache.qpid.server.model.Group;
import org.apache.qpid.server.model.GroupMember;
import org.apache.qpid.server.model.GroupProvider;
+import org.apache.qpid.server.model.KeyStore;
+import org.apache.qpid.server.model.Plugin;
import org.apache.qpid.server.model.Port;
import org.apache.qpid.server.model.Protocol;
import org.apache.qpid.server.model.Queue;
import org.apache.qpid.server.model.Session;
-import org.apache.qpid.server.model.Transport;
+import org.apache.qpid.server.model.State;
import org.apache.qpid.server.model.User;
import org.apache.qpid.server.model.VirtualHost;
+import org.apache.qpid.server.model.adapter.AbstractPluginAdapter;
+import org.apache.qpid.server.plugin.PluginFactory;
+import org.apache.qpid.server.util.MapValueConverter;
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.SessionManager;
@@ -62,98 +72,186 @@ import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.eclipse.jetty.util.ssl.SslContextFactory;
-public class HttpManagement implements ManagementPlugin
+public class HttpManagement extends AbstractPluginAdapter
{
private final Logger _logger = Logger.getLogger(HttpManagement.class);
+ // 10 minutes by default
+ public static final int DEFAULT_TIMEOUT_IN_SECONDS = 60 * 10;
+ public static final boolean DEFAULT_HTTP_BASIC_AUTHENTICATION_ENABLED = false;
+ public static final boolean DEFAULT_HTTPS_BASIC_AUTHENTICATION_ENABLED = true;
+ public static final boolean DEFAULT_HTTP_SASL_AUTHENTICATION_ENABLED = true;
+ public static final boolean DEFAULT_HTTPS_SASL_AUTHENTICATION_ENABLED = true;
+ public static final String DEFAULT_NAME = "httpManagement";
+
+ public static final String TIME_OUT = "sessionTimeout";
+ public static final String HTTP_BASIC_AUTHENTICATION_ENABLED = "httpBasicAuthenticationEnabled";
+ public static final String HTTPS_BASIC_AUTHENTICATION_ENABLED = "httpsBasicAuthenticationEnabled";
+ public static final String HTTP_SASL_AUTHENTICATION_ENABLED = "httpSaslAuthenticationEnabled";
+ public static final String HTTPS_SASL_AUTHENTICATION_ENABLED = "httpsSaslAuthenticationEnabled";
+
+ public static final String PLUGIN_TYPE = "MANAGEMENT-HTTP";
+
+ @SuppressWarnings("serial")
+ private static final Collection<String> AVAILABLE_ATTRIBUTES = Collections.unmodifiableSet(new HashSet<String>(Plugin.AVAILABLE_ATTRIBUTES)
+ {{
+ add(HTTP_BASIC_AUTHENTICATION_ENABLED);
+ add(HTTPS_BASIC_AUTHENTICATION_ENABLED);
+ add(HTTP_SASL_AUTHENTICATION_ENABLED);
+ add(HTTPS_SASL_AUTHENTICATION_ENABLED);
+ add(TIME_OUT);
+ add(PluginFactory.PLUGIN_TYPE);
+ }});
+
public static final String ENTRY_POINT_PATH = "/management";
private static final String OPERATIONAL_LOGGING_NAME = "Web";
- private final Broker _broker;
- private final Collection<Server> _servers = new ArrayList<Server>();
+ @SuppressWarnings("serial")
+ public static final Map<String, Object> DEFAULTS = Collections.unmodifiableMap(new HashMap<String, Object>()
+ {{
+ put(HTTP_BASIC_AUTHENTICATION_ENABLED, DEFAULT_HTTP_BASIC_AUTHENTICATION_ENABLED);
+ put(HTTPS_BASIC_AUTHENTICATION_ENABLED, DEFAULT_HTTPS_BASIC_AUTHENTICATION_ENABLED);
+ put(HTTP_SASL_AUTHENTICATION_ENABLED, DEFAULT_HTTP_SASL_AUTHENTICATION_ENABLED);
+ put(HTTPS_SASL_AUTHENTICATION_ENABLED, DEFAULT_HTTPS_SASL_AUTHENTICATION_ENABLED);
+ put(TIME_OUT, DEFAULT_TIMEOUT_IN_SECONDS);
+ put(NAME, DEFAULT_NAME);
+ }});
+
+ @SuppressWarnings("serial")
+ private static final Map<String, Class<?>> ATTRIBUTE_TYPES = Collections.unmodifiableMap(new HashMap<String, Class<?>>(){{
+ put(HTTP_BASIC_AUTHENTICATION_ENABLED, Boolean.class);
+ put(HTTPS_BASIC_AUTHENTICATION_ENABLED, Boolean.class);
+ put(HTTP_SASL_AUTHENTICATION_ENABLED, Boolean.class);
+ put(HTTPS_SASL_AUTHENTICATION_ENABLED, Boolean.class);
+ put(NAME, String.class);
+ put(TIME_OUT, Integer.class);
+ put(PluginFactory.PLUGIN_TYPE, String.class);
+ }});
+
+ private final Broker _broker;
- private final String _keyStorePassword;
- private final String _keyStorePath;
- private final int _sessionTimeout;
+ private Server _server;
- public HttpManagement(Broker broker, String keyStorePath, String keyStorePassword, int sessionTimeout) throws ConfigurationException
+ public HttpManagement(UUID id, Broker broker, Map<String, Object> attributes)
{
+ super(id, DEFAULTS, MapValueConverter.convert(attributes, ATTRIBUTE_TYPES), broker.getTaskExecutor());
_broker = broker;
- _keyStorePassword = keyStorePassword;
- _keyStorePath = keyStorePath;
- _sessionTimeout = sessionTimeout;
+ addParent(Broker.class, broker);
+ }
- Collection<Port> ports = broker.getPorts();
- int httpPort = -1, httpsPort = -1;
- for (Port port : ports)
+ @Override
+ protected boolean setState(State currentState, State desiredState)
+ {
+ if(desiredState == State.ACTIVE)
{
- if (port.getProtocols().contains(Protocol.HTTP))
- {
- if (port.getTransports().contains(Transport.TCP))
- {
- httpPort = port.getPort();
- }
- }
- if (port.getProtocols().contains(Protocol.HTTPS))
- {
- if (port.getTransports().contains(Transport.SSL))
- {
- httpsPort = port.getPort();
- }
- }
+ start();
+ return true;
+ }
+ else if(desiredState == State.STOPPED)
+ {
+ stop();
+ return true;
}
+ return false;
+ }
+
+ private void start()
+ {
+ CurrentActor.get().message(ManagementConsoleMessages.STARTUP(OPERATIONAL_LOGGING_NAME));
- if (httpPort != -1 || httpsPort != -1)
+ Collection<Port> httpPorts = getHttpPorts(_broker.getPorts());
+ _server = createServer(httpPorts);
+ try
{
- _servers.add(createServer(httpPort, httpsPort));
- if (_logger.isDebugEnabled())
- {
- _logger.debug(_servers.size() + " server(s) defined");
- }
+ _server.start();
+ logOperationalListenMessages(_server);
}
- else
+ catch (Exception e)
{
- if (_logger.isInfoEnabled())
+ throw new RuntimeException("Failed to start http management on ports " + httpPorts);
+ }
+
+ CurrentActor.get().message(ManagementConsoleMessages.READY(OPERATIONAL_LOGGING_NAME));
+ }
+
+ private void stop()
+ {
+ if (_server != null)
+ {
+ try
{
- _logger.info("Cannot create web server as neither HTTP nor HTTPS port specified");
+ _server.stop();
+ logOperationalShutdownMessage(_server);
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Failed to stop http management on port " + getHttpPorts(_broker.getPorts()));
}
}
+
+ CurrentActor.get().message(ManagementConsoleMessages.STOPPED(OPERATIONAL_LOGGING_NAME));
+ }
+
+ /** Added for testing purposes */
+ Broker getBroker()
+ {
+ return _broker;
+ }
+
+ /** Added for testing purposes */
+ int getSessionTimeout()
+ {
+ return (Integer)getAttribute(TIME_OUT);
+ }
+
+ private boolean isManagementHttp(Port port)
+ {
+ return port.getProtocols().contains(Protocol.HTTP) || port.getProtocols().contains(Protocol.HTTPS);
}
@SuppressWarnings("unchecked")
- private Server createServer(int port, int sslPort) throws ConfigurationException
+ private Server createServer(Collection<Port> ports)
{
if (_logger.isInfoEnabled())
{
- _logger.info("Starting up web server on" + (port == -1 ? "" : " HTTP port " + port)
- + (sslPort == -1 ? "" : " HTTPS port " + sslPort));
+ _logger.info("Starting up web server on " + ports);
}
Server server = new Server();
-
- if (port != -1)
+ for (Port port : ports)
{
- SelectChannelConnector connector = new SelectChannelConnector();
- connector.setPort(port);
- if (sslPort != -1)
+ final Collection<Protocol> protocols = port.getProtocols();
+ Connector connector = null;
+
+ //TODO: what to do if protocol HTTP and transport SSL?
+ if (protocols.contains(Protocol.HTTP))
{
- connector.setConfidentialPort(sslPort);
+ connector = new SelectChannelConnector();
}
- server.addConnector(connector);
- }
-
- if (sslPort != -1)
- {
- checkKeyStorePath(_keyStorePath);
+ else if (protocols.contains(Protocol.HTTPS))
+ {
+ KeyStore keyStore = _broker.getDefaultKeyStore();
+ if (keyStore == null)
+ {
+ throw new IllegalConfigurationException("Key store is not configured. Cannot start management on HTTPS port without keystore");
+ }
+ String keyStorePath = (String)keyStore.getAttribute(KeyStore.PATH);
+ String keyStorePassword = keyStore.getPassword();
+ validateKeystoreParameters(keyStorePath, keyStorePassword);
- SslContextFactory factory = new SslContextFactory();
- factory.setKeyStorePath(_keyStorePath);
- factory.setKeyStorePassword(_keyStorePassword);
+ SslContextFactory factory = new SslContextFactory();
+ factory.setKeyStorePath(keyStorePath);
+ factory.setKeyStorePassword(keyStorePassword);
- SslSocketConnector connector = new SslSocketConnector(factory);
- connector.setPort(sslPort);
+ connector = new SslSocketConnector(factory);
+ }
+ else
+ {
+ throw new IllegalArgumentException("Unexpected protocol " + protocols);
+ }
+ connector.setPort(port.getPort());
server.addConnector(connector);
}
@@ -161,6 +259,10 @@ public class HttpManagement implements ManagementPlugin
root.setContextPath("/");
server.setHandler(root);
+ // set servlet context attributes for broker and configuration
+ root.getServletContext().setAttribute(AbstractServlet.ATTR_BROKER, _broker);
+ root.getServletContext().setAttribute(AbstractServlet.ATTR_MANAGEMENT, this);
+
addRestServlet(root, "broker");
addRestServlet(root, "virtualhost", VirtualHost.class);
addRestServlet(root, "authenticationprovider", AuthenticationProvider.class);
@@ -175,13 +277,13 @@ public class HttpManagement implements ManagementPlugin
addRestServlet(root, "port", Port.class);
addRestServlet(root, "session", VirtualHost.class, Connection.class, Session.class);
- root.addServlet(new ServletHolder(new StructureServlet(_broker)), "/rest/structure");
- root.addServlet(new ServletHolder(new MessageServlet(_broker)), "/rest/message/*");
- root.addServlet(new ServletHolder(new MessageContentServlet(_broker)), "/rest/message-content/*");
+ root.addServlet(new ServletHolder(new StructureServlet()), "/rest/structure");
+ root.addServlet(new ServletHolder(new MessageServlet()), "/rest/message/*");
+ root.addServlet(new ServletHolder(new MessageContentServlet()), "/rest/message-content/*");
- root.addServlet(new ServletHolder(new LogRecordsServlet(_broker)), "/rest/logrecords");
+ root.addServlet(new ServletHolder(new LogRecordsServlet()), "/rest/logrecords");
- root.addServlet(new ServletHolder(new SaslServlet(_broker)), "/rest/sasl");
+ root.addServlet(new ServletHolder(new SaslServlet()), "/rest/sasl");
root.addServlet(new ServletHolder(new DefinedFileServlet("index.html")), ENTRY_POINT_PATH);
root.addServlet(new ServletHolder(new LogoutServlet()), "/logout");
@@ -199,61 +301,34 @@ public class HttpManagement implements ManagementPlugin
final SessionManager sessionManager = root.getSessionHandler().getSessionManager();
- sessionManager.setMaxInactiveInterval(_sessionTimeout);
+ sessionManager.setMaxInactiveInterval((Integer)getAttribute(TIME_OUT));
return server;
}
private void addRestServlet(ServletContextHandler root, String name, Class<? extends ConfiguredObject>... hierarchy)
{
- root.addServlet(new ServletHolder(new RestServlet(_broker, hierarchy)), "/rest/" + name + "/*");
+ root.addServlet(new ServletHolder(new RestServlet(hierarchy)), "/rest/" + name + "/*");
}
- @Override
- public void start() throws Exception
+ private void validateKeystoreParameters(String keyStorePath, String password)
{
- CurrentActor.get().message(ManagementConsoleMessages.STARTUP(OPERATIONAL_LOGGING_NAME));
-
- for (Server server : _servers)
+ if (keyStorePath == null)
{
- server.start();
-
- logOperationalListenMessages(server);
+ throw new RuntimeException("Management SSL keystore path not defined, unable to start SSL protected HTTP connector");
}
-
- CurrentActor.get().message(ManagementConsoleMessages.READY(OPERATIONAL_LOGGING_NAME));
- }
-
- @Override
- public void stop() throws Exception
- {
- for (Server server : _servers)
+ if (password == null)
{
- logOperationalShutdownMessage(server);
-
- server.stop();
+ throw new RuntimeException("Management SSL keystore password, unable to start SSL protected HTTP connector");
}
-
- CurrentActor.get().message(ManagementConsoleMessages.STOPPED(OPERATIONAL_LOGGING_NAME));
- }
-
- private void checkKeyStorePath(String keyStorePath) throws ConfigurationException
- {
- if (keyStorePath == null)
+ File ksf = new File(keyStorePath);
+ if (!ksf.exists())
{
- throw new ConfigurationException("Management SSL keystore path not defined, unable to start SSL protected HTTP connector");
+ throw new RuntimeException("Cannot find management SSL keystore file: " + ksf);
}
- else
+ if (!ksf.canRead())
{
- File ksf = new File(keyStorePath);
- if (!ksf.exists())
- {
- throw new ConfigurationException("Cannot find management SSL keystore file: " + ksf);
- }
- if (!ksf.canRead())
- {
- throw new ConfigurationException("Cannot read management SSL keystore file: " + ksf + ". Check permissions.");
- }
+ throw new RuntimeException("Cannot read management SSL keystore file: " + ksf + ". Check permissions.");
}
}
@@ -288,27 +363,50 @@ public class HttpManagement implements ManagementPlugin
return connector instanceof SslSocketConnector ? "HTTPS" : "HTTP";
}
- /** Added for testing purposes */
- Broker getBroker()
+ private Collection<Port> getHttpPorts(Collection<Port> ports)
{
- return _broker;
+ Collection<Port> httpPorts = new HashSet<Port>();
+ for (Port port : ports)
+ {
+ if (isManagementHttp(port))
+ {
+ httpPorts.add(port);
+ }
+ }
+ return httpPorts;
}
- /** Added for testing purposes */
- String getKeyStorePassword()
+
+ @Override
+ public String getName()
{
- return _keyStorePassword;
+ return (String)getAttribute(NAME);
}
- /** Added for testing purposes */
- String getKeyStorePath()
+ @Override
+ public Collection<String> getAttributeNames()
{
- return _keyStorePath;
+ return Collections.unmodifiableCollection(AVAILABLE_ATTRIBUTES);
}
- /** Added for testing purposes */
- int getSessionTimeout()
+ public boolean isHttpsSaslAuthenticationEnabled()
{
- return _sessionTimeout;
+ return (Boolean)getAttribute(HTTPS_SASL_AUTHENTICATION_ENABLED);
}
+
+ public boolean isHttpSaslAuthenticationEnabled()
+ {
+ return (Boolean)getAttribute(HTTP_SASL_AUTHENTICATION_ENABLED);
+ }
+
+ public boolean isHttpsBasicAuthenticationEnabled()
+ {
+ return (Boolean)getAttribute(HTTPS_BASIC_AUTHENTICATION_ENABLED);
+ }
+
+ public boolean isHttpBasicAuthenticationEnabled()
+ {
+ return (Boolean)getAttribute(HTTP_BASIC_AUTHENTICATION_ENABLED);
+ }
+
}
diff --git a/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/HttpManagementFactory.java b/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/HttpManagementFactory.java
index 452d52d598..ccf5373234 100644
--- a/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/HttpManagementFactory.java
+++ b/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/HttpManagementFactory.java
@@ -18,37 +18,24 @@
*/
package org.apache.qpid.server.management.plugin;
-import org.apache.commons.configuration.ConfigurationException;
-import org.apache.log4j.Logger;
-import org.apache.qpid.server.configuration.ServerConfiguration;
+import java.util.Map;
+import java.util.UUID;
+
import org.apache.qpid.server.model.Broker;
-import org.apache.qpid.server.plugin.ManagementFactory;
+import org.apache.qpid.server.model.Plugin;
+import org.apache.qpid.server.plugin.PluginFactory;
-public class HttpManagementFactory implements ManagementFactory
+public class HttpManagementFactory implements PluginFactory
{
- private static final Logger LOGGER = Logger.getLogger(HttpManagementFactory.class);
@Override
- public HttpManagement createInstance(ServerConfiguration configuration, Broker broker)
+ public Plugin createInstance(UUID id, Map<String, Object> attributes, Broker broker)
{
-
- if (!configuration.getHTTPManagementEnabled() && !configuration.getHTTPSManagementEnabled())
+ if (!HttpManagement.PLUGIN_TYPE.equals(attributes.get(PLUGIN_TYPE)))
{
- LOGGER.info("HttpManagement is disabled");
return null;
}
- try
- {
- return new HttpManagement(
- broker,
- configuration.getManagementKeyStorePath(),
- configuration.getManagementKeyStorePassword(),
- configuration.getHTTPManagementSessionTimeout());
- }
- catch (ConfigurationException e)
- {
- throw new RuntimeException(e);
- }
+ return new HttpManagement(id, broker, attributes);
}
}
diff --git a/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/AbstractServlet.java b/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/AbstractServlet.java
index 2d15b8a1d9..689bdb50d8 100644
--- a/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/AbstractServlet.java
+++ b/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/AbstractServlet.java
@@ -28,6 +28,8 @@ import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import javax.security.auth.Subject;
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
@@ -40,9 +42,9 @@ import org.apache.qpid.server.logging.LogActor;
import org.apache.qpid.server.logging.RootMessageLogger;
import org.apache.qpid.server.logging.actors.CurrentActor;
import org.apache.qpid.server.logging.actors.HttpManagementActor;
+import org.apache.qpid.server.management.plugin.HttpManagement;
import org.apache.qpid.server.management.plugin.session.LoginLogoutReporter;
import org.apache.qpid.server.model.Broker;
-import org.apache.qpid.server.registry.ApplicationRegistry;
import org.apache.qpid.server.security.SecurityManager;
import org.apache.qpid.server.security.SubjectCreator;
import org.apache.qpid.server.security.auth.AuthenticationResult.AuthenticationStatus;
@@ -53,25 +55,38 @@ public abstract class AbstractServlet extends HttpServlet
{
private static final Logger LOGGER = Logger.getLogger(AbstractServlet.class);
+ /**
+ * Servlet context attribute holding a reference to a broker instance
+ */
+ public static final String ATTR_BROKER = "Qpid.broker";
+
+ /**
+ * Servlet context attribute holding a reference to plugin configuration
+ */
+ public static final String ATTR_MANAGEMENT = "Qpid.management";
+
private static final String ATTR_LOGIN_LOGOUT_REPORTER = "AbstractServlet.loginLogoutReporter";
private static final String ATTR_SUBJECT = "AbstractServlet.subject";
private static final String ATTR_LOG_ACTOR = "AbstractServlet.logActor";
- private final Broker _broker;
-
+ private Broker _broker;
private RootMessageLogger _rootLogger;
+ private HttpManagement _httpManagement;
protected AbstractServlet()
{
super();
- _broker = ApplicationRegistry.getInstance().getBroker();
- _rootLogger = ApplicationRegistry.getInstance().getRootMessageLogger();
}
- protected AbstractServlet(Broker broker)
+ @Override
+ public void init() throws ServletException
{
- _broker = broker;
- _rootLogger = ApplicationRegistry.getInstance().getRootMessageLogger();
+ ServletConfig servletConfig = getServletConfig();
+ ServletContext servletContext = servletConfig.getServletContext();
+ _broker = (Broker)servletContext.getAttribute(ATTR_BROKER);
+ _rootLogger = _broker.getRootMessageLogger();
+ _httpManagement = (HttpManagement)servletContext.getAttribute(ATTR_MANAGEMENT);
+ super.init();
}
@Override
@@ -263,7 +278,7 @@ public abstract class AbstractServlet extends HttpServlet
return subject;
}
- SubjectCreator subjectCreator = ApplicationRegistry.getInstance().getSubjectCreator(getSocketAddress(request));
+ SubjectCreator subjectCreator = getSubjectCreator(request);
subject = authenticate(request, subjectCreator);
if (subject != null)
{
@@ -293,7 +308,7 @@ public abstract class AbstractServlet extends HttpServlet
@Override
public Void run() throws Exception
{
- boolean allowed = ApplicationRegistry.getInstance().getSecurityManager().accessManagement();
+ boolean allowed = getSecurityManager().accessManagement();
if (!allowed)
{
throw new AccessControlException("User is not authorised for management");
@@ -382,8 +397,8 @@ public abstract class AbstractServlet extends HttpServlet
private boolean isBasicAuthSupported(HttpServletRequest req)
{
- return req.isSecure() ? ApplicationRegistry.getInstance().getConfiguration().getHTTPSManagementBasicAuth()
- : ApplicationRegistry.getInstance().getConfiguration().getHTTPManagementBasicAuth();
+ return req.isSecure() ? _httpManagement.isHttpsBasicAuthenticationEnabled()
+ : _httpManagement.isHttpBasicAuthenticationEnabled();
}
private HttpManagementActor getLogActorAndCacheInSession(HttpServletRequest req)
@@ -441,5 +456,18 @@ public abstract class AbstractServlet extends HttpServlet
return new HttpManagementActor(_rootLogger, request.getRemoteAddr(), request.getRemotePort());
}
+ protected HttpManagement getManagement()
+ {
+ return _httpManagement;
+ }
+ protected SecurityManager getSecurityManager()
+ {
+ return _broker.getSecurityManager();
+ }
+
+ protected SubjectCreator getSubjectCreator(HttpServletRequest request)
+ {
+ return _broker.getSubjectCreator(getSocketAddress(request));
+ }
}
diff --git a/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/LogRecordsServlet.java b/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/LogRecordsServlet.java
index 04eda2a787..f2cf5d7734 100644
--- a/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/LogRecordsServlet.java
+++ b/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/LogRecordsServlet.java
@@ -26,8 +26,6 @@ import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.qpid.server.logging.LogRecorder;
-import org.apache.qpid.server.model.Broker;
-import org.apache.qpid.server.registry.ApplicationRegistry;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.map.SerializationConfig;
@@ -35,12 +33,7 @@ public class LogRecordsServlet extends AbstractServlet
{
public LogRecordsServlet()
{
- super(ApplicationRegistry.getInstance().getBroker());
- }
-
- public LogRecordsServlet(Broker broker)
- {
- super(broker);
+ super();
}
@Override
@@ -53,10 +46,10 @@ public class LogRecordsServlet extends AbstractServlet
response.setHeader("Pragma","no-cache");
response.setDateHeader ("Expires", 0);
- ApplicationRegistry applicationRegistry = (ApplicationRegistry) ApplicationRegistry.getInstance();
List<Map<String,Object>> logRecords = new ArrayList<Map<String, Object>>();
- for(LogRecorder.Record record : applicationRegistry.getLogRecorder())
+ LogRecorder logRecorder = getBroker().getLogRecorder();
+ for(LogRecorder.Record record : logRecorder)
{
logRecords.add(logRecordToObject(record));
}
diff --git a/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/MessageContentServlet.java b/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/MessageContentServlet.java
index ae794472bf..d61c48bb2c 100644
--- a/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/MessageContentServlet.java
+++ b/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/MessageContentServlet.java
@@ -29,7 +29,6 @@ import javax.servlet.http.HttpServletResponse;
import org.apache.qpid.server.message.MessageReference;
import org.apache.qpid.server.message.ServerMessage;
-import org.apache.qpid.server.model.Broker;
import org.apache.qpid.server.model.Queue;
import org.apache.qpid.server.model.VirtualHost;
import org.apache.qpid.server.queue.QueueEntry;
@@ -42,11 +41,6 @@ public class MessageContentServlet extends AbstractServlet
super();
}
- public MessageContentServlet(Broker broker)
- {
- super(broker);
- }
-
@Override
protected void doGetWithSubjectAndActor(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
diff --git a/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/MessageServlet.java b/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/MessageServlet.java
index 4bbb43be70..49e0c2b1bf 100644
--- a/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/MessageServlet.java
+++ b/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/MessageServlet.java
@@ -34,13 +34,10 @@ import org.apache.log4j.Logger;
import org.apache.qpid.server.message.AMQMessageHeader;
import org.apache.qpid.server.message.MessageReference;
import org.apache.qpid.server.message.ServerMessage;
-import org.apache.qpid.server.model.Broker;
import org.apache.qpid.server.model.Queue;
import org.apache.qpid.server.model.VirtualHost;
import org.apache.qpid.server.queue.QueueEntry;
import org.apache.qpid.server.queue.QueueEntryVisitor;
-import org.apache.qpid.server.registry.ApplicationRegistry;
-import org.apache.qpid.server.registry.IApplicationRegistry;
import org.apache.qpid.server.security.SecurityManager;
import org.apache.qpid.server.security.access.Operation;
import org.apache.qpid.server.subscription.Subscription;
@@ -56,11 +53,6 @@ public class MessageServlet extends AbstractServlet
super();
}
- public MessageServlet(Broker broker)
- {
- super(broker);
- }
-
@Override
protected void doGetWithSubjectAndActor(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
@@ -422,7 +414,7 @@ public class MessageServlet extends AbstractServlet
// FIXME: added temporary authorization check until we introduce management layer
// and review current ACL rules to have common rules for all management interfaces
String methodName = isMoveTransaction? "moveMessages":"copyMessages";
- if (isQueueUpdateMethodAuthorized(methodName, vhost.getName()))
+ if (isQueueUpdateMethodAuthorized(methodName, vhost))
{
final Queue destinationQueue = getQueueFromVirtualHost(destQueueName, vhost);
final List messageIds = new ArrayList((List) providedObject.get("messages"));
@@ -466,7 +458,7 @@ public class MessageServlet extends AbstractServlet
// FIXME: added temporary authorization check until we introduce management layer
// and review current ACL rules to have common rules for all management interfaces
- if (isQueueUpdateMethodAuthorized("deleteMessages", vhost.getName()))
+ if (isQueueUpdateMethodAuthorized("deleteMessages", vhost))
{
vhost.executeTransaction(new DeleteTransaction(sourceQueue, messageIds));
response.setStatus(HttpServletResponse.SC_OK);
@@ -478,25 +470,10 @@ public class MessageServlet extends AbstractServlet
}
- private boolean isQueueUpdateMethodAuthorized(String methodName, String virtualHost)
+ private boolean isQueueUpdateMethodAuthorized(String methodName, VirtualHost host)
{
- SecurityManager securityManager = getSecurityManager(virtualHost);
+ SecurityManager securityManager = host.getSecurityManager();
return securityManager.authoriseMethod(Operation.UPDATE, "VirtualHost.Queue", methodName);
}
- private SecurityManager getSecurityManager(String virtualHost)
- {
- IApplicationRegistry appRegistry = ApplicationRegistry.getInstance();
- SecurityManager security;
- if (virtualHost == null)
- {
- security = appRegistry.getSecurityManager();
- }
- else
- {
- security = appRegistry.getVirtualHostRegistry().getVirtualHost(virtualHost).getSecurityManager();
- }
- return security;
- }
-
}
diff --git a/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/RestServlet.java b/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/RestServlet.java
index 203fa66ff9..3fab26cde5 100644
--- a/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/RestServlet.java
+++ b/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/RestServlet.java
@@ -47,29 +47,29 @@ public class RestServlet extends AbstractServlet
private Class<? extends ConfiguredObject>[] _hierarchy;
- private volatile boolean initializationRequired = false;
-
private final ConfiguredObjectToMapConverter _objectConverter = new ConfiguredObjectToMapConverter();
+ private final boolean _hierarchyInitializationRequired;
public RestServlet()
{
super();
- initializationRequired = true;
+ _hierarchyInitializationRequired = true;
}
- public RestServlet(Broker broker, Class<? extends ConfiguredObject>... hierarchy)
+ public RestServlet(Class<? extends ConfiguredObject>... hierarchy)
{
- super(broker);
+ super();
_hierarchy = hierarchy;
+ _hierarchyInitializationRequired = false;
}
@Override
public void init() throws ServletException
{
- if (initializationRequired)
+ super.init();
+ if (_hierarchyInitializationRequired)
{
doInitialization();
- initializationRequired = false;
}
}
diff --git a/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/SaslServlet.java b/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/SaslServlet.java
index f8c8b52023..069132af1e 100644
--- a/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/SaslServlet.java
+++ b/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/SaslServlet.java
@@ -25,8 +25,7 @@ import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.map.SerializationConfig;
import org.apache.log4j.Logger;
-import org.apache.qpid.server.model.Broker;
-import org.apache.qpid.server.registry.ApplicationRegistry;
+import org.apache.qpid.server.management.plugin.HttpManagement;
import org.apache.qpid.server.security.SubjectCreator;
import org.apache.qpid.server.security.auth.AuthenticatedPrincipal;
@@ -48,6 +47,7 @@ import java.util.Random;
public class SaslServlet extends AbstractServlet
{
+
private static final Logger LOGGER = Logger.getLogger(SaslServlet.class);
private static final SecureRandom SECURE_RANDOM = new SecureRandom();
@@ -57,17 +57,11 @@ public class SaslServlet extends AbstractServlet
private static final String ATTR_EXPIRY = "SaslServlet.Expiry";
private static final long SASL_EXCHANGE_EXPIRY = 1000L;
-
public SaslServlet()
{
super();
}
- public SaslServlet(Broker broker)
- {
- super(broker);
- }
-
protected void doGetWithSubjectAndActor(HttpServletRequest request, HttpServletResponse response) throws
ServletException,
IOException
@@ -82,7 +76,7 @@ public class SaslServlet extends AbstractServlet
HttpSession session = request.getSession();
getRandom(session);
- SubjectCreator subjectCreator = ApplicationRegistry.getInstance().getSubjectCreator(getSocketAddress(request));
+ SubjectCreator subjectCreator = getSubjectCreator(request);
String[] mechanisms = subjectCreator.getMechanisms().split(" ");
Map<String, Object> outputObject = new LinkedHashMap<String, Object>();
@@ -140,7 +134,7 @@ public class SaslServlet extends AbstractServlet
String id = request.getParameter("id");
String saslResponse = request.getParameter("response");
- SubjectCreator subjectCreator = ApplicationRegistry.getInstance().getSubjectCreator(getSocketAddress(request));
+ SubjectCreator subjectCreator = getSubjectCreator(request);
if(mechanism != null)
{
@@ -202,13 +196,14 @@ public class SaslServlet extends AbstractServlet
private void checkSaslAuthEnabled(HttpServletRequest request)
{
boolean saslAuthEnabled;
+ HttpManagement management = getManagement();
if (request.isSecure())
{
- saslAuthEnabled = ApplicationRegistry.getInstance().getConfiguration().getHTTPSManagementSaslAuthEnabled();
+ saslAuthEnabled = management.isHttpsSaslAuthenticationEnabled();
}
else
{
- saslAuthEnabled = ApplicationRegistry.getInstance().getConfiguration().getHTTPManagementSaslAuthEnabled();
+ saslAuthEnabled = management.isHttpSaslAuthenticationEnabled();
}
if (!saslAuthEnabled)
diff --git a/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/StructureServlet.java b/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/StructureServlet.java
index 5f553beb26..40d3c02768 100644
--- a/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/StructureServlet.java
+++ b/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/StructureServlet.java
@@ -41,11 +41,6 @@ public class StructureServlet extends AbstractServlet
super();
}
- public StructureServlet(Broker broker)
- {
- super(broker);
- }
-
@Override
protected void doGetWithSubjectAndActor(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
diff --git a/qpid/java/broker-plugins/management-http/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.ManagementFactory b/qpid/java/broker-plugins/management-http/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.PluginFactory
index 7ffb9a9013..7ffb9a9013 100644
--- a/qpid/java/broker-plugins/management-http/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.ManagementFactory
+++ b/qpid/java/broker-plugins/management-http/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.PluginFactory
diff --git a/qpid/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/HttpManagementFactoryTest.java b/qpid/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/HttpManagementFactoryTest.java
index fedd9b88d8..bb4c46826c 100644
--- a/qpid/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/HttpManagementFactoryTest.java
+++ b/qpid/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/HttpManagementFactoryTest.java
@@ -19,64 +19,42 @@
package org.apache.qpid.server.management.plugin;
import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-import org.apache.qpid.server.configuration.ServerConfiguration;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+
import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.plugin.PluginFactory;
import org.apache.qpid.test.utils.QpidTestCase;
public class HttpManagementFactoryTest extends QpidTestCase
{
- private static final String KEY_STORE_PASSWORD = "keyStorePassword";
- private static final String KEY_STORE_PATH = "keyStorePath";
private static final int SESSION_TIMEOUT = 3600;
- private HttpManagementFactory _managementFactory = new HttpManagementFactory();
- private ServerConfiguration _configuration = mock(ServerConfiguration.class);
+ private PluginFactory _pluginFactory = new HttpManagementFactory();
+ private Map<String, Object> _attributes = new HashMap<String, Object>();
private Broker _broker = mock(Broker.class);
+ private UUID _id = UUID.randomUUID();
- public void testNoHttpManagementConfigured() throws Exception
+ public void testCreateInstanceReturnsNullWhenPluginTypeMissing() throws Exception
{
- ManagementPlugin management = _managementFactory.createInstance(_configuration, _broker);
- assertNull(management);
+ assertNull(_pluginFactory.createInstance(_id, _attributes, _broker));
}
-
- public void testHttpTransportConfigured() throws Exception
+ public void testCreateInstanceReturnsNullWhenPluginTypeNotHttp()
{
- when(_configuration.getHTTPManagementEnabled()).thenReturn(true);
- when(_configuration.getHTTPSManagementEnabled()).thenReturn(false);
-
- when(_configuration.getManagementKeyStorePassword()).thenReturn(null);
- when(_configuration.getManagementKeyStorePath()).thenReturn(null);
-
- when(_configuration.getHTTPManagementSessionTimeout()).thenReturn(SESSION_TIMEOUT);
-
- HttpManagement management = _managementFactory.createInstance(_configuration, _broker);
-
- assertNotNull(management);
- assertEquals(_broker, management.getBroker());
- assertNull(management.getKeyStorePassword());
- assertNull(management.getKeyStorePath());
- assertEquals(SESSION_TIMEOUT, management.getSessionTimeout());
-
+ _attributes.put(PluginFactory.PLUGIN_TYPE, "notHttp");
+ assertNull(_pluginFactory.createInstance(_id, _attributes, _broker));
}
- public void testHttpsTransportConfigured() throws Exception
+ public void testCreateInstance() throws Exception
{
- when(_configuration.getHTTPManagementEnabled()).thenReturn(false);
- when(_configuration.getHTTPSManagementEnabled()).thenReturn(true);
-
- when(_configuration.getManagementKeyStorePassword()).thenReturn(KEY_STORE_PASSWORD);
- when(_configuration.getManagementKeyStorePath()).thenReturn(KEY_STORE_PATH);
-
- when(_configuration.getHTTPManagementSessionTimeout()).thenReturn(SESSION_TIMEOUT);
+ _attributes.put(PluginFactory.PLUGIN_TYPE, HttpManagement.PLUGIN_TYPE);
+ _attributes.put(HttpManagement.TIME_OUT, SESSION_TIMEOUT);
- HttpManagement management = _managementFactory.createInstance(_configuration, _broker);
+ HttpManagement management = (HttpManagement) _pluginFactory.createInstance(_id, _attributes, _broker);
- assertNotNull(management);
assertEquals(_broker, management.getBroker());
- assertEquals(KEY_STORE_PASSWORD, management.getKeyStorePassword());
- assertEquals(KEY_STORE_PATH, management.getKeyStorePath());
assertEquals(SESSION_TIMEOUT, management.getSessionTimeout());
}
diff --git a/qpid/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/CustomRMIServerSocketFactory.java b/qpid/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/CustomRMIServerSocketFactory.java
new file mode 100644
index 0000000000..b7aab78e45
--- /dev/null
+++ b/qpid/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/CustomRMIServerSocketFactory.java
@@ -0,0 +1,68 @@
+/*
+ * 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.qpid.server.jmx;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.rmi.server.RMIServerSocketFactory;
+
+/**
+ * Custom RMIServerSocketFactory class, used to prevent updates to the RMI registry.
+ * Supplied to the registry at creation, this will prevent RMI-based operations on the
+ * registry such as attempting to bind a new object, thereby securing it from tampering.
+ * This is accomplished by always returning null when attempting to determine the address
+ * of the caller, thus ensuring the registry will refuse the attempt. Calls to bind etc
+ * made using the object reference will not be affected and continue to operate normally.
+ */
+class CustomRMIServerSocketFactory implements RMIServerSocketFactory
+{
+
+ public ServerSocket createServerSocket(int port) throws IOException
+ {
+ return new NoLocalAddressServerSocket(port);
+ }
+
+ private static class NoLocalAddressServerSocket extends ServerSocket
+ {
+ NoLocalAddressServerSocket(int port) throws IOException
+ {
+ super(port);
+ }
+
+ @Override
+ public Socket accept() throws IOException
+ {
+ Socket s = new NoLocalAddressSocket();
+ super.implAccept(s);
+ return s;
+ }
+ }
+
+ private static class NoLocalAddressSocket extends Socket
+ {
+ @Override
+ public InetAddress getInetAddress()
+ {
+ return null;
+ }
+ }
+} \ No newline at end of file
diff --git a/qpid/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/JMXManagedObjectRegistry.java b/qpid/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/JMXManagedObjectRegistry.java
index cf7a83a54e..a045683de1 100644
--- a/qpid/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/JMXManagedObjectRegistry.java
+++ b/qpid/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/JMXManagedObjectRegistry.java
@@ -20,56 +20,44 @@
*/
package org.apache.qpid.server.jmx;
-import org.apache.commons.configuration.ConfigurationException;
import org.apache.log4j.Logger;
-import org.apache.qpid.AMQException;
-import org.apache.qpid.server.configuration.ServerConfiguration;
+import org.apache.qpid.server.configuration.BrokerProperties;
+import org.apache.qpid.server.configuration.IllegalConfigurationException;
import org.apache.qpid.server.logging.actors.CurrentActor;
import org.apache.qpid.server.logging.messages.ManagementConsoleMessages;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.Port;
+import org.apache.qpid.server.model.Transport;
-
-import org.apache.qpid.server.registry.ApplicationRegistry;
-import org.apache.qpid.server.security.auth.AuthenticatedPrincipal;
import org.apache.qpid.server.security.auth.rmi.RMIPasswordAuthenticator;
+
import javax.management.JMException;
import javax.management.MBeanServer;
import javax.management.MBeanServerFactory;
-import javax.management.Notification;
-import javax.management.NotificationFilterSupport;
-import javax.management.NotificationListener;
import javax.management.ObjectName;
-import javax.management.remote.JMXConnectionNotification;
import javax.management.remote.JMXConnectorServer;
import javax.management.remote.JMXServiceURL;
import javax.management.remote.MBeanServerForwarder;
-import javax.management.remote.rmi.RMIConnection;
import javax.management.remote.rmi.RMIConnectorServer;
-import javax.management.remote.rmi.RMIJRMPServerImpl;
-import javax.management.remote.rmi.RMIServerImpl;
import javax.rmi.ssl.SslRMIClientSocketFactory;
import javax.rmi.ssl.SslRMIServerSocketFactory;
-import javax.security.auth.Subject;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.lang.management.ManagementFactory;
-import java.lang.reflect.Proxy;
import java.net.InetAddress;
import java.net.InetSocketAddress;
-import java.net.ServerSocket;
-import java.net.Socket;
import java.net.UnknownHostException;
import java.rmi.AlreadyBoundException;
import java.rmi.NoSuchObjectException;
import java.rmi.NotBoundException;
+import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.RMIClientSocketFactory;
import java.rmi.server.RMIServerSocketFactory;
import java.rmi.server.UnicastRemoteObject;
import java.util.HashMap;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
/**
* This class starts up an MBeanserver. If out of the box agent has been enabled then there are no
@@ -82,34 +70,32 @@ public class JMXManagedObjectRegistry implements ManagedObjectRegistry
private static final String OPERATIONAL_LOGGING_NAME = "JMX";
private final MBeanServer _mbeanServer;
+
private JMXConnectorServer _cs;
private Registry _rmiRegistry;
- private boolean _useCustomSocketFactory;
- private final int _jmxPortRegistryServer;
- private final int _jmxPortConnectorServer;
+ private final Broker _broker;
+ private final Port _registryPort;
+ private final Port _connectorPort;
- private final ServerConfiguration _serverConfiguration;
-
- public JMXManagedObjectRegistry(ServerConfiguration serverConfiguration) throws AMQException
+ public JMXManagedObjectRegistry(
+ Broker broker,
+ Port connectorPort, Port registryPort,
+ JMXManagement jmxManagement)
{
- _log.info("Initialising managed object registry using platform MBean server");
-
- _serverConfiguration = serverConfiguration;
+ _broker = broker;
+ _registryPort = registryPort;
+ _connectorPort = connectorPort;
- // Retrieve the config parameters
- _useCustomSocketFactory = _serverConfiguration.getUseCustomRMISocketFactory();
- boolean platformServer = _serverConfiguration.getPlatformMbeanserver();
+ boolean usePlatformServer = (Boolean)jmxManagement.getAttribute(JMXManagement.USE_PLATFORM_MBEAN_SERVER);
_mbeanServer =
- platformServer ? ManagementFactory.getPlatformMBeanServer()
+ usePlatformServer ? ManagementFactory.getPlatformMBeanServer()
: MBeanServerFactory.createMBeanServer(ManagedObject.DOMAIN);
+ }
- _jmxPortRegistryServer = _serverConfiguration.getJMXPortRegistryServer();
- _jmxPortConnectorServer = _serverConfiguration.getJMXConnectorServerPort();
- }
-
- public void start() throws IOException, ConfigurationException
+ @Override
+ public void start() throws IOException
{
CurrentActor.get().message(ManagementConsoleMessages.STARTUP(OPERATIONAL_LOGGING_NAME));
@@ -117,59 +103,31 @@ public class JMXManagedObjectRegistry implements ManagedObjectRegistry
if (areOutOfTheBoxJMXOptionsSet())
{
CurrentActor.get().message(ManagementConsoleMessages.READY(OPERATIONAL_LOGGING_NAME));
- return;
}
+ else
+ {
+ startRegistryAndConnector();
+ }
+ }
- //Socket factories for the RMIConnectorServer, either default or SLL depending on configuration
+ private void startRegistryAndConnector() throws IOException
+ {
+ //Socket factories for the RMIConnectorServer, either default or SSL depending on configuration
RMIClientSocketFactory csf;
RMIServerSocketFactory ssf;
- //check ssl enabled option in config, default to true if option is not set
- boolean sslEnabled = _serverConfiguration.getManagementSSLEnabled();
+ //check ssl enabled option on connector port (note we don't provide ssl for registry server at
+ //moment).
+ boolean connectorSslEnabled = _connectorPort.getTransports().contains(Transport.SSL);
- if (sslEnabled)
+ if (connectorSslEnabled)
{
- //set the SSL related system properties used by the SSL RMI socket factories to the values
- //given in the configuration file
- String keyStorePath = _serverConfiguration.getManagementKeyStorePath();
+ String keyStorePath = System.getProperty("javax.net.ssl.keyStore");
+ String keyStorePassword = System.getProperty("javax.net.ssl.keyStorePassword");
- //check the keystore path value is valid
- if (keyStorePath == null)
- {
- throw new ConfigurationException("JMX management SSL keystore path not defined, " +
- "unable to start SSL protected JMX ConnectorServer");
- }
- else
- {
- //ensure the system property is set (for use by SslRMIClientSocketFactory and SslRMIServerSocketFactory)
- System.setProperty("javax.net.ssl.keyStore", keyStorePath);
+ validateKeyStoreProperties(keyStorePath, keyStorePassword);
- //check the file is usable
- File ksf = new File(keyStorePath);
-
- if (!ksf.exists())
- {
- throw new FileNotFoundException("Cannot find JMX management SSL keystore file: " + ksf);
- }
- if (!ksf.canRead())
- {
- throw new FileNotFoundException("Cannot read JMX management SSL keystore file: "
- + ksf + ". Check permissions.");
- }
-
- CurrentActor.get().message(ManagementConsoleMessages.SSL_KEYSTORE(ksf.getAbsolutePath()));
- }
-
- if (_serverConfiguration.getManagementKeyStorePassword() == null)
- {
- throw new ConfigurationException("JMX management SSL keystore password not defined, " +
- "unable to start requested SSL protected JMX server");
- }
- else
- {
- System.setProperty("javax.net.ssl.keyStorePassword",
- _serverConfiguration.getManagementKeyStorePassword());
- }
+ CurrentActor.get().message(ManagementConsoleMessages.SSL_KEYSTORE(keyStorePath));
//create the SSL RMI socket factories
csf = new SslRMIClientSocketFactory();
@@ -182,29 +140,23 @@ public class JMXManagedObjectRegistry implements ManagedObjectRegistry
ssf = null;
}
+ int jmxPortRegistryServer = _registryPort.getPort();
+ int jmxPortConnectorServer = _connectorPort.getPort();
+
//add a JMXAuthenticator implementation the env map to authenticate the RMI based JMX connector server
- RMIPasswordAuthenticator rmipa = new RMIPasswordAuthenticator(ApplicationRegistry.getInstance(), new InetSocketAddress(_jmxPortRegistryServer));
- HashMap<String,Object> env = new HashMap<String,Object>();
- env.put(JMXConnectorServer.AUTHENTICATOR, rmipa);
+ RMIPasswordAuthenticator rmipa = new RMIPasswordAuthenticator(_broker, new InetSocketAddress(jmxPortConnectorServer));
+ HashMap<String,Object> connectorEnv = new HashMap<String,Object>();
+ connectorEnv.put(JMXConnectorServer.AUTHENTICATOR, rmipa);
+
+ System.setProperty("java.rmi.server.randomIDs", "true");
+ boolean useCustomSocketFactory = Boolean.parseBoolean(System.getProperty(BrokerProperties.PROPERTY_USE_CUSTOM_RMI_SOCKET_FACTORY, Boolean.TRUE.toString()));
/*
* Start a RMI registry on the management port, to hold the JMX RMI ConnectorServer stub.
* Using custom socket factory to prevent anyone (including us unfortunately) binding to the registry using RMI.
* As a result, only binds made using the object reference will succeed, thus securing it from external change.
*/
- System.setProperty("java.rmi.server.randomIDs", "true");
- if(_useCustomSocketFactory)
- {
- _log.debug("Using custom RMIServerSocketFactory");
- _rmiRegistry = LocateRegistry.createRegistry(_jmxPortRegistryServer, null, new CustomRMIServerSocketFactory());
- }
- else
- {
- _log.debug("Using default RMIServerSocketFactory");
- _rmiRegistry = LocateRegistry.createRegistry(_jmxPortRegistryServer, null, null);
- }
-
- CurrentActor.get().message(ManagementConsoleMessages.LISTENING("RMI Registry", _jmxPortRegistryServer));
+ _rmiRegistry = createRmiRegistry(jmxPortRegistryServer, useCustomSocketFactory);
/*
* We must now create the RMI ConnectorServer manually, as the JMX Factory methods use RMI calls
@@ -212,57 +164,16 @@ public class JMXManagedObjectRegistry implements ManagedObjectRegistry
* locked it from any RMI based modifications, including our own. Instead, we will manually bind
* the RMIConnectorServer stub to the registry using its object reference, which will still succeed.
*
- * The registry is exported on the defined management port 'port'. We will export the RMIConnectorServer
- * on 'port +1'. Use of these two well-defined ports will ease any navigation through firewall's.
+ * The registry is exported on the defined management port 'port'.
*/
- final Map<String, String> connectionIdUsernameMap = new ConcurrentHashMap<String, String>();
- final RMIServerImpl rmiConnectorServerStub = new RMIJRMPServerImpl(_jmxPortConnectorServer, csf, ssf, env)
- {
-
- /**
- * Override makeClient so we can cache the username of the client in a Map keyed by connectionId.
- * ConnectionId is guaranteed to be unique per client connection, according to the JMX spec.
- * An instance of NotificationListener (mapCleanupListener) will be responsible for removing these Map
- * entries.
- *
- * @see javax.management.remote.rmi.RMIJRMPServerImpl#makeClient(String, javax.security.auth.Subject)
- */
- @Override
- protected RMIConnection makeClient(String connectionId, Subject subject) throws IOException
- {
- final RMIConnection makeClient = super.makeClient(connectionId, subject);
- final AuthenticatedPrincipal authenticatedPrincipalFromSubject = AuthenticatedPrincipal.getAuthenticatedPrincipalFromSubject(subject);
- connectionIdUsernameMap.put(connectionId, authenticatedPrincipalFromSubject.getName());
- return makeClient;
- }
- };
-
- // Create a Listener responsible for removing the map entries add by the #makeClient entry above.
- final NotificationListener mapCleanupListener = new NotificationListener()
- {
+ final UsernameCachingRMIJRMPServer usernameCachingRmiServer = new UsernameCachingRMIJRMPServer(jmxPortConnectorServer, csf, ssf, connectorEnv);
- public void handleNotification(Notification notification, Object handback)
- {
- final String connectionId = ((JMXConnectionNotification) notification).getConnectionId();
- connectionIdUsernameMap.remove(connectionId);
- }
- };
-
- String localHost;
- try
- {
- localHost = InetAddress.getLocalHost().getHostName();
- }
- catch(UnknownHostException ex)
- {
- localHost="127.0.0.1";
- }
- final String hostname = localHost;
+ final String localHostName = getLocalhost();
final JMXServiceURL externalUrl = new JMXServiceURL(
- "service:jmx:rmi://"+hostname+":"+(_jmxPortConnectorServer)+"/jndi/rmi://"+hostname+":"+_jmxPortRegistryServer+"/jmxrmi");
+ "service:jmx:rmi://"+localHostName+":"+(jmxPortConnectorServer)+"/jndi/rmi://"+localHostName+":"+jmxPortRegistryServer+"/jmxrmi");
- final JMXServiceURL internalUrl = new JMXServiceURL("rmi", hostname, _jmxPortConnectorServer);
- _cs = new RMIConnectorServer(internalUrl, env, rmiConnectorServerStub, _mbeanServer)
+ final JMXServiceURL internalUrl = new JMXServiceURL("rmi", localHostName, jmxPortConnectorServer);
+ _cs = new RMIConnectorServer(internalUrl, connectorEnv, usernameCachingRmiServer, _mbeanServer)
{
@Override
public synchronized void start() throws IOException
@@ -270,7 +181,7 @@ public class JMXManagedObjectRegistry implements ManagedObjectRegistry
try
{
//manually bind the connector server to the registry at key 'jmxrmi', like the out-of-the-box agent
- _rmiRegistry.bind("jmxrmi", rmiConnectorServerStub);
+ _rmiRegistry.bind("jmxrmi", usernameCachingRmiServer);
}
catch (AlreadyBoundException abe)
{
@@ -298,7 +209,6 @@ public class JMXManagedObjectRegistry implements ManagedObjectRegistry
}
catch (NotBoundException nbe)
{
- // TODO consider if we want to keep new logging
_log.error("Failed to unbind jmxrmi", nbe);
//ignore
}
@@ -313,97 +223,100 @@ public class JMXManagedObjectRegistry implements ManagedObjectRegistry
//must return our pre-crafted url that includes the full details, inc JNDI details
return externalUrl;
}
-
};
-
//Add the custom invoker as an MBeanServerForwarder, and start the RMIConnectorServer.
- MBeanServerForwarder mbsf = MBeanInvocationHandlerImpl.newProxyInstance();
+ MBeanServerForwarder mbsf = MBeanInvocationHandlerImpl.newProxyInstance(_broker);
_cs.setMBeanServerForwarder(mbsf);
+ // Install a ManagementLogonLogoffReporter so we can report as users logon/logoff
+ ManagementLogonLogoffReporter jmxManagementUserLogonLogoffReporter = new ManagementLogonLogoffReporter(_broker.getRootMessageLogger(), usernameCachingRmiServer);
+ _cs.addNotificationListener(jmxManagementUserLogonLogoffReporter, jmxManagementUserLogonLogoffReporter, null);
- // Get the handler that is used by the above MBInvocationHandler Proxy.
- // which is the MBeanInvocationHandlerImpl and so also a NotificationListener.
- final NotificationListener invocationHandler = (NotificationListener) Proxy.getInvocationHandler(mbsf);
-
- // Install a notification listener on OPENED, CLOSED, and FAILED,
- // passing the map of connection-ids to usernames as hand-back data.
- final NotificationFilterSupport invocationHandlerFilter = new NotificationFilterSupport();
- invocationHandlerFilter.enableType(JMXConnectionNotification.OPENED);
- invocationHandlerFilter.enableType(JMXConnectionNotification.CLOSED);
- invocationHandlerFilter.enableType(JMXConnectionNotification.FAILED);
- _cs.addNotificationListener(invocationHandler, invocationHandlerFilter, connectionIdUsernameMap);
-
- // Install a second notification listener on CLOSED AND FAILED only to remove the entry from the
- // Map. Here we rely on the fact that JMX will call the listeners in the order in which they are
- // installed.
- final NotificationFilterSupport mapCleanupHandlerFilter = new NotificationFilterSupport();
- mapCleanupHandlerFilter.enableType(JMXConnectionNotification.CLOSED);
- mapCleanupHandlerFilter.enableType(JMXConnectionNotification.FAILED);
- _cs.addNotificationListener(mapCleanupListener, mapCleanupHandlerFilter, null);
+ // Install the usernameCachingRmiServer as a listener so it may cleanup as clients disconnect
+ _cs.addNotificationListener(usernameCachingRmiServer, usernameCachingRmiServer, null);
_cs.start();
- String connectorServer = (sslEnabled ? "SSL " : "") + "JMX RMIConnectorServer";
- CurrentActor.get().message(ManagementConsoleMessages.LISTENING(connectorServer, _jmxPortConnectorServer));
-
+ String connectorServer = (connectorSslEnabled ? "SSL " : "") + "JMX RMIConnectorServer";
+ CurrentActor.get().message(ManagementConsoleMessages.LISTENING(connectorServer, jmxPortConnectorServer));
CurrentActor.get().message(ManagementConsoleMessages.READY(OPERATIONAL_LOGGING_NAME));
}
- /*
- * Custom RMIServerSocketFactory class, used to prevent updates to the RMI registry.
- * Supplied to the registry at creation, this will prevent RMI-based operations on the
- * registry such as attempting to bind a new object, thereby securing it from tampering.
- * This is accomplished by always returning null when attempting to determine the address
- * of the caller, thus ensuring the registry will refuse the attempt. Calls to bind etc
- * made using the object reference will not be affected and continue to operate normally.
- */
-
- private static class CustomRMIServerSocketFactory implements RMIServerSocketFactory
+ private Registry createRmiRegistry(int jmxPortRegistryServer, boolean useCustomRmiRegistry)
+ throws RemoteException
{
-
- public ServerSocket createServerSocket(int port) throws IOException
+ Registry rmiRegistry;
+ if(useCustomRmiRegistry)
{
- return new NoLocalAddressServerSocket(port);
+ _log.debug("Using custom RMIServerSocketFactory");
+ rmiRegistry = LocateRegistry.createRegistry(jmxPortRegistryServer, null, new CustomRMIServerSocketFactory());
}
-
- private static class NoLocalAddressServerSocket extends ServerSocket
+ else
{
- NoLocalAddressServerSocket(int port) throws IOException
- {
- super(port);
- }
+ _log.debug("Using default RMIServerSocketFactory");
+ rmiRegistry = LocateRegistry.createRegistry(jmxPortRegistryServer, null, null);
+ }
- @Override
- public Socket accept() throws IOException
- {
- Socket s = new NoLocalAddressSocket();
- super.implAccept(s);
- return s;
- }
+ CurrentActor.get().message(ManagementConsoleMessages.LISTENING("RMI Registry", jmxPortRegistryServer));
+ return rmiRegistry;
+ }
+
+ private void validateKeyStoreProperties(String keyStorePath, String keyStorePassword) throws FileNotFoundException
+ {
+ if (keyStorePath == null)
+ {
+ throw new IllegalConfigurationException("JVM system property 'javax.net.ssl.keyStore' is not set, "
+ + "unable to start requested SSL protected JMX connector");
+ }
+ if (keyStorePassword == null)
+ {
+ throw new IllegalConfigurationException( "JVM system property 'javax.net.ssl.keyStorePassword' is not set, "
+ + "unable to start requested SSL protected JMX connector");
}
- private static class NoLocalAddressSocket extends Socket
+ File ksf = new File(keyStorePath);
+ if (!ksf.exists())
{
- @Override
- public InetAddress getInetAddress()
- {
- return null;
- }
+ throw new FileNotFoundException("Cannot find JMX management SSL keystore file: " + ksf);
+ }
+ if (!ksf.canRead())
+ {
+ throw new FileNotFoundException("Cannot read JMX management SSL keystore file: "
+ + ksf + ". Check permissions.");
}
}
-
+ @Override
public void registerObject(ManagedObject managedObject) throws JMException
{
_mbeanServer.registerMBean(managedObject, managedObject.getObjectName());
}
+ @Override
public void unregisterObject(ManagedObject managedObject) throws JMException
{
_mbeanServer.unregisterMBean(managedObject.getObjectName());
}
+ @Override
+ public void close()
+ {
+ _log.debug("close() called");
+
+ closeConnectorAndRegistryServers();
+
+ unregisterAllMbeans();
+
+ CurrentActor.get().message(ManagementConsoleMessages.STOPPED(OPERATIONAL_LOGGING_NAME));
+ }
+
+ private void closeConnectorAndRegistryServers()
+ {
+ closeConnectorServer();
+ closeRegistryServer();
+ }
+
// checks if the system properties are set which enable the JVM's out-of-the-box JMXAgent.
private boolean areOutOfTheBoxJMXOptionsSet()
{
@@ -420,29 +333,26 @@ public class JMXManagedObjectRegistry implements ManagedObjectRegistry
return false;
}
- //Stops the JMXConnectorServer and RMIRegistry, then unregisters any remaining MBeans from the MBeanServer
- public void close()
+ private String getLocalhost()
{
- _log.debug("close() called");
-
- if (_cs != null)
+ String localHost;
+ try
{
- // Stopping the JMX ConnectorServer
- try
- {
- CurrentActor.get().message(ManagementConsoleMessages.SHUTTING_DOWN("JMX RMIConnectorServer", _cs.getAddress().getPort()));
- _cs.stop();
- }
- catch (IOException e)
- {
- _log.error("Exception while closing the JMX ConnectorServer: ", e);
- }
+ localHost = InetAddress.getLocalHost().getHostName();
}
+ catch(UnknownHostException ex)
+ {
+ localHost="127.0.0.1";
+ }
+ return localHost;
+ }
+ private void closeRegistryServer()
+ {
if (_rmiRegistry != null)
{
// Stopping the RMI registry
- CurrentActor.get().message(ManagementConsoleMessages.SHUTTING_DOWN("RMI Registry", _jmxPortRegistryServer));
+ CurrentActor.get().message(ManagementConsoleMessages.SHUTTING_DOWN("RMI Registry", _registryPort.getPort()));
try
{
boolean success = UnicastRemoteObject.unexportObject(_rmiRegistry, false);
@@ -455,8 +365,36 @@ public class JMXManagedObjectRegistry implements ManagedObjectRegistry
{
_log.error("Exception while closing the RMI Registry: ", e);
}
+ finally
+ {
+ _rmiRegistry = null;
+ }
}
+ }
+ private void closeConnectorServer()
+ {
+ if (_cs != null)
+ {
+ // Stopping the JMX ConnectorServer
+ try
+ {
+ CurrentActor.get().message(ManagementConsoleMessages.SHUTTING_DOWN("JMX RMIConnectorServer", _cs.getAddress().getPort()));
+ _cs.stop();
+ }
+ catch (IOException e)
+ {
+ _log.error("Exception while closing the JMX ConnectorServer: ", e);
+ }
+ finally
+ {
+ _cs = null;
+ }
+ }
+ }
+
+ private void unregisterAllMbeans()
+ {
//ObjectName query to gather all Qpid related MBeans
ObjectName mbeanNameQuery = null;
try
@@ -479,8 +417,6 @@ public class JMXManagedObjectRegistry implements ManagedObjectRegistry
_log.error("Exception unregistering MBean '"+ name +"': " + e.getMessage());
}
}
-
- CurrentActor.get().message(ManagementConsoleMessages.STOPPED(OPERATIONAL_LOGGING_NAME));
}
}
diff --git a/qpid/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/JMXManagement.java b/qpid/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/JMXManagement.java
index f529793118..f307f5118a 100644
--- a/qpid/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/JMXManagement.java
+++ b/qpid/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/JMXManagement.java
@@ -21,81 +21,214 @@
package org.apache.qpid.server.jmx;
+import java.io.IOException;
+import java.util.Collection;
+import java.util.Collections;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Map;
+import java.util.UUID;
+
import javax.management.JMException;
-import javax.management.StandardMBean;
import org.apache.log4j.Logger;
-import org.apache.qpid.server.configuration.ServerConfiguration;
import org.apache.qpid.server.jmx.mbeans.LoggingManagementMBean;
import org.apache.qpid.server.jmx.mbeans.UserManagementMBean;
import org.apache.qpid.server.jmx.mbeans.ServerInformationMBean;
import org.apache.qpid.server.jmx.mbeans.Shutdown;
import org.apache.qpid.server.jmx.mbeans.VirtualHostMBean;
import org.apache.qpid.server.logging.log4j.LoggingManagementFacade;
-import org.apache.qpid.server.management.plugin.ManagementPlugin;
+import org.apache.qpid.server.model.AuthenticationProvider;
import org.apache.qpid.server.model.Broker;
import org.apache.qpid.server.model.ConfigurationChangeListener;
import org.apache.qpid.server.model.ConfiguredObject;
import org.apache.qpid.server.model.PasswordCredentialManagingAuthenticationProvider;
+import org.apache.qpid.server.model.Plugin;
+import org.apache.qpid.server.model.Port;
+import org.apache.qpid.server.model.Protocol;
import org.apache.qpid.server.model.State;
import org.apache.qpid.server.model.VirtualHost;
+import org.apache.qpid.server.model.adapter.AbstractPluginAdapter;
+import org.apache.qpid.server.plugin.PluginFactory;
import org.apache.qpid.server.plugin.QpidServiceLoader;
+import org.apache.qpid.server.util.MapValueConverter;
-public class JMXManagement implements ConfigurationChangeListener, ManagementPlugin
+public class JMXManagement extends AbstractPluginAdapter implements ConfigurationChangeListener
{
private static final Logger LOGGER = Logger.getLogger(JMXManagement.class);
+ public static final String PLUGIN_TYPE = "MANAGEMENT-JMX";
+
+ // attributes
+ public static final String USE_PLATFORM_MBEAN_SERVER = "usePlatformMBeanServer";
+ public static final String NAME = "name";
+
+ // default values
+ public static final String DEFAULT_NAME = "JMXManagement";
+ public static final boolean DEFAULT_USE_PLATFORM_MBEAN_SERVER = true;
+
+ @SuppressWarnings("serial")
+ private static final Collection<String> AVAILABLE_ATTRIBUTES = Collections.unmodifiableCollection(new HashSet<String>(Plugin.AVAILABLE_ATTRIBUTES){{
+ add(NAME);
+ add(USE_PLATFORM_MBEAN_SERVER);
+ add(PluginFactory.PLUGIN_TYPE);
+ }});
+
+ @SuppressWarnings("serial")
+ private static final Map<String, Object> DEFAULTS = new HashMap<String, Object>(){{
+ put(USE_PLATFORM_MBEAN_SERVER, DEFAULT_USE_PLATFORM_MBEAN_SERVER);
+ put(NAME, DEFAULT_NAME);
+ put(PluginFactory.PLUGIN_TYPE, PLUGIN_TYPE);
+ }};
+
+ @SuppressWarnings("serial")
+ private static final Map<String, Class<?>> ATTRIBUTE_TYPES = new HashMap<String, Class<?>>(){{
+ put(USE_PLATFORM_MBEAN_SERVER, Boolean.class);
+ put(NAME, String.class);
+ put(PluginFactory.PLUGIN_TYPE, String.class);
+ }};
+
private final Broker _broker;
private JMXManagedObjectRegistry _objectRegistry;
private final Map<ConfiguredObject, AMQManagedObject> _children = new HashMap<ConfiguredObject, AMQManagedObject>();
- private final ServerConfiguration _serverConfiguration;
-
- public JMXManagement(ServerConfiguration serverConfiguration, Broker broker)
+ public JMXManagement(UUID id, Broker broker, Map<String, Object> attributes)
{
+ super(id, DEFAULTS, MapValueConverter.convert(attributes, ATTRIBUTE_TYPES), broker.getTaskExecutor());
_broker = broker;
- _serverConfiguration = serverConfiguration;
+ addParent(Broker.class, broker);
}
@Override
- public void start() throws Exception
+ protected boolean setState(State currentState, State desiredState)
{
- _objectRegistry = new JMXManagedObjectRegistry(_serverConfiguration);
+ if(desiredState == State.ACTIVE)
+ {
+ try
+ {
+ start();
+ }
+ catch (JMException e)
+ {
+ throw new RuntimeException("Couldn't start JMX management", e);
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException("Couldn't start JMX management", e);
+ }
+ return true;
+ }
+ else if(desiredState == State.STOPPED)
+ {
+ stop();
+ return true;
+ }
+ return false;
+ }
+
+ private void start() throws JMException, IOException
+ {
+ Port connectorPort = null;
+ Port registryPort = null;
+ Collection<Port> ports = _broker.getPorts();
+ for (Port port : ports)
+ {
+ if(isRegistryPort(port))
+ {
+ registryPort = port;
+ }
+ else if(isConnectorPort(port))
+ {
+ connectorPort = port;
+ }
+ }
+ if(connectorPort == null)
+ {
+ throw new IllegalStateException("No JMX connector port found supporting protocol " + Protocol.JMX_RMI);
+ }
+ if(registryPort == null)
+ {
+ throw new IllegalStateException("No JMX RMI port found supporting protocol " + Protocol.RMI);
+ }
+
+ _objectRegistry = new JMXManagedObjectRegistry(_broker, connectorPort, registryPort, this);
_broker.addChangeListener(this);
+
synchronized (_children)
{
for(VirtualHost virtualHost : _broker.getVirtualHosts())
{
if(!_children.containsKey(virtualHost))
{
- _children.put(virtualHost, new VirtualHostMBean(virtualHost, _objectRegistry));
+ LOGGER.debug("Create MBean for virtual host:" + virtualHost.getName());
+ VirtualHostMBean mbean = new VirtualHostMBean(virtualHost, _objectRegistry);
+ LOGGER.debug("Check for additional MBeans for virtual host:" + virtualHost.getName());
+ createAdditionalMBeansFromProviders(virtualHost, mbean);
+ }
+ }
+ Collection<AuthenticationProvider> authenticationProviders = _broker.getAuthenticationProviders();
+ for (AuthenticationProvider authenticationProvider : authenticationProviders)
+ {
+ if(authenticationProvider instanceof PasswordCredentialManagingAuthenticationProvider)
+ {
+ UserManagementMBean mbean = new UserManagementMBean(
+ (PasswordCredentialManagingAuthenticationProvider) authenticationProvider,
+ _objectRegistry);
+ _children.put(authenticationProvider, mbean);
}
}
}
new Shutdown(_objectRegistry);
new ServerInformationMBean(_objectRegistry, _broker);
new LoggingManagementMBean(LoggingManagementFacade.getCurrentInstance(), _objectRegistry);
-
_objectRegistry.start();
}
- @Override
- public void stop()
+ private boolean isConnectorPort(Port port)
{
- _broker.removeChangeListener(this);
+ return port.getProtocols().contains(Protocol.JMX_RMI);
+ }
+ private boolean isRegistryPort(Port port)
+ {
+ return port.getProtocols().contains(Protocol.RMI);
+ }
+
+ private void stop()
+ {
+ synchronized (_children)
+ {
+ for(ConfiguredObject object : _children.keySet())
+ {
+ AMQManagedObject mbean = _children.get(object);
+ if (mbean instanceof ConfigurationChangeListener)
+ {
+ object.removeChangeListener((ConfigurationChangeListener)mbean);
+ }
+ try
+ {
+ mbean.unregister();
+ }
+ catch (JMException e)
+ {
+ LOGGER.error("Error unregistering mbean", e);
+ }
+ }
+ _children.clear();
+ }
+ _broker.removeChangeListener(this);
_objectRegistry.close();
}
+ @Override
public void stateChanged(ConfiguredObject object, State oldState, State newState)
{
-
+ // no-op
}
+ @Override
public void childAdded(ConfiguredObject object, ConfiguredObject child)
{
synchronized (_children)
@@ -130,7 +263,7 @@ public class JMXManagement implements ConfigurationChangeListener, ManagementPlu
}
}
-
+ @Override
public void childRemoved(ConfiguredObject object, ConfiguredObject child)
{
// TODO - implement vhost removal (possibly just removing the instanceof check below)
@@ -157,6 +290,12 @@ public class JMXManagement implements ConfigurationChangeListener, ManagementPlu
}
}
+ @Override
+ public void attributeSet(ConfiguredObject object, String attributeName, Object oldAttributeValue, Object newAttributeValue)
+ {
+ // no-op
+ }
+
private void createAdditionalMBeansFromProviders(ConfiguredObject child, AMQManagedObject mbean) throws JMException
{
_children.put(child, mbean);
@@ -168,7 +307,7 @@ public class JMXManagement implements ConfigurationChangeListener, ManagementPlu
if (provider.isChildManageableByMBean(child))
{
LOGGER.debug("Provider will create mbean ");
- StandardMBean bean = provider.createMBean(child, mbean);
+ provider.createMBean(child, mbean);
// TODO track the mbeans that have been created on behalf of a child in a map, then
// if the child is ever removed, destroy these beans too.
}
@@ -181,9 +320,16 @@ public class JMXManagement implements ConfigurationChangeListener, ManagementPlu
return _broker;
}
- /** Added for testing purposes */
- ServerConfiguration getServerConfiguration()
+ @Override
+ public String getName()
{
- return _serverConfiguration;
+ return (String)getAttribute(NAME);
}
+
+ @Override
+ public Collection<String> getAttributeNames()
+ {
+ return AVAILABLE_ATTRIBUTES;
+ }
+
}
diff --git a/qpid/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/JMXManagementFactory.java b/qpid/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/JMXManagementFactory.java
index 12d4711595..c2186c372b 100644
--- a/qpid/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/JMXManagementFactory.java
+++ b/qpid/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/JMXManagementFactory.java
@@ -18,27 +18,30 @@
*/
package org.apache.qpid.server.jmx;
+import java.util.Map;
+import java.util.UUID;
+
import org.apache.log4j.Logger;
-import org.apache.qpid.server.configuration.ServerConfiguration;
import org.apache.qpid.server.model.Broker;
-import org.apache.qpid.server.plugin.ManagementFactory;
+import org.apache.qpid.server.model.Plugin;
+import org.apache.qpid.server.plugin.PluginFactory;
-public class JMXManagementFactory implements ManagementFactory
+public class JMXManagementFactory implements PluginFactory
{
- private static final Logger _logger = Logger.getLogger(JMXManagementFactory.class);
+ private static final Logger LOGGER = Logger.getLogger(JMXManagementFactory.class);
@Override
- public JMXManagement createInstance(ServerConfiguration serverConfiguration, Broker broker)
+ public Plugin createInstance(UUID id, Map<String, Object> attributes, Broker broker)
{
- if (serverConfiguration.getJMXManagementEnabled())
+ if (JMXManagement.PLUGIN_TYPE.equals(attributes.get(PLUGIN_TYPE)))
{
- return new JMXManagement(serverConfiguration, broker);
+ return new JMXManagement(id, broker, attributes);
}
else
{
- if(_logger.isDebugEnabled())
+ if (LOGGER.isDebugEnabled())
{
- _logger.debug("Skipping registration of JMX plugin as JMX Management disabled in config.");
+ LOGGER.debug("Skipping registration of JMX plugin as JMX Management disabled in config.");
}
return null;
}
diff --git a/qpid/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/MBeanInvocationHandlerImpl.java b/qpid/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/MBeanInvocationHandlerImpl.java
index 694b0b2913..8bc2afb176 100644
--- a/qpid/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/MBeanInvocationHandlerImpl.java
+++ b/qpid/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/MBeanInvocationHandlerImpl.java
@@ -22,12 +22,11 @@ package org.apache.qpid.server.jmx;
import org.apache.log4j.Logger;
-import org.apache.qpid.server.logging.LogActor;
+import org.apache.qpid.server.configuration.BrokerProperties;
import org.apache.qpid.server.logging.actors.CurrentActor;
import org.apache.qpid.server.logging.actors.ManagementActor;
-import org.apache.qpid.server.logging.messages.ManagementConsoleMessages;
-import org.apache.qpid.server.registry.ApplicationRegistry;
-import org.apache.qpid.server.registry.IApplicationRegistry;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.VirtualHost;
import org.apache.qpid.server.security.SecurityManager;
import org.apache.qpid.server.security.access.Operation;
import org.apache.qpid.server.security.auth.AuthenticatedPrincipal;
@@ -37,11 +36,8 @@ import javax.management.JMException;
import javax.management.MBeanInfo;
import javax.management.MBeanOperationInfo;
import javax.management.MBeanServer;
-import javax.management.Notification;
-import javax.management.NotificationListener;
import javax.management.ObjectName;
import javax.management.RuntimeErrorException;
-import javax.management.remote.JMXConnectionNotification;
import javax.management.remote.MBeanServerForwarder;
import javax.security.auth.Subject;
import java.lang.reflect.InvocationHandler;
@@ -51,26 +47,32 @@ import java.lang.reflect.Proxy;
import java.security.AccessControlContext;
import java.security.AccessController;
import java.util.Arrays;
-import java.util.Map;
/**
* This class can be used by the JMXConnectorServer as an InvocationHandler for the mbean operations. It delegates
* JMX access decisions to the SecurityPlugin.
*/
-public class MBeanInvocationHandlerImpl implements InvocationHandler, NotificationListener
+public class MBeanInvocationHandlerImpl implements InvocationHandler
{
private static final Logger _logger = Logger.getLogger(MBeanInvocationHandlerImpl.class);
- private final IApplicationRegistry _appRegistry = ApplicationRegistry.getInstance();
private final static String DELEGATE = "JMImplementation:type=MBeanServerDelegate";
private MBeanServer _mbs;
- private final ManagementActor _logActor = new ManagementActor(_appRegistry.getRootMessageLogger());
- private final boolean _managementRightsInferAllAccess =
- _appRegistry.getConfiguration().getManagementRightsInferAllAccess();
+ private final ManagementActor _logActor;
- public static MBeanServerForwarder newProxyInstance()
+ private final boolean _managementRightsInferAllAccess;
+ private final Broker _broker;
+
+ MBeanInvocationHandlerImpl(Broker broker)
+ {
+ _managementRightsInferAllAccess = Boolean.valueOf(System.getProperty(BrokerProperties.PROPERTY_MANAGEMENT_RIGHTS_INFER_ALL_ACCESS, "true"));
+ _broker = broker;
+ _logActor = new ManagementActor(broker.getRootMessageLogger());
+ }
+
+ public static MBeanServerForwarder newProxyInstance(Broker broker)
{
- final InvocationHandler handler = new MBeanInvocationHandlerImpl();
+ final InvocationHandler handler = new MBeanInvocationHandlerImpl(broker);
final Class<?>[] interfaces = new Class[] { MBeanServerForwarder.class };
Object proxy = Proxy.newProxyInstance(MBeanServerForwarder.class.getClassLoader(), interfaces, handler);
@@ -212,11 +214,16 @@ public class MBeanInvocationHandlerImpl implements InvocationHandler, Notificati
SecurityManager security;
if (vhost == null)
{
- security = _appRegistry.getSecurityManager();
+ security = _broker.getSecurityManager();
}
else
{
- security = _appRegistry.getVirtualHostRegistry().getVirtualHost(vhost).getSecurityManager();
+ VirtualHost virtualHost = _broker.findVirtualHostByName(vhost);
+ if (virtualHost == null)
+ {
+ throw new IllegalArgumentException("Virtual host with name '" + vhost + "' is not found.");
+ }
+ security = virtualHost.getSecurityManager();
}
methodName = getMethodName(method, args);
@@ -361,51 +368,5 @@ public class MBeanInvocationHandlerImpl implements InvocationHandler, Notificati
return (methodName.startsWith("query") || methodName.startsWith("get") || methodName.startsWith("is"));
}
- /**
- * Receives notifications from the MBeanServer.
- */
- public void handleNotification(final Notification notification, final Object handback)
- {
- assert notification instanceof JMXConnectionNotification;
-
- final String connectionId = ((JMXConnectionNotification) notification).getConnectionId();
- final String type = notification.getType();
-
- if (_logger.isDebugEnabled())
- {
- _logger.debug("Notification connectionId : " + connectionId + " type : " + type
- + " Notification handback : " + handback);
- }
-
- // Normally JMXManagedObjectRegistry provides a Map as handback data containing a map
- // between connection id and username.
- String user = null;
- if (handback instanceof Map)
- {
- @SuppressWarnings("unchecked")
- final Map<String, String> connectionIdUsernameMap = (Map<String, String>) handback;
- user = connectionIdUsernameMap.get(connectionId);
- }
-
- // If user is still null, fallback to an unordered list of Principals from the connection id.
- if (user == null)
- {
- final String[] splitConnectionId = connectionId.split(" ");
- user = splitConnectionId[1];
- }
-
- // use a separate instance of actor as subject is not set on connect/disconnect
- // we need to pass principal name explicitly into log actor
- LogActor logActor = new ManagementActor(_appRegistry.getRootMessageLogger(), user);
- if (JMXConnectionNotification.OPENED.equals(type))
- {
- logActor.message(ManagementConsoleMessages.OPEN(user));
- }
- else if (JMXConnectionNotification.CLOSED.equals(type) ||
- JMXConnectionNotification.FAILED.equals(type))
- {
- logActor.message(ManagementConsoleMessages.CLOSE(user));
- }
- }
}
diff --git a/qpid/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/ManagementLogonLogoffReporter.java b/qpid/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/ManagementLogonLogoffReporter.java
new file mode 100644
index 0000000000..ae0574dc21
--- /dev/null
+++ b/qpid/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/ManagementLogonLogoffReporter.java
@@ -0,0 +1,95 @@
+/*
+ * 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.qpid.server.jmx;
+
+import static javax.management.remote.JMXConnectionNotification.CLOSED;
+import static javax.management.remote.JMXConnectionNotification.FAILED;
+import static javax.management.remote.JMXConnectionNotification.OPENED;
+
+import javax.management.Notification;
+import javax.management.NotificationFilter;
+import javax.management.NotificationListener;
+import javax.management.remote.JMXConnectionNotification;
+
+import org.apache.log4j.Logger;
+import org.apache.qpid.server.logging.LogActor;
+import org.apache.qpid.server.logging.RootMessageLogger;
+import org.apache.qpid.server.logging.actors.ManagementActor;
+import org.apache.qpid.server.logging.messages.ManagementConsoleMessages;
+
+public class ManagementLogonLogoffReporter implements NotificationListener, NotificationFilter
+{
+ private static final Logger LOGGER = Logger.getLogger(ManagementLogonLogoffReporter.class);
+ private final RootMessageLogger _rootMessageLogger;
+ private final UsernameAccessor _usernameAccessor;
+
+ public ManagementLogonLogoffReporter(RootMessageLogger rootMessageLogger, UsernameAccessor usernameAccessor)
+ {
+ _rootMessageLogger = rootMessageLogger;
+ _usernameAccessor = usernameAccessor;
+ }
+
+ @Override
+ public void handleNotification(final Notification notification, final Object handback)
+ {
+ final String connectionId = ((JMXConnectionNotification) notification).getConnectionId();
+ final String type = notification.getType();
+
+ if (LOGGER.isDebugEnabled())
+ {
+ LOGGER.debug("Notification connectionId : " + connectionId + " type : " + type);
+ }
+
+ String user = _usernameAccessor.getUsernameForConnectionId(connectionId);
+
+ // If user is still null, fallback to an unordered list of Principals from the connection id.
+ if (user == null)
+ {
+ final String[] splitConnectionId = connectionId.split(" ");
+ user = splitConnectionId[1];
+ }
+
+ // use a separate instance of actor as subject is not set on connect/disconnect
+ // we need to pass principal name explicitly into log actor
+ LogActor logActor = new ManagementActor(_rootMessageLogger, user);
+ if (JMXConnectionNotification.OPENED.equals(type))
+ {
+ logActor.message(ManagementConsoleMessages.OPEN(user));
+ }
+ else if (JMXConnectionNotification.CLOSED.equals(type) ||
+ JMXConnectionNotification.FAILED.equals(type))
+ {
+ logActor.message(ManagementConsoleMessages.CLOSE(user));
+ }
+ }
+
+ @Override
+ public boolean isNotificationEnabled(Notification notification)
+ {
+ return notification instanceof JMXConnectionNotification && isLogonTypeEvent(notification);
+ }
+
+ private boolean isLogonTypeEvent(Notification notification)
+ {
+ final String type = notification.getType();
+ return CLOSED.equals(type) || FAILED.equals(type) || OPENED.equals(type);
+ }
+
+}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/management/plugin/ManagementPlugin.java b/qpid/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/UsernameAccessor.java
index 86de4aa2f0..0cbb0d2687 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/management/plugin/ManagementPlugin.java
+++ b/qpid/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/UsernameAccessor.java
@@ -15,11 +15,12 @@
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
+ *
*/
-package org.apache.qpid.server.management.plugin;
+package org.apache.qpid.server.jmx;
-public interface ManagementPlugin
+public interface UsernameAccessor
{
- void start() throws Exception;
- void stop() throws Exception;
-} \ No newline at end of file
+ public String getUsernameForConnectionId(String connectionId);
+
+}
diff --git a/qpid/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/UsernameCachingRMIJRMPServer.java b/qpid/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/UsernameCachingRMIJRMPServer.java
new file mode 100644
index 0000000000..838e9e5664
--- /dev/null
+++ b/qpid/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/UsernameCachingRMIJRMPServer.java
@@ -0,0 +1,100 @@
+/*
+ * 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.qpid.server.jmx;
+
+import static javax.management.remote.JMXConnectionNotification.CLOSED;
+import static javax.management.remote.JMXConnectionNotification.FAILED;
+
+import java.io.IOException;
+import java.rmi.server.RMIClientSocketFactory;
+import java.rmi.server.RMIServerSocketFactory;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import javax.management.Notification;
+import javax.management.NotificationFilter;
+import javax.management.NotificationListener;
+import javax.management.remote.JMXConnectionNotification;
+import javax.management.remote.JMXConnectorServer;
+import javax.management.remote.rmi.RMIConnection;
+import javax.management.remote.rmi.RMIJRMPServerImpl;
+import javax.security.auth.Subject;
+
+import org.apache.qpid.server.security.auth.AuthenticatedPrincipal;
+
+/**
+ * An implementation of RMIJRMPServerImpl that caches the usernames of users as they log-on
+ * and makes the same available via {@link UsernameAccessor#getUsernameForConnectionId(String)}.
+ *
+ * Caller is responsible for installing this object as a {@link NotificationListener} of the
+ * {@link JMXConnectorServer} so the cache entries are removed as the clients disconnect.
+ *
+ */
+public class UsernameCachingRMIJRMPServer extends RMIJRMPServerImpl implements NotificationListener, NotificationFilter, UsernameAccessor
+{
+ // ConnectionId is guaranteed to be unique per client connection, according to the JMX spec.
+ private final Map<String, String> _connectionIdUsernameMap = new ConcurrentHashMap<String, String>();
+
+ UsernameCachingRMIJRMPServer(int port, RMIClientSocketFactory csf, RMIServerSocketFactory ssf,
+ Map<String, ?> env) throws IOException
+ {
+ super(port, csf, ssf, env);
+ }
+
+ @Override
+ protected RMIConnection makeClient(String connectionId, Subject subject) throws IOException
+ {
+ final RMIConnection makeClient = super.makeClient(connectionId, subject);
+ final AuthenticatedPrincipal authenticatedPrincipalFromSubject = AuthenticatedPrincipal.getAuthenticatedPrincipalFromSubject(subject);
+ _connectionIdUsernameMap.put(connectionId, authenticatedPrincipalFromSubject.getName());
+ return makeClient;
+ }
+
+ @Override
+ public String getUsernameForConnectionId(String connectionId)
+ {
+ return _connectionIdUsernameMap.get(connectionId);
+ }
+
+ @Override
+ public void handleNotification(Notification notification, Object handback)
+ {
+ final String connectionId = ((JMXConnectionNotification) notification).getConnectionId();
+ removeConnectionIdFromCache(connectionId);
+ }
+
+ @Override
+ public boolean isNotificationEnabled(Notification notification)
+ {
+ return isClientDisconnectEvent(notification);
+ }
+
+ private void removeConnectionIdFromCache(String connectionId)
+ {
+ _connectionIdUsernameMap.remove(connectionId);
+ }
+
+ private boolean isClientDisconnectEvent(Notification notification)
+ {
+ final String type = notification.getType();
+ return CLOSED.equals(type) || FAILED.equals(type);
+ }
+
+} \ No newline at end of file
diff --git a/qpid/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/mbeans/VirtualHostMBean.java b/qpid/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/mbeans/VirtualHostMBean.java
index 6990a40dee..51dea92775 100644
--- a/qpid/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/mbeans/VirtualHostMBean.java
+++ b/qpid/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/mbeans/VirtualHostMBean.java
@@ -65,7 +65,7 @@ public class VirtualHostMBean extends AMQManagedObject implements ManagedVirtual
_managerMBean = new VirtualHostManagerMBean(this);
}
- private void initQueues() throws JMException
+ private void initQueues()
{
synchronized (_children)
{
@@ -73,13 +73,20 @@ public class VirtualHostMBean extends AMQManagedObject implements ManagedVirtual
{
if(!_children.containsKey(queue))
{
- _children.put(queue, new QueueMBean(queue, this));
+ try
+ {
+ _children.put(queue, new QueueMBean(queue, this));
+ }
+ catch(Exception e)
+ {
+ LOGGER.error("Cannot create queue mbean for queue " + queue.getName(), e);
+ }
}
}
}
}
- private void initExchanges() throws JMException
+ private void initExchanges()
{
synchronized (_children)
{
@@ -87,13 +94,20 @@ public class VirtualHostMBean extends AMQManagedObject implements ManagedVirtual
{
if(!_children.containsKey(exchange))
{
- _children.put(exchange, new ExchangeMBean(exchange, this));
+ try
+ {
+ _children.put(exchange, new ExchangeMBean(exchange, this));
+ }
+ catch(Exception e)
+ {
+ LOGGER.error("Cannot create exchange mbean for exchange " + exchange.getName(), e);
+ }
}
}
}
}
- private void initConnections() throws JMException
+ private void initConnections()
{
synchronized (_children)
{
@@ -101,7 +115,14 @@ public class VirtualHostMBean extends AMQManagedObject implements ManagedVirtual
{
if(!_children.containsKey(conn))
{
- _children.put(conn, new ConnectionMBean(conn, this));
+ try
+ {
+ _children.put(conn, new ConnectionMBean(conn, this));
+ }
+ catch(Exception e)
+ {
+ LOGGER.error("Cannot create connection mbean for connection " + conn.getName(), e);
+ }
}
}
}
@@ -119,7 +140,7 @@ public class VirtualHostMBean extends AMQManagedObject implements ManagedVirtual
public void stateChanged(ConfiguredObject object, State oldState, State newState)
{
- // ignore
+ // no-op
}
public void childAdded(ConfiguredObject object, ConfiguredObject child)
@@ -208,4 +229,35 @@ public class VirtualHostMBean extends AMQManagedObject implements ManagedVirtual
return queues;
}
+
+ @Override
+ public void unregister() throws JMException
+ {
+ synchronized (_children)
+ {
+ for (AMQManagedObject mbean : _children.values())
+ {
+ if(mbean != null)
+ {
+ try
+ {
+ mbean.unregister();
+ }
+ catch(JMException e)
+ {
+ LOGGER.error("Failed to remove mbean for child : " + mbean, e);
+ }
+ }
+ }
+ _children.clear();
+ }
+ _managerMBean.unregister();
+ }
+
+ @Override
+ public void attributeSet(ConfiguredObject object, String attributeName, Object oldAttributeValue, Object newAttributeValue)
+ {
+ // no-op
+ }
+
}
diff --git a/qpid/java/broker-plugins/management-jmx/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.ManagementFactory b/qpid/java/broker-plugins/management-jmx/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.PluginFactory
index 8fa778269e..8fa778269e 100644
--- a/qpid/java/broker-plugins/management-jmx/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.ManagementFactory
+++ b/qpid/java/broker-plugins/management-jmx/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.PluginFactory
diff --git a/qpid/java/broker-plugins/management-jmx/src/test/java/org/apache/qpid/server/jmx/JMXManagementFactoryTest.java b/qpid/java/broker-plugins/management-jmx/src/test/java/org/apache/qpid/server/jmx/JMXManagementFactoryTest.java
index 6b6d4018aa..5af1369239 100644
--- a/qpid/java/broker-plugins/management-jmx/src/test/java/org/apache/qpid/server/jmx/JMXManagementFactoryTest.java
+++ b/qpid/java/broker-plugins/management-jmx/src/test/java/org/apache/qpid/server/jmx/JMXManagementFactoryTest.java
@@ -19,33 +19,42 @@
package org.apache.qpid.server.jmx;
import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-import org.apache.qpid.server.configuration.ServerConfiguration;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+
import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.plugin.PluginFactory;
import org.apache.qpid.test.utils.QpidTestCase;
public class JMXManagementFactoryTest extends QpidTestCase
{
private final JMXManagementFactory _jmxManagementFactory = new JMXManagementFactory();
- private final ServerConfiguration _serverConfiguration = mock(ServerConfiguration.class);
+ private final Map<String, Object> _attributes = new HashMap<String, Object>();
private final Broker _broker = mock(Broker.class);
+ private UUID _id = UUID.randomUUID();
public void testJMXConfigured() throws Exception
{
- when(_serverConfiguration.getJMXManagementEnabled()).thenReturn(true);
+ _attributes.put(PluginFactory.PLUGIN_TYPE, JMXManagement.PLUGIN_TYPE);
- JMXManagement jmxManagement = _jmxManagementFactory.createInstance(_serverConfiguration, _broker);
+ JMXManagement jmxManagement = (JMXManagement) _jmxManagementFactory.createInstance(_id, _attributes, _broker);
assertNotNull(jmxManagement);
+ assertEquals("Unexpected plugin type", JMXManagement.PLUGIN_TYPE, jmxManagement.getAttribute(JMXManagementFactory.PLUGIN_TYPE));
+ assertEquals("Unexpected default mbean platform", JMXManagement.DEFAULT_USE_PLATFORM_MBEAN_SERVER, jmxManagement.getAttribute(JMXManagement.USE_PLATFORM_MBEAN_SERVER));
+ assertEquals("Unexpected default name", JMXManagement.DEFAULT_NAME, jmxManagement.getAttribute(JMXManagement.NAME));
}
- public void testJMXNotConfigured() throws Exception
+ public void testCreateInstanceReturnsNullWhenPluginTypeMissing()
{
- when(_serverConfiguration.getJMXManagementEnabled()).thenReturn(false);
-
- JMXManagement jmxManagement = _jmxManagementFactory.createInstance(_serverConfiguration, _broker);
+ assertNull(_jmxManagementFactory.createInstance(_id, _attributes, _broker));
+ }
- assertNull(jmxManagement);
+ public void testCreateInstanceReturnsNullWhenPluginTypeNotJmx()
+ {
+ _attributes.put(PluginFactory.PLUGIN_TYPE, "notJmx");
+ assertNull(_jmxManagementFactory.createInstance(_id, _attributes, _broker));
}
}
diff --git a/qpid/java/broker-plugins/management-jmx/src/test/java/org/apache/qpid/server/jmx/ManagementLogActorTest.java b/qpid/java/broker-plugins/management-jmx/src/test/java/org/apache/qpid/server/jmx/ManagementLogActorTest.java
deleted file mode 100644
index b055cc476f..0000000000
--- a/qpid/java/broker-plugins/management-jmx/src/test/java/org/apache/qpid/server/jmx/ManagementLogActorTest.java
+++ /dev/null
@@ -1,173 +0,0 @@
-/*
- *
- * 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.qpid.server.jmx;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.management.JMException;
-import javax.management.MBeanServerConnection;
-import javax.management.MBeanServerInvocationHandler;
-import javax.management.ObjectName;
-import javax.management.remote.JMXConnector;
-import javax.management.remote.JMXConnectorFactory;
-import javax.management.remote.JMXServiceURL;
-
-import org.apache.commons.configuration.XMLConfiguration;
-import org.apache.qpid.server.configuration.ServerConfiguration;
-import org.apache.qpid.server.logging.actors.CurrentActor;
-import org.apache.qpid.server.registry.ApplicationRegistry;
-import org.apache.qpid.server.security.Result;
-import org.apache.qpid.server.security.AccessControl;
-import org.apache.qpid.server.security.access.ObjectProperties;
-import org.apache.qpid.server.security.access.ObjectType;
-import org.apache.qpid.server.security.access.Operation;
-import org.apache.qpid.server.util.TestApplicationRegistry;
-import org.apache.qpid.test.utils.QpidTestCase;
-
-public class ManagementLogActorTest extends QpidTestCase
-{
- private ApplicationRegistry _registry;
- private JMXManagedObjectRegistry _objectRegistry;
- private int _registryPort;
- private int _connectorPort;
- private TestPlugin _plugin;
-
- @Override
- public void setUp() throws Exception
- {
- super.setUp();
-
- _registryPort = findFreePort();
- _connectorPort = getNextAvailable(_registryPort + 1);
-
- //Start a TestApplicationRegistry with (JMX) management disabled, because we
- //will instantiate our own directly in order to manipulate it for the test.
- XMLConfiguration config = new XMLConfiguration();
- config.addProperty("management.enabled", "false");
- _registry = new TestApplicationRegistry(new ServerConfiguration(config));
- ApplicationRegistry.initialise(_registry);
-
- _plugin = new TestPlugin();
- _registry.getSecurityManager().addHostPlugin(_plugin);
-
- //Now start up a test JMXManagedObjectRegistry directly
- XMLConfiguration jmxConfig = new XMLConfiguration();
- jmxConfig.addProperty(ServerConfiguration.MGMT_JMXPORT_REGISTRYSERVER, _registryPort + "");
- jmxConfig.addProperty(ServerConfiguration.MGMT_JMXPORT_CONNECTORSERVER, _connectorPort + "");
-
- _objectRegistry = new JMXManagedObjectRegistry(new ServerConfiguration(jmxConfig));
- new TestMBean(_objectRegistry);
- _objectRegistry.start();
- }
-
- public void tearDown() throws Exception
- {
- _objectRegistry.close();
- ApplicationRegistry.remove();
- super.tearDown();
- }
-
- public void testPrincipalInLogMessage() throws Throwable
- {
- Map<String, Object> environment = new HashMap<String, Object>();
- environment.put(JMXConnector.CREDENTIALS, new String[] { "admin", "admin" });
- String urlString = "service:jmx:rmi:///jndi/rmi://localhost:" + _registryPort + "/jmxrmi";
- JMXServiceURL url = new JMXServiceURL(urlString);
- JMXConnector jmxConnector = JMXConnectorFactory.connect(url, environment);
- MBeanServerConnection mbsc = jmxConnector.getMBeanServerConnection();
- ObjectName mbeanObject = new ObjectName("org.apache.qpid:type=TestMBean,name=test");
-
- CurrentActorRetriever mbean = MBeanServerInvocationHandler.newProxyInstance(mbsc,
- mbeanObject, CurrentActorRetriever.class, false);
- String actorLogMessage = mbean.getActorLogMessage();
-
- assertTrue("Unexpected log principal in security plugin", _plugin.getLogMessage().startsWith("[mng:admin"));
- assertTrue("Unexpected log principal in MBean", actorLogMessage.startsWith("[mng:admin"));
- }
-
- public static class TestMBean extends DefaultManagedObject implements CurrentActorRetriever
- {
-
- public TestMBean(ManagedObjectRegistry registry) throws JMException
- {
- super(CurrentActorRetriever.class, "TestMBean", registry);
- register();
- }
-
- @Override
- public String getObjectInstanceName()
- {
- return "test";
- }
-
- @Override
- public ManagedObject getParentObject()
- {
- return null;
- }
-
- @Override
- public String getActorLogMessage()
- {
- return CurrentActor.get().getLogMessage();
- }
-
- }
-
- public static interface CurrentActorRetriever
- {
- String getActorLogMessage();
- }
-
- public static class TestPlugin implements AccessControl
- {
- private String _logMessage;
-
- @Override
- public Result getDefault()
- {
- return Result.ALLOWED;
- }
-
- @Override
- public Result access(ObjectType objectType, Object instance)
- {
- return Result.ALLOWED;
- }
-
- @Override
- public Result authorise(Operation operation, ObjectType objectType, ObjectProperties properties)
- {
- // set thread name to work around logic in MangementActor
- Thread.currentThread().setName("RMI TCP Connection(1)-" + System.currentTimeMillis());
- _logMessage = CurrentActor.get().getLogMessage();
- return Result.ALLOWED;
- }
-
- public String getLogMessage()
- {
- return _logMessage;
- }
-
- }
-
-}
diff --git a/qpid/java/broker-plugins/management-jmx/src/test/java/org/apache/qpid/server/jmx/ManagementLogonLogoffReporterTest.java b/qpid/java/broker-plugins/management-jmx/src/test/java/org/apache/qpid/server/jmx/ManagementLogonLogoffReporterTest.java
new file mode 100644
index 0000000000..ba9c2cdaa5
--- /dev/null
+++ b/qpid/java/broker-plugins/management-jmx/src/test/java/org/apache/qpid/server/jmx/ManagementLogonLogoffReporterTest.java
@@ -0,0 +1,101 @@
+/*
+ * 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.qpid.server.jmx;
+
+import static javax.management.remote.JMXConnectionNotification.OPENED;
+import static javax.management.remote.JMXConnectionNotification.CLOSED;
+import static javax.management.remote.JMXConnectionNotification.FAILED;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyString;
+
+import javax.management.remote.JMXConnectionNotification;
+
+import org.apache.qpid.server.logging.LogActor;
+import org.apache.qpid.server.logging.RootMessageLogger;
+
+import junit.framework.TestCase;
+
+public class ManagementLogonLogoffReporterTest extends TestCase
+{
+ private static final String TEST_JMX_UNIQUE_CONNECTION_ID = "jmxconnectionid1 jmxuser,group";
+ private static final String TEST_USER = "jmxuser";
+
+ private ManagementLogonLogoffReporter _reporter;
+ private UsernameAccessor _usernameAccessor;
+ private RootMessageLogger _rootMessageLogger;
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ _usernameAccessor = mock(UsernameAccessor.class);
+ _rootMessageLogger = mock(RootMessageLogger.class);
+ // Enable messaging so we can valid the generated strings
+ when(_rootMessageLogger.isMessageEnabled(any(LogActor.class), anyString())).thenReturn(true);
+
+ _reporter = new ManagementLogonLogoffReporter(_rootMessageLogger, _usernameAccessor);
+ }
+
+ public void testOpenedNotification()
+ {
+ when(_usernameAccessor.getUsernameForConnectionId(TEST_JMX_UNIQUE_CONNECTION_ID)).thenReturn(TEST_USER);
+ JMXConnectionNotification openNotification = createMockNotification(TEST_JMX_UNIQUE_CONNECTION_ID, OPENED);
+
+ _reporter.handleNotification(openNotification, null);
+
+ verify(_rootMessageLogger).rawMessage("[main] MNG-1007 : Open : User jmxuser", "qpid.message.managementconsole.open");
+ }
+
+ public void testClosedNotification()
+ {
+ when(_usernameAccessor.getUsernameForConnectionId(TEST_JMX_UNIQUE_CONNECTION_ID)).thenReturn(TEST_USER);
+ JMXConnectionNotification closeNotification = createMockNotification(TEST_JMX_UNIQUE_CONNECTION_ID, CLOSED);
+
+ _reporter.handleNotification(closeNotification, null);
+
+ verify(_rootMessageLogger).rawMessage("[main] MNG-1008 : Close : User jmxuser", "qpid.message.managementconsole.close");
+ }
+
+ public void tesNotifiedForLogOnTypeEvents()
+ {
+ JMXConnectionNotification openNotification = createMockNotification(TEST_JMX_UNIQUE_CONNECTION_ID, OPENED);
+ JMXConnectionNotification closeNotification = createMockNotification(TEST_JMX_UNIQUE_CONNECTION_ID, CLOSED);
+ JMXConnectionNotification failedNotification = createMockNotification(TEST_JMX_UNIQUE_CONNECTION_ID, FAILED);
+
+ assertTrue(_reporter.isNotificationEnabled(openNotification));
+ assertTrue(_reporter.isNotificationEnabled(closeNotification));
+ assertTrue(_reporter.isNotificationEnabled(failedNotification));
+
+ JMXConnectionNotification otherNotification = createMockNotification(TEST_JMX_UNIQUE_CONNECTION_ID, "other");
+ assertFalse(_reporter.isNotificationEnabled(otherNotification));
+ }
+
+ private JMXConnectionNotification createMockNotification(String connectionId, String notificationType)
+ {
+ JMXConnectionNotification notification = mock(JMXConnectionNotification.class);
+ when(notification.getConnectionId()).thenReturn(connectionId);
+ when(notification.getType()).thenReturn(notificationType);
+ return notification;
+ }
+}
diff --git a/qpid/java/broker/etc/config.xml b/qpid/java/broker/etc/config.xml
deleted file mode 100644
index 4469186835..0000000000
--- a/qpid/java/broker/etc/config.xml
+++ /dev/null
@@ -1,119 +0,0 @@
-<?xml version="1.0" encoding="ISO-8859-1"?>
-<!--
- -
- - 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.
- -
- -->
-<broker>
- <prefix>${QPID_HOME}</prefix>
- <work>${QPID_WORK}</work>
- <conf>${prefix}/etc</conf>
-
- <connector>
- <!-- To enable SSL edit the keystorePath and keystorePassword
- and set enabled to true.
- To disable Non-SSL port set sslOnly to true -->
- <ssl>
- <enabled>false</enabled>
- <port>5671</port>
- <sslOnly>false</sslOnly>
- <keyStorePath>/path/to/keystore.ks</keyStorePath>
- <keyStorePassword>keystorepass</keyStorePassword>
- </ssl>
- <port>5672</port>
- <socketReceiveBuffer>262144</socketReceiveBuffer>
- <socketSendBuffer>262144</socketSendBuffer>
- </connector>
-
- <management>
- <enabled>true</enabled>
- <jmxport>
- <registryServer>8999</registryServer>
- <!--
- If unspecified, connectorServer defaults to 100 + registryServer port.
- <connectorServer>9099</connectorServer>
- -->
- </jmxport>
- <ssl>
- <enabled>false</enabled>
- <!-- Update below path to your keystore location. -->
- <keyStorePath>${conf}/qpid.keystore</keyStorePath>
- <keyStorePassword>password</keyStorePassword>
- </ssl>
- <http>
- <enabled>true</enabled>
- </http>
- <https>
- <enabled>false</enabled>
- </https>
- </management>
-
- <advanced>
- <framesize>65535</framesize>
- <locale>en_US</locale>
- </advanced>
-
- <security>
- <pd-auth-manager>
- <principal-database>
- <class>org.apache.qpid.server.security.auth.database.PlainPasswordFilePrincipalDatabase</class>
- <attributes>
- <attribute>
- <name>passwordFile</name>
- <value>${conf}/passwd</value>
- </attribute>
- </attributes>
- </principal-database>
- </pd-auth-manager>
-
- <!--
- <file-group-manager>
- <attributes>
- <attribute>
- <name>groupFile</name>
- <value>${conf}/groups</value>
- </attribute>
- </attributes>
- </file-group-manager>
- -->
-
- <!--
- ACL Example. This example illustrates securing both management and messaging.
- By default, all authenticated users have permissions to perform all actions
-
- <acl>${conf}/broker_example.acl</acl>
- -->
-
- <msg-auth>false</msg-auth>
- </security>
-
- <virtualhosts>${conf}/virtualhosts.xml</virtualhosts>
-
- <heartbeat>
- <delay>0</delay>
- <timeoutFactor>2.0</timeoutFactor>
- </heartbeat>
- <queue>
- <auto_register>true</auto_register>
- </queue>
-
- <status-updates>ON</status-updates>
-
-</broker>
-
-
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/AMQChannel.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/AMQChannel.java
index a05b53f7d4..ab4ca81d05 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/AMQChannel.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/AMQChannel.java
@@ -54,6 +54,7 @@ import org.apache.qpid.protocol.AMQConstant;
import org.apache.qpid.server.TransactionTimeoutHelper.CloseAction;
import org.apache.qpid.server.ack.UnacknowledgedMessageMap;
import org.apache.qpid.server.ack.UnacknowledgedMessageMapImpl;
+import org.apache.qpid.server.configuration.BrokerProperties;
import org.apache.qpid.server.exchange.Exchange;
import org.apache.qpid.server.flow.FlowCreditManager;
import org.apache.qpid.server.flow.Pre0_10CreditManager;
@@ -78,7 +79,6 @@ import org.apache.qpid.server.queue.BaseQueue;
import org.apache.qpid.server.queue.InboundMessageAdapter;
import org.apache.qpid.server.queue.IncomingMessage;
import org.apache.qpid.server.queue.QueueEntry;
-import org.apache.qpid.server.registry.ApplicationRegistry;
import org.apache.qpid.server.store.MessageStore;
import org.apache.qpid.server.store.StoreFuture;
import org.apache.qpid.server.store.StoredMessage;
@@ -99,9 +99,8 @@ public class AMQChannel implements AMQSessionModel, AsyncAutoCommitTransaction.F
private static final Logger _logger = Logger.getLogger(AMQChannel.class);
- private static final boolean MSG_AUTH =
- ApplicationRegistry.getInstance().getConfiguration().getMsgAuth();
-
+ //TODO use Broker property to configure message authorization requirements
+ private boolean _messageAuthorizationRequired = Boolean.getBoolean(BrokerProperties.PROPERTY_MSG_AUTH);
private final int _channelId;
@@ -1121,7 +1120,7 @@ public class AMQChannel implements AMQSessionModel, AsyncAutoCommitTransaction.F
? ((BasicContentHeaderProperties) header.getProperties()).getUserId()
: null;
- return (!MSG_AUTH || _session.getAuthorizedPrincipal().getName().equals(userID == null? "" : userID.toString()));
+ return (!_messageAuthorizationRequired || _session.getAuthorizedPrincipal().getName().equals(userID == null? "" : userID.toString()));
}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/Broker.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/Broker.java
index 3848c97a99..e4a95363ef 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/Broker.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/Broker.java
@@ -23,37 +23,30 @@ package org.apache.qpid.server;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
-import java.net.InetAddress;
-import java.net.InetSocketAddress;
-import java.util.*;
-import javax.net.ssl.SSLContext;
+import java.util.List;
+import java.util.Properties;
+import java.util.Set;
+
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
import org.apache.qpid.framing.AMQShortString;
-import org.apache.qpid.server.configuration.ServerConfiguration;
-import org.apache.qpid.server.configuration.ServerNetworkTransportConfiguration;
+import org.apache.qpid.server.configuration.BrokerProperties;
+import org.apache.qpid.server.configuration.ConfigurationEntryStore;
+import org.apache.qpid.server.configuration.BrokerConfigurationStoreCreator;
import org.apache.qpid.server.logging.SystemOutMessageLogger;
import org.apache.qpid.server.logging.actors.BrokerActor;
import org.apache.qpid.server.logging.actors.CurrentActor;
-import org.apache.qpid.server.logging.actors.GenericActor;
import org.apache.qpid.server.logging.log4j.LoggingManagementFacade;
import org.apache.qpid.server.logging.messages.BrokerMessages;
-import org.apache.qpid.server.protocol.AmqpProtocolVersion;
-import org.apache.qpid.server.protocol.MultiVersionProtocolEngineFactory;
import org.apache.qpid.server.registry.ApplicationRegistry;
-import org.apache.qpid.server.transport.QpidAcceptor;
-import org.apache.qpid.ssl.SSLContextFactory;
-import org.apache.qpid.transport.NetworkTransportConfiguration;
-import org.apache.qpid.transport.network.IncomingNetworkTransport;
-import org.apache.qpid.transport.network.Transport;
-
-import static org.apache.qpid.transport.ConnectionSettings.WILDCARD_ADDRESS;
+import org.apache.qpid.server.registry.IApplicationRegistry;
public class Broker
{
private static final Logger LOGGER = Logger.getLogger(Broker.class);
private volatile Thread _shutdownHookThread;
+ private volatile IApplicationRegistry _applicationRegistry;
protected static class InitException extends RuntimeException
{
@@ -75,7 +68,10 @@ public class Broker
{
try
{
- ApplicationRegistry.remove();
+ if (_applicationRegistry != null)
+ {
+ _applicationRegistry.close();
+ }
}
finally
{
@@ -112,260 +108,49 @@ public class Broker
private void startupImpl(final BrokerOptions options) throws Exception
{
- final String qpidHome = options.getQpidHome();
- final File configFile = getConfigFile(options.getConfigFile(),
- BrokerOptions.DEFAULT_CONFIG_FILE, qpidHome, true);
-
- CurrentActor.get().message(BrokerMessages.CONFIG(configFile.getAbsolutePath()));
+ final String qpidHome = System.getProperty(BrokerProperties.PROPERTY_QPID_HOME);
+ String storeLocation = options.getConfigurationStoreLocation();
+ String storeType = options.getConfigurationStoreType();
- File logConfigFile = getConfigFile(options.getLogConfigFile(),
- BrokerOptions.DEFAULT_LOG_CONFIG_FILE, qpidHome, false);
-
- configureLogging(logConfigFile, options.getLogWatchFrequency());
-
- ServerConfiguration serverConfig = new ServerConfiguration(configFile);
- ApplicationRegistry config = new ApplicationRegistry(serverConfig);
- if (options.getQpidWork() != null)
- {
- serverConfig.setQpidWork(options.getQpidWork());
- }
- if (options.getQpidHome() != null)
+ if (storeLocation == null)
{
- serverConfig.setQpidHome(options.getQpidHome());
+ String qpidWork = System.getProperty(BrokerProperties.PROPERTY_QPID_WORK);
+ if (qpidWork == null)
+ {
+ qpidWork = new File(System.getProperty("user.dir"), "work").getAbsolutePath();
+ }
+ storeLocation = new File(qpidWork, BrokerOptions.DEFAULT_CONFIG_FILE + "." + storeType).getAbsolutePath();
}
- updateManagementPorts(serverConfig, options.getJmxPortRegistryServer(), options.getJmxPortConnectorServer());
- ApplicationRegistry.initialise(config);
+ CurrentActor.get().message(BrokerMessages.CONFIG(storeLocation));
- // We have already loaded the BrokerMessages class by this point so we
- // need to refresh the locale setting incase we had a different value in
- // the configuration.
- BrokerMessages.reload();
+ File logConfigFile = getConfigFile(options.getLogConfigFile(), BrokerOptions.DEFAULT_LOG_CONFIG_FILE, qpidHome, false);
+ configureLogging(logConfigFile, options.getLogWatchFrequency());
- // AR.initialise() sets and removes its own actor so we now need to set the actor
- // for the remainder of the startup, and the default actor if the stack is empty
- CurrentActor.set(new BrokerActor(config.getCompositeStartupMessageLogger()));
- CurrentActor.setDefault(new BrokerActor(config.getRootMessageLogger()));
- GenericActor.setDefaultMessageLogger(config.getRootMessageLogger());
+ BrokerConfigurationStoreCreator storeCreator = new BrokerConfigurationStoreCreator();
+ ConfigurationEntryStore store = storeCreator.createStore(storeLocation, storeType, options);
+ _applicationRegistry = new ApplicationRegistry(store);
try
{
- Set<Integer> ports = new HashSet<Integer>(options.getPorts());
- if(ports.isEmpty())
- {
- parsePortList(ports, serverConfig.getPorts());
- }
-
- Set<Integer> sslPorts = new HashSet<Integer>(options.getSSLPorts());
- if(sslPorts.isEmpty())
- {
- parsePortList(sslPorts, serverConfig.getSSLPorts());
- }
-
- //1-0 excludes and includes
- Set<Integer> exclude_1_0 = new HashSet<Integer>(options.getExcludedPorts(ProtocolExclusion.v1_0));
- if(exclude_1_0.isEmpty())
- {
- parsePortList(exclude_1_0, serverConfig.getPortExclude10());
- }
-
- Set<Integer> include_1_0 = new HashSet<Integer>(options.getIncludedPorts(ProtocolInclusion.v1_0));
- if(include_1_0.isEmpty())
- {
- parsePortList(include_1_0, serverConfig.getPortInclude10());
- }
-
- //0-10 excludes and includes
- Set<Integer> exclude_0_10 = new HashSet<Integer>(options.getExcludedPorts(ProtocolExclusion.v0_10));
- if(exclude_0_10.isEmpty())
- {
- parsePortList(exclude_0_10, serverConfig.getPortExclude010());
- }
-
- Set<Integer> include_0_10 = new HashSet<Integer>(options.getIncludedPorts(ProtocolInclusion.v0_10));
- if(include_0_10.isEmpty())
- {
- parsePortList(include_0_10, serverConfig.getPortInclude010());
- }
-
- //0-9-1 excludes and includes
- Set<Integer> exclude_0_9_1 = new HashSet<Integer>(options.getExcludedPorts(ProtocolExclusion.v0_9_1));
- if(exclude_0_9_1.isEmpty())
- {
- parsePortList(exclude_0_9_1, serverConfig.getPortExclude091());
- }
-
- Set<Integer> include_0_9_1 = new HashSet<Integer>(options.getIncludedPorts(ProtocolInclusion.v0_9_1));
- if(include_0_9_1.isEmpty())
- {
- parsePortList(include_0_9_1, serverConfig.getPortInclude091());
- }
-
- //0-9 excludes and includes
- Set<Integer> exclude_0_9 = new HashSet<Integer>(options.getExcludedPorts(ProtocolExclusion.v0_9));
- if(exclude_0_9.isEmpty())
- {
- parsePortList(exclude_0_9, serverConfig.getPortExclude09());
- }
-
- Set<Integer> include_0_9 = new HashSet<Integer>(options.getIncludedPorts(ProtocolInclusion.v0_9));
- if(include_0_9.isEmpty())
- {
- parsePortList(include_0_9, serverConfig.getPortInclude09());
- }
-
- //0-8 excludes and includes
- Set<Integer> exclude_0_8 = new HashSet<Integer>(options.getExcludedPorts(ProtocolExclusion.v0_8));
- if(exclude_0_8.isEmpty())
- {
- parsePortList(exclude_0_8, serverConfig.getPortExclude08());
- }
-
- Set<Integer> include_0_8 = new HashSet<Integer>(options.getIncludedPorts(ProtocolInclusion.v0_8));
- if(include_0_8.isEmpty())
- {
- parsePortList(include_0_8, serverConfig.getPortInclude08());
- }
-
- String bindAddr = options.getBind();
- if (bindAddr == null)
- {
- bindAddr = serverConfig.getBind();
- }
-
- InetAddress bindAddress;
- if (bindAddr.equals(WILDCARD_ADDRESS))
- {
- bindAddress = null;
- }
- else
+ _applicationRegistry.initialise();
+ }
+ catch(Exception e)
+ {
+ try
{
- bindAddress = InetAddress.getByName(bindAddr);
+ _applicationRegistry.close();
}
-
- final AmqpProtocolVersion defaultSupportedProtocolReply = serverConfig.getDefaultSupportedProtocolReply();
-
- if (!serverConfig.getSSLOnly())
+ catch(Exception ce)
{
- for(int port : ports)
- {
- final InetSocketAddress inetSocketAddress = new InetSocketAddress(bindAddress, port);
-
- final Set<AmqpProtocolVersion> supported =
- getSupportedVersions(port, exclude_1_0, exclude_0_10, exclude_0_9_1, exclude_0_9, exclude_0_8,
- include_1_0, include_0_10, include_0_9_1, include_0_9, include_0_8,serverConfig);
-
- final NetworkTransportConfiguration settings =
- new ServerNetworkTransportConfiguration(serverConfig, inetSocketAddress, Transport.TCP);
-
- final IncomingNetworkTransport transport = Transport.getIncomingTransportInstance();
- final MultiVersionProtocolEngineFactory protocolEngineFactory =
- new MultiVersionProtocolEngineFactory(supported, defaultSupportedProtocolReply);
-
- transport.accept(settings, protocolEngineFactory, null);
-
- ApplicationRegistry.getInstance().addAcceptor(inetSocketAddress,
- new QpidAcceptor(transport,QpidAcceptor.Transport.TCP, supported));
- CurrentActor.get().message(BrokerMessages.LISTENING("TCP", port));
- }
+ LOGGER.debug("An error occured when closing the registry following initialization failure", ce);
}
-
- if (serverConfig.getEnableSSL())
- {
- final String keystorePath = serverConfig.getConnectorKeyStorePath();
- final String keystorePassword = serverConfig.getConnectorKeyStorePassword();
- final String keystoreType = serverConfig.getConnectorKeyStoreType();
- final String keyManagerFactoryAlgorithm = serverConfig.getConnectorKeyManagerFactoryAlgorithm();
- final SSLContext sslContext;
- if(serverConfig.getConnectorTrustStorePath()!=null)
- {
- sslContext = SSLContextFactory.buildClientContext(serverConfig.getConnectorTrustStorePath(),
- serverConfig.getConnectorTrustStorePassword(),
- serverConfig.getConnectorTrustStoreType(),
- serverConfig.getConnectorTrustManagerFactoryAlgorithm(),
- keystorePath,
- keystorePassword, keystoreType, keyManagerFactoryAlgorithm,
- serverConfig.getCertAlias());
- }
- else
- {
- sslContext = SSLContextFactory.buildServerContext(keystorePath, keystorePassword, keystoreType, keyManagerFactoryAlgorithm);
- }
-
- for(int sslPort : sslPorts)
- {
- final InetSocketAddress inetSocketAddress = new InetSocketAddress(bindAddress, sslPort);
-
- final Set<AmqpProtocolVersion> supported =
- getSupportedVersions(sslPort, exclude_1_0, exclude_0_10, exclude_0_9_1, exclude_0_9, exclude_0_8,
- include_1_0, include_0_10, include_0_9_1, include_0_9, include_0_8, serverConfig);
- final NetworkTransportConfiguration settings =
- new ServerNetworkTransportConfiguration(serverConfig, inetSocketAddress, Transport.TCP);
-
- final IncomingNetworkTransport transport = Transport.getIncomingTransportInstance();
- final MultiVersionProtocolEngineFactory protocolEngineFactory =
- new MultiVersionProtocolEngineFactory(supported, defaultSupportedProtocolReply);
-
- transport.accept(settings, protocolEngineFactory, sslContext);
-
- ApplicationRegistry.getInstance().addAcceptor(inetSocketAddress,
- new QpidAcceptor(transport,QpidAcceptor.Transport.SSL, supported));
- CurrentActor.get().message(BrokerMessages.LISTENING("TCP/SSL", sslPort));
- }
- }
-
- CurrentActor.get().message(BrokerMessages.READY());
- }
- finally
- {
- // Startup is complete so remove the AR initialised Startup actor
- CurrentActor.remove();
+ throw e;
}
- }
-
- private static Set<AmqpProtocolVersion> getSupportedVersions(final int port,
- final Set<Integer> exclude_1_0,
- final Set<Integer> exclude_0_10,
- final Set<Integer> exclude_0_9_1,
- final Set<Integer> exclude_0_9,
- final Set<Integer> exclude_0_8,
- final Set<Integer> include_1_0,
- final Set<Integer> include_0_10,
- final Set<Integer> include_0_9_1,
- final Set<Integer> include_0_9,
- final Set<Integer> include_0_8,
- final ServerConfiguration serverConfig)
- {
- final EnumSet<AmqpProtocolVersion> supported = EnumSet.allOf(AmqpProtocolVersion.class);
- if((exclude_1_0.contains(port) || !serverConfig.isAmqp10enabled()) && !include_1_0.contains(port))
- {
- supported.remove(AmqpProtocolVersion.v1_0_0);
- }
-
- if((exclude_0_10.contains(port) || !serverConfig.isAmqp010enabled()) && !include_0_10.contains(port))
- {
- supported.remove(AmqpProtocolVersion.v0_10);
- }
-
- if((exclude_0_9_1.contains(port) || !serverConfig.isAmqp091enabled()) && !include_0_9_1.contains(port))
- {
- supported.remove(AmqpProtocolVersion.v0_9_1);
- }
-
- if((exclude_0_9.contains(port) || !serverConfig.isAmqp09enabled()) && !include_0_9.contains(port))
- {
- supported.remove(AmqpProtocolVersion.v0_9);
- }
-
- if((exclude_0_8.contains(port) || !serverConfig.isAmqp08enabled()) && !include_0_8.contains(port))
- {
- supported.remove(AmqpProtocolVersion.v0_8);
- }
-
- return supported;
}
+
private File getConfigFile(final String fileName,
final String defaultFileName,
final String qpidHome, boolean throwOnFileNotFound) throws InitException
@@ -386,7 +171,7 @@ public class Broker
if (qpidHome == null)
{
- error = error + "\nNote: " + BrokerOptions.QPID_HOME + " is not set.";
+ error = error + "\nNote: " + BrokerProperties.PROPERTY_QPID_HOME + " is not set.";
}
throw new InitException(error, null);
@@ -413,37 +198,6 @@ public class Broker
}
}
- /**
- * Update the configuration data with the management port.
- * @param configuration
- * @param registryServerPort The string from the command line
- */
- private void updateManagementPorts(ServerConfiguration configuration, Integer registryServerPort, Integer connectorServerPort)
- {
- if (registryServerPort != null)
- {
- try
- {
- configuration.setJMXPortRegistryServer(registryServerPort);
- }
- catch (NumberFormatException e)
- {
- throw new InitException("Invalid management (registry server) port: " + registryServerPort, null);
- }
- }
- if (connectorServerPort != null)
- {
- try
- {
- configuration.setJMXPortConnectorServer(connectorServerPort);
- }
- catch (NumberFormatException e)
- {
- throw new InitException("Invalid management (connector server) port: " + connectorServerPort, null);
- }
- }
- }
-
private void configureLogging(File logConfigFile, int logWatchTime) throws InitException, IOException
{
if (logConfigFile.exists() && logConfigFile.canRead())
@@ -545,6 +299,15 @@ public class Broker
LOGGER.debug("Skipping shutdown hook removal as there either isnt one, or we are it.");
}
}
+ /**
+ * Workaround that prevents AMQShortStrings cache from being left in the thread local. This is important
+ * when embedding the Broker in containers where the starting thread may not belong to Qpid.
+ * The long term solution here is to stop our use of AMQShortString outside the AMQP transport layer.
+ */
+ private void clearAMQShortStringCache()
+ {
+ AMQShortString.clearLocalCache();
+ }
private class ShutdownService implements Runnable
{
@@ -555,13 +318,4 @@ public class Broker
}
}
- /**
- * Workaround that prevents AMQShortStrings cache from being left in the thread local. This is important
- * when embedding the Broker in containers where the starting thread may not belong to Qpid.
- * The long term solution here is to stop our use of AMQShortString outside the AMQP transport layer.
- */
- private void clearAMQShortStringCache()
- {
- AMQShortString.clearLocalCache();
- }
}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/BrokerOptions.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/BrokerOptions.java
index 1a00467c3d..f85cf202a1 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/BrokerOptions.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/BrokerOptions.java
@@ -20,63 +20,17 @@
*/
package org.apache.qpid.server;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
public class BrokerOptions
{
- public static final String DEFAULT_CONFIG_FILE = "etc/config.xml";
+ public static final String DEFAULT_STORE_TYPE = "json";
+ public static final String DEFAULT_CONFIG_FILE = "config";
public static final String DEFAULT_LOG_CONFIG_FILE = "etc/log4j.xml";
- public static final String QPID_HOME = "QPID_HOME";
- public static final String QPID_WORK = "QPID_WORK";
-
- private final Set<Integer> _ports = new HashSet<Integer>();
- private final Set<Integer> _sslPorts = new HashSet<Integer>();
- private final Map<ProtocolExclusion,Set<Integer>> _exclusionMap = new HashMap<ProtocolExclusion, Set<Integer>>();
- private final Map<ProtocolInclusion,Set<Integer>> _inclusionMap = new HashMap<ProtocolInclusion, Set<Integer>>();
- private String _configFile;
private String _logConfigFile;
- private String _bind;
- private Integer _jmxPortRegistryServer;
- private Integer _jmxPortConnectorServer;
-
private Integer _logWatchFrequency = 0;
- private String _qpidWorkFolder;
- private String _qpidHomeFolder;
- public void addPort(final int port)
- {
- _ports.add(port);
- }
-
- public void addSSLPort(final int sslPort)
- {
- _sslPorts.add(sslPort);
- }
-
- public Set<Integer> getPorts()
- {
- return Collections.unmodifiableSet(_ports);
- }
-
- public Set<Integer> getSSLPorts()
- {
- return Collections.unmodifiableSet(_sslPorts);
- }
-
- public String getConfigFile()
- {
- return _configFile;
- }
-
- public void setConfigFile(final String configFile)
- {
- _configFile = configFile;
- }
+ private String _configurationStoreLocation;
+ private String _configurationStoreType = DEFAULT_STORE_TYPE;
public String getLogConfigFile()
{
@@ -88,57 +42,6 @@ public class BrokerOptions
_logConfigFile = logConfigFile;
}
- public Integer getJmxPortRegistryServer()
- {
- return _jmxPortRegistryServer;
- }
-
- public void setJmxPortRegistryServer(final int jmxPortRegistryServer)
- {
- _jmxPortRegistryServer = jmxPortRegistryServer;
- }
-
- public Integer getJmxPortConnectorServer()
- {
- return _jmxPortConnectorServer;
- }
-
- public void setJmxPortConnectorServer(final int jmxPortConnectorServer)
- {
- _jmxPortConnectorServer = jmxPortConnectorServer;
- }
- public String getQpidHome()
- {
- return _qpidHomeFolder == null? System.getProperty(QPID_HOME): _qpidHomeFolder;
- }
-
- public Set<Integer> getExcludedPorts(final ProtocolExclusion excludeProtocol)
- {
- final Set<Integer> excludedPorts = _exclusionMap.get(excludeProtocol);
- return excludedPorts == null ? Collections.<Integer>emptySet() : excludedPorts;
- }
-
- public void addExcludedPort(final ProtocolExclusion excludeProtocol, final int port)
- {
- if (!_exclusionMap.containsKey(excludeProtocol))
- {
- _exclusionMap.put(excludeProtocol, new HashSet<Integer>());
- }
-
- Set<Integer> ports = _exclusionMap.get(excludeProtocol);
- ports.add(port);
- }
-
- public String getBind()
- {
- return _bind;
- }
-
- public void setBind(final String bind)
- {
- _bind = bind;
- }
-
public int getLogWatchFrequency()
{
return _logWatchFrequency;
@@ -153,35 +56,24 @@ public class BrokerOptions
_logWatchFrequency = logWatchFrequency;
}
- public Set<Integer> getIncludedPorts(final ProtocolInclusion includeProtocol)
+ public String getConfigurationStoreLocation()
{
- final Set<Integer> includedPorts = _inclusionMap.get(includeProtocol);
- return includedPorts == null ? Collections.<Integer>emptySet() : includedPorts;
+ return _configurationStoreLocation;
}
- public void addIncludedPort(final ProtocolInclusion includeProtocol, final int port)
+ public void setConfigurationStoreLocation(String cofigurationStore)
{
- if (!_inclusionMap.containsKey(includeProtocol))
- {
- _inclusionMap.put(includeProtocol, new HashSet<Integer>());
- }
-
- Set<Integer> ports = _inclusionMap.get(includeProtocol);
- ports.add(port);
+ _configurationStoreLocation = cofigurationStore;
}
- public String getQpidWork()
+ public String getConfigurationStoreType()
{
- return _qpidWorkFolder;
+ return _configurationStoreType;
}
- public void setQpidWork(String qpidWorkFolder)
+ public void setConfigurationStoreType(String cofigurationStoreType)
{
- _qpidWorkFolder = qpidWorkFolder;
+ _configurationStoreType = cofigurationStoreType;
}
- public void setQpidHome(String qpidHomeFolder)
- {
- _qpidHomeFolder = qpidHomeFolder;
- }
} \ No newline at end of file
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/Main.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/Main.java
index 9fe7a6619f..d834dd0b1e 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/Main.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/Main.java
@@ -30,9 +30,6 @@ import org.apache.commons.cli.PosixParser;
import org.apache.log4j.Logger;
import org.apache.qpid.common.QpidProperties;
import org.apache.qpid.framing.ProtocolVersion;
-import org.apache.qpid.server.Broker.InitException;
-import org.apache.qpid.server.registry.ApplicationRegistry;
-
/**
* Main entry point for AMQPD.
@@ -45,86 +42,11 @@ public class Main
private static final Option OPTION_VERSION = new Option("v", "version", false, "print the version information and exit");
- private static final Option OPTION_CONFIG_FILE =
- OptionBuilder.withArgName("file").hasArg().withDescription("use given configuration file").withLongOpt("config")
- .create("c");
-
- private static final Option OPTION_PORT =
- OptionBuilder.withArgName("port").hasArg()
- .withDescription("listen on the specified port. Overrides any value in the config file")
- .withLongOpt("port").create("p");
-
- private static final Option OPTION_SSLPORT =
- OptionBuilder.withArgName("port").hasArg()
- .withDescription("SSL port. Overrides any value in the config file")
- .withLongOpt("sslport").create("s");
-
-
- private static final Option OPTION_EXCLUDE_1_0 =
- OptionBuilder.withArgName("port").hasArg()
- .withDescription("when listening on the specified port do not accept AMQP1-0 connections. The specified port must be one specified on the command line")
- .withLongOpt("exclude-1-0").create();
-
- private static final Option OPTION_EXCLUDE_0_10 =
- OptionBuilder.withArgName("port").hasArg()
- .withDescription("when listening on the specified port do not accept AMQP0-10 connections. The specified port must be one specified on the command line")
- .withLongOpt("exclude-0-10").create();
-
- private static final Option OPTION_EXCLUDE_0_9_1 =
- OptionBuilder.withArgName("port").hasArg()
- .withDescription("when listening on the specified port do not accept AMQP0-9-1 connections. The specified port must be one specified on the command line")
- .withLongOpt("exclude-0-9-1").create();
-
- private static final Option OPTION_EXCLUDE_0_9 =
- OptionBuilder.withArgName("port").hasArg()
- .withDescription("when listening on the specified port do not accept AMQP0-9 connections. The specified port must be one specified on the command line")
- .withLongOpt("exclude-0-9").create();
-
- private static final Option OPTION_EXCLUDE_0_8 =
- OptionBuilder.withArgName("port").hasArg()
- .withDescription("when listening on the specified port do not accept AMQP0-8 connections. The specified port must be one specified on the command line")
- .withLongOpt("exclude-0-8").create();
-
- private static final Option OPTION_INCLUDE_1_0 =
- OptionBuilder.withArgName("port").hasArg()
- .withDescription("accept AMQP1-0 connections on this port, overriding configuration to the contrary. The specified port must be one specified on the command line")
- .withLongOpt("include-1-0").create();
+ private static final Option OPTION_CONFIGURATION_STORE_PATH = OptionBuilder.withArgName("path").hasArg()
+ .withDescription("use given configuration store location").withLongOpt("store-path").create("sp");
-private static final Option OPTION_INCLUDE_0_10 =
- OptionBuilder.withArgName("port").hasArg()
- .withDescription("accept AMQP0-10 connections on this port, overriding configuration to the contrary. The specified port must be one specified on the command line")
- .withLongOpt("include-0-10").create();
-
-private static final Option OPTION_INCLUDE_0_9_1 =
- OptionBuilder.withArgName("port").hasArg()
- .withDescription("accept AMQP0-9-1 connections on this port, overriding configuration to the contrary. The specified port must be one specified on the command line")
- .withLongOpt("include-0-9-1").create();
-
-private static final Option OPTION_INCLUDE_0_9 =
- OptionBuilder.withArgName("port").hasArg()
- .withDescription("accept AMQP0-9 connections on this port, overriding configuration to the contrary. The specified port must be one specified on the command line")
- .withLongOpt("include-0-9").create();
-
-private static final Option OPTION_INCLUDE_0_8 =
- OptionBuilder.withArgName("port").hasArg()
- .withDescription("accept AMQP0-8 connections on this port, overriding configuration to the contrary. The specified port must be one specified on the command line")
- .withLongOpt("include-0-8").create();
-
-
- private static final Option OPTION_JMX_PORT_REGISTRY_SERVER =
- OptionBuilder.withArgName("port").hasArg()
- .withDescription("listen on the specified management (registry server) port. Overrides any value in the config file")
- .withLongOpt("jmxregistryport").create("m");
-
- private static final Option OPTION_JMX_PORT_CONNECTOR_SERVER =
- OptionBuilder.withArgName("port").hasArg()
- .withDescription("listen on the specified management (connector server) port. Overrides any value in the config file")
- .withLongOpt("jmxconnectorport").create();
-
- private static final Option OPTION_BIND =
- OptionBuilder.withArgName("address").hasArg()
- .withDescription("bind to the specified address. Overrides any value in the config file")
- .withLongOpt("bind").create("b");
+ private static final Option OPTION_CONFIGURATION_STORE_TYPE = OptionBuilder.withArgName("type").hasArg()
+ .withDescription("use given store type").withLongOpt("store-type").create("st");
private static final Option OPTION_LOG_CONFIG_FILE =
OptionBuilder.withArgName("file").hasArg()
@@ -143,25 +65,10 @@ private static final Option OPTION_INCLUDE_0_8 =
{
OPTIONS.addOption(OPTION_HELP);
OPTIONS.addOption(OPTION_VERSION);
- OPTIONS.addOption(OPTION_CONFIG_FILE);
+ OPTIONS.addOption(OPTION_CONFIGURATION_STORE_PATH);
+ OPTIONS.addOption(OPTION_CONFIGURATION_STORE_TYPE);
OPTIONS.addOption(OPTION_LOG_CONFIG_FILE);
OPTIONS.addOption(OPTION_LOG_WATCH);
- OPTIONS.addOption(OPTION_PORT);
- OPTIONS.addOption(OPTION_SSLPORT);
- OPTIONS.addOption(OPTION_EXCLUDE_1_0);
- OPTIONS.addOption(OPTION_EXCLUDE_0_10);
- OPTIONS.addOption(OPTION_EXCLUDE_0_9_1);
- OPTIONS.addOption(OPTION_EXCLUDE_0_9);
- OPTIONS.addOption(OPTION_EXCLUDE_0_8);
- OPTIONS.addOption(OPTION_INCLUDE_1_0);
- OPTIONS.addOption(OPTION_INCLUDE_0_10);
- OPTIONS.addOption(OPTION_INCLUDE_0_9_1);
- OPTIONS.addOption(OPTION_INCLUDE_0_9);
- OPTIONS.addOption(OPTION_INCLUDE_0_8);
- OPTIONS.addOption(OPTION_BIND);
-
- OPTIONS.addOption(OPTION_JMX_PORT_REGISTRY_SERVER);
- OPTIONS.addOption(OPTION_JMX_PORT_CONNECTOR_SERVER);
}
protected CommandLine _commandLine;
@@ -243,10 +150,15 @@ private static final Option OPTION_INCLUDE_0_8 =
else
{
BrokerOptions options = new BrokerOptions();
- String configFile = _commandLine.getOptionValue(OPTION_CONFIG_FILE.getOpt());
- if(configFile != null)
+ String configurationStore = _commandLine.getOptionValue(OPTION_CONFIGURATION_STORE_PATH.getOpt());
+ if (configurationStore != null)
+ {
+ options.setConfigurationStoreLocation(configurationStore);
+ }
+ String configurationStoreType = _commandLine.getOptionValue(OPTION_CONFIGURATION_STORE_TYPE.getOpt());
+ if (configurationStoreType != null)
{
- options.setConfigFile(configFile);
+ options.setConfigurationStoreType(configurationStoreType);
}
String logWatchConfig = _commandLine.getOptionValue(OPTION_LOG_WATCH.getOpt());
@@ -261,52 +173,6 @@ private static final Option OPTION_INCLUDE_0_8 =
options.setLogConfigFile(logConfig);
}
- String jmxPortRegistryServer = _commandLine.getOptionValue(OPTION_JMX_PORT_REGISTRY_SERVER.getOpt());
- if(jmxPortRegistryServer != null)
- {
- options.setJmxPortRegistryServer(Integer.parseInt(jmxPortRegistryServer));
- }
-
- String jmxPortConnectorServer = _commandLine.getOptionValue(OPTION_JMX_PORT_CONNECTOR_SERVER.getLongOpt());
- if(jmxPortConnectorServer != null)
- {
- options.setJmxPortConnectorServer(Integer.parseInt(jmxPortConnectorServer));
- }
-
- String bindAddr = _commandLine.getOptionValue(OPTION_BIND.getOpt());
- if (bindAddr != null)
- {
- options.setBind(bindAddr);
- }
-
- String[] portStr = _commandLine.getOptionValues(OPTION_PORT.getOpt());
- if(portStr != null)
- {
- parsePortArray(options, portStr, false);
- for(ProtocolExclusion pe : ProtocolExclusion.values())
- {
- parsePortArray(options, _commandLine.getOptionValues(pe.getExcludeName()), pe);
- }
- for(ProtocolInclusion pe : ProtocolInclusion.values())
- {
- parseProtocolInclusions(options, _commandLine.getOptionValues(pe.getIncludeName()), pe);
- }
- }
-
- String[] sslPortStr = _commandLine.getOptionValues(OPTION_SSLPORT.getOpt());
- if(sslPortStr != null)
- {
- parsePortArray(options, sslPortStr, true);
- for(ProtocolExclusion pe : ProtocolExclusion.values())
- {
- parsePortArray(options, _commandLine.getOptionValues(pe.getExcludeName()), pe);
- }
- for(ProtocolInclusion pe : ProtocolInclusion.values())
- {
- parseProtocolInclusions(options, _commandLine.getOptionValues(pe.getIncludeName()), pe);
- }
- }
-
setExceptionHandler();
startBroker(options);
@@ -389,72 +255,7 @@ private static final Option OPTION_INCLUDE_0_8 =
protected void shutdown(final int status)
{
- ApplicationRegistry.remove();
System.exit(status);
}
- private static void parsePortArray(final BrokerOptions options,final Object[] ports,
- final boolean ssl) throws InitException
- {
- if(ports != null)
- {
- for(int i = 0; i < ports.length; i++)
- {
- try
- {
- if(ssl)
- {
- options.addSSLPort(Integer.parseInt(String.valueOf(ports[i])));
- }
- else
- {
- options.addPort(Integer.parseInt(String.valueOf(ports[i])));
- }
- }
- catch (NumberFormatException e)
- {
- throw new InitException("Invalid port: " + ports[i], e);
- }
- }
- }
- }
-
- private static void parsePortArray(final BrokerOptions options, final Object[] ports,
- final ProtocolExclusion excludedProtocol) throws InitException
- {
- if(ports != null)
- {
- for(int i = 0; i < ports.length; i++)
- {
- try
- {
- options.addExcludedPort(excludedProtocol,
- Integer.parseInt(String.valueOf(ports[i])));
- }
- catch (NumberFormatException e)
- {
- throw new InitException("Invalid port for exclusion: " + ports[i], e);
- }
- }
- }
- }
-
- private static void parseProtocolInclusions(final BrokerOptions options, final Object[] ports,
- final ProtocolInclusion includedProtocol) throws InitException
- {
- if(ports != null)
- {
- for(int i = 0; i < ports.length; i++)
- {
- try
- {
- options.addIncludedPort(includedProtocol, Integer.parseInt(String.valueOf(ports[i])));
- }
- catch (NumberFormatException e)
- {
- throw new InitException("Invalid port for inclusion: " + ports[i], e);
- }
- }
- }
- }
}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/ProtocolExclusion.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/ProtocolExclusion.java
deleted file mode 100644
index fe6e32173f..0000000000
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/ProtocolExclusion.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- *
- * 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.qpid.server;
-
-import java.util.HashMap;
-import java.util.Map;
-
-public enum ProtocolExclusion
-{
- v0_8("exclude-0-8","--exclude-0-8"),
- v0_9("exclude-0-9", "--exclude-0-9"),
- v0_9_1("exclude-0-9-1", "--exclude-0-9-1"),
- v0_10("exclude-0-10", "--exclude-0-10"),
- v1_0("exclude-1-0", "--exclude-1-0");
-
- private static final Map<String, ProtocolExclusion> MAP = new HashMap<String,ProtocolExclusion>();
-
- static
- {
- for(ProtocolExclusion pe : ProtocolExclusion.values())
- {
- MAP.put(pe.getArg(), pe);
- }
- }
-
- private String _arg;
- private String _excludeName;
-
- private ProtocolExclusion(final String excludeName, final String arg)
- {
- _excludeName = excludeName;
- _arg = arg;
- }
-
- public String getArg()
- {
- return _arg;
- }
-
- public String getExcludeName()
- {
- return _excludeName;
- }
-
- public static ProtocolExclusion lookup(final String arg)
- {
- ProtocolExclusion ex = MAP.get(arg);
-
- if(ex == null)
- {
- throw new IllegalArgumentException(arg + " is not a valid protocol exclusion");
- }
-
- return ex;
- }
-}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/ProtocolInclusion.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/ProtocolInclusion.java
deleted file mode 100644
index 85fbe2e02e..0000000000
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/ProtocolInclusion.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- *
- * 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.qpid.server;
-
-import java.util.HashMap;
-import java.util.Map;
-
-public enum ProtocolInclusion
-{
- v0_8("include-0-8","--include-0-8"),
- v0_9("include-0-9", "--include-0-9"),
- v0_9_1("include-0-9-1", "--include-0-9-1"),
- v0_10("include-0-10", "--include-0-10"),
- v1_0("include-1-0", "--include-1-0");
-
- private static final Map<String, ProtocolInclusion> MAP = new HashMap<String,ProtocolInclusion>();
-
- static
- {
- for(ProtocolInclusion pe : ProtocolInclusion.values())
- {
- MAP.put(pe.getArg(), pe);
- }
- }
-
- private String _arg;
- private String _includeName;
-
- private ProtocolInclusion(final String includeName, final String arg)
- {
- _includeName = includeName;
- _arg = arg;
- }
-
- public String getArg()
- {
- return _arg;
- }
-
- public String getIncludeName()
- {
- return _includeName;
- }
-
- public static ProtocolInclusion lookup(final String arg)
- {
- ProtocolInclusion ex = MAP.get(arg);
-
- if(ex == null)
- {
- throw new IllegalArgumentException(arg + " is not a valid protocol inclusion");
- }
-
- return ex;
- }
-}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/BrokerConfigurationStoreCreator.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/BrokerConfigurationStoreCreator.java
new file mode 100644
index 0000000000..efae100c9d
--- /dev/null
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/BrokerConfigurationStoreCreator.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.qpid.server.configuration;
+
+import org.apache.qpid.server.BrokerOptions;
+import org.apache.qpid.server.plugin.QpidServiceLoader;
+
+public class BrokerConfigurationStoreCreator
+{
+ /**
+ * Path to resource containing broker default configuration
+ */
+ public static final String INITIAL_STORE_LOCATION = "initial-store.json";
+
+ /**
+ * Create broker configuration store for given store location, store type
+ * and command line options
+ */
+ public ConfigurationEntryStore createStore(String storeLocation, String storeType, BrokerOptions options)
+ {
+ ConfigurationEntryStore store = null;
+ QpidServiceLoader<ConfigurationStoreFactory> serviceLoader = new QpidServiceLoader<ConfigurationStoreFactory>();
+ Iterable<ConfigurationStoreFactory> configurationStoreFactories = serviceLoader.instancesOf(ConfigurationStoreFactory.class);
+ for (ConfigurationStoreFactory storeFactory : configurationStoreFactories)
+ {
+ if (storeFactory.getStoreType().equals(storeType))
+ {
+ store = storeFactory.createStore();
+ break;
+ }
+ }
+ if (store == null)
+ {
+ throw new IllegalConfigurationException("Cannot create store for the type " + storeType);
+ }
+ store.open(storeLocation);
+ return store;
+ }
+
+}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/BrokerProperties.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/BrokerProperties.java
new file mode 100644
index 0000000000..179d4a5640
--- /dev/null
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/BrokerProperties.java
@@ -0,0 +1,54 @@
+package org.apache.qpid.server.configuration;
+
+import java.util.Locale;
+
+/**
+ * Declares broker system property names
+ */
+public class BrokerProperties
+{
+ public static final int DEFAULT_HEART_BEAT_TIMEOUT_FACTOR = 2;
+
+ public static final String PROPERTY_DEAD_LETTER_EXCHANGE_SUFFIX = "qpid.dead_letter_exchange_suffix";
+ public static final String PROPERTY_DEAD_LETTER_QUEUE_SUFFIX = "qpid.dead_letter_queue_suffix";
+
+ public static final String PROPERTY_FRAME_SIZE = "qpid.frame_size";
+ public static final String PROPERTY_MSG_AUTH = "qpid.msg_auth";
+ public static final String PROPERTY_STATUS_UPDATES = "qpid.status_updates";
+ public static final String PROPERTY_LOCALE = "qpid.locale";
+ public static final String PROPERTY_DEFAULT_SUPPORTED_PROTOCOL_REPLY = "qpid.default_supported_protocol_version_reply";
+ public static final String PROPERTY_DISABLED_FEATURES = "qpid.broker_disabled_features";
+
+ public static final int DEFAULT_FRAME_SIZE = Integer.getInteger(PROPERTY_FRAME_SIZE, 65535);
+ public static final String PROPERTY_BROKER_DEFAULT_AMQP_PROTOCOL_EXCLUDES = "qpid.broker_default_amqp_protocol_excludes";
+ public static final String PROPERTY_BROKER_DEFAULT_AMQP_PROTOCOL_INCLUDES = "qpid.broker_default_amqp_protocol_includes";
+
+ public static final String PROPERTY_MANAGEMENT_RIGHTS_INFER_ALL_ACCESS = "qpid.broker_jmx_method_rights_infer_all_access";
+ public static final String PROPERTY_USE_CUSTOM_RMI_SOCKET_FACTORY = "qpid.broker_jmx_use_custom_rmi_socket_factory";
+
+ public static final String PROPERTY_QPID_HOME = "QPID_HOME";
+ public static final String PROPERTY_QPID_WORK = "QPID_WORK";
+
+ private BrokerProperties()
+ {
+ }
+
+ public static Locale getLocale()
+ {
+ Locale locale = Locale.US;
+ String localeSetting = System.getProperty(BrokerProperties.PROPERTY_LOCALE);
+ if (localeSetting != null)
+ {
+ String[] localeParts = localeSetting.split("_");
+ String language = (localeParts.length > 0 ? localeParts[0] : "");
+ String country = (localeParts.length > 1 ? localeParts[1] : "");
+ String variant = "";
+ if (localeParts.length > 2)
+ {
+ variant = localeSetting.substring(language.length() + 1 + country.length() + 1);
+ }
+ locale = new Locale(language, country, variant);
+ }
+ return locale;
+ }
+}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigurationEntry.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigurationEntry.java
new file mode 100644
index 0000000000..4771c4af6d
--- /dev/null
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigurationEntry.java
@@ -0,0 +1,213 @@
+/*
+ *
+ * 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.qpid.server.configuration;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+
+public class ConfigurationEntry
+{
+ public static final String ATTRIBUTE_NAME = "name";
+
+ private final UUID _id;
+ private final String _type;
+ private final Map<String, Object> _attributes;
+ private final Set<UUID> _childrenIds;
+ private final ConfigurationEntryStore _store;
+
+ public ConfigurationEntry(UUID id, String type, Map<String, Object> attributes, Set<UUID> childrenIds,
+ ConfigurationEntryStore store)
+ {
+ super();
+ _id = id;
+ _type = type;
+ _attributes = attributes;
+ _childrenIds = childrenIds;
+ _store = store;
+ }
+
+ public UUID getId()
+ {
+ return _id;
+ }
+
+ public String getType()
+ {
+ return _type;
+ }
+
+ public Map<String, Object> getAttributes()
+ {
+ return _attributes;
+ }
+
+ public Set<UUID> getChildrenIds()
+ {
+ return _childrenIds;
+ }
+
+ public ConfigurationEntryStore getStore()
+ {
+ return _store;
+ }
+
+ /**
+ * Returns this entry's children. The collection should not be modified.
+ */
+ public Map<String, Collection<ConfigurationEntry>> getChildren()
+ {
+ Map<String, Collection<ConfigurationEntry>> children = null;
+ if (_childrenIds == null)
+ {
+ children = Collections.emptyMap();
+ }
+ else
+ {
+ children = new HashMap<String, Collection<ConfigurationEntry>>();
+ for (UUID childId : _childrenIds)
+ {
+ ConfigurationEntry entry = _store.getEntry(childId);
+ String type = entry.getType();
+ Collection<ConfigurationEntry> childrenOfType = children.get(type);
+ if (childrenOfType == null)
+ {
+ childrenOfType = new ArrayList<ConfigurationEntry>();
+ children.put(type, childrenOfType);
+ }
+ childrenOfType.add(entry);
+ }
+ }
+ return Collections.unmodifiableMap(children);
+ }
+
+ public boolean hasChild(UUID id)
+ {
+ return _childrenIds.contains(id);
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return _id.hashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (this == obj)
+ {
+ return true;
+ }
+ if (obj == null)
+ {
+ return false;
+ }
+ if (getClass() != obj.getClass())
+ {
+ return false;
+ }
+
+ ConfigurationEntry other = (ConfigurationEntry) obj;
+ if (_id == null)
+ {
+ if (other._id != null)
+ {
+ return false;
+ }
+ }
+ else if (!_id.equals(other._id))
+ {
+ return false;
+ }
+
+ if (_type == null)
+ {
+ if (other._type != null)
+ {
+ return false;
+ }
+ }
+ else if (!_type.equals(other._type))
+ {
+ return false;
+ }
+
+ if (_store == null)
+ {
+ if (other._store != null)
+ {
+ return false;
+ }
+ }
+ else if (!_store.equals(other._store))
+ {
+ return false;
+ }
+
+ if (_childrenIds == null)
+ {
+ if (other._childrenIds != null)
+ {
+ return false;
+ }
+ }
+ else if (!_childrenIds.equals(other._childrenIds))
+ {
+ return false;
+ }
+
+ if (_attributes == null)
+ {
+ if (other._attributes != null)
+ {
+ return false;
+ }
+ }
+ else if (!_attributes.equals(other._attributes))
+ {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public String toString()
+ {
+ return "ConfigurationEntry [_id=" + _id + ", _type=" + _type + ", _attributes=" + _attributes + ", _childrenIds="
+ + _childrenIds + "]";
+ }
+
+ public Object setAttribute(String name, Object value)
+ {
+ return _attributes.put(name, value);
+ }
+
+ public ConfigurationEntry clone()
+ {
+ return new ConfigurationEntry(_id, _type, new HashMap<String, Object>(_attributes), new HashSet<UUID>(_childrenIds), _store);
+ }
+}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigurationEntryStore.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigurationEntryStore.java
new file mode 100644
index 0000000000..08736c36f1
--- /dev/null
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigurationEntryStore.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.qpid.server.configuration;
+
+import java.util.UUID;
+
+public interface ConfigurationEntryStore
+{
+ void open(String storeLocation);
+
+ ConfigurationEntry getRootEntry();
+
+ ConfigurationEntry getEntry(UUID id);
+
+ void save(ConfigurationEntry... entries);
+
+ UUID[] remove(UUID... entryIds);
+
+}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigurationStoreFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigurationStoreFactory.java
new file mode 100644
index 0000000000..dced38d260
--- /dev/null
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigurationStoreFactory.java
@@ -0,0 +1,35 @@
+/*
+ *
+ * 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.qpid.server.configuration;
+
+
+public interface ConfigurationStoreFactory
+{
+ /**
+ * Returns the type of the store this factory can create
+ */
+ public String getStoreType();
+
+ /**
+ * Creates the store instance.
+ */
+ public ConfigurationEntryStore createStore();
+}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfiguredObjectRecoverer.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfiguredObjectRecoverer.java
new file mode 100644
index 0000000000..65d97e6db1
--- /dev/null
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfiguredObjectRecoverer.java
@@ -0,0 +1,28 @@
+/*
+ *
+ * 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.qpid.server.configuration;
+
+import org.apache.qpid.server.model.ConfiguredObject;
+
+public interface ConfiguredObjectRecoverer<T extends ConfiguredObject>
+{
+ T create(RecovererProvider recovererProvider, ConfigurationEntry entry, ConfiguredObject... parents);
+}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/IllegalConfigurationException.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/IllegalConfigurationException.java
new file mode 100644
index 0000000000..bedd470ddf
--- /dev/null
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/IllegalConfigurationException.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.qpid.server.configuration;
+
+public class IllegalConfigurationException extends RuntimeException
+{
+ private static final long serialVersionUID = 1130064756291179812L;
+
+ public IllegalConfigurationException(String message)
+ {
+ super(message);
+ }
+
+ public IllegalConfigurationException(String message, Throwable cause)
+ {
+ super(message, cause);
+ }
+
+}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/RecovererProvider.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/RecovererProvider.java
new file mode 100644
index 0000000000..963d019ec3
--- /dev/null
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/RecovererProvider.java
@@ -0,0 +1,28 @@
+/*
+ *
+ * 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.qpid.server.configuration;
+
+import org.apache.qpid.server.model.ConfiguredObject;
+
+public interface RecovererProvider
+{
+ ConfiguredObjectRecoverer<? extends ConfiguredObject> getRecoverer(String type);
+}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ServerConfiguration.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ServerConfiguration.java
deleted file mode 100644
index 62ed2e44f4..0000000000
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ServerConfiguration.java
+++ /dev/null
@@ -1,994 +0,0 @@
-/*
- * 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.qpid.server.configuration;
-
-import java.io.File;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-import java.util.Map.Entry;
-import javax.net.ssl.KeyManagerFactory;
-import javax.net.ssl.TrustManagerFactory;
-import org.apache.commons.configuration.CompositeConfiguration;
-import org.apache.commons.configuration.Configuration;
-import org.apache.commons.configuration.ConfigurationException;
-import org.apache.commons.configuration.ConfigurationFactory;
-import org.apache.commons.configuration.HierarchicalConfiguration;
-import org.apache.commons.configuration.SystemConfiguration;
-import org.apache.commons.configuration.XMLConfiguration;
-import org.apache.log4j.Logger;
-import org.apache.qpid.server.configuration.plugins.AbstractConfiguration;
-import org.apache.qpid.server.exchange.DefaultExchangeFactory;
-import org.apache.qpid.server.protocol.AmqpProtocolVersion;
-import org.apache.qpid.server.queue.AMQQueueFactory;
-import org.apache.qpid.server.registry.ApplicationRegistry;
-import static org.apache.qpid.transport.ConnectionSettings.WILDCARD_ADDRESS;
-
-public class ServerConfiguration extends AbstractConfiguration
-{
- protected static final Logger _logger = Logger.getLogger(ServerConfiguration.class);
-
- // Default Configuration values
- public static final int DEFAULT_BUFFER_SIZE = 262144;
- public static final String DEFAULT_STATUS_UPDATES = "on";
- public static final String SECURITY_CONFIG_RELOADED = "SECURITY CONFIGURATION RELOADED";
-
- public static final int DEFAULT_FRAME_SIZE = 65536;
- public static final int DEFAULT_PORT = 5672;
- public static final int DEFAULT_SSL_PORT = 5671;
- public static final long DEFAULT_HOUSEKEEPING_PERIOD = 30000L;
- public static final int DEFAULT_JMXPORT_REGISTRYSERVER = 8999;
- public static final int JMXPORT_CONNECTORSERVER_OFFSET = 100;
- public static final int DEFAULT_HTTP_MANAGEMENT_PORT = 8080;
- public static final int DEFAULT_HTTPS_MANAGEMENT_PORT = 8443;
- public static final long DEFAULT_MINIMUM_ALERT_REPEAT_GAP = 30000l;
- public static final String SKIP_SIGHUP_HANDLER_REGISTRATION = "qpid.skip_sighup_handler_registration";
- public static final String USE_CUSTOM_RMI_SOCKET_FACTORY = "qpid.use_custom_rmi_socket_factory";
-
- public static final String QPID_HOME = "QPID_HOME";
- public static final String QPID_WORK = "QPID_WORK";
- public static final String LIB_DIR = "lib";
-
- private Map<String, VirtualHostConfiguration> _virtualHosts = new HashMap<String, VirtualHostConfiguration>();
-
- private File _configFile;
- private File _vhostsFile;
- private String _qpidWork;
- private String _qpidHome;
-
- // Map of environment variables to config items
- private static final Map<String, String> envVarMap = new HashMap<String, String>();
-
- // Configuration values to be read from the configuration file
- //todo Move all properties to static values to ensure system testing can be performed.
- public static final String MGMT_CUSTOM_REGISTRY_SOCKET = "management.custom-registry-socket";
- public static final String MGMT_JMXPORT_REGISTRYSERVER = "management.jmxport.registryServer";
- public static final String MGMT_JMXPORT_CONNECTORSERVER = "management.jmxport.connectorServer";
- public static final String SECURITY_DEFAULT_AUTH_MANAGER = "security.default-auth-manager";
- public static final String SECURITY_PORT_MAPPINGS_PORT_MAPPING_AUTH_MANAGER = "security.port-mappings.port-mapping.auth-manager";
- public static final String SECURITY_PORT_MAPPINGS_PORT_MAPPING_PORT = "security.port-mappings.port-mapping.port";
- public static final String STATUS_UPDATES = "status-updates";
- public static final String ADVANCED_LOCALE = "advanced.locale";
- public static final String CONNECTOR_AMQP10ENABLED = "connector.amqp10enabled";
- public static final String CONNECTOR_AMQP010ENABLED = "connector.amqp010enabled";
- public static final String CONNECTOR_AMQP091ENABLED = "connector.amqp091enabled";
- public static final String CONNECTOR_AMQP09ENABLED = "connector.amqp09enabled";
- public static final String CONNECTOR_AMQP08ENABLED = "connector.amqp08enabled";
- public static final String CONNECTOR_AMQP_SUPPORTED_REPLY = "connector.amqpDefaultSupportedProtocolReply";
- public static final String CONNECTOR_INCLUDE_10 = "connector.include10";
- public static final String CONNECTOR_INCLUDE_010 = "connector.include010";
- public static final String CONNECTOR_INCLUDE_091 = "connector.include091";
- public static final String CONNECTOR_INCLUDE_09 = "connector.include09";
- public static final String CONNECTOR_INCLUDE_08 = "connector.include08";
-
- {
- envVarMap.put("QPID_PORT", "connector.port");
- envVarMap.put("QPID_SSLPORT", "connector.ssl.port");
- envVarMap.put("QPID_JMXPORT_REGISTRYSERVER", MGMT_JMXPORT_REGISTRYSERVER);
- envVarMap.put("QPID_JMXPORT_CONNECTORSERVER", MGMT_JMXPORT_CONNECTORSERVER);
- envVarMap.put("QPID_FRAMESIZE", "advanced.framesize");
- envVarMap.put("QPID_MSGAUTH", "security.msg-auth");
- envVarMap.put("QPID_AUTOREGISTER", "auto_register");
- envVarMap.put("QPID_MANAGEMENTENABLED", "management.enabled");
- envVarMap.put("QPID_HTTPMANAGEMENTENABLED", "management.http.enabled");
- envVarMap.put("QPID_HTTPMANAGEMENTPORT", "management.http.port");
- envVarMap.put("QPID_HEARTBEATDELAY", "heartbeat.delay");
- envVarMap.put("QPID_HEARTBEATTIMEOUTFACTOR", "heartbeat.timeoutFactor");
- envVarMap.put("QPID_MAXIMUMMESSAGEAGE", "maximumMessageAge");
- envVarMap.put("QPID_MAXIMUMMESSAGECOUNT", "maximumMessageCount");
- envVarMap.put("QPID_MAXIMUMQUEUEDEPTH", "maximumQueueDepth");
- envVarMap.put("QPID_MAXIMUMMESSAGESIZE", "maximumMessageSize");
- envVarMap.put("QPID_MAXIMUMCHANNELCOUNT", "maximumChannelCount");
- envVarMap.put("QPID_MINIMUMALERTREPEATGAP", "minimumAlertRepeatGap");
- envVarMap.put("QPID_QUEUECAPACITY", "capacity");
- envVarMap.put("QPID_FLOWRESUMECAPACITY", "flowResumeCapacity");
- envVarMap.put("QPID_SOCKETRECEIVEBUFFER", "connector.socketReceiveBuffer");
- envVarMap.put("QPID_SOCKETWRITEBUFFER", "connector.socketWriteBuffer");
- envVarMap.put("QPID_TCPNODELAY", "connector.tcpNoDelay");
- envVarMap.put("QPID_STATUS-UPDATES", "status-updates");
- }
-
- /**
- * Loads the given file and sets up the HUP signal handler.
- *
- * This will load the file and present the root level properties but will
- * not perform any virtualhost configuration.
- * <p>
- * To perform this {@link #initialise()} must be called.
- * <p>
- * This has been made a two step process to allow the Plugin Manager and
- * Configuration Manager to be initialised in the Application Registry.
- * <p>
- * If using this ServerConfiguration via an ApplicationRegistry there is no
- * need to explicitly call {@link #initialise()} as this is done via the
- * {@link ApplicationRegistry#initialise()} method.
- *
- * @param configurationURL
- * @throws org.apache.commons.configuration.ConfigurationException
- */
- public ServerConfiguration(File configurationURL) throws ConfigurationException
- {
- this(parseConfig(configurationURL));
- _configFile = configurationURL;
- }
-
- /**
- * Wraps the given Commons Configuration as a ServerConfiguration.
- *
- * Mainly used during testing and in locations where configuration is not
- * desired but the interface requires configuration.
- * <p>
- * If the given configuration has VirtualHost configuration then
- * {@link #initialise()} must be called to perform the required setup.
- * <p>
- * This has been made a two step process to allow the Plugin Manager and
- * Configuration Manager to be initialised in the Application Registry.
- * <p>
- * If using this ServerConfiguration via an ApplicationRegistry there is no
- * need to explicitly call {@link #initialise()} as this is done via the
- * {@link ApplicationRegistry#initialise()} method.
- *
- * @param conf
- */
- public ServerConfiguration(Configuration conf)
- {
- setConfig(conf);
- }
-
- /**
- * Processes this configuration and setups any VirtualHosts defined in the
- * configuration.
- *
- * <p>
- * Called by {@link ApplicationRegistry#initialise()}.
- * <p>
- * NOTE: A DEFAULT ApplicationRegistry must exist when using this method
- * or a new ApplicationRegistry will be created.
- *
- * @throws ConfigurationException
- */
- public void initialise() throws ConfigurationException
- {
- setConfiguration("", getConfig());
- setupVirtualHosts(getConfig());
- }
-
- public String[] getElementsProcessed()
- {
- return new String[] { "" };
- }
-
- @Override
- public void validateConfiguration() throws ConfigurationException
- {
- // Support for security.jmx.access was removed when JMX access rights were incorporated into the main ACL.
- // This ensure that users remove the element from their configuration file.
-
- if (getListValue("security.jmx.access").size() > 0)
- {
- String message = "Validation error : security/jmx/access is no longer a supported element within the configuration xml."
- + (_configFile == null ? "" : " Configuration file : " + _configFile);
- throw new ConfigurationException(message);
- }
-
- if (getListValue("security.jmx.principal-database").size() > 0)
- {
- String message = "Validation error : security/jmx/principal-database is no longer a supported element within the configuration xml."
- + (_configFile == null ? "" : " Configuration file : " + _configFile);
- throw new ConfigurationException(message);
- }
-
- if (getListValue("security.principal-databases.principal-database(0).class").size() > 0)
- {
- String message = "Validation error : security/principal-databases is no longer supported within the configuration xml."
- + (_configFile == null ? "" : " Configuration file : " + _configFile);
- throw new ConfigurationException(message);
- }
-
- // QPID-3266. Tidy up housekeeping configuration option for scheduling frequency
- if (contains("housekeeping.expiredMessageCheckPeriod"))
- {
- String message = "Validation error : housekeeping/expiredMessageCheckPeriod must be replaced by housekeeping/checkPeriod."
- + (_configFile == null ? "" : " Configuration file : " + _configFile);
- throw new ConfigurationException(message);
- }
-
- String[] ports = getConfig().getStringArray(SECURITY_PORT_MAPPINGS_PORT_MAPPING_PORT);
- String[] authManagers = getConfig().getStringArray(SECURITY_PORT_MAPPINGS_PORT_MAPPING_AUTH_MANAGER);
- if (ports.length != authManagers.length)
- {
- throw new ConfigurationException("Validation error: Each port-mapping must have exactly one port and exactly one auth-manager.");
- }
-
- // QPID-3517: Inconsistency in capitalisation in the SSL configuration keys used within the connector and management configuration
- // sections. For the moment, continue to understand both but generate a deprecated warning if the less preferred keystore is used.
- for (String key : new String[] {"management.ssl.keystorePath",
- "management.ssl.keystorePassword," +
- "connector.ssl.keystorePath",
- "connector.ssl.keystorePassword"})
- {
- if (contains(key))
- {
- final String deprecatedXpath = key.replaceAll("\\.", "/");
- final String preferredXpath = deprecatedXpath.replaceAll("keystore", "keyStore");
- _logger.warn("Validation warning: " + deprecatedXpath + " is deprecated and must be replaced by " + preferredXpath
- + (_configFile == null ? "" : " Configuration file : " + _configFile));
- }
- }
-
- // QPID-3739 certType was a misleading name.
- if (contains("connector.ssl.certType"))
- {
- _logger.warn("Validation warning: connector/ssl/certType is deprecated and must be replaced by connector/ssl/keyManagerFactoryAlgorithm"
- + (_configFile == null ? "" : " Configuration file : " + _configFile));
- }
- }
-
- /*
- * Modified to enforce virtualhosts configuration in external file or main file, but not
- * both, as a fix for QPID-2360 and QPID-2361.
- */
- @SuppressWarnings("unchecked")
- protected void setupVirtualHosts(Configuration conf) throws ConfigurationException
- {
- List<String> vhostFiles = (List) conf.getList("virtualhosts");
- Configuration vhostConfig = conf.subset("virtualhosts");
-
- // Only one configuration mechanism allowed
- if (!vhostFiles.isEmpty() && !vhostConfig.subset("virtualhost").isEmpty())
- {
- throw new ConfigurationException("Only one of external or embedded virtualhosts configuration allowed.");
- }
-
- // We can only have one vhosts XML file included
- if (vhostFiles.size() > 1)
- {
- throw new ConfigurationException("Only one external virtualhosts configuration file allowed, multiple filenames found.");
- }
-
- // Virtualhost configuration object
- Configuration vhostConfiguration = new HierarchicalConfiguration();
-
- // Load from embedded configuration if possible
- if (!vhostConfig.subset("virtualhost").isEmpty())
- {
- vhostConfiguration = vhostConfig;
- }
- else
- {
- // Load from the external configuration if possible
- for (String fileName : vhostFiles)
- {
- // Open the vhosts XML file and copy values from it to our config
- _vhostsFile = new File(fileName);
- if (!_vhostsFile.exists())
- {
- throw new ConfigurationException("Virtualhosts file does not exist");
- }
- vhostConfiguration = parseConfig(new File(fileName));
-
- // save the default virtualhost name
- String defaultVirtualHost = vhostConfiguration.getString("default");
- getConfig().setProperty("virtualhosts.default", defaultVirtualHost);
- }
- }
-
- // Now extract the virtual host names from the configuration object
- List hosts = vhostConfiguration.getList("virtualhost.name");
- for (int j = 0; j < hosts.size(); j++)
- {
- String name = (String) hosts.get(j);
-
- // Add the virtual hosts to the server configuration
- VirtualHostConfiguration virtualhost = new VirtualHostConfiguration(name, vhostConfiguration.subset("virtualhost." + escapeTagName(name)));
- _virtualHosts.put(virtualhost.getName(), virtualhost);
- }
- }
-
- private static void substituteEnvironmentVariables(Configuration conf)
- {
- for (Entry<String, String> var : envVarMap.entrySet())
- {
- String val = System.getenv(var.getKey());
- if (val != null)
- {
- conf.setProperty(var.getValue(), val);
- }
- }
- }
-
- private static Configuration parseConfig(File file) throws ConfigurationException
- {
- ConfigurationFactory factory = new ConfigurationFactory();
- factory.setConfigurationFileName(file.getAbsolutePath());
- Configuration conf = factory.getConfiguration();
-
- Iterator<?> keys = conf.getKeys();
- if (!keys.hasNext())
- {
- keys = null;
- conf = flatConfig(file);
- }
-
- substituteEnvironmentVariables(conf);
-
- return conf;
- }
-
- /**
- * Check the configuration file to see if status updates are enabled.
- *
- * @return true if status updates are enabled
- */
- public boolean getStatusUpdatesEnabled()
- {
- // Retrieve the setting from configuration but default to on.
- String value = getStringValue(STATUS_UPDATES, DEFAULT_STATUS_UPDATES);
-
- return value.equalsIgnoreCase("on");
- }
-
- /**
- * The currently defined {@see Locale} for this broker
- *
- * @return the configuration defined locale
- */
- public Locale getLocale()
- {
- String localeString = getStringValue(ADVANCED_LOCALE);
- // Expecting locale of format langauge_country_variant
-
- // If the configuration does not have a defined locale use the JVM default
- if (localeString == null)
- {
- return Locale.getDefault();
- }
-
- String[] parts = localeString.split("_");
-
- Locale locale;
- switch (parts.length)
- {
- case 1:
- locale = new Locale(localeString);
- break;
- case 2:
- locale = new Locale(parts[0], parts[1]);
- break;
- default:
- StringBuilder variant = new StringBuilder(parts[2]);
- // If we have a variant such as the Java doc suggests for Spanish
- // Traditional_WIN we may end up with more than 3 parts on a
- // split with '_'. So we should recombine the variant.
- if (parts.length > 3)
- {
- for (int index = 3; index < parts.length; index++)
- {
- variant.append('_').append(parts[index]);
- }
- }
-
- locale = new Locale(parts[0], parts[1], variant.toString());
- }
-
- return locale;
- }
-
- // Our configuration class needs to make the interpolate method
- // public so it can be called below from the config method.
- public static class MyConfiguration extends CompositeConfiguration
- {
- public String interpolate(String obj)
- {
- return super.interpolate(obj);
- }
- }
-
- public final static Configuration flatConfig(File file) throws ConfigurationException
- {
- // We have to override the interpolate methods so that
- // interpolation takes place across the entirety of the
- // composite configuration. Without doing this each
- // configuration object only interpolates variables defined
- // inside itself.
- final MyConfiguration conf = new MyConfiguration();
- conf.addConfiguration(new SystemConfiguration()
- {
- protected String interpolate(String o)
- {
- return conf.interpolate(o);
- }
- });
- conf.addConfiguration(new XMLConfiguration(file)
- {
- protected String interpolate(String o)
- {
- return conf.interpolate(o);
- }
- });
- return conf;
- }
-
- public String getConfigurationURL()
- {
- return _configFile == null ? "" : _configFile.getAbsolutePath();
- }
-
-
- public String getQpidWork()
- {
- if ( _qpidWork == null )
- {
- return System.getProperty(QPID_WORK, System.getProperty("java.io.tmpdir"));
- }
- else
- {
- return _qpidWork;
- }
- }
-
- public String getQpidHome()
- {
- if ( _qpidHome == null )
- {
- return System.getProperty(QPID_HOME);
- }
- else
- {
- return _qpidHome;
- }
- }
-
- public void setJMXPortRegistryServer(int registryServerPort)
- {
- getConfig().setProperty(MGMT_JMXPORT_REGISTRYSERVER, registryServerPort);
- }
-
- public int getJMXPortRegistryServer()
- {
- return getIntValue(MGMT_JMXPORT_REGISTRYSERVER, DEFAULT_JMXPORT_REGISTRYSERVER);
- }
-
- public void setJMXPortConnectorServer(int connectorServerPort)
- {
- getConfig().setProperty(MGMT_JMXPORT_CONNECTORSERVER, connectorServerPort);
- }
-
- public int getJMXConnectorServerPort()
- {
- return getIntValue(MGMT_JMXPORT_CONNECTORSERVER, getJMXPortRegistryServer() + JMXPORT_CONNECTORSERVER_OFFSET);
- }
-
- public boolean getUseCustomRMISocketFactory()
- {
- return getBooleanValue(MGMT_CUSTOM_REGISTRY_SOCKET,
- Boolean.parseBoolean(System.getProperty(USE_CUSTOM_RMI_SOCKET_FACTORY, "true")));
- }
-
- public void setUseCustomRMISocketFactory(boolean bool)
- {
- getConfig().setProperty(MGMT_CUSTOM_REGISTRY_SOCKET, bool);
- }
-
- public boolean getPlatformMbeanserver()
- {
- return getBooleanValue("management.platform-mbeanserver", true);
- }
-
- public boolean getHTTPManagementEnabled()
- {
- return getBooleanValue("management.http.enabled", true);
- }
-
- public int getHTTPManagementPort()
- {
- return getIntValue("management.http.port", DEFAULT_HTTP_MANAGEMENT_PORT);
- }
-
- public boolean getHTTPManagementBasicAuth()
- {
- return getBooleanValue("management.http.basic-auth", false);
- }
-
- /**
- * @return value in seconds
- */
- public int getHTTPManagementSessionTimeout()
- {
- return getIntValue("management.http.session-timeout", 60 * 15);
- }
-
- public boolean getHTTPSManagementEnabled()
- {
- return getBooleanValue("management.https.enabled", false);
- }
-
- public int getHTTPSManagementPort()
- {
- return getIntValue("management.https.port", DEFAULT_HTTPS_MANAGEMENT_PORT);
- }
-
- public boolean getHTTPSManagementBasicAuth()
- {
- return getBooleanValue("management.https.basic-auth", true);
- }
-
- public boolean getHTTPManagementSaslAuthEnabled()
- {
- return getBooleanValue("management.http.sasl-auth", true);
- }
-
- public boolean getHTTPSManagementSaslAuthEnabled()
- {
- return getBooleanValue("management.https.sasl-auth", true);
- }
-
- public String[] getVirtualHosts()
- {
- return _virtualHosts.keySet().toArray(new String[_virtualHosts.size()]);
- }
-
- public VirtualHostConfiguration getVirtualHostConfig(String name)
- {
- return _virtualHosts.get(name);
- }
-
- public void setVirtualHostConfig(VirtualHostConfiguration config)
- {
- _virtualHosts.put(config.getName(), config);
- }
-
- public int getFrameSize()
- {
- return getIntValue("advanced.framesize", DEFAULT_FRAME_SIZE);
- }
-
- public boolean getSynchedClocks()
- {
- return getBooleanValue("advanced.synced-clocks");
- }
-
- public boolean getMsgAuth()
- {
- return getBooleanValue("security.msg-auth");
- }
-
- public String getDefaultAuthenticationManager()
- {
- return getStringValue(SECURITY_DEFAULT_AUTH_MANAGER);
- }
-
- public Map<Integer, String> getPortAuthenticationMappings()
- {
- String[] ports = getConfig().getStringArray(SECURITY_PORT_MAPPINGS_PORT_MAPPING_PORT);
- String[] authManagers = getConfig().getStringArray(SECURITY_PORT_MAPPINGS_PORT_MAPPING_AUTH_MANAGER);
-
- Map<Integer,String> portMappings = new HashMap<Integer, String>();
- for(int i = 0; i < ports.length; i++)
- {
- portMappings.put(Integer.valueOf(ports[i]), authManagers[i]);
- }
-
- return portMappings;
- }
-
-
- public String getManagementKeyStorePath()
- {
- // note difference in capitalisation used in fallback
- final String fallback = getStringValue("management.ssl.keystorePath");
- return getStringValue("management.ssl.keyStorePath", fallback);
- }
-
- public boolean getManagementSSLEnabled()
- {
- return getBooleanValue("management.ssl.enabled", false);
- }
-
- public String getManagementKeyStorePassword()
- {
- // note difference in capitalisation used in fallback
- final String fallback = getStringValue("management.ssl.keystorePassword");
- return getStringValue("management.ssl.keyStorePassword", fallback);
- }
-
- public boolean getQueueAutoRegister()
- {
- return getBooleanValue("queue.auto_register", true);
- }
-
- public boolean getJMXManagementEnabled()
- {
- return getBooleanValue("management.enabled", true);
- }
-
- public int getHeartBeatDelay()
- {
- return getIntValue("heartbeat.delay", 5);
- }
-
- public double getHeartBeatTimeout()
- {
- return getDoubleValue("heartbeat.timeoutFactor", 2.0);
- }
-
- public long getMaximumMessageAge()
- {
- return getLongValue("maximumMessageAge");
- }
-
- public long getMaximumMessageCount()
- {
- return getLongValue("maximumMessageCount");
- }
-
- public long getMaximumQueueDepth()
- {
- return getLongValue("maximumQueueDepth");
- }
-
- public long getMaximumMessageSize()
- {
- return getLongValue("maximumMessageSize");
- }
-
- public long getMinimumAlertRepeatGap()
- {
- return getLongValue("minimumAlertRepeatGap", DEFAULT_MINIMUM_ALERT_REPEAT_GAP);
- }
-
- public long getCapacity()
- {
- return getLongValue("capacity");
- }
-
- public long getFlowResumeCapacity()
- {
- return getLongValue("flowResumeCapacity", getCapacity());
- }
-
- public int getConnectorProcessors()
- {
- return getIntValue("connector.processors", 4);
- }
-
- public List getPorts()
- {
- return getListValue("connector.port", Collections.<Integer>singletonList(DEFAULT_PORT));
- }
-
- public List getPortExclude10()
- {
- return getListValue("connector.non10port");
- }
-
- public List getPortExclude010()
- {
- return getListValue("connector.non010port");
- }
-
- public List getPortExclude091()
- {
- return getListValue("connector.non091port");
- }
-
- public List getPortExclude09()
- {
- return getListValue("connector.non09port");
- }
-
- public List getPortExclude08()
- {
- return getListValue("connector.non08port");
- }
-
- public List getPortInclude08()
- {
- return getListValue(CONNECTOR_INCLUDE_08);
- }
-
- public List getPortInclude09()
- {
- return getListValue(CONNECTOR_INCLUDE_09);
- }
-
- public List getPortInclude091()
- {
- return getListValue(CONNECTOR_INCLUDE_091);
- }
-
- public List getPortInclude010()
- {
- return getListValue(CONNECTOR_INCLUDE_010);
- }
-
- public List getPortInclude10()
- {
- return getListValue(CONNECTOR_INCLUDE_10);
- }
-
- public String getBind()
- {
- return getStringValue("connector.bind", WILDCARD_ADDRESS);
- }
-
- public int getReceiveBufferSize()
- {
- return getIntValue("connector.socketReceiveBuffer", DEFAULT_BUFFER_SIZE);
- }
-
- public int getWriteBufferSize()
- {
- return getIntValue("connector.socketWriteBuffer", DEFAULT_BUFFER_SIZE);
- }
-
- public boolean getTcpNoDelay()
- {
- return getBooleanValue("connector.tcpNoDelay", true);
- }
-
- public boolean getEnableSSL()
- {
- return getBooleanValue("connector.ssl.enabled");
- }
-
- public boolean getSSLOnly()
- {
- return getBooleanValue("connector.ssl.sslOnly");
- }
-
- public List getSSLPorts()
- {
- return getListValue("connector.ssl.port", Collections.<Integer>singletonList(DEFAULT_SSL_PORT));
- }
-
- public String getConnectorKeyStorePath()
- {
- final String fallback = getStringValue("connector.ssl.keystorePath"); // pre-0.13 broker supported this name.
- return getStringValue("connector.ssl.keyStorePath", fallback);
- }
-
- public String getConnectorKeyStorePassword()
- {
- final String fallback = getStringValue("connector.ssl.keystorePassword"); // pre-0.13 brokers supported this name.
- return getStringValue("connector.ssl.keyStorePassword", fallback);
- }
-
- public String getConnectorKeyStoreType()
- {
- return getStringValue("connector.ssl.keyStoreType", "JKS");
- }
-
- public String getConnectorKeyManagerFactoryAlgorithm()
- {
- final String systemFallback = KeyManagerFactory.getDefaultAlgorithm();
- // deprecated, pre-0.17 brokers supported this name.
- final String fallback = getStringValue("connector.ssl.certType", systemFallback);
- return getStringValue("connector.ssl.keyManagerFactoryAlgorithm", fallback);
- }
-
- public String getConnectorTrustStorePath()
- {
- return getStringValue("connector.ssl.trustStorePath", null);
- }
-
- public String getConnectorTrustStorePassword()
- {
- return getStringValue("connector.ssl.trustStorePassword", null);
- }
-
- public String getConnectorTrustStoreType()
- {
- return getStringValue("connector.ssl.trustStoreType", "JKS");
- }
-
- public String getConnectorTrustManagerFactoryAlgorithm()
- {
- return getStringValue("connector.ssl.trustManagerFactoryAlgorithm", TrustManagerFactory.getDefaultAlgorithm());
- }
-
- public String getCertAlias()
- {
- return getStringValue("connector.ssl.certAlias", null);
- }
-
- public boolean needClientAuth()
- {
- return getConfig().getBoolean("connector.ssl.needClientAuth", false);
- }
-
- public boolean wantClientAuth()
- {
- return getConfig().getBoolean("connector.ssl.wantClientAuth", false);
- }
-
- public String getDefaultVirtualHost()
- {
- return getStringValue("virtualhosts.default");
- }
-
- public void setDefaultVirtualHost(String vhost)
- {
- getConfig().setProperty("virtualhosts.default", vhost);
- }
-
- public void setHousekeepingCheckPeriod(long value)
- {
- getConfig().setProperty("housekeeping.checkPeriod", value);
- }
-
- public long getHousekeepingCheckPeriod()
- {
- return getLongValue("housekeeping.checkPeriod", DEFAULT_HOUSEKEEPING_PERIOD);
- }
-
- public long getStatisticsSamplePeriod()
- {
- return getConfig().getLong("statistics.sample.period", 5000L);
- }
-
- public boolean isStatisticsGenerationBrokerEnabled()
- {
- return getConfig().getBoolean("statistics.generation.broker", false);
- }
-
- public boolean isStatisticsGenerationVirtualhostsEnabled()
- {
- return getConfig().getBoolean("statistics.generation.virtualhosts", false);
- }
-
- public boolean isStatisticsGenerationConnectionsEnabled()
- {
- return getConfig().getBoolean("statistics.generation.connections", false);
- }
-
- public long getStatisticsReportingPeriod()
- {
- return getConfig().getLong("statistics.reporting.period", 0L);
- }
-
- public boolean isStatisticsReportResetEnabled()
- {
- return getConfig().getBoolean("statistics.reporting.reset", false);
- }
-
- public int getMaxChannelCount()
- {
- return getIntValue("maximumChannelCount", 256);
- }
-
- /**
- * List of Broker features that have been disabled within configuration. Disabled
- * features won't be advertised to the clients on connection.
- *
- * @return list of disabled features, or empty list if no features are disabled.
- */
- public List<String> getDisabledFeatures()
- {
- final List<String> disabledFeatures = getListValue("disabledFeatures", Collections.emptyList());
- return disabledFeatures;
- }
-
- public boolean getManagementRightsInferAllAccess()
- {
- return getBooleanValue("management.managementRightsInferAllAccess", true);
- }
-
- public int getMaxDeliveryCount()
- {
- return getConfig().getInt("maximumDeliveryCount", 0);
- }
-
- /**
- * Check if dead letter queue delivery is enabled, defaults to disabled if not set.
- */
- public boolean isDeadLetterQueueEnabled()
- {
- return getConfig().getBoolean("deadLetterQueues", false);
- }
-
- /**
- * String to affix to end of queue name when generating an alternate exchange for DLQ purposes.
- */
- public String getDeadLetterExchangeSuffix()
- {
- return getConfig().getString("deadLetterExchangeSuffix", DefaultExchangeFactory.DEFAULT_DLE_NAME_SUFFIX);
- }
-
- /**
- * String to affix to end of queue name when generating a queue for DLQ purposes.
- */
- public String getDeadLetterQueueSuffix()
- {
- return getConfig().getString("deadLetterQueueSuffix", AMQQueueFactory.DEFAULT_DLQ_NAME_SUFFIX);
- }
-
- public boolean isAmqp10enabled()
- {
- return getConfig().getBoolean(CONNECTOR_AMQP10ENABLED, true);
- }
-
- public boolean isAmqp010enabled()
- {
- return getConfig().getBoolean(CONNECTOR_AMQP010ENABLED, true);
- }
-
- public boolean isAmqp091enabled()
- {
- return getConfig().getBoolean(CONNECTOR_AMQP091ENABLED, true);
- }
-
- public boolean isAmqp09enabled()
- {
- return getConfig().getBoolean(CONNECTOR_AMQP09ENABLED, true);
- }
-
- public boolean isAmqp08enabled()
- {
- return getConfig().getBoolean(CONNECTOR_AMQP08ENABLED, true);
- }
-
- /**
- * Returns the configured default reply to an unsupported AMQP protocol initiation, or null if there is none
- */
- public AmqpProtocolVersion getDefaultSupportedProtocolReply()
- {
- String reply = getConfig().getString(CONNECTOR_AMQP_SUPPORTED_REPLY, null);
-
- return reply == null ? null : AmqpProtocolVersion.valueOf(reply);
- }
-
- public void setQpidWork(String path)
- {
- _qpidWork = path;
- }
-
- public void setQpidHome(String path)
- {
- _qpidHome = path;
- }
-
-
-
-}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ServerNetworkTransportConfiguration.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ServerNetworkTransportConfiguration.java
deleted file mode 100644
index 51dcc38c47..0000000000
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ServerNetworkTransportConfiguration.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * 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.qpid.server.configuration;
-
-import java.net.InetSocketAddress;
-import org.apache.qpid.transport.NetworkTransportConfiguration;
-
-public class ServerNetworkTransportConfiguration implements NetworkTransportConfiguration
-{
- private final ServerConfiguration _serverConfig;
- private final String _transport;
- private InetSocketAddress _address;
-
- public ServerNetworkTransportConfiguration(final ServerConfiguration serverConfig,
- final InetSocketAddress address,
- final String transport)
- {
- _serverConfig = serverConfig;
- _address = address;
- _transport = transport;
- }
-
- public Boolean getTcpNoDelay()
- {
- return _serverConfig.getTcpNoDelay();
- }
-
- public Integer getSendBufferSize()
- {
- return _serverConfig.getWriteBufferSize();
- }
-
- public Integer getReceiveBufferSize()
- {
- return _serverConfig.getReceiveBufferSize();
- }
-
- public Integer getPort()
- {
- return _address.getPort();
- }
-
- public String getHost()
- {
- return _address.getHostName();
- }
-
- public String getTransport()
- {
- return _transport;
- }
-
- public Integer getConnectorProcessors()
- {
- return _serverConfig.getConnectorProcessors();
- }
-
- public InetSocketAddress getAddress()
- {
- return _address;
- }
-
- public boolean needClientAuth()
- {
- return _serverConfig.needClientAuth();
- }
-
- @Override
- public boolean wantClientAuth()
- {
- return _serverConfig.wantClientAuth();
- }
-}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/VirtualHostConfiguration.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/VirtualHostConfiguration.java
index a14977ec1b..eada676b65 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/VirtualHostConfiguration.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/VirtualHostConfiguration.java
@@ -25,9 +25,10 @@ import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.qpid.server.configuration.plugins.AbstractConfiguration;
-import org.apache.qpid.server.registry.ApplicationRegistry;
+import org.apache.qpid.server.model.Broker;
import org.apache.qpid.server.store.MemoryMessageStore;
+import java.io.File;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
@@ -38,13 +39,50 @@ public class VirtualHostConfiguration extends AbstractConfiguration
private final String _name;
private final Map<String, QueueConfiguration> _queues = new HashMap<String, QueueConfiguration>();
private final Map<String, ExchangeConfiguration> _exchanges = new HashMap<String, ExchangeConfiguration>();
+ private final Broker _broker;
+ private final long _defaultHouseKeepingCheckPeriod;
- public VirtualHostConfiguration(String name, Configuration config) throws ConfigurationException
+ public VirtualHostConfiguration(String name, Configuration config, Broker broker) throws ConfigurationException
{
_name = name;
+ _broker = broker;
+
+ // store value of this attribute for running life of virtual host since updating of this value has no run-time effect
+ _defaultHouseKeepingCheckPeriod = ((Number)_broker.getAttribute(Broker.HOUSEKEEPING_CHECK_PERIOD)).longValue();
setConfiguration(config);
}
+ public VirtualHostConfiguration(String name, File configurationFile, Broker broker) throws ConfigurationException
+ {
+ this(name, loadConfiguration(name, configurationFile), broker);
+ }
+
+ private static Configuration loadConfiguration(String name, File configurationFile) throws ConfigurationException
+ {
+ Configuration configuration = null;
+ if (configurationFile == null)
+ {
+ throw new IllegalConfigurationException("Virtualhost configuration file must be supplied!");
+ }
+ else
+ {
+ Configuration virtualHostConfig = XmlConfigurationUtilities.parseConfig(configurationFile, null);
+
+ // check if it is an old virtual host configuration file which has an element of the same name as virtual host
+ Configuration config = virtualHostConfig.subset("virtualhost." + XmlConfigurationUtilities.escapeTagName(name));
+ if (config.isEmpty())
+ {
+ // assume it is a new configuration which does not have an element of the same name as the virtual host
+ configuration = virtualHostConfig;
+ }
+ else
+ {
+ configuration = config;
+ }
+ }
+ return configuration;
+ }
+
/**
* Apply the given configuration to this VirtualHostConfiguration
*
@@ -82,7 +120,7 @@ public class VirtualHostConfiguration extends AbstractConfiguration
public long getHousekeepingCheckPeriod()
{
- return getLongValue("housekeeping.checkPeriod", ApplicationRegistry.getInstance().getConfiguration().getHousekeepingCheckPeriod());
+ return getLongValue("housekeeping.checkPeriod", _defaultHouseKeepingCheckPeriod);
}
public Configuration getStoreConfiguration()
@@ -139,37 +177,37 @@ public class VirtualHostConfiguration extends AbstractConfiguration
public int getMaximumMessageAge()
{
- return getIntValue("queues.maximumMessageAge");
+ return getIntValue("queues.maximumMessageAge", getBrokerAttributeAsInt(Broker.ALERT_THRESHOLD_MESSAGE_AGE));
}
public Long getMaximumQueueDepth()
{
- return getLongValue("queues.maximumQueueDepth");
+ return getLongValue("queues.maximumQueueDepth", getBrokerAttributeAsLong(Broker.ALERT_THRESHOLD_QUEUE_DEPTH));
}
public Long getMaximumMessageSize()
{
- return getLongValue("queues.maximumMessageSize");
+ return getLongValue("queues.maximumMessageSize", getBrokerAttributeAsLong(Broker.ALERT_THRESHOLD_MESSAGE_SIZE));
}
public Long getMaximumMessageCount()
{
- return getLongValue("queues.maximumMessageCount");
+ return getLongValue("queues.maximumMessageCount", getBrokerAttributeAsLong(Broker.ALERT_THRESHOLD_MESSAGE_COUNT));
}
public Long getMinimumAlertRepeatGap()
{
- return getLongValue("queues.minimumAlertRepeatGap", ApplicationRegistry.getInstance().getConfiguration().getMinimumAlertRepeatGap());
+ return getLongValue("queues.minimumAlertRepeatGap", getBrokerAttributeAsLong(Broker.ALERT_REPEAT_GAP));
}
public long getCapacity()
{
- return getLongValue("queues.capacity");
+ return getLongValue("queues.capacity", getBrokerAttributeAsLong(Broker.FLOW_CONTROL_SIZE_BYTES));
}
public long getFlowResumeCapacity()
{
- return getLongValue("queues.flowResumeCapacity", getCapacity());
+ return getLongValue("queues.flowResumeCapacity", getBrokerAttributeAsLong(Broker.FLOW_CONTROL_RESUME_SIZE_BYTES));
}
public String[] getElementsProcessed()
@@ -225,7 +263,7 @@ public class VirtualHostConfiguration extends AbstractConfiguration
public int getMaxDeliveryCount()
{
- return getIntValue("queues.maximumDeliveryCount", ApplicationRegistry.getInstance().getConfiguration().getMaxDeliveryCount());
+ return getIntValue("queues.maximumDeliveryCount", getBrokerAttributeAsInt(Broker.MAXIMUM_DELIVERY_ATTEMPTS));
}
/**
@@ -233,7 +271,25 @@ public class VirtualHostConfiguration extends AbstractConfiguration
*/
public boolean isDeadLetterQueueEnabled()
{
- return getBooleanValue("queues.deadLetterQueues", ApplicationRegistry.getInstance().getConfiguration().isDeadLetterQueueEnabled());
+ return getBooleanValue("queues.deadLetterQueues", getBrokerAttributeAsBoolean(Broker.DEAD_LETTER_QUEUE_ENABLED));
+ }
+
+ private long getBrokerAttributeAsLong(String name)
+ {
+ Number brokerValue = (Number)_broker.getAttribute(name);
+ return brokerValue == null? 0 : brokerValue.longValue();
+ }
+
+ private int getBrokerAttributeAsInt(String name)
+ {
+ Number brokerValue = (Number)_broker.getAttribute(name);
+ return brokerValue == null? 0 : brokerValue.intValue();
+ }
+
+ private boolean getBrokerAttributeAsBoolean(String name)
+ {
+ Boolean brokerValue = (Boolean)_broker.getAttribute(name);
+ return brokerValue == null? false : brokerValue.booleanValue();
}
}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/XmlConfigurationUtilities.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/XmlConfigurationUtilities.java
new file mode 100644
index 0000000000..c0cff2c109
--- /dev/null
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/XmlConfigurationUtilities.java
@@ -0,0 +1,111 @@
+/*
+ *
+ * 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.qpid.server.configuration;
+
+import java.io.File;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.apache.commons.configuration.CompositeConfiguration;
+import org.apache.commons.configuration.Configuration;
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.ConfigurationFactory;
+import org.apache.commons.configuration.SystemConfiguration;
+import org.apache.commons.configuration.XMLConfiguration;
+
+public class XmlConfigurationUtilities
+{
+
+ // Our configuration class needs to make the interpolate method
+ // public so it can be called below from the config method.
+ public static class MyConfiguration extends CompositeConfiguration
+ {
+ public String interpolate(String obj)
+ {
+ return super.interpolate(obj);
+ }
+ }
+
+ public static Configuration parseConfig(File file, Map<String, String> envVarMap) throws ConfigurationException
+ {
+ ConfigurationFactory factory = new ConfigurationFactory();
+ factory.setConfigurationFileName(file.getAbsolutePath());
+ Configuration conf = factory.getConfiguration();
+
+ Iterator<?> keys = conf.getKeys();
+ if (!keys.hasNext())
+ {
+ keys = null;
+ conf = flatConfig(file);
+ }
+
+ XmlConfigurationUtilities.substituteEnvironmentVariables(conf, envVarMap);
+ return conf;
+ }
+
+ public final static Configuration flatConfig(File file) throws ConfigurationException
+ {
+ // We have to override the interpolate methods so that
+ // interpolation takes place across the entirety of the
+ // composite configuration. Without doing this each
+ // configuration object only interpolates variables defined
+ // inside itself.
+ final MyConfiguration conf = new MyConfiguration();
+ conf.addConfiguration(new SystemConfiguration()
+ {
+ protected String interpolate(String o)
+ {
+ return conf.interpolate(o);
+ }
+ });
+ conf.addConfiguration(new XMLConfiguration(file)
+ {
+ protected String interpolate(String o)
+ {
+ return conf.interpolate(o);
+ }
+ });
+ return conf;
+ }
+
+ static void substituteEnvironmentVariables(Configuration conf, Map<String, String> envVarMap)
+ {
+ if (envVarMap == null || envVarMap.isEmpty())
+ {
+ return;
+ }
+ for (Entry<String, String> var : envVarMap.entrySet())
+ {
+ String val = System.getenv(var.getKey());
+ if (val != null)
+ {
+ conf.setProperty(var.getValue(), val);
+ }
+ }
+ }
+
+
+ public static String escapeTagName(String name)
+ {
+ return name.replaceAll("\\.", "\\.\\.");
+ }
+}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/plugins/AbstractConfiguration.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/plugins/AbstractConfiguration.java
index 0e7c19df87..3c17faef75 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/plugins/AbstractConfiguration.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/plugins/AbstractConfiguration.java
@@ -315,7 +315,7 @@ public abstract class AbstractConfiguration
}
}
- public String escapeTagName(String name)
+ public static String escapeTagName(String name)
{
return name.replaceAll("\\.", "\\.\\.");
}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/AuthenticationProviderRecoverer.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/AuthenticationProviderRecoverer.java
new file mode 100644
index 0000000000..9b06a2b499
--- /dev/null
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/AuthenticationProviderRecoverer.java
@@ -0,0 +1,55 @@
+/*
+ *
+ * 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.qpid.server.configuration.startup;
+
+import java.util.Map;
+
+import org.apache.qpid.server.configuration.ConfigurationEntry;
+import org.apache.qpid.server.configuration.ConfiguredObjectRecoverer;
+import org.apache.qpid.server.configuration.RecovererProvider;
+import org.apache.qpid.server.model.AuthenticationProvider;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.ConfiguredObject;
+import org.apache.qpid.server.model.adapter.AuthenticationProviderFactory;
+
+public class AuthenticationProviderRecoverer implements ConfiguredObjectRecoverer<AuthenticationProvider>
+{
+ private final AuthenticationProviderFactory _authenticationProviderFactory;
+
+ public AuthenticationProviderRecoverer(AuthenticationProviderFactory authenticationProviderFactory)
+ {
+ _authenticationProviderFactory = authenticationProviderFactory;
+ }
+
+ @Override
+ public AuthenticationProvider create(RecovererProvider recovererProvider, ConfigurationEntry configurationEntry, ConfiguredObject... parents)
+ {
+ Broker broker = RecovererHelper.verifyOnlyBrokerIsParent(parents);
+ Map<String, Object> attributes = configurationEntry.getAttributes();
+ AuthenticationProvider authenticationProvider = _authenticationProviderFactory.create(
+ configurationEntry.getId(),
+ broker,
+ attributes, null);
+
+ return authenticationProvider;
+ }
+
+}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/BrokerRecoverer.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/BrokerRecoverer.java
new file mode 100644
index 0000000000..4bfa0ca7a3
--- /dev/null
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/BrokerRecoverer.java
@@ -0,0 +1,139 @@
+package org.apache.qpid.server.configuration.startup;
+
+import java.util.Collection;
+import java.util.Map;
+
+import org.apache.qpid.server.configuration.ConfigurationEntry;
+import org.apache.qpid.server.configuration.ConfiguredObjectRecoverer;
+import org.apache.qpid.server.configuration.IllegalConfigurationException;
+import org.apache.qpid.server.configuration.RecovererProvider;
+import org.apache.qpid.server.logging.LogRecorder;
+import org.apache.qpid.server.logging.RootMessageLogger;
+import org.apache.qpid.server.model.AuthenticationProvider;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.ConfiguredObject;
+import org.apache.qpid.server.model.Port;
+import org.apache.qpid.server.model.adapter.AuthenticationProviderFactory;
+import org.apache.qpid.server.model.adapter.BrokerAdapter;
+import org.apache.qpid.server.model.adapter.PortFactory;
+import org.apache.qpid.server.configuration.store.StoreConfigurationChangeListener;
+import org.apache.qpid.server.configuration.updater.TaskExecutor;
+import org.apache.qpid.server.security.group.GroupPrincipalAccessor;
+import org.apache.qpid.server.stats.StatisticsGatherer;
+import org.apache.qpid.server.virtualhost.VirtualHostRegistry;
+
+public class BrokerRecoverer implements ConfiguredObjectRecoverer<Broker>
+{
+ private final StatisticsGatherer _statisticsGatherer;
+ private final VirtualHostRegistry _virtualHostRegistry;
+ private final LogRecorder _logRecorder;
+ private final RootMessageLogger _rootMessageLogger;
+ private final AuthenticationProviderFactory _authenticationProviderFactory;
+ private final PortFactory _portFactory;
+ private final TaskExecutor _taskExecutor;
+
+ public BrokerRecoverer(AuthenticationProviderFactory authenticationProviderFactory, PortFactory portFactory,
+ StatisticsGatherer statisticsGatherer, VirtualHostRegistry virtualHostRegistry, LogRecorder logRecorder,
+ RootMessageLogger rootMessageLogger, TaskExecutor taskExecutor)
+ {
+ _portFactory = portFactory;
+ _authenticationProviderFactory = authenticationProviderFactory;
+ _statisticsGatherer = statisticsGatherer;
+ _virtualHostRegistry = virtualHostRegistry;
+ _logRecorder = logRecorder;
+ _rootMessageLogger = rootMessageLogger;
+ _taskExecutor = taskExecutor;
+ }
+
+ @Override
+ public Broker create(RecovererProvider recovererProvider, ConfigurationEntry entry, ConfiguredObject... parents)
+ {
+ StoreConfigurationChangeListener storeChangeListener = new StoreConfigurationChangeListener(entry.getStore());
+ BrokerAdapter broker = new BrokerAdapter(entry.getId(), entry.getAttributes(), _statisticsGatherer, _virtualHostRegistry,
+ _logRecorder, _rootMessageLogger, _authenticationProviderFactory, _portFactory, _taskExecutor);
+ broker.addChangeListener(storeChangeListener);
+ Map<String, Collection<ConfigurationEntry>> childEntries = entry.getChildren();
+ for (String type : childEntries.keySet())
+ {
+ ConfiguredObjectRecoverer<?> recoverer = recovererProvider.getRecoverer(type);
+ if (recoverer == null)
+ {
+ throw new IllegalConfigurationException("Cannot recover entry for the type '" + type + "' from broker");
+ }
+ Collection<ConfigurationEntry> entries = childEntries.get(type);
+ for (ConfigurationEntry childEntry : entries)
+ {
+ ConfiguredObject object = recoverer.create(recovererProvider, childEntry, broker);
+ if (object == null)
+ {
+ throw new IllegalConfigurationException("Cannot create configured object for the entry " + childEntry);
+ }
+ broker.recoverChild(object);
+ object.addChangeListener(storeChangeListener);
+ }
+ }
+ wireUpConfiguredObjects(broker, entry.getAttributes());
+
+ return broker;
+ }
+
+ private void wireUpConfiguredObjects(BrokerAdapter broker, Map<String, Object> brokerAttributes)
+ {
+ AuthenticationProvider defaultAuthenticationProvider = null;
+ Collection<AuthenticationProvider> authenticationProviders = broker.getAuthenticationProviders();
+ int numberOfAuthenticationProviders = authenticationProviders.size();
+ if (numberOfAuthenticationProviders == 0)
+ {
+ throw new IllegalConfigurationException("No authentication provider was configured");
+ }
+ else if (numberOfAuthenticationProviders == 1)
+ {
+ defaultAuthenticationProvider = authenticationProviders.iterator().next();
+ }
+ else
+ {
+ String name = (String) brokerAttributes.get(Broker.DEFAULT_AUTHENTICATION_PROVIDER);
+ if (name == null)
+ {
+ throw new IllegalConfigurationException("Multiple authentication providers defined, but no default was configured.");
+ }
+
+ defaultAuthenticationProvider = getAuthenticationProviderByName(broker, name);
+ }
+ broker.setDefaultAuthenticationProvider(defaultAuthenticationProvider);
+
+ GroupPrincipalAccessor groupPrincipalAccessor = new GroupPrincipalAccessor(broker.getGroupProviders());
+ for (AuthenticationProvider authenticationProvider : authenticationProviders)
+ {
+ authenticationProvider.setGroupAccessor(groupPrincipalAccessor);
+ }
+
+ Collection<Port> ports = broker.getPorts();
+ for (Port port : ports)
+ {
+ String authenticationProviderName = (String) port.getAttribute(Port.AUTHENTICATION_MANAGER);
+ AuthenticationProvider provider = null;
+ if (authenticationProviderName != null)
+ {
+ provider = getAuthenticationProviderByName(broker, authenticationProviderName);
+ }
+ else
+ {
+ provider = defaultAuthenticationProvider;
+ }
+ port.setAuthenticationProvider(provider);
+ }
+ }
+
+ private AuthenticationProvider getAuthenticationProviderByName(BrokerAdapter broker, String authenticationProviderName)
+ {
+ AuthenticationProvider provider = broker.getAuthenticationProviderByName(authenticationProviderName);
+ if (provider == null)
+ {
+ throw new IllegalConfigurationException("Cannot find the authentication provider with name: "
+ + authenticationProviderName);
+ }
+ return provider;
+ }
+
+}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/DefaultRecovererProvider.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/DefaultRecovererProvider.java
new file mode 100644
index 0000000000..15cb229d8a
--- /dev/null
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/DefaultRecovererProvider.java
@@ -0,0 +1,112 @@
+/*
+ *
+ * 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.qpid.server.configuration.startup;
+
+import org.apache.qpid.server.configuration.ConfiguredObjectRecoverer;
+import org.apache.qpid.server.configuration.RecovererProvider;
+import org.apache.qpid.server.logging.LogRecorder;
+import org.apache.qpid.server.logging.RootMessageLogger;
+import org.apache.qpid.server.model.AuthenticationProvider;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.GroupProvider;
+import org.apache.qpid.server.model.KeyStore;
+import org.apache.qpid.server.model.Plugin;
+import org.apache.qpid.server.model.Port;
+import org.apache.qpid.server.model.TrustStore;
+import org.apache.qpid.server.model.VirtualHost;
+import org.apache.qpid.server.model.adapter.AuthenticationProviderFactory;
+import org.apache.qpid.server.model.adapter.PortFactory;
+import org.apache.qpid.server.configuration.updater.TaskExecutor;
+import org.apache.qpid.server.plugin.AuthenticationManagerFactory;
+import org.apache.qpid.server.plugin.GroupManagerFactory;
+import org.apache.qpid.server.plugin.PluginFactory;
+import org.apache.qpid.server.plugin.QpidServiceLoader;
+import org.apache.qpid.server.stats.StatisticsGatherer;
+import org.apache.qpid.server.virtualhost.VirtualHostRegistry;
+
+public class DefaultRecovererProvider implements RecovererProvider
+{
+
+ private final StatisticsGatherer _brokerStatisticsGatherer;
+ private final VirtualHostRegistry _virtualHostRegistry;
+ private final LogRecorder _logRecorder;
+ private final RootMessageLogger _rootMessageLogger;
+ private final AuthenticationProviderFactory _authenticationProviderFactory;
+ private final PortFactory _portFactory;
+ private final QpidServiceLoader<GroupManagerFactory> _groupManagerServiceLoader;
+ private final QpidServiceLoader<PluginFactory> _pluginFactoryServiceLoader;
+ private final TaskExecutor _taskExecutor;
+
+ public DefaultRecovererProvider(StatisticsGatherer brokerStatisticsGatherer, VirtualHostRegistry virtualHostRegistry,
+ LogRecorder logRecorder, RootMessageLogger rootMessageLogger, TaskExecutor taskExecutor)
+ {
+ _authenticationProviderFactory = new AuthenticationProviderFactory(new QpidServiceLoader<AuthenticationManagerFactory>());
+ _portFactory = new PortFactory();
+ _brokerStatisticsGatherer = brokerStatisticsGatherer;
+ _virtualHostRegistry = virtualHostRegistry;
+ _logRecorder = logRecorder;
+ _rootMessageLogger = rootMessageLogger;
+ _groupManagerServiceLoader = new QpidServiceLoader<GroupManagerFactory>();
+ _pluginFactoryServiceLoader = new QpidServiceLoader<PluginFactory>();
+ _taskExecutor = taskExecutor;
+ }
+
+ @Override
+ public ConfiguredObjectRecoverer<?> getRecoverer(String type)
+ {
+ if (Broker.class.getSimpleName().equals(type))
+ {
+ return new BrokerRecoverer(_authenticationProviderFactory, _portFactory, _brokerStatisticsGatherer, _virtualHostRegistry,
+ _logRecorder, _rootMessageLogger, _taskExecutor);
+ }
+ else if(VirtualHost.class.getSimpleName().equals(type))
+ {
+ return new VirtualHostRecoverer(_brokerStatisticsGatherer);
+ }
+ else if(AuthenticationProvider.class.getSimpleName().equals(type))
+ {
+ return new AuthenticationProviderRecoverer(_authenticationProviderFactory);
+ }
+ else if(Port.class.getSimpleName().equals(type))
+ {
+ return new PortRecoverer(_portFactory);
+ }
+ else if(GroupProvider.class.getSimpleName().equals(type))
+ {
+ return new GroupProviderRecoverer(_groupManagerServiceLoader);
+ }
+ else if(KeyStore.class.getSimpleName().equals(type))
+ {
+ return new KeyStoreRecoverer();
+ }
+ else if(TrustStore.class.getSimpleName().equals(type))
+ {
+ return new TrustStoreRecoverer();
+ }
+ else if(Plugin.class.getSimpleName().equals(type))
+ {
+ return new PluginRecoverer(_pluginFactoryServiceLoader);
+ }
+
+ return null;
+ }
+
+}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/GroupProviderRecoverer.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/GroupProviderRecoverer.java
new file mode 100644
index 0000000000..275a0c736c
--- /dev/null
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/GroupProviderRecoverer.java
@@ -0,0 +1,74 @@
+/*
+ *
+ * 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.qpid.server.configuration.startup;
+
+import java.util.Map;
+
+import org.apache.qpid.server.configuration.ConfigurationEntry;
+import org.apache.qpid.server.configuration.ConfiguredObjectRecoverer;
+import org.apache.qpid.server.configuration.IllegalConfigurationException;
+import org.apache.qpid.server.configuration.RecovererProvider;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.ConfiguredObject;
+import org.apache.qpid.server.model.GroupProvider;
+import org.apache.qpid.server.model.adapter.GroupProviderAdapter;
+import org.apache.qpid.server.plugin.GroupManagerFactory;
+import org.apache.qpid.server.plugin.QpidServiceLoader;
+import org.apache.qpid.server.security.group.GroupManager;
+
+public class GroupProviderRecoverer implements ConfiguredObjectRecoverer<GroupProvider>
+{
+ private QpidServiceLoader<GroupManagerFactory> _groupManagerServiceLoader;
+
+ public GroupProviderRecoverer(QpidServiceLoader<GroupManagerFactory> groupManagerServiceLoader)
+ {
+ super();
+ _groupManagerServiceLoader = groupManagerServiceLoader;
+ }
+
+ @Override
+ public GroupProvider create(RecovererProvider recovererProvider, ConfigurationEntry configurationEntry, ConfiguredObject... parents)
+ {
+ Broker broker = RecovererHelper.verifyOnlyBrokerIsParent(parents);
+ Map<String, Object> attributes = configurationEntry.getAttributes();
+ GroupManager groupManager = createGroupManager(attributes);
+ if (groupManager == null)
+ {
+ throw new IllegalConfigurationException("Cannot create GroupManager from attributes : " + attributes);
+ }
+ GroupProviderAdapter groupProviderAdapter = new GroupProviderAdapter(configurationEntry.getId(), groupManager, broker);
+ return groupProviderAdapter;
+ }
+
+ private GroupManager createGroupManager(Map<String, Object> attributes)
+ {
+ for(GroupManagerFactory factory : _groupManagerServiceLoader.instancesOf(GroupManagerFactory.class))
+ {
+ GroupManager groupManager = factory.createInstance(attributes);
+ if (groupManager != null)
+ {
+ return groupManager;
+ }
+ }
+ return null;
+ }
+
+}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/KeyStoreRecoverer.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/KeyStoreRecoverer.java
new file mode 100644
index 0000000000..8efedd37b5
--- /dev/null
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/KeyStoreRecoverer.java
@@ -0,0 +1,40 @@
+/*
+ *
+ * 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.qpid.server.configuration.startup;
+
+import org.apache.qpid.server.configuration.ConfigurationEntry;
+import org.apache.qpid.server.configuration.ConfiguredObjectRecoverer;
+import org.apache.qpid.server.configuration.RecovererProvider;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.ConfiguredObject;
+import org.apache.qpid.server.model.KeyStore;
+import org.apache.qpid.server.model.adapter.KeyStoreAdapter;
+
+public class KeyStoreRecoverer implements ConfiguredObjectRecoverer<KeyStore>
+{
+ @Override
+ public KeyStore create(RecovererProvider recovererProvider, ConfigurationEntry entry, ConfiguredObject... parents)
+ {
+ Broker broker = RecovererHelper.verifyOnlyBrokerIsParent(parents);
+ return new KeyStoreAdapter(entry.getId(), broker, entry.getAttributes());
+ }
+
+}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/PluginRecoverer.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/PluginRecoverer.java
new file mode 100644
index 0000000000..ddc4482953
--- /dev/null
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/PluginRecoverer.java
@@ -0,0 +1,66 @@
+/*
+ *
+ * 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.qpid.server.configuration.startup;
+
+import java.util.Map;
+import java.util.UUID;
+
+import org.apache.qpid.server.configuration.ConfigurationEntry;
+import org.apache.qpid.server.configuration.ConfiguredObjectRecoverer;
+import org.apache.qpid.server.configuration.IllegalConfigurationException;
+import org.apache.qpid.server.configuration.RecovererProvider;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.ConfiguredObject;
+import org.apache.qpid.server.plugin.PluginFactory;
+import org.apache.qpid.server.plugin.QpidServiceLoader;
+
+public class PluginRecoverer implements ConfiguredObjectRecoverer<ConfiguredObject>
+{
+ private QpidServiceLoader<PluginFactory> _serviceLoader;
+
+ public PluginRecoverer(QpidServiceLoader<PluginFactory> serviceLoader)
+ {
+ _serviceLoader = serviceLoader;
+ }
+
+ @Override
+ public ConfiguredObject create(RecovererProvider recovererProvider, ConfigurationEntry configurationEntry, ConfiguredObject... parents)
+ {
+ Broker broker = RecovererHelper.verifyOnlyBrokerIsParent(parents);
+ Map<String, Object> attributes = configurationEntry.getAttributes();
+ Iterable<PluginFactory> factories = _serviceLoader.instancesOf(PluginFactory.class);
+ for (PluginFactory pluginFactory : factories)
+ {
+ UUID configurationId = configurationEntry.getId();
+ ConfiguredObject pluginObject = pluginFactory.createInstance(configurationId, attributes, broker);
+ if (pluginObject != null)
+ {
+ UUID pluginId = pluginObject.getId();
+ if (!configurationId.equals(pluginId))
+ {
+ throw new IllegalStateException("Plugin object id '" + pluginId + "' does not equal expected id " + configurationId);
+ }
+ return pluginObject;
+ }
+ }
+ throw new IllegalConfigurationException("Cannot create a plugin object for " + attributes + " with factories " + factories);
+ }
+}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/PortRecoverer.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/PortRecoverer.java
new file mode 100644
index 0000000000..147e835a8d
--- /dev/null
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/PortRecoverer.java
@@ -0,0 +1,52 @@
+/*
+ *
+ * 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.qpid.server.configuration.startup;
+
+import org.apache.qpid.server.configuration.ConfigurationEntry;
+import org.apache.qpid.server.configuration.ConfiguredObjectRecoverer;
+import org.apache.qpid.server.configuration.RecovererProvider;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.ConfiguredObject;
+import org.apache.qpid.server.model.Port;
+import org.apache.qpid.server.model.adapter.BrokerAdapter;
+import org.apache.qpid.server.model.adapter.PortFactory;
+
+public class PortRecoverer implements ConfiguredObjectRecoverer<Port>
+{
+ /**
+ * delegates to a {@link PortFactory} so that the logic can be shared by
+ * {@link BrokerAdapter}
+ */
+ private final PortFactory _portFactory;
+
+ public PortRecoverer(PortFactory portFactory)
+ {
+ _portFactory = portFactory;
+ }
+
+ @Override
+ public Port create(RecovererProvider recovererProvider, ConfigurationEntry configurationEntry, ConfiguredObject... parents)
+ {
+ Broker broker = RecovererHelper.verifyOnlyBrokerIsParent(parents);
+ return _portFactory.createPort(configurationEntry.getId(), broker, configurationEntry.getAttributes());
+ }
+
+}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/RecovererHelper.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/RecovererHelper.java
new file mode 100644
index 0000000000..b60c9c289f
--- /dev/null
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/RecovererHelper.java
@@ -0,0 +1,44 @@
+/*
+ *
+ * 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.qpid.server.configuration.startup;
+
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.ConfiguredObject;
+
+public class RecovererHelper
+{
+ public static Broker verifyOnlyBrokerIsParent(ConfiguredObject... parents)
+ {
+ if (parents == null || parents.length == 0)
+ {
+ throw new IllegalArgumentException("Broker parent is not passed!");
+ }
+ if (parents.length != 1)
+ {
+ throw new IllegalArgumentException("Only one parent is expected!");
+ }
+ if (!(parents[0] instanceof Broker))
+ {
+ throw new IllegalArgumentException("Parent is not a broker");
+ }
+ return (Broker)parents[0];
+ }
+}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/TrustStoreRecoverer.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/TrustStoreRecoverer.java
new file mode 100644
index 0000000000..7e9428a4d6
--- /dev/null
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/TrustStoreRecoverer.java
@@ -0,0 +1,40 @@
+/*
+ *
+ * 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.qpid.server.configuration.startup;
+
+import org.apache.qpid.server.configuration.ConfigurationEntry;
+import org.apache.qpid.server.configuration.ConfiguredObjectRecoverer;
+import org.apache.qpid.server.configuration.RecovererProvider;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.ConfiguredObject;
+import org.apache.qpid.server.model.TrustStore;
+import org.apache.qpid.server.model.adapter.TrustStoreAdapter;
+
+public class TrustStoreRecoverer implements ConfiguredObjectRecoverer<TrustStore>
+{
+ @Override
+ public TrustStore create(RecovererProvider recovererProvider, ConfigurationEntry entry, ConfiguredObject... parents)
+ {
+ Broker broker = RecovererHelper.verifyOnlyBrokerIsParent(parents);
+ return new TrustStoreAdapter(entry.getId(), broker, entry.getAttributes());
+ }
+
+}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/VirtualHostRecoverer.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/VirtualHostRecoverer.java
new file mode 100644
index 0000000000..4f863adfb5
--- /dev/null
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/VirtualHostRecoverer.java
@@ -0,0 +1,51 @@
+/*
+ *
+ * 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.qpid.server.configuration.startup;
+
+
+import org.apache.qpid.server.configuration.ConfigurationEntry;
+import org.apache.qpid.server.configuration.ConfiguredObjectRecoverer;
+import org.apache.qpid.server.configuration.RecovererProvider;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.ConfiguredObject;
+import org.apache.qpid.server.model.VirtualHost;
+import org.apache.qpid.server.model.adapter.VirtualHostAdapter;
+import org.apache.qpid.server.stats.StatisticsGatherer;
+
+public class VirtualHostRecoverer implements ConfiguredObjectRecoverer<VirtualHost>
+{
+ private StatisticsGatherer _brokerStatisticsGatherer;
+
+ public VirtualHostRecoverer(StatisticsGatherer brokerStatisticsGatherer)
+ {
+ super();
+ _brokerStatisticsGatherer = brokerStatisticsGatherer;
+ }
+
+ @Override
+ public VirtualHost create(RecovererProvider recovererProvider, ConfigurationEntry entry, ConfiguredObject... parents)
+ {
+ Broker broker = RecovererHelper.verifyOnlyBrokerIsParent(parents);
+
+ return new VirtualHostAdapter(entry.getId(), entry.getAttributes(), broker, _brokerStatisticsGatherer, broker.getTaskExecutor());
+ }
+
+}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/JsonConfigurationEntryStore.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/JsonConfigurationEntryStore.java
new file mode 100644
index 0000000000..b8481de2cc
--- /dev/null
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/JsonConfigurationEntryStore.java
@@ -0,0 +1,528 @@
+package org.apache.qpid.server.configuration.store;
+
+import static org.apache.qpid.server.configuration.ConfigurationEntry.ATTRIBUTE_NAME;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+import java.util.TreeSet;
+import java.util.UUID;
+
+import org.apache.qpid.server.configuration.ConfigurationEntry;
+import org.apache.qpid.server.configuration.ConfigurationEntryStore;
+import org.apache.qpid.server.configuration.BrokerConfigurationStoreCreator;
+import org.apache.qpid.server.configuration.IllegalConfigurationException;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.ConfiguredObject;
+import org.apache.qpid.server.model.Model;
+import org.apache.qpid.server.model.UUIDGenerator;
+import org.apache.qpid.util.FileUtils;
+import org.apache.qpid.util.Strings;
+import org.codehaus.jackson.JsonGenerationException;
+import org.codehaus.jackson.JsonNode;
+import org.codehaus.jackson.JsonParser;
+import org.codehaus.jackson.JsonProcessingException;
+import org.codehaus.jackson.map.JsonMappingException;
+import org.codehaus.jackson.map.ObjectMapper;
+import org.codehaus.jackson.map.SerializationConfig;
+import org.codehaus.jackson.node.ArrayNode;
+
+public class JsonConfigurationEntryStore implements ConfigurationEntryStore
+{
+ private static final String DEFAULT_BROKER_NAME = "Broker";
+ private static final String ID = "id";
+ private static final String TYPE = "@type";
+
+ private ObjectMapper _objectMapper;
+ private Map<UUID, ConfigurationEntry> _entries;
+ private File _storeFile;
+ private UUID _rootId;
+ private String _initialStoreLocation;
+ private Map<String, Class<? extends ConfiguredObject>> _relationshipClasses;
+
+ public JsonConfigurationEntryStore()
+ {
+ this(BrokerConfigurationStoreCreator.INITIAL_STORE_LOCATION);
+ }
+
+ public JsonConfigurationEntryStore(String initialStore)
+ {
+ _initialStoreLocation = initialStore;
+ _objectMapper = new ObjectMapper();
+ _objectMapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, true);
+ _objectMapper.configure(JsonParser.Feature.ALLOW_COMMENTS, true);
+ _entries = new HashMap<UUID, ConfigurationEntry>();
+ _relationshipClasses = buildRelationshipClassMap();
+ }
+
+ private Map<String, Class<? extends ConfiguredObject>> buildRelationshipClassMap()
+ {
+ Map<String, Class<? extends ConfiguredObject>> relationships = new HashMap<String, Class<? extends ConfiguredObject>>();
+
+ Collection<Class<? extends ConfiguredObject>> children = Model.getInstance().getChildTypes(Broker.class);
+ for (Class<? extends ConfiguredObject> childClass : children)
+ {
+ String name = childClass.getSimpleName().toLowerCase();
+ String relationshipName = name + (name.endsWith("s") ? "es" : "s");
+ relationships.put(relationshipName, childClass);
+ }
+ return relationships;
+ }
+
+ public void load(URL storeURL)
+ {
+ if (_rootId != null)
+ {
+ throw new IllegalStateException("Cannot load the store from");
+ }
+ JsonNode node = load(storeURL, _objectMapper);
+ ConfigurationEntry brokerEntry = toEntry(node, Broker.class, _entries);
+ _rootId = brokerEntry.getId();
+ }
+
+ @Override
+ public void open(String storeLocation)
+ {
+ _storeFile = new File(storeLocation);
+ if (!_storeFile.exists() || _storeFile.length() == 0)
+ {
+ copyInitialStore();
+ }
+
+ load(fileToURL(_storeFile));
+ }
+
+ private void copyInitialStore()
+ {
+ InputStream in = null;
+ try
+ {
+ in = JsonConfigurationEntryStore.class.getClassLoader().getResourceAsStream(_initialStoreLocation);
+ FileUtils.copy(in, _storeFile);
+ }
+ catch (IOException e)
+ {
+ throw new IllegalConfigurationException("Cannot create store file by copying initial store", e);
+ }
+ finally
+ {
+ if (in != null)
+ {
+ try
+ {
+ in.close();
+ }
+ catch (IOException e)
+ {
+ throw new IllegalConfigurationException("Cannot close initial store input stream", e);
+ }
+ }
+ }
+ }
+
+ @Override
+ public synchronized UUID[] remove(UUID... entryIds)
+ {
+ List<UUID> removedIds = new ArrayList<UUID>();
+ boolean anyRemoved = false;
+ for (UUID uuid : entryIds)
+ {
+ if (_rootId.equals(uuid))
+ {
+ throw new IllegalConfigurationException("Cannot remove root entry");
+ }
+ }
+ for (UUID uuid : entryIds)
+ {
+ if (removeInternal(uuid))
+ {
+ anyRemoved = true;
+
+ // remove references to the entry from parent entries
+ for (ConfigurationEntry entry : _entries.values())
+ {
+ if (entry.hasChild(uuid))
+ {
+ Set<UUID> children = new HashSet<UUID>(entry.getChildrenIds());
+ children.remove(uuid);
+ ConfigurationEntry referal = new ConfigurationEntry(entry.getId(), entry.getType(),
+ entry.getAttributes(), children, this);
+ _entries.put(entry.getId(), referal);
+ }
+ }
+ removedIds.add(uuid);
+ }
+ }
+ if (anyRemoved)
+ {
+ saveAsTree();
+ }
+ return removedIds.toArray(new UUID[removedIds.size()]);
+ }
+
+ @Override
+ public synchronized void save(ConfigurationEntry... entries)
+ {
+ boolean anySaved = false;
+ for (ConfigurationEntry entry : entries)
+ {
+ ConfigurationEntry oldEntry = _entries.put(entry.getId(), entry);
+ if (!entry.equals(oldEntry))
+ {
+ anySaved = true;
+ }
+ }
+ if (anySaved)
+ {
+ saveAsTree();
+ }
+ }
+
+ @Override
+ public ConfigurationEntry getRootEntry()
+ {
+ return getEntry(_rootId);
+ }
+
+ @Override
+ public synchronized ConfigurationEntry getEntry(UUID id)
+ {
+ return _entries.get(id);
+ }
+
+ public void saveTo(File file)
+ {
+ saveAsTree(_rootId, _entries, _objectMapper, file);
+ }
+
+ private URL fileToURL(File storeFile)
+ {
+ URL storeURL = null;
+ try
+ {
+ storeURL = storeFile.toURI().toURL();
+ }
+ catch (MalformedURLException e)
+ {
+ throw new IllegalConfigurationException("Cannot create URL for file " + storeFile, e);
+ }
+ return storeURL;
+ }
+
+ private boolean removeInternal(UUID entryId)
+ {
+ ConfigurationEntry oldEntry = _entries.remove(entryId);
+ if (oldEntry != null)
+ {
+ Set<UUID> children = oldEntry.getChildrenIds();
+ if (children != null && !children.isEmpty())
+ {
+ for (UUID childId : children)
+ {
+ removeInternal(childId);
+ }
+ }
+ return true;
+ }
+ return false;
+ }
+
+ private void saveAsTree()
+ {
+ if (_storeFile != null)
+ {
+ saveAsTree(_rootId, _entries, _objectMapper, _storeFile);
+ }
+ }
+
+ private void saveAsTree(UUID rootId, Map<UUID, ConfigurationEntry> entries, ObjectMapper mapper, File file)
+ {
+ Map<String, Object> tree = toTree(rootId, entries);
+ try
+ {
+ mapper.writeValue(file, tree);
+ }
+ catch (JsonGenerationException e)
+ {
+ throw new IllegalConfigurationException("Cannot generate json!", e);
+ }
+ catch (JsonMappingException e)
+ {
+ throw new IllegalConfigurationException("Cannot map objects for json serialization!", e);
+ }
+ catch (IOException e)
+ {
+ throw new IllegalConfigurationException("Cannot save configuration into " + file + "!", e);
+ }
+ }
+
+ private Map<String, Object> toTree(UUID rootId, Map<UUID, ConfigurationEntry> entries)
+ {
+ ConfigurationEntry entry = entries.get(rootId);
+ if (entry == null || !entry.getId().equals(rootId))
+ {
+ throw new IllegalConfigurationException("Cannot find entry with id " + rootId + "!");
+ }
+ Map<String, Object> tree = new TreeMap<String, Object>();
+ Map<String, Object> attributes = entry.getAttributes();
+ if (attributes != null)
+ {
+ tree.putAll( attributes);
+ }
+ tree.put(ID, entry.getId());
+ tree.put(TYPE, entry.getType());
+ Set<UUID> childrenIds = entry.getChildrenIds();
+ if (childrenIds != null && !childrenIds.isEmpty())
+ {
+ for (UUID relationship : childrenIds)
+ {
+ ConfigurationEntry child = entries.get(relationship);
+ if (child != null)
+ {
+ String relationshipName = child.getType().toLowerCase() + "s";
+
+ @SuppressWarnings("unchecked")
+ Collection<Map<String, Object>> children = (Collection<Map<String, Object>>) tree.get(relationshipName);
+ if (children == null)
+ {
+ children = new ArrayList<Map<String, Object>>();
+ tree.put(relationshipName, children);
+ }
+ Map<String, Object> childAsMap = toTree(relationship, entries);
+ children.add(childAsMap);
+ }
+ }
+ }
+ return tree;
+ }
+
+ private JsonNode load(URL url, ObjectMapper mapper)
+ {
+ JsonNode root = null;
+ try
+ {
+ root = mapper.readTree(url);
+ }
+ catch (JsonProcessingException e)
+ {
+ throw new IllegalConfigurationException("Cannot parse json from '" + url + "'", e);
+ }
+ catch (IOException e)
+ {
+ throw new IllegalConfigurationException("Cannot read from '" + url + "'", e);
+ }
+ return root;
+ }
+
+ private ConfigurationEntry toEntry(JsonNode parent, Class<? extends ConfiguredObject> expectedConfiguredObjectClass, Map<UUID, ConfigurationEntry> entries)
+ {
+ Map<String, Object> attributes = null;
+ Set<UUID> childrenIds = new TreeSet<UUID>();
+ Iterator<String> fieldNames = parent.getFieldNames();
+ String type = null;
+ String idAsString = null;
+ while (fieldNames.hasNext())
+ {
+ String fieldName = fieldNames.next();
+ JsonNode fieldNode = parent.get(fieldName);
+ if (fieldName.equals(ID))
+ {
+ idAsString = fieldNode.asText();
+ }
+ else if (fieldName.equals(TYPE))
+ {
+ type = fieldNode.asText();
+ }
+ else if (fieldNode.isArray())
+ {
+ // array containing either broker children or attribute values
+ Iterator<JsonNode> elements = fieldNode.getElements();
+ List<Object> fieldValues = null;
+ while (elements.hasNext())
+ {
+ JsonNode element = elements.next();
+ if (element.isObject())
+ {
+ Class<? extends ConfiguredObject> expectedChildConfiguredObjectClass = _relationshipClasses.get(fieldName);
+ // assuming it is a child node
+ ConfigurationEntry entry = toEntry(element, expectedChildConfiguredObjectClass, entries);
+ childrenIds.add(entry.getId());
+ }
+ else
+ {
+ if (fieldValues == null)
+ {
+ fieldValues = new ArrayList<Object>();
+ }
+ fieldValues.add(toObject(element));
+ }
+ }
+ if (fieldValues != null)
+ {
+ Object[] array = fieldValues.toArray(new Object[fieldValues.size()]);
+ attributes.put(fieldName, array);
+ }
+ }
+ else if (fieldNode.isObject())
+ {
+ // ignore, in-line objects are not supported yet
+ }
+ else
+ {
+ // primitive attribute
+ Object value = toObject(fieldNode);
+ if (attributes == null)
+ {
+ attributes = new HashMap<String, Object>();
+ }
+ attributes.put(fieldName, value);
+ }
+ }
+
+ if (type == null)
+ {
+ if (expectedConfiguredObjectClass == null)
+ {
+ throw new IllegalConfigurationException("Type attribute is not provided for configuration entry " + parent);
+ }
+ else
+ {
+ type = expectedConfiguredObjectClass.getSimpleName();
+ }
+ }
+ String name = null;
+ if (attributes != null)
+ {
+ name = (String) attributes.get(ATTRIBUTE_NAME);
+ }
+ if ((name == null || "".equals(name)))
+ {
+ if (expectedConfiguredObjectClass == Broker.class)
+ {
+ name = DEFAULT_BROKER_NAME;
+ }
+ else
+ {
+ throw new IllegalConfigurationException("Name attribute is not provided for configuration entry " + parent);
+ }
+ }
+ UUID id = null;
+ if (idAsString == null)
+ {
+ if (expectedConfiguredObjectClass == Broker.class)
+ {
+ id = UUIDGenerator.generateRandomUUID();
+ }
+ else
+ {
+ id = UUIDGenerator.generateBrokerChildUUID(type, name);
+ }
+ }
+ else
+ {
+ try
+ {
+ id = UUID.fromString(idAsString);
+ }
+ catch (Exception e)
+ {
+ throw new IllegalConfigurationException(
+ "ID attribute value does not conform to UUID format for configuration entry " + parent);
+ }
+ }
+ ConfigurationEntry entry = new ConfigurationEntry(id, type, attributes, childrenIds, this);
+ if (entries.containsKey(id))
+ {
+ throw new IllegalConfigurationException("Duplicate id is found: " + id
+ + "! The following configuration entries have the same id: " + entries.get(id) + ", " + entry);
+ }
+ entries.put(id, entry);
+ return entry;
+ }
+
+ private Object toObject(JsonNode node)
+ {
+ if (node.isValueNode())
+ {
+ if (node.isBoolean())
+ {
+ return node.asBoolean();
+ }
+ else if (node.isDouble())
+ {
+ return node.asDouble();
+ }
+ else if (node.isInt())
+ {
+ return node.asInt();
+ }
+ else if (node.isLong())
+ {
+ return node.asLong();
+ }
+ else if (node.isNull())
+ {
+ return null;
+ }
+ else
+ {
+ return Strings.expand(node.asText());
+ }
+ }
+ else if (node.isArray())
+ {
+ return toArray(node);
+ }
+ else if (node.isObject())
+ {
+ return toMap(node);
+ }
+ else
+ {
+ throw new IllegalConfigurationException("Unexpected node: " + node);
+ }
+ }
+
+ private Map<String, Object> toMap(JsonNode node)
+ {
+ Map<String, Object> object = new TreeMap<String, Object>();
+ Iterator<String> fieldNames = node.getFieldNames();
+ while (fieldNames.hasNext())
+ {
+ String name = fieldNames.next();
+ Object value = toObject(node.get(name));
+ object.put(name, value);
+ }
+ return object;
+ }
+
+ private Object toArray(JsonNode node)
+ {
+ ArrayNode arrayNode = (ArrayNode) node;
+ Object[] array = new Object[arrayNode.size()];
+ Iterator<JsonNode> elements = arrayNode.getElements();
+ for (int i = 0; i < array.length; i++)
+ {
+ array[i] = toObject(elements.next());
+ }
+ return array;
+ }
+
+ @Override
+ public String toString()
+ {
+ return "JsonConfigurationEntryStore [_storeFile=" + _storeFile + ", _rootId=" + _rootId + ", _initialStoreLocation="
+ + _initialStoreLocation + "]";
+ }
+}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/StoreConfigurationChangeListener.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/StoreConfigurationChangeListener.java
new file mode 100644
index 0000000000..813702d0a6
--- /dev/null
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/StoreConfigurationChangeListener.java
@@ -0,0 +1,205 @@
+/*
+ *
+ * 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.qpid.server.configuration.store;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.TreeSet;
+import java.util.UUID;
+
+import org.apache.qpid.server.configuration.ConfigurationEntry;
+import org.apache.qpid.server.configuration.ConfigurationEntryStore;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.ConfigurationChangeListener;
+import org.apache.qpid.server.model.ConfiguredObject;
+import org.apache.qpid.server.model.Model;
+import org.apache.qpid.server.model.State;
+import org.apache.qpid.server.model.VirtualHost;
+
+public class StoreConfigurationChangeListener implements ConfigurationChangeListener
+{
+ private ConfigurationEntryStore _store;
+
+ public StoreConfigurationChangeListener(ConfigurationEntryStore store)
+ {
+ super();
+ _store = store;
+ }
+
+ @Override
+ public void stateChanged(ConfiguredObject object, State oldState, State newState)
+ {
+ if (newState == State.DELETED)
+ {
+ _store.remove(object.getId());
+ object.removeChangeListener(this);
+ }
+ }
+
+ @Override
+ public void childAdded(ConfiguredObject object, ConfiguredObject child)
+ {
+ // exclude VirtualHost children from storing in broker store
+ if (!(object instanceof VirtualHost))
+ {
+ child.addChangeListener(this);
+ ConfigurationEntry parentEntry = toConfigurationEntry(object);
+ ConfigurationEntry childEntry = toConfigurationEntry(child);
+ _store.save(parentEntry, childEntry);
+ }
+
+ }
+
+ @Override
+ public void childRemoved(ConfiguredObject object, ConfiguredObject child)
+ {
+ _store.save(toConfigurationEntry(object));
+ }
+
+ @Override
+ public void attributeSet(ConfiguredObject object, String attrinuteName, Object oldAttributeValue, Object newAttributeValue)
+ {
+ _store.save(toConfigurationEntry(object));
+ }
+
+ private ConfigurationEntry toConfigurationEntry(ConfiguredObject object)
+ {
+ Class<? extends ConfiguredObject> objectType = getConfiguredObjectType(object);
+ Set<UUID> childrenIds = getChildernIds(object, objectType);
+ ConfigurationEntry entry = new ConfigurationEntry(object.getId(), objectType.getSimpleName(),
+ object.getActualAttributes(), childrenIds, _store);
+ return entry;
+ }
+
+ private Set<UUID> getChildernIds(ConfiguredObject object, Class<? extends ConfiguredObject> objectType)
+ {
+ // Virtual Host children's IDs should not be stored in broker store
+ if (object instanceof VirtualHost)
+ {
+ return Collections.emptySet();
+ }
+ Set<UUID> childrenIds = new TreeSet<UUID>();
+ Collection<Class<? extends ConfiguredObject>> childClasses = Model.getInstance().getChildTypes(objectType);
+ if (childClasses != null)
+ {
+ for (Class<? extends ConfiguredObject> childClass : childClasses)
+ {
+ Collection<? extends ConfiguredObject> children = object.getChildren(childClass);
+ if (children != null)
+ {
+ for (ConfiguredObject childObject : children)
+ {
+ childrenIds.add(childObject.getId());
+ }
+ }
+ }
+ }
+ return childrenIds;
+ }
+
+ private Class<? extends ConfiguredObject> getConfiguredObjectType(ConfiguredObject object)
+ {
+ if (object instanceof Broker)
+ {
+ return Broker.class;
+ }
+ return getConfiguredObjectTypeFromImplementedInterfaces(object.getClass());
+ }
+
+ @SuppressWarnings("unchecked")
+ private Class<? extends ConfiguredObject> getConfiguredObjectTypeFromImplementedInterfaces(Class<?> objectClass)
+ {
+ // get all implemented interfaces extending ConfiguredObject
+ Set<Class<?>> interfaces = getImplementedInterfacesExtendingSuper(objectClass, ConfiguredObject.class);
+
+ if (interfaces.size() == 0)
+ {
+ throw new RuntimeException("Can not identify the configured object type");
+ }
+
+ if (interfaces.size() == 1)
+ {
+ return (Class<? extends ConfiguredObject>)interfaces.iterator().next();
+ }
+
+ Set<Class<?>> superInterfaces = new HashSet<Class<?>>();
+
+ // find all super interfaces
+ for (Class<?> interfaceClass : interfaces)
+ {
+ for (Class<?> interfaceClass2 : interfaces)
+ {
+ if (interfaceClass != interfaceClass2)
+ {
+ if (interfaceClass.isAssignableFrom(interfaceClass2))
+ {
+ superInterfaces.add(interfaceClass);
+ }
+ }
+ }
+ }
+
+ // remove super interfaces
+ for (Class<?> superInterface : superInterfaces)
+ {
+ interfaces.remove(superInterface);
+ }
+
+ if (interfaces.size() == 1)
+ {
+ return (Class<? extends ConfiguredObject>)interfaces.iterator().next();
+ }
+ else
+ {
+ throw new RuntimeException("Can not identify the configured object type as an it implements"
+ + " more than one configured object interfaces: " + interfaces);
+ }
+
+ }
+
+ private Set<Class<?>> getImplementedInterfacesExtendingSuper(Class<?> classInstance, Class<?> superInterface)
+ {
+ Set<Class<?>> interfaces = new HashSet<Class<?>>();
+ Class<?>[] classInterfaces = classInstance.getInterfaces();
+ for (Class<?> interfaceClass : classInterfaces)
+ {
+ if (interfaceClass!= superInterface && superInterface.isAssignableFrom(interfaceClass))
+ {
+ interfaces.add(interfaceClass);
+ }
+ }
+ Class<?> superClass = classInstance.getSuperclass();
+ if (superClass != null)
+ {
+ Set<Class<?>> superClassInterfaces = getImplementedInterfacesExtendingSuper(superClass, superInterface);
+ interfaces.addAll(superClassInterfaces);
+ }
+ return interfaces;
+ }
+
+ @Override
+ public String toString()
+ {
+ return "StoreConfigurationChangeListener [store=" + _store + "]";
+ }
+}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/factory/JsonConfigurationStoreFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/factory/JsonConfigurationStoreFactory.java
new file mode 100644
index 0000000000..a2664219bc
--- /dev/null
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/factory/JsonConfigurationStoreFactory.java
@@ -0,0 +1,43 @@
+/*
+ *
+ * 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.qpid.server.configuration.store.factory;
+
+import org.apache.qpid.server.configuration.ConfigurationEntryStore;
+import org.apache.qpid.server.configuration.ConfigurationStoreFactory;
+import org.apache.qpid.server.configuration.store.JsonConfigurationEntryStore;
+
+public class JsonConfigurationStoreFactory implements ConfigurationStoreFactory
+{
+ private static final String STORE_TYPE = "json";
+
+ @Override
+ public ConfigurationEntryStore createStore()
+ {
+ return new JsonConfigurationEntryStore();
+ }
+
+ @Override
+ public String getStoreType()
+ {
+ return STORE_TYPE;
+ }
+
+}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/updater/ChangeStateTask.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/updater/ChangeStateTask.java
new file mode 100644
index 0000000000..b6de1e136a
--- /dev/null
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/updater/ChangeStateTask.java
@@ -0,0 +1,67 @@
+/*
+ *
+ * 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.qpid.server.configuration.updater;
+
+import java.util.concurrent.Callable;
+
+import org.apache.qpid.server.model.ConfiguredObject;
+import org.apache.qpid.server.model.State;
+
+public final class ChangeStateTask implements Callable<State>
+{
+ private ConfiguredObject _object;
+ private State _expectedState;
+ private State _desiredState;
+
+ public ChangeStateTask(ConfiguredObject object, State expectedState, State desiredState)
+ {
+ _object = object;
+ _expectedState = expectedState;
+ _desiredState = desiredState;
+ }
+
+ public ConfiguredObject getObject()
+ {
+ return _object;
+ }
+
+ public State getExpectedState()
+ {
+ return _expectedState;
+ }
+
+ public State getDesiredState()
+ {
+ return _desiredState;
+ }
+
+ @Override
+ public State call()
+ {
+ return _object.setDesiredState(_expectedState, _desiredState);
+ }
+
+ @Override
+ public String toString()
+ {
+ return "ChangeStateTask [object=" + _object + ", expectedState=" + _expectedState + ", desiredState=" + _desiredState + "]";
+ }
+}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/updater/CreateChildTask.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/updater/CreateChildTask.java
new file mode 100644
index 0000000000..d3a8f5b797
--- /dev/null
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/updater/CreateChildTask.java
@@ -0,0 +1,78 @@
+/*
+ *
+ * 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.qpid.server.configuration.updater;
+
+import java.util.Arrays;
+import java.util.Map;
+import java.util.concurrent.Callable;
+
+import org.apache.qpid.server.model.ConfiguredObject;
+
+public final class CreateChildTask implements Callable<ConfiguredObject>
+{
+ private ConfiguredObject _object;
+ private Class<? extends ConfiguredObject> _childClass;
+ private Map<String, Object> _attributes;
+ private ConfiguredObject[] _otherParents;
+
+ public CreateChildTask(ConfiguredObject object, Class<? extends ConfiguredObject> childClass, Map<String, Object> attributes,
+ ConfiguredObject... otherParents)
+ {
+ _object = object;
+ _childClass = childClass;
+ _attributes = attributes;
+ _otherParents = otherParents;
+ }
+
+ public ConfiguredObject getObject()
+ {
+ return _object;
+ }
+
+ public Class<? extends ConfiguredObject> getChildClass()
+ {
+ return _childClass;
+ }
+
+ public Map<String, Object> getAttributes()
+ {
+ return _attributes;
+ }
+
+ public ConfiguredObject[] getOtherParents()
+ {
+ return _otherParents;
+ }
+
+ @Override
+ public ConfiguredObject call()
+ {
+ return _object.createChild(_childClass, _attributes, _otherParents);
+ }
+
+ @Override
+ public String toString()
+ {
+ return "CreateChildTask [object=" + _object + ", childClass=" + _childClass + ", attributes=" + _attributes
+ + ", otherParents=" + Arrays.toString(_otherParents) + "]";
+ }
+
+}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/updater/SetAttributeTask.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/updater/SetAttributeTask.java
new file mode 100644
index 0000000000..94649434e6
--- /dev/null
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/updater/SetAttributeTask.java
@@ -0,0 +1,74 @@
+/*
+ *
+ * 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.qpid.server.configuration.updater;
+
+import java.util.concurrent.Callable;
+
+import org.apache.qpid.server.model.ConfiguredObject;
+
+public final class SetAttributeTask implements Callable<Object>
+{
+ private ConfiguredObject _object;
+ private String _attributeName;
+ private Object _expectedValue;
+ private Object _desiredValue;
+
+ public SetAttributeTask(ConfiguredObject object, String attributeName, Object expectedValue, Object desiredValue)
+ {
+ _object = object;
+ _attributeName = attributeName;
+ _expectedValue = expectedValue;
+ _desiredValue = desiredValue;
+ }
+
+ public ConfiguredObject getObject()
+ {
+ return _object;
+ }
+
+ public String getAttributeName()
+ {
+ return _attributeName;
+ }
+
+ public Object getExpectedValue()
+ {
+ return _expectedValue;
+ }
+
+ public Object getDesiredValue()
+ {
+ return _desiredValue;
+ }
+
+ @Override
+ public Object call()
+ {
+ return _object.setAttribute(_attributeName, _expectedValue, _desiredValue);
+ }
+
+ @Override
+ public String toString()
+ {
+ return "SetAttributeTask [object=" + _object + ", attributeName=" + _attributeName + ", expectedValue=" + _expectedValue
+ + ", desiredValue=" + _desiredValue + "]";
+ }
+}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/updater/TaskExecutor.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/updater/TaskExecutor.java
new file mode 100644
index 0000000000..671104d413
--- /dev/null
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/updater/TaskExecutor.java
@@ -0,0 +1,324 @@
+/*
+ *
+ * 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.qpid.server.configuration.updater;
+
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+import java.util.List;
+import java.util.concurrent.Callable;
+import java.util.concurrent.CancellationException;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.RunnableFuture;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicReference;
+
+import javax.security.auth.Subject;
+
+import org.apache.log4j.Logger;
+import org.apache.qpid.server.logging.LogActor;
+import org.apache.qpid.server.logging.actors.CurrentActor;
+import org.apache.qpid.server.model.State;
+import org.apache.qpid.server.security.SecurityManager;
+
+public class TaskExecutor
+{
+ private static final String TASK_EXECUTION_THREAD_NAME = "Broker-Configuration-Thread";
+ private static final Logger LOGGER = Logger.getLogger(TaskExecutor.class);
+
+ private volatile Thread _taskThread;
+ private final AtomicReference<State> _state;
+ private volatile ExecutorService _executor;
+
+ public TaskExecutor()
+ {
+ _state = new AtomicReference<State>(State.INITIALISING);
+ }
+
+ public State getState()
+ {
+ return _state.get();
+ }
+
+ public void start()
+ {
+ if (_state.compareAndSet(State.INITIALISING, State.ACTIVE))
+ {
+ LOGGER.debug("Starting task executor");
+ _executor = Executors.newFixedThreadPool(1, new ThreadFactory()
+ {
+ @Override
+ public Thread newThread(Runnable r)
+ {
+ _taskThread = new Thread(r, TASK_EXECUTION_THREAD_NAME);
+ return _taskThread;
+ }
+ });
+ LOGGER.debug("Task executor is started");
+ }
+ }
+
+ public void stopImmediately()
+ {
+ if (_state.compareAndSet(State.ACTIVE, State.STOPPED))
+ {
+ ExecutorService executor = _executor;
+ if (executor != null)
+ {
+ LOGGER.debug("Stopping task executor immediately");
+ List<Runnable> cancelledTasks = executor.shutdownNow();
+ if (cancelledTasks != null)
+ {
+ for (Runnable runnable : cancelledTasks)
+ {
+ if (runnable instanceof RunnableFuture<?>)
+ {
+ ((RunnableFuture<?>) runnable).cancel(true);
+ }
+ }
+ }
+ _executor = null;
+ _taskThread = null;
+ LOGGER.debug("Task executor was stopped immediately. Number of unfinished tasks: " + cancelledTasks.size());
+ }
+ }
+ }
+
+ public void stop()
+ {
+ if (_state.compareAndSet(State.ACTIVE, State.STOPPED))
+ {
+ ExecutorService executor = _executor;
+ if (executor != null)
+ {
+ LOGGER.debug("Stopping task executor");
+ executor.shutdown();
+ _executor = null;
+ _taskThread = null;
+ LOGGER.debug("Task executor is stopped");
+ }
+ }
+ }
+
+ Future<?> submit(Callable<?> task)
+ {
+ checkState();
+ if (LOGGER.isDebugEnabled())
+ {
+ LOGGER.debug("Submitting task: " + task);
+ }
+ Future<?> future = null;
+ if (isTaskExecutorThread())
+ {
+ Object result = executeTaskAndHandleExceptions(task);
+ return new ImmediateFuture(result);
+ }
+ else
+ {
+ future = _executor.submit(new CallableWrapper(task));
+ }
+ return future;
+ }
+
+ public Object submitAndWait(Callable<?> task) throws CancellationException
+ {
+ try
+ {
+ Future<?> future = submit(task);
+ return future.get();
+ }
+ catch (InterruptedException e)
+ {
+ throw new RuntimeException("Task execution was interrupted: " + task, e);
+ }
+ catch (ExecutionException e)
+ {
+ Throwable cause = e.getCause();
+ if (cause instanceof RuntimeException)
+ {
+ throw (RuntimeException) cause;
+ }
+ else if (cause instanceof Exception)
+ {
+ throw new RuntimeException("Failed to execute user task: " + task, cause);
+ }
+ else if (cause instanceof Error)
+ {
+ throw (Error) cause;
+ }
+ else
+ {
+ throw new RuntimeException("Failed to execute user task: " + task, cause);
+ }
+ }
+ }
+
+ public boolean isTaskExecutorThread()
+ {
+ return Thread.currentThread() == _taskThread;
+ }
+
+ private void checkState()
+ {
+ if (_state.get() != State.ACTIVE)
+ {
+ throw new IllegalStateException("Task executor is not in ACTIVE state");
+ }
+ }
+
+ private Object executeTaskAndHandleExceptions(Callable<?> userTask)
+ {
+ try
+ {
+ return executeTask(userTask);
+ }
+ catch (Exception e)
+ {
+ if (e instanceof RuntimeException)
+ {
+ throw (RuntimeException) e;
+ }
+ throw new RuntimeException("Failed to execute user task: " + userTask, e);
+ }
+ }
+
+ private Object executeTask(Callable<?> userTask) throws Exception
+ {
+ if (LOGGER.isDebugEnabled())
+ {
+ LOGGER.debug("Performing task " + userTask);
+ }
+ Object result = userTask.call();
+ if (LOGGER.isDebugEnabled())
+ {
+ LOGGER.debug("Task " + userTask + " is performed successfully with result:" + result);
+ }
+ return result;
+ }
+
+ private class CallableWrapper implements Callable<Object>
+ {
+ private Callable<?> _userTask;
+ private Subject _securityManagerSubject;
+ private LogActor _actor;
+ private Subject _contextSubject;
+
+ public CallableWrapper(Callable<?> userWork)
+ {
+ _userTask = userWork;
+ _securityManagerSubject = SecurityManager.getThreadSubject();
+ _actor = CurrentActor.get();
+ _contextSubject = Subject.getSubject(AccessController.getContext());
+ }
+
+ @Override
+ public Object call() throws Exception
+ {
+ SecurityManager.setThreadSubject(_securityManagerSubject);
+ CurrentActor.set(_actor);
+
+ try
+ {
+ Object result = null;
+ try
+ {
+ result = Subject.doAs(_contextSubject, new PrivilegedExceptionAction<Object>()
+ {
+ @Override
+ public Object run() throws Exception
+ {
+ return executeTask(_userTask);
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw e.getException();
+ }
+ return result;
+ }
+ finally
+ {
+ try
+ {
+ CurrentActor.remove();
+ }
+ catch (Exception e)
+ {
+ LOGGER.warn("Unxpected exception on current actor removal", e);
+ }
+ try
+ {
+ SecurityManager.setThreadSubject(null);
+ }
+ catch (Exception e)
+ {
+ LOGGER.warn("Unxpected exception on nullifying of subject for a security manager", e);
+ }
+ }
+ }
+ }
+
+ private class ImmediateFuture implements Future<Object>
+ {
+ private Object _result;
+
+ public ImmediateFuture(Object result)
+ {
+ super();
+ this._result = result;
+ }
+
+ @Override
+ public boolean cancel(boolean mayInterruptIfRunning)
+ {
+ return false;
+ }
+
+ @Override
+ public boolean isCancelled()
+ {
+ return false;
+ }
+
+ @Override
+ public boolean isDone()
+ {
+ return true;
+ }
+
+ @Override
+ public Object get()
+ {
+ return _result;
+ }
+
+ @Override
+ public Object get(long timeout, TimeUnit unit)
+ {
+ return get();
+ }
+ }
+}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/handler/ConnectionSecureOkMethodHandler.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/handler/ConnectionSecureOkMethodHandler.java
index e65fe10eb5..0339287e38 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/handler/ConnectionSecureOkMethodHandler.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/handler/ConnectionSecureOkMethodHandler.java
@@ -30,8 +30,9 @@ import org.apache.qpid.framing.ConnectionSecureOkBody;
import org.apache.qpid.framing.ConnectionTuneBody;
import org.apache.qpid.framing.MethodRegistry;
import org.apache.qpid.protocol.AMQConstant;
+import org.apache.qpid.server.configuration.BrokerProperties;
+import org.apache.qpid.server.model.Broker;
import org.apache.qpid.server.protocol.AMQProtocolSession;
-import org.apache.qpid.server.registry.ApplicationRegistry;
import org.apache.qpid.server.security.SubjectCreator;
import org.apache.qpid.server.security.auth.SubjectAuthenticationResult;
import org.apache.qpid.server.state.AMQState;
@@ -58,6 +59,7 @@ public class ConnectionSecureOkMethodHandler implements StateAwareMethodListener
public void methodReceived(AMQStateManager stateManager, ConnectionSecureOkBody body, int channelId) throws AMQException
{
+ Broker broker = stateManager.getBroker();
AMQProtocolSession session = stateManager.getProtocolSession();
SubjectCreator subjectCreator = stateManager.getSubjectCreator();
@@ -96,9 +98,9 @@ public class ConnectionSecureOkMethodHandler implements StateAwareMethodListener
stateManager.changeState(AMQState.CONNECTION_NOT_TUNED);
ConnectionTuneBody tuneBody =
- methodRegistry.createConnectionTuneBody(ApplicationRegistry.getInstance().getConfiguration().getMaxChannelCount(),
- ConnectionStartOkMethodHandler.getConfiguredFrameSize(),
- ApplicationRegistry.getInstance().getConfiguration().getHeartBeatDelay());
+ methodRegistry.createConnectionTuneBody((Integer)broker.getAttribute(Broker.SESSION_COUNT_LIMIT),
+ BrokerProperties.DEFAULT_FRAME_SIZE,
+ (Integer)broker.getAttribute(Broker.HEART_BEAT_DELAY));
session.writeFrame(tuneBody.generateFrame(0));
session.setAuthorizedSubject(authResult.getSubject());
disposeSaslServer(session);
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/handler/ConnectionStartOkMethodHandler.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/handler/ConnectionStartOkMethodHandler.java
index 9f596a4637..e70fa6a37b 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/handler/ConnectionStartOkMethodHandler.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/handler/ConnectionStartOkMethodHandler.java
@@ -29,9 +29,9 @@ import org.apache.qpid.framing.ConnectionStartOkBody;
import org.apache.qpid.framing.ConnectionTuneBody;
import org.apache.qpid.framing.MethodRegistry;
import org.apache.qpid.protocol.AMQConstant;
-import org.apache.qpid.server.configuration.ServerConfiguration;
+import org.apache.qpid.server.configuration.BrokerProperties;
+import org.apache.qpid.server.model.Broker;
import org.apache.qpid.server.protocol.AMQProtocolSession;
-import org.apache.qpid.server.registry.ApplicationRegistry;
import org.apache.qpid.server.security.SubjectCreator;
import org.apache.qpid.server.security.auth.SubjectAuthenticationResult;
import org.apache.qpid.server.state.AMQState;
@@ -59,6 +59,7 @@ public class ConnectionStartOkMethodHandler implements StateAwareMethodListener<
public void methodReceived(AMQStateManager stateManager, ConnectionStartOkBody body, int channelId) throws AMQException
{
+ Broker broker = stateManager.getBroker();
AMQProtocolSession session = stateManager.getProtocolSession();
_logger.info("SASL Mechanism selected: " + body.getMechanism());
@@ -111,9 +112,9 @@ public class ConnectionStartOkMethodHandler implements StateAwareMethodListener<
stateManager.changeState(AMQState.CONNECTION_NOT_TUNED);
- ConnectionTuneBody tuneBody = methodRegistry.createConnectionTuneBody(ApplicationRegistry.getInstance().getConfiguration().getMaxChannelCount(),
- getConfiguredFrameSize(),
- ApplicationRegistry.getInstance().getConfiguration().getHeartBeatDelay());
+ ConnectionTuneBody tuneBody = methodRegistry.createConnectionTuneBody((Integer)broker.getAttribute(Broker.SESSION_COUNT_LIMIT),
+ BrokerProperties.DEFAULT_FRAME_SIZE,
+ (Integer)broker.getAttribute(Broker.HEART_BEAT_DELAY));
session.writeFrame(tuneBody.generateFrame(0));
break;
case CONTINUE:
@@ -147,13 +148,6 @@ public class ConnectionStartOkMethodHandler implements StateAwareMethodListener<
}
}
- static int getConfiguredFrameSize()
- {
- final ServerConfiguration config = ApplicationRegistry.getInstance().getConfiguration();
- final int framesize = config.getFrameSize();
- _logger.info("Framesize set to " + framesize);
- return framesize;
- }
}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/handler/QueueDeclareHandler.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/handler/QueueDeclareHandler.java
index ae725b9ec1..194c3d6351 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/handler/QueueDeclareHandler.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/handler/QueueDeclareHandler.java
@@ -38,7 +38,6 @@ import org.apache.qpid.server.protocol.AMQSessionModel;
import org.apache.qpid.server.queue.AMQQueue;
import org.apache.qpid.server.queue.AMQQueueFactory;
import org.apache.qpid.server.queue.QueueRegistry;
-import org.apache.qpid.server.registry.ApplicationRegistry;
import org.apache.qpid.server.state.AMQStateManager;
import org.apache.qpid.server.state.StateAwareMethodListener;
import org.apache.qpid.server.store.DurableConfigurationStore;
@@ -59,8 +58,6 @@ public class QueueDeclareHandler implements StateAwareMethodListener<QueueDeclar
return _instance;
}
- private boolean autoRegister = ApplicationRegistry.getInstance().getConfiguration().getQueueAutoRegister();
-
public void methodReceived(AMQStateManager stateManager, QueueDeclareBody body, int channelId) throws AMQException
{
final AMQProtocolSession protocolConnection = stateManager.getProtocolSession();
@@ -148,13 +145,11 @@ public class QueueDeclareHandler implements StateAwareMethodListener<QueueDeclar
});
}
}
- if (autoRegister)
- {
- Exchange defaultExchange = exchangeRegistry.getDefaultExchange();
+ Exchange defaultExchange = exchangeRegistry.getDefaultExchange();
- virtualHost.getBindingFactory().addBinding(String.valueOf(queueName), queue, defaultExchange, Collections.EMPTY_MAP);
- _logger.info("Queue " + queueName + " bound to default exchange(" + defaultExchange.getNameShortString() + ")");
- }
+ virtualHost.getBindingFactory().addBinding(String.valueOf(queueName), queue, defaultExchange,
+ Collections.<String, Object> emptyMap());
+ _logger.info("Queue " + queueName + " bound to default exchange(" + defaultExchange.getNameShortString() + ")");
}
}
else if (queue.isExclusive() && !queue.isDurable() && (owningSession == null || owningSession.getConnectionModel() != protocolConnection))
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/AbstractRootMessageLogger.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/AbstractRootMessageLogger.java
index 545f2adea2..98da9074ef 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/AbstractRootMessageLogger.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/AbstractRootMessageLogger.java
@@ -20,7 +20,6 @@
*/
package org.apache.qpid.server.logging;
-import org.apache.qpid.server.configuration.ServerConfiguration;
public abstract class AbstractRootMessageLogger implements RootMessageLogger
{
@@ -33,9 +32,9 @@ public abstract class AbstractRootMessageLogger implements RootMessageLogger
}
- public AbstractRootMessageLogger(ServerConfiguration config)
+ public AbstractRootMessageLogger(boolean statusUpdatesEnabled)
{
- _enabled = config.getStatusUpdatesEnabled();
+ _enabled = statusUpdatesEnabled;
}
public boolean isEnabled()
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/Log4jMessageLogger.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/Log4jMessageLogger.java
index 62f0e75ceb..b4e9f2f333 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/Log4jMessageLogger.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/Log4jMessageLogger.java
@@ -21,7 +21,6 @@
package org.apache.qpid.server.logging;
import org.apache.log4j.Logger;
-import org.apache.qpid.server.configuration.ServerConfiguration;
public class Log4jMessageLogger extends AbstractRootMessageLogger
{
@@ -30,9 +29,9 @@ public class Log4jMessageLogger extends AbstractRootMessageLogger
super();
}
- public Log4jMessageLogger(ServerConfiguration config)
+ public Log4jMessageLogger(boolean statusUpdatesEnabled)
{
- super(config);
+ super(statusUpdatesEnabled);
}
@Override
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/AuthenticationProvider.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/AuthenticationProvider.java
index 6000886956..417f6036ab 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/AuthenticationProvider.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/AuthenticationProvider.java
@@ -24,6 +24,9 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
+import org.apache.qpid.server.security.SubjectCreator;
+import org.apache.qpid.server.security.group.GroupPrincipalAccessor;
+
public interface AuthenticationProvider extends ConfiguredObject
{
@@ -52,4 +55,15 @@ public interface AuthenticationProvider extends ConfiguredObject
TYPE));
//children
Collection<VirtualHostAlias> getVirtualHostPortBindings();
+
+ String getName();
+
+ /**
+ * A temporary method to create SubjectCreator.
+ *
+ * TODO: move all the functionality from SubjectCreator into AuthenticationProvider
+ */
+ SubjectCreator getSubjectCreator();
+
+ void setGroupAccessor(GroupPrincipalAccessor groupPrincipalAccessor);
}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Broker.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Broker.java
index 08b01a1b65..fbecf1965b 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Broker.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Broker.java
@@ -20,12 +20,20 @@
*/
package org.apache.qpid.server.model;
+import java.net.SocketAddress;
import java.security.AccessControlException;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
+import org.apache.qpid.server.logging.LogRecorder;
+import org.apache.qpid.server.logging.RootMessageLogger;
+import org.apache.qpid.server.configuration.updater.TaskExecutor;
+import org.apache.qpid.server.security.SecurityManager;
+import org.apache.qpid.server.security.SubjectCreator;
+import org.apache.qpid.server.virtualhost.VirtualHostRegistry;
+
public interface Broker extends ConfiguredObject
{
@@ -44,9 +52,49 @@ public interface Broker extends ConfiguredObject
String STATE = "state";
String TIME_TO_LIVE = "timeToLive";
String UPDATED = "updated";
+ String DEFAULT_AUTHENTICATION_PROVIDER = "defaultAuthenticationProvider";
+ String DEFAULT_VIRTUAL_HOST = "defaultVirtualHost";
+
+ String ALERT_THRESHOLD_MESSAGE_AGE = "alertThresholdMessageAge";
+ String ALERT_THRESHOLD_MESSAGE_COUNT = "alertThresholdMessageCount";
+ String ALERT_THRESHOLD_QUEUE_DEPTH = "alertThresholdQueueDepth";
+ String ALERT_THRESHOLD_MESSAGE_SIZE = "alertThresholdMessageSize";
+ String ALERT_REPEAT_GAP = "alertRepeatGap";
+ String FLOW_CONTROL_SIZE_BYTES = "queueFlowControlSizeBytes";
+ String FLOW_CONTROL_RESUME_SIZE_BYTES = "queueFlowResumeSizeBytes";
+ String MAXIMUM_DELIVERY_ATTEMPTS = "maximumDeliveryAttempts";
+ String DEAD_LETTER_QUEUE_ENABLED = "deadLetterQueueEnabled";
+ String HOUSEKEEPING_CHECK_PERIOD = "housekeepingCheckPeriod";
+
+ String SESSION_COUNT_LIMIT = "sessionCountLimit";
+ String HEART_BEAT_DELAY = "heartBeatDelay";
+ String STATISTICS_REPORTING_PERIOD = "statisticsReportingPeriod";
+ String STATISTICS_REPORTING_RESET_ENABLED = "statisticsReportingResetEnabled";
+
+ /*
+ * A temporary attribute to pass the path to ACL file.
+ * TODO: It should be a part of AuthorizationProvider.
+ */
+ String ACL_FILE = "aclFile";
+
+ /*
+ * A temporary attributes to set the broker default key/trust stores.
+ * TODO: Remove them after adding a full support to configure KeyStore/TrustStore via management layers.
+ */
+ String KEY_STORE_PATH = "keyStorePath";
+ String KEY_STORE_PASSWORD = "keyStorePassword";
+ String KEY_STORE_CERT_ALIAS = "keyStoreCertAlias";
+ String TRUST_STORE_PATH = "trustStorePath";
+ String TRUST_STORE_PASSWORD = "trustStorePassword";
+
+ /*
+ * A temporary attributes to set the broker group file.
+ * TODO: Remove them after adding a full support to configure authorization providers via management layers.
+ */
+ String GROUP_FILE = "groupFile";
// Attributes
- public static final Collection<String> AVAILABLE_ATTRIBUTES =
+ Collection<String> AVAILABLE_ATTRIBUTES =
Collections.unmodifiableList(
Arrays.asList(BUILD_VERSION,
BYTES_RETAINED,
@@ -62,7 +110,32 @@ public interface Broker extends ConfiguredObject
NAME,
STATE,
TIME_TO_LIVE,
- UPDATED));
+ UPDATED,
+ DEFAULT_AUTHENTICATION_PROVIDER,
+ DEFAULT_VIRTUAL_HOST,
+ ALERT_THRESHOLD_MESSAGE_AGE,
+ ALERT_THRESHOLD_MESSAGE_COUNT,
+ ALERT_THRESHOLD_QUEUE_DEPTH,
+ ALERT_THRESHOLD_MESSAGE_SIZE,
+ ALERT_REPEAT_GAP,
+ FLOW_CONTROL_SIZE_BYTES,
+ FLOW_CONTROL_RESUME_SIZE_BYTES,
+ MAXIMUM_DELIVERY_ATTEMPTS,
+ DEAD_LETTER_QUEUE_ENABLED,
+ HOUSEKEEPING_CHECK_PERIOD,
+ SESSION_COUNT_LIMIT,
+ HEART_BEAT_DELAY,
+ STATISTICS_REPORTING_PERIOD,
+ STATISTICS_REPORTING_RESET_ENABLED,
+
+ ACL_FILE,
+ KEY_STORE_PATH,
+ KEY_STORE_PASSWORD,
+ KEY_STORE_CERT_ALIAS,
+ TRUST_STORE_PATH,
+ TRUST_STORE_PASSWORD,
+ GROUP_FILE
+ ));
//children
Collection < VirtualHost > getVirtualHosts();
@@ -75,6 +148,49 @@ public interface Broker extends ConfiguredObject
LifetimePolicy lifetime, long ttl, Map<String, Object> attributes)
throws AccessControlException, IllegalArgumentException;
- void deleteVirtualHost(VirtualHost virtualHost)
- throws AccessControlException, IllegalStateException;
+ AuthenticationProvider getDefaultAuthenticationProvider();
+
+ Collection<GroupProvider> getGroupProviders();
+
+ /**
+ * A temporary hack to expose root message logger via broker instance.
+ * TODO We need a better way to do operational logging, for example, via logging listeners
+ */
+ RootMessageLogger getRootMessageLogger();
+
+ /**
+ * A temporary hack to expose security manager via broker instance.
+ * TODO We need to add and implement an authorization provider configured object instead
+ */
+ SecurityManager getSecurityManager();
+
+ /**
+ * TODO: A temporary hack to expose log recorder via broker instance.
+ */
+ LogRecorder getLogRecorder();
+
+ VirtualHost findVirtualHostByName(String name);
+
+ /**
+ * Get the SubjectCreator for the given socket address.
+ * TODO: move the authentication related functionality into host aliases and AuthenticationProviders
+ *
+ * @param address The (listening) socket address for which the AuthenticationManager is required
+ */
+ SubjectCreator getSubjectCreator(SocketAddress localAddress);
+
+ Collection<KeyStore> getKeyStores();
+
+ Collection<TrustStore> getTrustStores();
+
+ /*
+ * TODO: Remove this method. Eventually the broker will become a registry.
+ */
+ VirtualHostRegistry getVirtualHostRegistry();
+
+ KeyStore getDefaultKeyStore();
+
+ TrustStore getDefaultTrustStore();
+
+ TaskExecutor getTaskExecutor();
}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/ConfigurationChangeListener.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/ConfigurationChangeListener.java
index 78b98faffe..bd7da962ba 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/ConfigurationChangeListener.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/ConfigurationChangeListener.java
@@ -36,4 +36,5 @@ public interface ConfigurationChangeListener
void childRemoved(ConfiguredObject object, ConfiguredObject child);
+ void attributeSet(ConfiguredObject object, String attributeName, Object oldAttributeValue, Object newAttributeValue);
}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/ConfiguredObject.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/ConfiguredObject.java
index 414b2d083a..d567a3aa44 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/ConfiguredObject.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/ConfiguredObject.java
@@ -25,6 +25,9 @@ import java.util.Collection;
import java.util.Map;
import java.util.UUID;
+/**
+ * An object that can be "managed" (eg via the web interface) and usually read from configuration.
+ */
public interface ConfiguredObject
{
@@ -47,7 +50,7 @@ public interface ConfiguredObject
* Attempt to change the name of the object
*
* Request a change to the name of the object. The caller must pass in the name it believes the object currently
- * has. If the current name differes from this expected value, then no name change will occur
+ * has. If the current name differs from this expected value, then no name change will occur
*
* @param currentName the name the caller believes the object to have
* @param desiredName the name the caller would like the object to have
@@ -198,14 +201,25 @@ public interface ConfiguredObject
/**
- * Return the value for the given attribute
+ * Return the value for the given attribute name. The actual attribute value
+ * is returned if the configured object has such attribute set. If not, the
+ * value is looked default attributes.
*
- * @param name the name of the attribute
- * @return the value of the attribute at the object (or null if the attribute is not set
+ * @param name
+ * the name of the attribute
+ * @return the value of the attribute at the object (or null if the
+ * attribute value is set neither on object itself no in defaults)
*/
Object getAttribute(String name);
/**
+ * Return the map containing only explicitly set attributes
+ *
+ * @return the map with the attributes
+ */
+ Map<String, Object> getActualAttributes();
+
+ /**
* Set the value of an attribute
*
* @param name the name of the attribute to be set
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/GroupProvider.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/GroupProvider.java
index 76fa379c1b..9016f97927 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/GroupProvider.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/GroupProvider.java
@@ -19,9 +19,11 @@
*/
package org.apache.qpid.server.model;
+import java.security.Principal;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
+import java.util.Set;
public interface GroupProvider extends ConfiguredObject
{
@@ -48,4 +50,6 @@ public interface GroupProvider extends ConfiguredObject
CREATED,
UPDATED,
TYPE));
+
+ Set<Principal> getGroupPrincipalsForUser(String username);
}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/KeyStore.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/KeyStore.java
new file mode 100644
index 0000000000..959714656b
--- /dev/null
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/KeyStore.java
@@ -0,0 +1,51 @@
+/*
+ *
+ * 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.qpid.server.model;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+
+public interface KeyStore extends TrustStore
+{
+
+ String CERTIFICATE_ALIAS = "certificateAlias";
+
+ public static final Collection<String> AVAILABLE_ATTRIBUTES =
+ Collections.unmodifiableList(
+ Arrays.asList(
+ ID,
+ NAME,
+ STATE,
+ DURABLE,
+ LIFETIME_POLICY,
+ TIME_TO_LIVE,
+ CREATED,
+ UPDATED,
+ DESCRIPTION,
+ PATH,
+ PASSWORD,
+ TYPE,
+ KEY_MANAGER_FACTORY_ALGORITHM,
+ CERTIFICATE_ALIAS
+ ));
+
+}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Model.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Model.java
index 329574f017..2c05dce9cb 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Model.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Model.java
@@ -48,6 +48,9 @@ public class Model
addRelationship(Broker.class, Port.class);
addRelationship(Broker.class, AuthenticationProvider.class);
addRelationship(Broker.class, GroupProvider.class);
+ addRelationship(Broker.class, TrustStore.class);
+ addRelationship(Broker.class, KeyStore.class);
+ addRelationship(Broker.class, Plugin.class);
addRelationship(VirtualHost.class, Exchange.class);
addRelationship(VirtualHost.class, Queue.class);
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Plugin.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Plugin.java
new file mode 100644
index 0000000000..b9503a5841
--- /dev/null
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Plugin.java
@@ -0,0 +1,52 @@
+/*
+ *
+ * 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.qpid.server.model;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+
+public interface Plugin extends ConfiguredObject
+{
+ //Hack, using it for the class name only for consistency with the other things.
+ String CREATED = "created";
+ String DURABLE = "durable";
+ String ID = "id";
+ String LIFETIME_POLICY = "lifetimePolicy";
+ String NAME = "name";
+ String STATE = "state";
+ String TIME_TO_LIVE = "timeToLive";
+ String UPDATED = "updated";
+
+ // Attributes
+ public static final Collection<String> AVAILABLE_ATTRIBUTES =
+ Collections.unmodifiableList(
+ Arrays.asList(
+ ID,
+ NAME,
+ STATE,
+ DURABLE,
+ LIFETIME_POLICY,
+ TIME_TO_LIVE,
+ CREATED,
+ UPDATED
+ ));
+}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Port.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Port.java
index 50c0ebcd14..2f94c3cab7 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Port.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Port.java
@@ -39,6 +39,16 @@ public interface Port extends ConfiguredObject
String PORT = "port";
String PROTOCOLS = "protocols";
String TRANSPORTS = "transports";
+ String TCP_NO_DELAY = "tcpNoDelay";
+ String SEND_BUFFER_SIZE = "sendBufferSize";
+ String RECEIVE_BUFFER_SIZE = "receiveBufferSize";
+ String NEED_CLIENT_AUTH = "needClientAuth";
+ String WANT_CLIENT_AUTH = "wantClientAuth";
+
+ /**
+ * TODO: rename it to AUTHENTICATION_MANAGER_ID or introduce relationships
+ */
+ String AUTHENTICATION_MANAGER = "authenticationManager";
// Attributes
public static final Collection<String> AVAILABLE_ATTRIBUTES =
@@ -55,7 +65,13 @@ public interface Port extends ConfiguredObject
BINDING_ADDRESS,
PORT,
PROTOCOLS,
- TRANSPORTS
+ TRANSPORTS,
+ TCP_NO_DELAY,
+ SEND_BUFFER_SIZE,
+ RECEIVE_BUFFER_SIZE,
+ NEED_CLIENT_AUTH,
+ WANT_CLIENT_AUTH,
+ AUTHENTICATION_MANAGER
));
@@ -88,4 +104,8 @@ public interface Port extends ConfiguredObject
//children
Collection<VirtualHostAlias> getVirtualHostBindings();
Collection<Connection> getConnections();
+
+ AuthenticationProvider getAuthenticationProvider();
+
+ void setAuthenticationProvider(AuthenticationProvider authenticationProvider);
}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Protocol.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Protocol.java
index 5d9de69f9a..6cd5eb23a4 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Protocol.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Protocol.java
@@ -20,14 +20,95 @@
*/
package org.apache.qpid.server.model;
+import java.util.Collection;
+import java.util.EnumSet;
+
+import org.apache.qpid.server.protocol.AmqpProtocolVersion;
+
public enum Protocol
{
- AMQP_0_8,
- AMQP_0_9,
- AMQP_0_9_1,
- AMQP_0_10,
- AMQP_1_0,
- JMX,
- HTTP,
- HTTPS
+ AMQP_0_8(ProtocolType.AMQP),
+ AMQP_0_9(ProtocolType.AMQP),
+ AMQP_0_9_1(ProtocolType.AMQP),
+ AMQP_0_10(ProtocolType.AMQP),
+ AMQP_1_0(ProtocolType.AMQP),
+ JMX_RMI(ProtocolType.JMX),
+ HTTP(ProtocolType.HTTP),
+ HTTPS(ProtocolType.HTTP),
+ RMI(ProtocolType.RMI);
+
+ private final ProtocolType _protocolType;
+
+ private Protocol(ProtocolType type)
+ {
+ _protocolType = type;
+ }
+
+ public ProtocolType getProtocolType()
+ {
+ return _protocolType;
+ }
+
+ public boolean isAMQP()
+ {
+ return _protocolType == ProtocolType.AMQP;
+ }
+
+ public AmqpProtocolVersion toAmqpProtocolVersion()
+ {
+ switch(this)
+ {
+ case AMQP_0_8:
+ return AmqpProtocolVersion.v0_8;
+ case AMQP_0_9:
+ return AmqpProtocolVersion.v0_9;
+ case AMQP_0_9_1:
+ return AmqpProtocolVersion.v0_9_1;
+ case AMQP_0_10:
+ return AmqpProtocolVersion.v0_10;
+ case AMQP_1_0:
+ return AmqpProtocolVersion.v1_0_0;
+ default:
+ throw new IllegalArgumentException(this + " is not an known AMQP protocol");
+ }
+ }
+
+ public static Protocol valueOfObject(Object protocolObject)
+ {
+ Protocol protocol;
+ if (protocolObject instanceof Protocol)
+ {
+ protocol = (Protocol) protocolObject;
+ }
+ else
+ {
+ try
+ {
+ protocol = Protocol.valueOf(String.valueOf(protocolObject));
+ }
+ catch (Exception e)
+ {
+ throw new IllegalArgumentException("Can't convert '" + protocolObject
+ + "' to one of the supported protocols: " + EnumSet.allOf(Protocol.class), e);
+ }
+ }
+ return protocol;
+ }
+
+ public static boolean hasAmqpProtocol(Collection<Protocol> protocols)
+ {
+ for (Protocol protocol : protocols)
+ {
+ if (protocol.isAMQP())
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public static enum ProtocolType
+ {
+ AMQP, HTTP, JMX, RMI;
+ }
}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Transport.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Transport.java
index 03cd46be01..ae6e5ac43a 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Transport.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Transport.java
@@ -20,8 +20,32 @@
*/
package org.apache.qpid.server.model;
+import java.util.EnumSet;
+
public enum Transport
{
TCP,
- SSL
+ SSL;
+
+ public static Transport valueOfObject(Object transportObject)
+ {
+ Transport transport;
+ if (transportObject instanceof Transport)
+ {
+ transport = (Transport) transportObject;
+ }
+ else
+ {
+ try
+ {
+ transport = Transport.valueOf(String.valueOf(transportObject));
+ }
+ catch (Exception e)
+ {
+ throw new IllegalArgumentException("Can't convert '" + transportObject
+ + "' to one of the supported transports: " + EnumSet.allOf(Transport.class), e);
+ }
+ }
+ return transport;
+ }
}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/TrustStore.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/TrustStore.java
new file mode 100644
index 0000000000..0c322ae02f
--- /dev/null
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/TrustStore.java
@@ -0,0 +1,65 @@
+/*
+ *
+ * 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.qpid.server.model;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+
+public interface TrustStore extends ConfiguredObject
+{
+ String ID = "id";
+ String NAME = "name";
+ String DURABLE = "durable";
+ String LIFETIME_POLICY = "lifetimePolicy";
+ String STATE = "state";
+ String TIME_TO_LIVE = "timeToLive";
+ String CREATED = "created";
+ String UPDATED = "updated";
+ String DESCRIPTION = "description";
+
+ String PATH = "path";
+ String PASSWORD = "password";
+ String TYPE = "type";
+ String KEY_MANAGER_FACTORY_ALGORITHM = "keyManagerFactoryAlgorithm";
+
+ public static final Collection<String> AVAILABLE_ATTRIBUTES =
+ Collections.unmodifiableList(
+ Arrays.asList(
+ ID,
+ NAME,
+ STATE,
+ DURABLE,
+ LIFETIME_POLICY,
+ TIME_TO_LIVE,
+ CREATED,
+ UPDATED,
+ DESCRIPTION,
+ PATH,
+ PASSWORD,
+ TYPE,
+ KEY_MANAGER_FACTORY_ALGORITHM
+ ));
+
+ public String getPassword();
+
+ public void setPassword(String password);
+}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/UUIDGenerator.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/UUIDGenerator.java
index 6606944dc5..bcedd91596 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/UUIDGenerator.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/UUIDGenerator.java
@@ -87,4 +87,9 @@ public class UUIDGenerator
{
return createUUID(GroupMember.class.getName(), groupProviderName, groupName, groupMemberName);
}
+
+ public static UUID generateBrokerChildUUID(String type, String childName)
+ {
+ return createUUID(type, childName);
+ }
}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/VirtualHost.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/VirtualHost.java
index 01257d588f..5f4ec1d3a8 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/VirtualHost.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/VirtualHost.java
@@ -21,6 +21,9 @@
package org.apache.qpid.server.model;
import org.apache.qpid.server.queue.QueueEntry;
+import org.apache.qpid.server.security.SecurityManager;
+import org.apache.qpid.server.store.MessageStore;
+
import java.security.AccessControlException;
import java.util.Arrays;
import java.util.Collection;
@@ -64,12 +67,12 @@ public interface VirtualHost extends ConfiguredObject
String MAXIMUM_DELIVERY_ATTEMPTS = "maximumDeliveryAttempts";
String QUEUE_FLOW_CONTROL_SIZE_BYTES = "queueFlowControlSizeBytes";
String QUEUE_FLOW_RESUME_SIZE_BYTES = "queueFlowResumeSizeBytes";
- String STORE_CONFIGURATION = "storeConfiguration";
String STORE_TRANSACTION_IDLE_TIMEOUT_CLOSE = "storeTransactionIdleTimeoutClose";
String STORE_TRANSACTION_IDLE_TIMEOUT_WARN = "storeTransactionIdleTimeoutWarn";
String STORE_TRANSACTION_OPEN_TIMEOUT_CLOSE = "storeTransactionOpenTimeoutClose";
String STORE_TRANSACTION_OPEN_TIMEOUT_WARN = "storeTransactionOpenTimeoutWarn";
String STORE_TYPE = "storeType";
+ String STORE_PATH = "storePath";
String SUPPORTED_EXCHANGE_TYPES = "supportedExchangeTypes";
String SUPPORTED_QUEUE_TYPES = "supportedQueueTypes";
String CREATED = "created";
@@ -80,6 +83,8 @@ public interface VirtualHost extends ConfiguredObject
String STATE = "state";
String TIME_TO_LIVE = "timeToLive";
String UPDATED = "updated";
+ String CONFIG_PATH = "configPath";
+
// Attributes
public static final Collection<String> AVAILABLE_ATTRIBUTES =
Collections.unmodifiableList(
@@ -100,7 +105,7 @@ public interface VirtualHost extends ConfiguredObject
QUEUE_FLOW_CONTROL_SIZE_BYTES,
QUEUE_FLOW_RESUME_SIZE_BYTES,
STORE_TYPE,
- STORE_CONFIGURATION,
+ STORE_PATH,
STORE_TRANSACTION_IDLE_TIMEOUT_CLOSE,
STORE_TRANSACTION_IDLE_TIMEOUT_WARN,
STORE_TRANSACTION_OPEN_TIMEOUT_CLOSE,
@@ -109,7 +114,8 @@ public interface VirtualHost extends ConfiguredObject
ALERT_THRESHOLD_MESSAGE_AGE,
ALERT_THRESHOLD_MESSAGE_SIZE,
ALERT_THRESHOLD_QUEUE_DEPTH_BYTES,
- ALERT_THRESHOLD_QUEUE_DEPTH_MESSAGES));
+ ALERT_THRESHOLD_QUEUE_DEPTH_MESSAGES,
+ CONFIG_PATH));
@@ -147,4 +153,12 @@ public interface VirtualHost extends ConfiguredObject
}
void executeTransaction(TransactionalOperation op);
+
+ /**
+ * A temporary hack to expose host security manager.
+ * TODO We need to add and implement an authorization provider configured object instead
+ */
+ SecurityManager getSecurityManager();
+
+ MessageStore getMessageStore();
}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/AbstractAdapter.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/AbstractAdapter.java
index 7d6aa9b2cb..387b1b6b58 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/AbstractAdapter.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/AbstractAdapter.java
@@ -24,12 +24,18 @@ import java.security.AccessControlException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import java.util.UUID;
+
import org.apache.qpid.server.model.ConfigurationChangeListener;
import org.apache.qpid.server.model.ConfiguredObject;
import org.apache.qpid.server.model.IllegalStateTransitionException;
import org.apache.qpid.server.model.State;
+import org.apache.qpid.server.configuration.updater.ChangeStateTask;
+import org.apache.qpid.server.configuration.updater.CreateChildTask;
+import org.apache.qpid.server.configuration.updater.SetAttributeTask;
+import org.apache.qpid.server.configuration.updater.TaskExecutor;
abstract class AbstractAdapter implements ConfiguredObject
{
@@ -40,134 +46,78 @@ abstract class AbstractAdapter implements ConfiguredObject
new ArrayList<ConfigurationChangeListener>();
private final UUID _id;
+ private final Map<String, Object> _defaultAttributes = new HashMap<String, Object>();
+ private final TaskExecutor _taskExecutor;
- protected AbstractAdapter(UUID id)
+ protected AbstractAdapter(UUID id, Map<String, Object> defaults, Map<String, Object> attributes, TaskExecutor taskExecutor)
{
+ _taskExecutor = taskExecutor;
_id = id;
- }
-
- static String getStringAttribute(String name, Map<String,Object> attributes, String defaultVal)
- {
- final Object value = attributes.get(name);
- return value == null ? defaultVal : String.valueOf(value);
- }
-
- static Map getMapAttribute(String name, Map<String,Object> attributes, Map defaultVal)
- {
- final Object value = attributes.get(name);
- if(value == null)
- {
- return defaultVal;
- }
- else if(value instanceof Map)
+ if (attributes != null)
{
- return (Map) value;
+ Collection<String> names = getAttributeNames();
+ for (String name : names)
+ {
+ if (attributes.containsKey(name))
+ {
+ _attributes.put(name, attributes.get(name));
+ }
+ }
}
- else
+ if (defaults != null)
{
- throw new IllegalArgumentException("Value for attribute " + name + " is not of required type Map");
+ _defaultAttributes.putAll(defaults);
}
}
-
- static <E extends Enum> E getEnumAttribute(Class<E> clazz, String name, Map<String,Object> attributes, E defaultVal)
+ protected AbstractAdapter(UUID id, TaskExecutor taskExecutor)
{
- Object obj = attributes.get(name);
- if(obj == null)
- {
- return defaultVal;
- }
- else if(clazz.isInstance(obj))
- {
- return (E) obj;
- }
- else if(obj instanceof String)
- {
- return (E) Enum.valueOf(clazz, (String)obj);
- }
- else
- {
- throw new IllegalArgumentException("Value for attribute " + name + " is not of required type " + clazz.getSimpleName());
- }
+ this(id, null, null, taskExecutor);
}
- static Boolean getBooleanAttribute(String name, Map<String,Object> attributes, Boolean defaultValue)
+ public final UUID getId()
{
- Object obj = attributes.get(name);
- if(obj == null)
- {
- return defaultValue;
- }
- else if(obj instanceof Boolean)
- {
- return (Boolean) obj;
- }
- else if(obj instanceof String)
- {
- return Boolean.parseBoolean((String) obj);
- }
- else
- {
- throw new IllegalArgumentException("Value for attribute " + name + " is not of required type Boolean");
- }
+ return _id;
}
- static Integer getIntegerAttribute(String name, Map<String,Object> attributes, Integer defaultValue)
+ public State getDesiredState()
{
- Object obj = attributes.get(name);
- if(obj == null)
- {
- return defaultValue;
- }
- else if(obj instanceof Number)
- {
- return ((Number) obj).intValue();
- }
- else if(obj instanceof String)
- {
- return Integer.valueOf((String) obj);
- }
- else
- {
- throw new IllegalArgumentException("Value for attribute " + name + " is not of required type Integer");
- }
+ return null; //TODO
}
- static Long getLongAttribute(String name, Map<String,Object> attributes, Long defaultValue)
+ @Override
+ public final State setDesiredState(final State currentState, final State desiredState)
+ throws IllegalStateTransitionException, AccessControlException
{
- Object obj = attributes.get(name);
- if(obj == null)
- {
- return defaultValue;
- }
- else if(obj instanceof Number)
+ if (_taskExecutor.isTaskExecutorThread())
{
- return ((Number) obj).longValue();
- }
- else if(obj instanceof String)
- {
- return Long.valueOf((String) obj);
+ if (setState(currentState, desiredState))
+ {
+ notifyStateChanged(currentState, desiredState);
+ }
}
else
{
- throw new IllegalArgumentException("Value for attribute " + name + " is not of required type Long");
+ _taskExecutor.submitAndWait(new ChangeStateTask(this, currentState, desiredState));
}
+ return getActualState();
}
- public final UUID getId()
- {
- return _id;
- }
+ /**
+ * @return true when the state has been successfully updated to desiredState or false otherwise
+ */
+ protected abstract boolean setState(State currentState, State desiredState);
- public State getDesiredState()
+ protected void notifyStateChanged(final State currentState, final State desiredState)
{
- return null; //TODO
- }
-
- public State setDesiredState(final State currentState, final State desiredState)
- throws IllegalStateTransitionException, AccessControlException
- {
- return null; //TODO
+ synchronized (_changeListeners)
+ {
+ List<ConfigurationChangeListener> copy = new ArrayList<ConfigurationChangeListener>(_changeListeners);
+ for(ConfigurationChangeListener listener : copy)
+ {
+ listener.stateChanged(this, currentState, desiredState);
+ }
+ }
}
public void addChangeListener(final ConfigurationChangeListener listener)
@@ -176,7 +126,7 @@ abstract class AbstractAdapter implements ConfiguredObject
{
throw new NullPointerException("Cannot add a null listener");
}
- synchronized (this)
+ synchronized (_changeListeners)
{
if(!_changeListeners.contains(listener))
{
@@ -191,39 +141,76 @@ abstract class AbstractAdapter implements ConfiguredObject
{
throw new NullPointerException("Cannot remove a null listener");
}
- synchronized (this)
+ synchronized (_changeListeners)
{
return _changeListeners.remove(listener);
}
}
-
protected void childAdded(ConfiguredObject child)
{
- synchronized (this)
+ synchronized (_changeListeners)
{
- for(ConfigurationChangeListener listener : _changeListeners)
+ List<ConfigurationChangeListener> copy = new ArrayList<ConfigurationChangeListener>(_changeListeners);
+ for(ConfigurationChangeListener listener : copy)
{
listener.childAdded(this, child);
}
}
}
-
protected void childRemoved(ConfiguredObject child)
{
- synchronized (this)
+ synchronized (_changeListeners)
{
- for(ConfigurationChangeListener listener : _changeListeners)
+ List<ConfigurationChangeListener> copy = new ArrayList<ConfigurationChangeListener>(_changeListeners);
+ for(ConfigurationChangeListener listener : copy)
{
listener.childRemoved(this, child);
}
}
}
- public Object getAttribute(final String name)
+ protected void attributeSet(String attrinuteName, Object oldAttributeValue, Object newAttributeValue)
{
- synchronized (this)
+ synchronized (_changeListeners)
+ {
+ List<ConfigurationChangeListener> copy = new ArrayList<ConfigurationChangeListener>(_changeListeners);
+ for(ConfigurationChangeListener listener : copy)
+ {
+ listener.attributeSet(this, attrinuteName, oldAttributeValue, newAttributeValue);
+ }
+ }
+ }
+
+ private final Object getDefaultAttribute(String name)
+ {
+ return _defaultAttributes.get(name);
+ }
+
+ @Override
+ public Object getAttribute(String name)
+ {
+ Object value = getActualAttribute(name);
+ if (value == null)
+ {
+ value = getDefaultAttribute(name);
+ }
+ return value;
+ }
+
+ @Override
+ public final Map<String, Object> getActualAttributes()
+ {
+ synchronized (_attributes)
+ {
+ return new HashMap<String, Object>(_attributes);
+ }
+ }
+
+ private Object getActualAttribute(final String name)
+ {
+ synchronized (_attributes)
{
return _attributes.get(name);
}
@@ -232,25 +219,41 @@ abstract class AbstractAdapter implements ConfiguredObject
public Object setAttribute(final String name, final Object expected, final Object desired)
throws IllegalStateException, AccessControlException, IllegalArgumentException
{
- synchronized (this)
+ if (_taskExecutor.isTaskExecutorThread())
{
- Object currentValue = _attributes.get(name);
+ if (changeAttribute(name, expected, desired))
+ {
+ attributeSet(name, expected, desired);
+ }
+ }
+ else
+ {
+ _taskExecutor.submitAndWait(new SetAttributeTask(this, name, expected, desired));
+ }
+ return getAttribute(name);
+ }
+
+ protected boolean changeAttribute(final String name, final Object expected, final Object desired)
+ {
+ synchronized (_attributes)
+ {
+ Object currentValue = getAttribute(name);
if((currentValue == null && expected == null)
|| (currentValue != null && currentValue.equals(expected)))
{
_attributes.put(name, desired);
- return desired;
+ return true;
}
else
{
- return currentValue;
+ return false;
}
}
}
public <T extends ConfiguredObject> T getParent(final Class<T> clazz)
{
- synchronized (this)
+ synchronized (_parents)
{
return (T) _parents.get(clazz);
}
@@ -258,7 +261,7 @@ abstract class AbstractAdapter implements ConfiguredObject
protected <T extends ConfiguredObject> void addParent(Class<T> clazz, T parent)
{
- synchronized (this)
+ synchronized (_parents)
{
_parents.put(clazz, parent);
}
@@ -280,4 +283,40 @@ abstract class AbstractAdapter implements ConfiguredObject
}
}
+ @Override
+ public String toString()
+ {
+ return getClass().getSimpleName() + " [id=" + _id + "]";
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public <C extends ConfiguredObject> C createChild(Class<C> childClass, Map<String, Object> attributes, ConfiguredObject... otherParents)
+ {
+ if (_taskExecutor.isTaskExecutorThread())
+ {
+ C child = addChild(childClass, attributes, otherParents);
+ if (child != null)
+ {
+ childAdded(child);
+ }
+ return child;
+ }
+ else
+ {
+ return (C)_taskExecutor.submitAndWait(new CreateChildTask(this, childClass, attributes, otherParents));
+ }
+ }
+
+ protected <C extends ConfiguredObject> C addChild(Class<C> childClass, Map<String, Object> attributes, ConfiguredObject... otherParents)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+
+ protected TaskExecutor getTaskExecutor()
+ {
+ return _taskExecutor;
+ }
+
}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/AbstractKeyStoreAdapter.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/AbstractKeyStoreAdapter.java
new file mode 100644
index 0000000000..ebd98f915d
--- /dev/null
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/AbstractKeyStoreAdapter.java
@@ -0,0 +1,198 @@
+/*
+ *
+ * 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.qpid.server.model.adapter;
+
+import java.security.AccessControlException;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Map;
+import java.util.UUID;
+
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.ConfiguredObject;
+import org.apache.qpid.server.model.KeyStore;
+import org.apache.qpid.server.model.LifetimePolicy;
+import org.apache.qpid.server.model.State;
+import org.apache.qpid.server.model.Statistics;
+import org.apache.qpid.server.model.TrustStore;
+import org.apache.qpid.server.util.MapValueConverter;
+
+public abstract class AbstractKeyStoreAdapter extends AbstractAdapter
+{
+ private String _name;
+ private String _password;
+
+ protected AbstractKeyStoreAdapter(UUID id, Broker broker, Map<String, Object> attributes)
+ {
+ super(id, broker.getTaskExecutor());
+ addParent(Broker.class, broker);
+ _name = MapValueConverter.getStringAttribute(TrustStore.NAME, attributes);
+ _password = MapValueConverter.getStringAttribute(TrustStore.PASSWORD, attributes);
+ setMandatoryAttribute(TrustStore.PATH, attributes);
+ setOptionalAttribute(TrustStore.TYPE, attributes);
+ setOptionalAttribute(TrustStore.KEY_MANAGER_FACTORY_ALGORITHM, attributes);
+ setOptionalAttribute(TrustStore.DESCRIPTION, attributes);
+ }
+
+ @Override
+ public String getName()
+ {
+ return _name;
+ }
+
+ @Override
+ public String setName(String currentName, String desiredName) throws IllegalStateException, AccessControlException
+ {
+ throw new IllegalStateException();
+ }
+
+ @Override
+ public State getActualState()
+ {
+ return State.ACTIVE;
+ }
+
+ @Override
+ public boolean isDurable()
+ {
+ return true;
+ }
+
+ @Override
+ public void setDurable(boolean durable) throws IllegalStateException, AccessControlException, IllegalArgumentException
+ {
+ throw new IllegalStateException();
+ }
+
+ @Override
+ public LifetimePolicy getLifetimePolicy()
+ {
+ return LifetimePolicy.PERMANENT;
+ }
+
+ @Override
+ public LifetimePolicy setLifetimePolicy(LifetimePolicy expected, LifetimePolicy desired) throws IllegalStateException, AccessControlException,
+ IllegalArgumentException
+ {
+ throw new IllegalStateException();
+ }
+
+ @Override
+ public long getTimeToLive()
+ {
+ return 0;
+ }
+
+ @Override
+ public long setTimeToLive(long expected, long desired) throws IllegalStateException, AccessControlException, IllegalArgumentException
+ {
+ throw new IllegalStateException();
+ }
+
+ @Override
+ public Statistics getStatistics()
+ {
+ return NoStatistics.getInstance();
+ }
+
+ @Override
+ public <C extends ConfiguredObject> Collection<C> getChildren(Class<C> clazz)
+ {
+ return Collections.emptySet();
+ }
+
+ @Override
+ public <C extends ConfiguredObject> C createChild(Class<C> childClass, Map<String, Object> attributes, ConfiguredObject... otherParents)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Object getAttribute(String name)
+ {
+ if(KeyStore.ID.equals(name))
+ {
+ return getId();
+ }
+ else if(KeyStore.NAME.equals(name))
+ {
+ return getName();
+ }
+ else if(KeyStore.STATE.equals(name))
+ {
+ return getActualState();
+ }
+ else if(KeyStore.DURABLE.equals(name))
+ {
+ return isDurable();
+ }
+ else if(KeyStore.LIFETIME_POLICY.equals(name))
+ {
+ return getLifetimePolicy();
+ }
+ else if(KeyStore.TIME_TO_LIVE.equals(name))
+ {
+ return getTimeToLive();
+ }
+ else if(KeyStore.CREATED.equals(name))
+ {
+
+ }
+ else if(KeyStore.UPDATED.equals(name))
+ {
+
+ }
+ else if(KeyStore.PASSWORD.equals(name))
+ {
+ return null; // for security reasons we don't expose the password
+ }
+ return super.getAttribute(name);
+ }
+
+ @Override
+ protected boolean setState(State currentState, State desiredState)
+ {
+ return false;
+ }
+
+ public String getPassword()
+ {
+ return _password;
+ }
+
+ public void setPassword(String password)
+ {
+ _password = password;
+ }
+
+ private void setMandatoryAttribute(String name, Map<String, Object> attributeValues)
+ {
+ changeAttribute(name, null, MapValueConverter.getStringAttribute(name, attributeValues));
+ }
+
+ private void setOptionalAttribute(String name, Map<String, Object> attributeValues)
+ {
+ if (attributeValues.get(name) != null)
+ {
+ changeAttribute(name, null, MapValueConverter.getStringAttribute(name, attributeValues));
+ }
+ }
+}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/AbstractPluginAdapter.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/AbstractPluginAdapter.java
new file mode 100644
index 0000000000..ed4af9881f
--- /dev/null
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/AbstractPluginAdapter.java
@@ -0,0 +1,152 @@
+/*
+ *
+ * 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.qpid.server.model.adapter;
+
+import java.security.AccessControlException;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Map;
+import java.util.UUID;
+
+import org.apache.qpid.server.configuration.updater.TaskExecutor;
+import org.apache.qpid.server.model.ConfiguredObject;
+import org.apache.qpid.server.model.LifetimePolicy;
+import org.apache.qpid.server.model.Plugin;
+import org.apache.qpid.server.model.State;
+import org.apache.qpid.server.model.Statistics;
+
+public abstract class AbstractPluginAdapter extends AbstractAdapter implements Plugin
+{
+
+ protected AbstractPluginAdapter(UUID id, Map<String, Object> defaults, Map<String, Object> attributes, TaskExecutor taskExecutor)
+ {
+ super(id, defaults, attributes, taskExecutor);
+ }
+
+ @Override
+ public String setName(String currentName, String desiredName) throws IllegalStateException, AccessControlException
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public State getActualState()
+ {
+ return null;
+ }
+
+ @Override
+ public boolean isDurable()
+ {
+ return true;
+ }
+
+ @Override
+ public void setDurable(boolean durable) throws IllegalStateException, AccessControlException, IllegalArgumentException
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public LifetimePolicy getLifetimePolicy()
+ {
+ return LifetimePolicy.PERMANENT;
+ }
+
+ @Override
+ public LifetimePolicy setLifetimePolicy(LifetimePolicy expected, LifetimePolicy desired) throws IllegalStateException,
+ AccessControlException, IllegalArgumentException
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public long getTimeToLive()
+ {
+ return 0;
+ }
+
+ @Override
+ public long setTimeToLive(long expected, long desired) throws IllegalStateException, AccessControlException,
+ IllegalArgumentException
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Statistics getStatistics()
+ {
+ return null;
+ }
+
+ @Override
+ public <C extends ConfiguredObject> Collection<C> getChildren(Class<C> clazz)
+ {
+ return Collections.emptyList();
+ }
+
+ @Override
+ public <C extends ConfiguredObject> C createChild(Class<C> childClass, Map<String, Object> attributes,
+ ConfiguredObject... otherParents)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Collection<String> getAttributeNames()
+ {
+ return AVAILABLE_ATTRIBUTES;
+ }
+
+ @Override
+ public Object getAttribute(String name)
+ {
+ if (ID.equals(name))
+ {
+ return getId();
+ }
+ else if (STATE.equals(name))
+ {
+ return getActualState();
+ }
+ else if (DURABLE.equals(name))
+ {
+ return isDurable();
+ }
+ else if (LIFETIME_POLICY.equals(name))
+ {
+ return getLifetimePolicy();
+ }
+ else if (TIME_TO_LIVE.equals(name))
+ {
+ return getTimeToLive();
+ }
+ else if (CREATED.equals(name))
+ {
+
+ }
+ else if (UPDATED.equals(name))
+ {
+
+ }
+ return super.getAttribute(name);
+ }
+}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/AmqpPortAdapter.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/AmqpPortAdapter.java
new file mode 100644
index 0000000000..2f7e89bb2b
--- /dev/null
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/AmqpPortAdapter.java
@@ -0,0 +1,251 @@
+/*
+ * 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.qpid.server.model.adapter;
+
+import static org.apache.qpid.transport.ConnectionSettings.WILDCARD_ADDRESS;
+
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.security.GeneralSecurityException;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+
+import javax.net.ssl.SSLContext;
+
+import org.apache.qpid.server.configuration.BrokerProperties;
+import org.apache.qpid.server.configuration.IllegalConfigurationException;
+import org.apache.qpid.server.logging.actors.CurrentActor;
+import org.apache.qpid.server.logging.messages.BrokerMessages;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.KeyStore;
+import org.apache.qpid.server.model.Port;
+import org.apache.qpid.server.model.Protocol;
+import org.apache.qpid.server.model.Transport;
+import org.apache.qpid.server.model.TrustStore;
+import org.apache.qpid.server.configuration.updater.TaskExecutor;
+import org.apache.qpid.server.protocol.AmqpProtocolVersion;
+import org.apache.qpid.server.protocol.MultiVersionProtocolEngineFactory;
+import org.apache.qpid.ssl.SSLContextFactory;
+import org.apache.qpid.transport.NetworkTransportConfiguration;
+import org.apache.qpid.transport.network.IncomingNetworkTransport;
+
+public class AmqpPortAdapter extends PortAdapter
+{
+ private final Broker _broker;
+ private IncomingNetworkTransport _transport;
+
+ public AmqpPortAdapter(UUID id, Broker broker, Map<String, Object> attributes, Map<String, Object> defaultAttributes, TaskExecutor taskExecutor)
+ {
+ super(id, broker, attributes, defaultAttributes, taskExecutor);
+ _broker = broker;
+ }
+
+ @Override
+ protected void onActivate()
+ {
+ Collection<Transport> transports = getTransports();
+ Set<AmqpProtocolVersion> supported = convertFromModelProtocolsToAmqp(getProtocols());
+
+ SSLContext sslContext = null;
+ if (transports.contains(Transport.SSL))
+ {
+ sslContext = createSslContext();
+ }
+
+ AmqpProtocolVersion defaultSupportedProtocolReply = getDefaultAmqpSupportedReply();
+
+ String bindingAddress = (String) getAttribute(Port.BINDING_ADDRESS);
+ if (WILDCARD_ADDRESS.equals(bindingAddress))
+ {
+ bindingAddress = null;
+ }
+ Integer port = (Integer) getAttribute(Port.PORT);
+ InetSocketAddress bindingSocketAddress = null;
+ if ( bindingAddress == null )
+ {
+ bindingSocketAddress = new InetSocketAddress(port);
+ }
+ else
+ {
+ bindingSocketAddress = new InetSocketAddress(bindingAddress, port);
+ }
+
+ final NetworkTransportConfiguration settings = new ServerNetworkTransportConfiguration(
+ bindingSocketAddress, (Boolean)getAttribute(TCP_NO_DELAY),
+ (Integer)getAttribute(SEND_BUFFER_SIZE), (Integer)getAttribute(RECEIVE_BUFFER_SIZE),
+ (Boolean)getAttribute(NEED_CLIENT_AUTH), (Boolean)getAttribute(WANT_CLIENT_AUTH));
+
+ _transport = org.apache.qpid.transport.network.Transport.getIncomingTransportInstance();
+ final MultiVersionProtocolEngineFactory protocolEngineFactory = new MultiVersionProtocolEngineFactory(
+ _broker, supported, defaultSupportedProtocolReply);
+
+ _transport.accept(settings, protocolEngineFactory, sslContext);
+ CurrentActor.get().message(BrokerMessages.LISTENING(getTransports().toString(), getPort()));
+ }
+
+ @Override
+ protected void onStop()
+ {
+ if (_transport != null)
+ {
+ CurrentActor.get().message(BrokerMessages.SHUTTING_DOWN(getTransports().toString(), getPort()));
+ _transport.close();
+ }
+ }
+
+ private Set<AmqpProtocolVersion> convertFromModelProtocolsToAmqp(Collection<Protocol> modelProtocols)
+ {
+ Set<AmqpProtocolVersion> amqpProtocols = new HashSet<AmqpProtocolVersion>();
+ for (Protocol protocol : modelProtocols)
+ {
+ amqpProtocols.add(protocol.toAmqpProtocolVersion());
+ }
+ return amqpProtocols;
+ }
+
+ private SSLContext createSslContext()
+ {
+ KeyStore keyStore = _broker.getDefaultKeyStore();
+ if (keyStore == null)
+ {
+ throw new IllegalConfigurationException("SSL was requested on AMQP port '"
+ + this.getName() + "' but no key store defined");
+ }
+
+ TrustStore trustStore = _broker.getDefaultTrustStore();
+ if (((Boolean)getAttribute(NEED_CLIENT_AUTH) || (Boolean)getAttribute(WANT_CLIENT_AUTH)) && trustStore == null)
+ {
+ throw new IllegalConfigurationException("Client certificate authentication is enabled on AMQP port '"
+ + this.getName() + "' but no trust store defined");
+ }
+
+ String keystorePath = (String)keyStore.getAttribute(KeyStore.PATH);
+ String keystorePassword = keyStore.getPassword();
+ String keystoreType = (String)keyStore.getAttribute(KeyStore.TYPE);
+ String keyManagerFactoryAlgorithm = (String)keyStore.getAttribute(KeyStore.KEY_MANAGER_FACTORY_ALGORITHM);
+ String certAlias = (String)keyStore.getAttribute(KeyStore.CERTIFICATE_ALIAS);
+
+ final SSLContext sslContext;
+ try
+ {
+ if(trustStore != null)
+ {
+ String trustStorePassword = trustStore.getPassword();
+ String trustStoreType = (String)trustStore.getAttribute(TrustStore.TYPE);
+ String trustManagerFactoryAlgorithm = (String)trustStore.getAttribute(TrustStore.KEY_MANAGER_FACTORY_ALGORITHM);
+ String trustStorePath = (String)trustStore.getAttribute(TrustStore.PATH);
+
+ sslContext = SSLContextFactory.buildClientContext(trustStorePath,
+ trustStorePassword,
+ trustStoreType,
+ trustManagerFactoryAlgorithm,
+ keystorePath,
+ keystorePassword, keystoreType, keyManagerFactoryAlgorithm,
+ certAlias);
+ }
+ else
+ {
+ sslContext = SSLContextFactory.buildServerContext(keystorePath, keystorePassword, keystoreType, keyManagerFactoryAlgorithm);
+ }
+ }
+ catch (GeneralSecurityException e)
+ {
+ throw new RuntimeException("Unable to create SSLContext for key or trust store", e);
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException("Unable to create SSLContext - unable to load key/trust store", e);
+ }
+ return sslContext;
+ }
+
+ private AmqpProtocolVersion getDefaultAmqpSupportedReply()
+ {
+ String defaultAmqpSupportedReply = System.getProperty(BrokerProperties.PROPERTY_DEFAULT_SUPPORTED_PROTOCOL_REPLY);
+ if (defaultAmqpSupportedReply != null)
+ {
+ return AmqpProtocolVersion.valueOf(defaultAmqpSupportedReply);
+ }
+ return null;
+ }
+
+
+ class ServerNetworkTransportConfiguration implements NetworkTransportConfiguration
+ {
+ private final InetSocketAddress _bindingSocketAddress;
+ private final Boolean _tcpNoDelay;
+ private final Integer _sendBufferSize;
+ private final Integer _receiveBufferSize;
+ private final boolean _needClientAuth;
+ private final boolean _wantClientAuth;
+
+ public ServerNetworkTransportConfiguration(
+ InetSocketAddress bindingSocketAddress, boolean tcpNoDelay,
+ int sendBufferSize, int receiveBufferSize,
+ boolean needClientAuth, boolean wantClientAuth)
+ {
+ _bindingSocketAddress = bindingSocketAddress;
+ _tcpNoDelay = tcpNoDelay;
+ _sendBufferSize = sendBufferSize;
+ _receiveBufferSize = receiveBufferSize;
+ _needClientAuth = needClientAuth;
+ _wantClientAuth = wantClientAuth;
+ }
+
+ @Override
+ public boolean wantClientAuth()
+ {
+ return _wantClientAuth;
+ }
+
+ @Override
+ public boolean needClientAuth()
+ {
+ return _needClientAuth;
+ }
+
+ @Override
+ public Boolean getTcpNoDelay()
+ {
+ return _tcpNoDelay;
+ }
+
+ @Override
+ public Integer getSendBufferSize()
+ {
+ return _sendBufferSize;
+ }
+
+ @Override
+ public Integer getReceiveBufferSize()
+ {
+ return _receiveBufferSize;
+ }
+
+ @Override
+ public InetSocketAddress getAddress()
+ {
+ return _bindingSocketAddress;
+ }
+ };
+}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/AuthenticationProviderAdapter.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/AuthenticationProviderAdapter.java
index adad2a355c..ac4b0255d5 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/AuthenticationProviderAdapter.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/AuthenticationProviderAdapter.java
@@ -29,38 +29,50 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.UUID;
+
import javax.security.auth.login.AccountNotFoundException;
import org.apache.log4j.Logger;
-import org.apache.qpid.server.model.*;
-import org.apache.qpid.server.registry.ApplicationRegistry;
+import org.apache.qpid.server.model.AuthenticationProvider;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.ConfiguredObject;
+import org.apache.qpid.server.model.IllegalStateTransitionException;
+import org.apache.qpid.server.model.LifetimePolicy;
+import org.apache.qpid.server.model.PasswordCredentialManagingAuthenticationProvider;
+import org.apache.qpid.server.model.State;
+import org.apache.qpid.server.model.Statistics;
+import org.apache.qpid.server.model.UUIDGenerator;
+import org.apache.qpid.server.model.User;
+import org.apache.qpid.server.model.VirtualHostAlias;
+import org.apache.qpid.server.configuration.updater.TaskExecutor;
+import org.apache.qpid.server.security.SubjectCreator;
import org.apache.qpid.server.security.access.Operation;
+import org.apache.qpid.server.security.auth.UsernamePrincipal;
import org.apache.qpid.server.security.auth.database.PrincipalDatabase;
import org.apache.qpid.server.security.auth.manager.AuthenticationManager;
import org.apache.qpid.server.security.auth.manager.PrincipalDatabaseAuthenticationManager;
-import org.apache.qpid.server.security.auth.UsernamePrincipal;
+import org.apache.qpid.server.security.group.GroupPrincipalAccessor;
+import org.apache.qpid.server.security.SecurityManager;
public abstract class AuthenticationProviderAdapter<T extends AuthenticationManager> extends AbstractAdapter implements AuthenticationProvider
{
private static final Logger LOGGER = Logger.getLogger(AuthenticationProviderAdapter.class);
- private final BrokerAdapter _broker;
private final T _authManager;
+ protected final Broker _broker;
- private AuthenticationProviderAdapter(BrokerAdapter brokerAdapter,
- final T authManager)
- {
- super(UUIDGenerator.generateRandomUUID());
- _broker = brokerAdapter;
- _authManager = authManager;
- }
+ private GroupPrincipalAccessor _groupAccessor;
+
+ private Object _type;
- public static AuthenticationProviderAdapter createAuthenticationProviderAdapter(BrokerAdapter brokerAdapter,
- final AuthenticationManager authManager)
+ private AuthenticationProviderAdapter(UUID id, Broker broker, final T authManager, Map<String, Object> attributes)
{
- return authManager instanceof PrincipalDatabaseAuthenticationManager
- ? new PrincipalDatabaseAuthenticationManagerAdapter(brokerAdapter, (PrincipalDatabaseAuthenticationManager) authManager)
- : new SimpleAuthenticationProviderAdapter(brokerAdapter, authManager);
+ super(id, null, attributes, broker.getTaskExecutor());
+ _authManager = authManager;
+ _broker = broker;
+ _type = authManager instanceof PrincipalDatabaseAuthenticationManager? PrincipalDatabaseAuthenticationManager.class.getSimpleName() : AuthenticationManager.class.getSimpleName() ;
+ addParent(Broker.class, broker);
}
T getAuthManager()
@@ -77,7 +89,7 @@ public abstract class AuthenticationProviderAdapter<T extends AuthenticationMana
@Override
public String getName()
{
- return _authManager.getClass().getSimpleName();
+ return (String)getAttribute(AuthenticationProvider.NAME);
}
@Override
@@ -147,7 +159,7 @@ public abstract class AuthenticationProviderAdapter<T extends AuthenticationMana
{
if(TYPE.equals(name))
{
- return getName();
+ return _type;
}
else if(CREATED.equals(name))
{
@@ -165,10 +177,6 @@ public abstract class AuthenticationProviderAdapter<T extends AuthenticationMana
{
return LifetimePolicy.PERMANENT;
}
- else if(NAME.equals(name))
- {
- return getName();
- }
else if(STATE.equals(name))
{
return State.ACTIVE; // TODO
@@ -191,31 +199,67 @@ public abstract class AuthenticationProviderAdapter<T extends AuthenticationMana
}
@Override
- public <C extends ConfiguredObject> C createChild(Class<C> childClass,
- Map<String, Object> attributes,
- ConfiguredObject... otherParents)
+ public boolean setState(State currentState, State desiredState)
+ throws IllegalStateTransitionException, AccessControlException
{
- throw new IllegalArgumentException("This authentication provider does not support" +
- " creating children of type: " + childClass);
+ if(desiredState == State.DELETED)
+ {
+ return true;
+ }
+ else if(desiredState == State.ACTIVE)
+ {
+ if (_groupAccessor == null)
+ {
+ throw new IllegalStateTransitionException("Cannot transit into ACTIVE state with null group accessor!");
+ }
+ _authManager.initialise();
+ return true;
+ }
+ else if(desiredState == State.STOPPED)
+ {
+ _authManager.close();
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ public SubjectCreator getSubjectCreator()
+ {
+ return new SubjectCreator(_authManager, _groupAccessor);
+ }
+
+ public void setGroupAccessor(GroupPrincipalAccessor groupAccessor)
+ {
+ _groupAccessor = groupAccessor;
}
- private static class SimpleAuthenticationProviderAdapter extends AuthenticationProviderAdapter<AuthenticationManager>
+ public static class SimpleAuthenticationProviderAdapter extends AuthenticationProviderAdapter<AuthenticationManager>
{
+
public SimpleAuthenticationProviderAdapter(
- BrokerAdapter brokerAdapter, AuthenticationManager authManager)
+ UUID id, Broker broker, AuthenticationManager authManager, Map<String, Object> attributes)
{
- super(brokerAdapter,authManager);
+ super(id, broker,authManager, attributes);
+ }
+
+ @Override
+ public <C extends ConfiguredObject> C createChild(Class<C> childClass,
+ Map<String, Object> attributes,
+ ConfiguredObject... otherParents)
+ {
+ throw new UnsupportedOperationException();
}
}
- private static class PrincipalDatabaseAuthenticationManagerAdapter
+ public static class PrincipalDatabaseAuthenticationManagerAdapter
extends AuthenticationProviderAdapter<PrincipalDatabaseAuthenticationManager>
implements PasswordCredentialManagingAuthenticationProvider
{
public PrincipalDatabaseAuthenticationManagerAdapter(
- BrokerAdapter brokerAdapter, PrincipalDatabaseAuthenticationManager authManager)
+ UUID id, Broker broker, PrincipalDatabaseAuthenticationManager authManager, Map<String, Object> attributes)
{
- super(brokerAdapter, authManager);
+ super(id, broker, authManager, attributes);
}
@Override
@@ -245,9 +289,9 @@ public abstract class AuthenticationProviderAdapter<T extends AuthenticationMana
}
}
- private org.apache.qpid.server.security.SecurityManager getSecurityManager()
+ private SecurityManager getSecurityManager()
{
- return ApplicationRegistry.getInstance().getSecurityManager();
+ return _broker.getSecurityManager();
}
private PrincipalDatabase getPrincipalDatabase()
@@ -275,7 +319,7 @@ public abstract class AuthenticationProviderAdapter<T extends AuthenticationMana
Map<String, Map<String,String>> users = new HashMap<String, Map<String, String>>();
for(Principal principal : getPrincipalDatabase().getUsers())
{
- users.put(principal.getName(), Collections.EMPTY_MAP);
+ users.put(principal.getName(), Collections.<String, String>emptyMap());
}
return users;
}
@@ -286,7 +330,7 @@ public abstract class AuthenticationProviderAdapter<T extends AuthenticationMana
}
@Override
- public <C extends ConfiguredObject> C createChild(Class<C> childClass,
+ public <C extends ConfiguredObject> C addChild(Class<C> childClass,
Map<String, Object> attributes,
ConfiguredObject... otherParents)
{
@@ -298,7 +342,9 @@ public abstract class AuthenticationProviderAdapter<T extends AuthenticationMana
if(createUser(username, password,null))
{
- return (C) new PrincipalAdapter(p);
+ @SuppressWarnings("unchecked")
+ C pricipalAdapter = (C) new PrincipalAdapter(p, getTaskExecutor());
+ return pricipalAdapter;
}
else
{
@@ -307,7 +353,7 @@ public abstract class AuthenticationProviderAdapter<T extends AuthenticationMana
}
}
- return super.createChild(childClass, attributes, otherParents);
+ return super.addChild(childClass, attributes, otherParents);
}
@Override
@@ -319,9 +365,11 @@ public abstract class AuthenticationProviderAdapter<T extends AuthenticationMana
Collection<User> principals = new ArrayList<User>(users.size());
for(Principal user : users)
{
- principals.add(new PrincipalAdapter(user));
+ principals.add(new PrincipalAdapter(user, getTaskExecutor()));
}
- return (Collection<C>) Collections.unmodifiableCollection(principals);
+ @SuppressWarnings("unchecked")
+ Collection<C> unmodifiablePrincipals = (Collection<C>) Collections.unmodifiableCollection(principals);
+ return unmodifiablePrincipals;
}
else
{
@@ -334,9 +382,9 @@ public abstract class AuthenticationProviderAdapter<T extends AuthenticationMana
private final Principal _user;
- public PrincipalAdapter(Principal user)
+ public PrincipalAdapter(Principal user, TaskExecutor taskExecutor)
{
- super(UUIDGenerator.generateUserUUID(PrincipalDatabaseAuthenticationManagerAdapter.this.getName(), user.getName()));
+ super(UUIDGenerator.generateUserUUID(PrincipalDatabaseAuthenticationManagerAdapter.this.getName(), user.getName()), taskExecutor);
_user = user;
}
@@ -457,20 +505,19 @@ public abstract class AuthenticationProviderAdapter<T extends AuthenticationMana
}
@Override
- public Object setAttribute(String name, Object expected, Object desired)
+ public boolean changeAttribute(String name, Object expected, Object desired)
throws IllegalStateException, AccessControlException, IllegalArgumentException
{
if(name.equals(PASSWORD))
{
setPassword((String)desired);
+ return true;
}
- return super.setAttribute(name,
- expected,
- desired);
+ return super.changeAttribute(name, expected, desired);
}
@Override
- public State setDesiredState(State currentState, State desiredState)
+ protected boolean setState(State currentState, State desiredState)
throws IllegalStateTransitionException, AccessControlException
{
if(desiredState == State.DELETED)
@@ -483,9 +530,9 @@ public abstract class AuthenticationProviderAdapter<T extends AuthenticationMana
{
LOGGER.warn("Failed to delete user " + _user, e);
}
- return State.DELETED;
+ return true;
}
- return super.setDesiredState(currentState, desiredState);
+ return false;
}
}
}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/AuthenticationProviderFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/AuthenticationProviderFactory.java
new file mode 100644
index 0000000000..e5108ebbcf
--- /dev/null
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/AuthenticationProviderFactory.java
@@ -0,0 +1,77 @@
+/*
+ *
+ * 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.qpid.server.model.adapter;
+
+import java.util.Map;
+import java.util.UUID;
+
+import org.apache.qpid.server.model.AuthenticationProvider;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.plugin.AuthenticationManagerFactory;
+import org.apache.qpid.server.plugin.QpidServiceLoader;
+import org.apache.qpid.server.security.auth.manager.AuthenticationManager;
+import org.apache.qpid.server.security.auth.manager.PrincipalDatabaseAuthenticationManager;
+import org.apache.qpid.server.security.group.GroupPrincipalAccessor;
+import org.apache.qpid.server.model.adapter.AuthenticationProviderAdapter.PrincipalDatabaseAuthenticationManagerAdapter;
+import org.apache.qpid.server.model.adapter.AuthenticationProviderAdapter.SimpleAuthenticationProviderAdapter;
+
+public class AuthenticationProviderFactory
+{
+ private final Iterable<AuthenticationManagerFactory> _factories;
+
+ public AuthenticationProviderFactory(QpidServiceLoader<AuthenticationManagerFactory> authManagerFactoryServiceLoader)
+ {
+ _factories = authManagerFactoryServiceLoader.atLeastOneInstanceOf(AuthenticationManagerFactory.class);
+ }
+
+ /**
+ * Creates {@link AuthenticationProvider} for given ID, {@link Broker} and attributes.
+ * <p>
+ * The configured {@link AuthenticationManagerFactory}'s are used to try to create the {@link AuthenticationProvider}.
+ * The first non-null instance is returned. The factories are used in non-deterministic order.
+ * @param groupPrincipalAccessor TODO
+ */
+ public AuthenticationProvider create(UUID id, Broker broker, Map<String, Object> attributes, GroupPrincipalAccessor groupPrincipalAccessor)
+ {
+ for (AuthenticationManagerFactory factory : _factories)
+ {
+ AuthenticationManager manager = factory.createInstance(attributes);
+ if (manager != null)
+ {
+ AuthenticationProviderAdapter<?> authenticationProvider;
+ if (manager instanceof PrincipalDatabaseAuthenticationManager)
+ {
+ authenticationProvider = new PrincipalDatabaseAuthenticationManagerAdapter(id, broker,
+ (PrincipalDatabaseAuthenticationManager) manager, attributes);
+ }
+ else
+ {
+ authenticationProvider = new SimpleAuthenticationProviderAdapter(id, broker, manager, attributes);
+ }
+ authenticationProvider.setGroupAccessor(groupPrincipalAccessor);
+ return authenticationProvider;
+ }
+ }
+
+ throw new IllegalArgumentException("No authentication provider factory found for configuration attributes " + attributes);
+ }
+
+}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/BindingAdapter.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/BindingAdapter.java
index abd3160686..eb2d0dd7e2 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/BindingAdapter.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/BindingAdapter.java
@@ -48,7 +48,7 @@ final class BindingAdapter extends AbstractAdapter implements Binding
ExchangeAdapter exchangeAdapter,
QueueAdapter queueAdapter)
{
- super(binding.getId());
+ super(binding.getId(), queueAdapter.getTaskExecutor());
_binding = binding;
_exchange = exchangeAdapter;
_queue = queueAdapter;
@@ -206,27 +206,20 @@ final class BindingAdapter extends AbstractAdapter implements Binding
}
@Override
- public Object setAttribute(final String name, final Object expected, final Object desired)
- throws IllegalStateException, AccessControlException, IllegalArgumentException
- {
- return super.setAttribute(name, expected, desired); //TODO
- }
-
- @Override
public Collection<String> getAttributeNames()
{
return Binding.AVAILABLE_ATTRIBUTES;
}
@Override
- public State setDesiredState(State currentState, State desiredState) throws IllegalStateTransitionException,
+ protected boolean setState(State currentState, State desiredState) throws IllegalStateTransitionException,
AccessControlException
{
if (desiredState == State.DELETED)
{
delete();
- return State.DELETED;
+ return true;
}
- return super.setDesiredState(currentState, desiredState);
+ return false;
}
}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/BrokerAdapter.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/BrokerAdapter.java
index 276dc83540..d6c18a1141 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/BrokerAdapter.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/BrokerAdapter.java
@@ -21,89 +21,211 @@
package org.apache.qpid.server.model.adapter;
import java.net.InetSocketAddress;
+import java.net.SocketAddress;
import java.security.AccessControlException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
-import java.util.List;
import java.util.Map;
+import java.util.UUID;
+
+import javax.net.ssl.KeyManagerFactory;
+
+import org.apache.log4j.Logger;
import org.apache.qpid.common.QpidProperties;
+import org.apache.qpid.server.configuration.IllegalConfigurationException;
+import org.apache.qpid.server.logging.LogRecorder;
+import org.apache.qpid.server.logging.RootMessageLogger;
+import org.apache.qpid.server.logging.actors.BrokerActor;
+import org.apache.qpid.server.logging.actors.CurrentActor;
import org.apache.qpid.server.model.AuthenticationProvider;
import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.ConfigurationChangeListener;
import org.apache.qpid.server.model.ConfiguredObject;
import org.apache.qpid.server.model.GroupProvider;
+import org.apache.qpid.server.model.KeyStore;
import org.apache.qpid.server.model.LifetimePolicy;
+import org.apache.qpid.server.model.Plugin;
import org.apache.qpid.server.model.Port;
-import org.apache.qpid.server.model.Protocol;
import org.apache.qpid.server.model.State;
import org.apache.qpid.server.model.Statistics;
-import org.apache.qpid.server.model.Transport;
+import org.apache.qpid.server.model.TrustStore;
import org.apache.qpid.server.model.UUIDGenerator;
import org.apache.qpid.server.model.VirtualHost;
-import org.apache.qpid.server.registry.IApplicationRegistry;
-import org.apache.qpid.server.security.auth.manager.AuthenticationManager;
-import org.apache.qpid.server.security.auth.manager.IAuthenticationManagerRegistry;
+import org.apache.qpid.server.configuration.updater.TaskExecutor;
+import org.apache.qpid.server.security.group.FileGroupManager;
import org.apache.qpid.server.security.group.GroupManager;
-import org.apache.qpid.server.transport.QpidAcceptor;
+import org.apache.qpid.server.security.group.GroupPrincipalAccessor;
+import org.apache.qpid.server.security.SecurityManager;
+import org.apache.qpid.server.security.SubjectCreator;
+import org.apache.qpid.server.stats.StatisticsGatherer;
+import org.apache.qpid.server.util.MapValueConverter;
import org.apache.qpid.server.virtualhost.VirtualHostRegistry;
-public class BrokerAdapter extends AbstractAdapter implements Broker, VirtualHostRegistry.RegistryChangeListener,
- IApplicationRegistry.PortBindingListener,
- IAuthenticationManagerRegistry.RegistryChangeListener,
- IApplicationRegistry.GroupManagerChangeListener
+public class BrokerAdapter extends AbstractAdapter implements Broker, ConfigurationChangeListener
{
-
- private final IApplicationRegistry _applicationRegistry;
- private String _name;
- private final Map<org.apache.qpid.server.virtualhost.VirtualHost, VirtualHostAdapter> _vhostAdapters =
- new HashMap<org.apache.qpid.server.virtualhost.VirtualHost, VirtualHostAdapter>();
- private final StatisticsAdapter _statistics;
- private final Map<QpidAcceptor, PortAdapter> _portAdapters = new HashMap<QpidAcceptor, PortAdapter>();
- private Collection<HTTPPortAdapter> _httpManagementPorts;
-
- private final Map<AuthenticationManager, AuthenticationProviderAdapter> _authManagerAdapters =
- new HashMap<AuthenticationManager, AuthenticationProviderAdapter>();
- private final Map<GroupManager, GroupProviderAdapter> _groupManagerAdapters =
- new HashMap<GroupManager, GroupProviderAdapter>();
-
-
- public BrokerAdapter(final IApplicationRegistry instance)
- {
- super(UUIDGenerator.generateRandomUUID());
- _applicationRegistry = instance;
- _name = "Broker";
- _statistics = new StatisticsAdapter(instance);
-
- instance.getVirtualHostRegistry().addRegistryChangeListener(this);
- populateVhosts();
- instance.addPortBindingListener(this);
- populatePorts();
- instance.addAuthenticationManagerRegistryChangeListener(this);
- populateAuthenticationManagers();
- instance.addGroupManagerChangeListener(this);
- populateGroupManagers();
- }
-
- private void populateVhosts()
- {
- synchronized(_vhostAdapters)
- {
- Collection<org.apache.qpid.server.virtualhost.VirtualHost> actualVhosts =
- _applicationRegistry.getVirtualHostRegistry().getVirtualHosts();
- for(org.apache.qpid.server.virtualhost.VirtualHost vh : actualVhosts)
- {
- if(!_vhostAdapters.containsKey(vh))
- {
- _vhostAdapters.put(vh, new VirtualHostAdapter(this, vh));
- }
- }
-
+ private static final Logger LOGGER = Logger.getLogger(BrokerAdapter.class);
+
+ @SuppressWarnings("serial")
+ public static final Map<String, Class<?>> ATTRIBUTE_TYPES = Collections.unmodifiableMap(new HashMap<String, Class<?>>(){{
+ put(ALERT_THRESHOLD_MESSAGE_AGE, Long.class);
+ put(ALERT_THRESHOLD_MESSAGE_COUNT, Long.class);
+ put(ALERT_THRESHOLD_QUEUE_DEPTH, Long.class);
+ put(ALERT_THRESHOLD_MESSAGE_SIZE, Long.class);
+ put(ALERT_REPEAT_GAP, Long.class);
+ put(FLOW_CONTROL_SIZE_BYTES, Long.class);
+ put(FLOW_CONTROL_RESUME_SIZE_BYTES, Long.class);
+ put(HOUSEKEEPING_CHECK_PERIOD, Long.class);
+
+ put(DEAD_LETTER_QUEUE_ENABLED, Boolean.class);
+ put(STATISTICS_REPORTING_RESET_ENABLED, Boolean.class);
+
+ put(MAXIMUM_DELIVERY_ATTEMPTS, Integer.class);
+ put(SESSION_COUNT_LIMIT, Integer.class);
+ put(HEART_BEAT_DELAY, Integer.class);
+ put(STATISTICS_REPORTING_PERIOD, Integer.class);
+
+ put(ACL_FILE, String.class);
+ put(NAME, String.class);
+ put(DEFAULT_VIRTUAL_HOST, String.class);
+ put(DEFAULT_AUTHENTICATION_PROVIDER, String.class);
+
+ put(KEY_STORE_PATH, String.class);
+ put(KEY_STORE_PASSWORD, String.class);
+ put(KEY_STORE_CERT_ALIAS, String.class);
+ put(TRUST_STORE_PATH, String.class);
+ put(TRUST_STORE_PASSWORD, String.class);
+ put(GROUP_FILE, String.class);
+ }});
+
+ public static final int DEFAULT_STATISTICS_REPORTING_PERIOD = 0;
+ public static final boolean DEFAULT_STATISTICS_REPORTING_RESET_ENABLED = false;
+ public static final long DEFAULT_ALERT_REPEAT_GAP = 30000l;
+ public static final long DEFAULT_ALERT_THRESHOLD_MESSAGE_AGE = 0l;
+ public static final long DEFAULT_ALERT_THRESHOLD_MESSAGE_COUNT = 0l;
+ public static final long DEFAULT_ALERT_THRESHOLD_MESSAGE_SIZE = 0l;
+ public static final long DEFAULT_ALERT_THRESHOLD_QUEUE_DEPTH = 0l;
+ public static final boolean DEFAULT_DEAD_LETTER_QUEUE_ENABLED = false;
+ public static final int DEFAULT_MAXIMUM_DELIVERY_ATTEMPTS = 0;
+ public static final long DEFAULT_FLOW_CONTROL_RESUME_SIZE_BYTES = 0l;
+ public static final long DEFAULT_FLOW_CONTROL_SIZE_BYTES = 0l;
+ public static final long DEFAULT_HOUSEKEEPING_CHECK_PERIOD = 30000l;
+ public static final int DEFAULT_HEART_BEAT_DELAY = 0;
+ public static final int DEFAULT_SESSION_COUNT_LIMIT = 256;
+ public static final String DEFAULT_NAME = "QpidBroker";
+ private static final String DEFAULT_KEY_STORE_NAME = "defaultKeyStore";
+ private static final String DEFAULT_TRUST_STORE_NAME = "defaultTrustStore";
+ private static final String DEFAULT_GROUP_PROFIDER_NAME = "defaultGroupProvider";
+
+ private static final String DUMMY_PASSWORD_MASK = "********";
+
+ @SuppressWarnings("serial")
+ private static final Map<String, Object> DEFAULTS = Collections.unmodifiableMap(new HashMap<String, Object>(){{
+ put(Broker.STATISTICS_REPORTING_PERIOD, DEFAULT_STATISTICS_REPORTING_PERIOD);
+ put(Broker.STATISTICS_REPORTING_RESET_ENABLED, DEFAULT_STATISTICS_REPORTING_RESET_ENABLED);
+ put(Broker.ALERT_REPEAT_GAP, DEFAULT_ALERT_REPEAT_GAP);
+ put(Broker.ALERT_THRESHOLD_MESSAGE_AGE, DEFAULT_ALERT_THRESHOLD_MESSAGE_AGE);
+ put(Broker.ALERT_THRESHOLD_MESSAGE_COUNT, DEFAULT_ALERT_THRESHOLD_MESSAGE_COUNT);
+ put(Broker.ALERT_THRESHOLD_MESSAGE_SIZE, DEFAULT_ALERT_THRESHOLD_MESSAGE_SIZE);
+ put(Broker.ALERT_THRESHOLD_QUEUE_DEPTH, DEFAULT_ALERT_THRESHOLD_QUEUE_DEPTH);
+ put(Broker.DEAD_LETTER_QUEUE_ENABLED, DEFAULT_DEAD_LETTER_QUEUE_ENABLED);
+ put(Broker.MAXIMUM_DELIVERY_ATTEMPTS, DEFAULT_MAXIMUM_DELIVERY_ATTEMPTS);
+ put(Broker.FLOW_CONTROL_RESUME_SIZE_BYTES, DEFAULT_FLOW_CONTROL_RESUME_SIZE_BYTES);
+ put(Broker.FLOW_CONTROL_SIZE_BYTES, DEFAULT_FLOW_CONTROL_SIZE_BYTES);
+ put(Broker.HOUSEKEEPING_CHECK_PERIOD, DEFAULT_HOUSEKEEPING_CHECK_PERIOD);
+ put(Broker.HEART_BEAT_DELAY, DEFAULT_HEART_BEAT_DELAY);
+ put(Broker.SESSION_COUNT_LIMIT, DEFAULT_SESSION_COUNT_LIMIT);
+ put(Broker.NAME, DEFAULT_NAME);
+ }});
+
+
+
+
+ private final StatisticsGatherer _statisticsGatherer;
+ private final VirtualHostRegistry _virtualHostRegistry;
+ private final LogRecorder _logRecorder;
+ private final RootMessageLogger _rootMessageLogger;
+ private StatisticsAdapter _statistics;
+
+ private final Map<String, VirtualHost> _vhostAdapters = new HashMap<String, VirtualHost>();
+ private final Map<Integer, Port> _portAdapters = new HashMap<Integer, Port>();
+ private final Map<String, AuthenticationProvider> _authenticationProviders = new HashMap<String, AuthenticationProvider>();
+ private final Map<String, GroupProvider> _groupProviders = new HashMap<String, GroupProvider>();
+ private final Map<UUID, ConfiguredObject> _plugins = new HashMap<UUID, ConfiguredObject>();
+ private final Map<UUID, KeyStore> _keyStores = new HashMap<UUID, KeyStore>();
+ private final Map<UUID, TrustStore> _trustStores = new HashMap<UUID, TrustStore>();
+
+ private final AuthenticationProviderFactory _authenticationProviderFactory;
+ private AuthenticationProvider _defaultAuthenticationProvider;
+
+ private final PortFactory _portFactory;
+ private final SecurityManager _securityManager;
+ private final UUID _defaultKeyStoreId;
+ private final UUID _defaultTrustStoreId;
+
+ public BrokerAdapter(UUID id, Map<String, Object> attributes, StatisticsGatherer statisticsGatherer, VirtualHostRegistry virtualHostRegistry,
+ LogRecorder logRecorder, RootMessageLogger rootMessageLogger, AuthenticationProviderFactory authenticationProviderFactory,
+ PortFactory portFactory, TaskExecutor taskExecutor)
+ {
+ super(id, DEFAULTS, MapValueConverter.convert(attributes, ATTRIBUTE_TYPES), taskExecutor);
+ _statisticsGatherer = statisticsGatherer;
+ _virtualHostRegistry = virtualHostRegistry;
+ _logRecorder = logRecorder;
+ _rootMessageLogger = rootMessageLogger;
+ _statistics = new StatisticsAdapter(statisticsGatherer);
+ _authenticationProviderFactory = authenticationProviderFactory;
+ _portFactory = portFactory;
+ _securityManager = new SecurityManager((String)getAttribute(ACL_FILE));
+
+ _defaultKeyStoreId = UUIDGenerator.generateBrokerChildUUID(KeyStore.class.getSimpleName(), DEFAULT_KEY_STORE_NAME);
+ _defaultTrustStoreId = UUIDGenerator.generateBrokerChildUUID(TrustStore.class.getSimpleName(), DEFAULT_TRUST_STORE_NAME);
+ createBrokerChildrenFromAttributes();
+ }
+
+ /*
+ * A temporary method to create broker children that can be only configured via broker attributes
+ */
+ private void createBrokerChildrenFromAttributes()
+ {
+ String groupFile = (String) getAttribute(GROUP_FILE);
+ if (groupFile != null)
+ {
+ GroupManager groupManager = new FileGroupManager(groupFile);
+ UUID groupProviderId = UUIDGenerator.generateBrokerChildUUID(GroupProvider.class.getSimpleName(),
+ DEFAULT_GROUP_PROFIDER_NAME);
+ GroupProviderAdapter groupProviderAdapter = new GroupProviderAdapter(groupProviderId, groupManager, this);
+ addGroupProvider(groupProviderAdapter);
+ }
+ Map<String, Object> actualAttributes = getActualAttributes();
+ String keyStorePath = (String) getAttribute(KEY_STORE_PATH);
+ if (keyStorePath != null)
+ {
+ Map<String, Object> keyStoreAttributes = new HashMap<String, Object>();
+ keyStoreAttributes.put(KeyStore.NAME, DEFAULT_KEY_STORE_NAME);
+ keyStoreAttributes.put(KeyStore.PATH, keyStorePath);
+ keyStoreAttributes.put(KeyStore.PASSWORD, (String) actualAttributes.get(KEY_STORE_PASSWORD));
+ keyStoreAttributes.put(KeyStore.TYPE, java.security.KeyStore.getDefaultType());
+ keyStoreAttributes.put(KeyStore.CERTIFICATE_ALIAS, getAttribute(KEY_STORE_CERT_ALIAS));
+ keyStoreAttributes.put(KeyStore.KEY_MANAGER_FACTORY_ALGORITHM, KeyManagerFactory.getDefaultAlgorithm());
+ KeyStoreAdapter KeyStoreAdapter = new KeyStoreAdapter(_defaultKeyStoreId, this, keyStoreAttributes);
+ addKeyStore(KeyStoreAdapter);
+ }
+ String trustStorePath = (String) getAttribute(TRUST_STORE_PATH);
+ if (trustStorePath != null)
+ {
+ Map<String, Object> trsustStoreAttributes = new HashMap<String, Object>();
+ trsustStoreAttributes.put(TrustStore.NAME, DEFAULT_TRUST_STORE_NAME);
+ trsustStoreAttributes.put(TrustStore.PATH, trustStorePath);
+ trsustStoreAttributes.put(TrustStore.PASSWORD, (String) actualAttributes.get(TRUST_STORE_PASSWORD));
+ trsustStoreAttributes.put(TrustStore.TYPE, java.security.KeyStore.getDefaultType());
+ trsustStoreAttributes.put(TrustStore.KEY_MANAGER_FACTORY_ALGORITHM, KeyManagerFactory.getDefaultAlgorithm());
+ TrustStoreAdapter trustStore = new TrustStoreAdapter(_defaultTrustStoreId, this, trsustStoreAttributes);
+ addTrustStore(trustStore);
}
}
-
public Collection<VirtualHost> getVirtualHosts()
{
synchronized(_vhostAdapters)
@@ -112,107 +234,55 @@ public class BrokerAdapter extends AbstractAdapter implements Broker, VirtualHos
}
}
- private void populatePorts()
- {
- synchronized (_portAdapters)
- {
- Map<InetSocketAddress, QpidAcceptor> acceptors = _applicationRegistry.getAcceptors();
-
- for(Map.Entry<InetSocketAddress, QpidAcceptor> entry : acceptors.entrySet())
- {
- if(!_portAdapters.containsKey(entry.getValue()))
- {
- _portAdapters.put(entry.getValue(), new PortAdapter(this, entry.getValue(), entry.getKey()));
- }
- }
- if(_applicationRegistry.useHTTPManagement() || _applicationRegistry.useHTTPSManagement())
- {
- ArrayList<HTTPPortAdapter> httpPorts = new ArrayList<HTTPPortAdapter>();
- if (_applicationRegistry.useHTTPManagement())
- {
- httpPorts.add(new HTTPPortAdapter(this, _applicationRegistry.getHTTPManagementPort()));
- }
- if (_applicationRegistry.useHTTPSManagement())
- {
- httpPorts.add(new HTTPPortAdapter(this, _applicationRegistry.getHTTPSManagementPort(), Protocol.HTTPS, Transport.SSL));
- }
- _httpManagementPorts = Collections.unmodifiableCollection(httpPorts);
- }
- }
- }
public Collection<Port> getPorts()
{
synchronized (_portAdapters)
{
final ArrayList<Port> ports = new ArrayList<Port>(_portAdapters.values());
- if(_httpManagementPorts != null)
- {
- ports.addAll(_httpManagementPorts);
- }
return ports;
}
}
- private void populateAuthenticationManagers()
+ public Collection<AuthenticationProvider> getAuthenticationProviders()
{
- synchronized (_authManagerAdapters)
+ synchronized (_authenticationProviders)
{
- IAuthenticationManagerRegistry authenticationManagerRegistry =
- _applicationRegistry.getAuthenticationManagerRegistry();
- if(authenticationManagerRegistry != null)
- {
- Map<String, AuthenticationManager> authenticationManagers =
- authenticationManagerRegistry.getAvailableAuthenticationManagers();
-
- for(Map.Entry<String, AuthenticationManager> entry : authenticationManagers.entrySet())
- {
- if(!_authManagerAdapters.containsKey(entry.getValue()))
- {
- _authManagerAdapters.put(entry.getValue(),
- AuthenticationProviderAdapter.createAuthenticationProviderAdapter(this,
- entry.getValue()));
- }
- }
- }
+ return new ArrayList<AuthenticationProvider>(_authenticationProviders.values());
}
}
- private void populateGroupManagers()
+ public AuthenticationProvider getAuthenticationProviderByName(String authenticationProviderName)
{
- synchronized (_groupManagerAdapters)
+ Collection<AuthenticationProvider> providers = getAuthenticationProviders();
+ for (AuthenticationProvider authenticationProvider : providers)
{
- List<GroupManager> groupManagers = _applicationRegistry.getGroupManagers();
- if(groupManagers != null)
+ if (authenticationProvider.getName().equals(authenticationProviderName))
{
- for (GroupManager groupManager : groupManagers)
- {
- if(!_groupManagerAdapters.containsKey(groupManager))
- {
- _groupManagerAdapters.put(groupManager,
- GroupProviderAdapter.createGroupProviderAdapter(this, groupManager));
- }
- }
+ return authenticationProvider;
}
}
+ return null;
}
- public Collection<AuthenticationProvider> getAuthenticationProviders()
+ @Override
+ public AuthenticationProvider getDefaultAuthenticationProvider()
{
- synchronized (_authManagerAdapters)
- {
- final ArrayList<AuthenticationProvider> authManagers =
- new ArrayList<AuthenticationProvider>(_authManagerAdapters.values());
- return authManagers;
- }
+ return _defaultAuthenticationProvider;
}
+ public void setDefaultAuthenticationProvider(AuthenticationProvider provider)
+ {
+ _defaultAuthenticationProvider = provider;
+ }
+
+ @Override
public Collection<GroupProvider> getGroupProviders()
{
- synchronized (_groupManagerAdapters)
+ synchronized (_groupProviders)
{
final ArrayList<GroupProvider> groupManagers =
- new ArrayList<GroupProvider>(_groupManagerAdapters.values());
+ new ArrayList<GroupProvider>(_groupProviders.values());
return groupManagers;
}
}
@@ -228,22 +298,29 @@ public class BrokerAdapter extends AbstractAdapter implements Broker, VirtualHos
return null; //TODO
}
- public VirtualHost createVirtualHost(final Map<String, Object> attributes)
+ private VirtualHost createVirtualHost(final Map<String, Object> attributes)
throws AccessControlException, IllegalArgumentException
{
- return null; //TODO
+ final VirtualHostAdapter virtualHostAdapter = new VirtualHostAdapter(UUID.randomUUID(), attributes, this,
+ _statisticsGatherer, getTaskExecutor());
+ addVirtualHost(virtualHostAdapter);
+ virtualHostAdapter.setDesiredState(State.INITIALISING, State.ACTIVE);
+ return virtualHostAdapter;
}
- public void deleteVirtualHost(final VirtualHost vhost)
- throws AccessControlException, IllegalStateException
+ private boolean deleteVirtualHost(final VirtualHost vhost) throws AccessControlException, IllegalStateException
{
- //TODO
- throw new UnsupportedOperationException("Not yet implemented");
+ synchronized (_vhostAdapters)
+ {
+ _vhostAdapters.remove(vhost);
+ }
+ vhost.removeChangeListener(this);
+ return true;
}
public String getName()
{
- return _name;
+ return (String)getAttribute(NAME);
}
public String setName(final String currentName, final String desiredName)
@@ -297,6 +374,7 @@ public class BrokerAdapter extends AbstractAdapter implements Broker, VirtualHos
return _statistics;
}
+ @SuppressWarnings("unchecked")
@Override
public <C extends ConfiguredObject> Collection<C> getChildren(Class<C> clazz)
{
@@ -316,12 +394,26 @@ public class BrokerAdapter extends AbstractAdapter implements Broker, VirtualHos
{
return (Collection<C>) getGroupProviders();
}
+ else if(clazz == KeyStore.class)
+ {
+ return (Collection<C>) getKeyStores();
+ }
+ else if(clazz == TrustStore.class)
+ {
+ return (Collection<C>) getTrustStores();
+ }
+ else if(clazz == Plugin.class)
+ {
+ return (Collection<C>) getPlugins();
+ }
return Collections.emptySet();
}
+ //TODO: ACL
+ @SuppressWarnings("unchecked")
@Override
- public <C extends ConfiguredObject> C createChild(Class<C> childClass, Map<String, Object> attributes, ConfiguredObject... otherParents)
+ public <C extends ConfiguredObject> C addChild(Class<C> childClass, Map<String, Object> attributes, ConfiguredObject... otherParents)
{
if(childClass == VirtualHost.class)
{
@@ -341,111 +433,107 @@ public class BrokerAdapter extends AbstractAdapter implements Broker, VirtualHos
}
}
- private Port createPort(Map<String, Object> attributes)
+ private void addPort(Port port)
{
- // TODO
- return null;
+ synchronized (_portAdapters)
+ {
+ int portNumber = port.getPort();
+ if(_portAdapters.containsKey(portNumber))
+ {
+ throw new IllegalArgumentException("Cannot add port " + port + " because port number " + portNumber + " already configured");
+ }
+ _portAdapters.put(portNumber, port);
+ }
+ port.addChangeListener(this);
}
- private AuthenticationProvider createAuthenticationProvider(Map<String,Object> attributes)
+ private Port createPort(Map<String, Object> attributes)
{
- // TODO
- return null;
+ Port port = _portFactory.createPort(UUID.randomUUID(), this, attributes);
+ addPort(port);
+ return port;
}
+ private AuthenticationProvider createAuthenticationProvider(Map<String, Object> attributes)
+ {
+ // it's cheap to create the groupPrincipalAccessor on the fly
+ GroupPrincipalAccessor groupPrincipalAccessor = new GroupPrincipalAccessor(_groupProviders.values());
+
+ AuthenticationProvider authenticationProvider = _authenticationProviderFactory.create(UUID.randomUUID(), this, attributes, groupPrincipalAccessor);
+ addAuthenticationProvider(authenticationProvider);
+ return authenticationProvider;
+ }
- public void virtualHostRegistered(org.apache.qpid.server.virtualhost.VirtualHost virtualHost)
+ /**
+ * @throws IllegalConfigurationException if an AuthenticationProvider with the same name already exists
+ */
+ private void addAuthenticationProvider(AuthenticationProvider authenticationProvider)
{
- VirtualHostAdapter adapter = null;
- synchronized (_vhostAdapters)
+ String name = authenticationProvider.getName();
+ synchronized (_authenticationProviders)
{
- if(!_vhostAdapters.containsKey(virtualHost))
+ if(_authenticationProviders.containsKey(name))
{
- adapter = new VirtualHostAdapter(this, virtualHost);
- _vhostAdapters.put(virtualHost, adapter);
+ throw new IllegalConfigurationException("Cannot add AuthenticationProvider because one with name " + name + " already exists");
}
+ _authenticationProviders.put(name, authenticationProvider);
}
- if(adapter != null)
- {
- childAdded(adapter);
- }
+ authenticationProvider.addChangeListener(this);
}
- public void virtualHostUnregistered(org.apache.qpid.server.virtualhost.VirtualHost virtualHost)
+ private void addGroupProvider(GroupProvider groupProvider)
{
- VirtualHostAdapter adapter = null;
-
- synchronized (_vhostAdapters)
- {
- adapter = _vhostAdapters.remove(virtualHost);
- }
- if(adapter != null)
+ synchronized (_groupProviders)
{
- childRemoved(adapter);
+ String name = groupProvider.getName();
+ if(_groupProviders.containsKey(name))
+ {
+ throw new IllegalConfigurationException("Cannot add GroupProvider because one with name " + name + " already exists");
+ }
+ _groupProviders.put(name, groupProvider);
}
+ groupProvider.addChangeListener(this);
}
- @Override
- public void authenticationManagerRegistered(AuthenticationManager authenticationManager)
+ private boolean deleteGroupProvider(GroupProvider object)
{
- AuthenticationProviderAdapter adapter = null;
- synchronized (_authManagerAdapters)
+ throw new UnsupportedOperationException("Not implemented yet!");
+ }
+
+ private void addKeyStore(KeyStore keyStore)
+ {
+ synchronized (_keyStores)
{
- if(!_authManagerAdapters.containsKey(authenticationManager))
+ if(_keyStores.containsKey(keyStore.getId()))
{
- adapter =
- AuthenticationProviderAdapter.createAuthenticationProviderAdapter(this, authenticationManager);
- _authManagerAdapters.put(authenticationManager, adapter);
+ throw new IllegalConfigurationException("Cannot add KeyStore because one with id " + keyStore.getId() + " already exists");
}
+ _keyStores.put(keyStore.getId(), keyStore);
}
- if(adapter != null)
- {
- childAdded(adapter);
- }
+ keyStore.addChangeListener(this);
}
- @Override
- public void authenticationManagerUnregistered(AuthenticationManager authenticationManager)
+ private boolean deleteKeyStore(KeyStore object)
{
- AuthenticationProviderAdapter adapter;
- synchronized (_authManagerAdapters)
- {
- adapter = _authManagerAdapters.remove(authenticationManager);
- }
- if(adapter != null)
- {
- childRemoved(adapter);
- }
+ throw new UnsupportedOperationException("Not implemented yet!");
}
-
- @Override
- public void bound(QpidAcceptor acceptor, InetSocketAddress bindAddress)
+ private void addTrustStore(TrustStore trustStore)
{
- synchronized (_portAdapters)
+ synchronized (_trustStores)
{
- if(!_portAdapters.containsKey(acceptor))
+ if(_trustStores.containsKey(trustStore.getId()))
{
- PortAdapter adapter = new PortAdapter(this, acceptor, bindAddress);
- _portAdapters.put(acceptor, adapter);
- childAdded(adapter);
+ throw new IllegalConfigurationException("Cannot add TrustStore because one with id " + trustStore.getId() + " already exists");
}
+ _trustStores.put(trustStore.getId(), trustStore);
}
+ trustStore.addChangeListener(this);
}
- @Override
- public void unbound(QpidAcceptor acceptor)
+ private boolean deleteTrustStore(TrustStore object)
{
- PortAdapter adapter = null;
-
- synchronized (_portAdapters)
- {
- adapter = _portAdapters.remove(acceptor);
- }
- if(adapter != null)
- {
- childRemoved(adapter);
- }
+ throw new UnsupportedOperationException("Not implemented yet!");
}
@Override
@@ -461,10 +549,6 @@ public class BrokerAdapter extends AbstractAdapter implements Broker, VirtualHos
{
return getId();
}
- else if(NAME.equals(name))
- {
- return getName();
- }
else if(STATE.equals(name))
{
return State.ACTIVE;
@@ -520,46 +604,308 @@ public class BrokerAdapter extends AbstractAdapter implements Broker, VirtualHos
{
// TODO
}
+ else if (DEFAULT_AUTHENTICATION_PROVIDER.equals(name))
+ {
+ return _defaultAuthenticationProvider == null ? null : _defaultAuthenticationProvider.getName();
+ }
+ else if (KEY_STORE_PASSWORD.equals(name))
+ {
+ return DUMMY_PASSWORD_MASK;
+ }
+ else if (TRUST_STORE_PASSWORD.equals(name))
+ {
+ return DUMMY_PASSWORD_MASK;
+ }
+ return super.getAttribute(name);
+ }
+
+ private boolean deletePort(Port portAdapter)
+ {
+ Port removedPort = null;
+ synchronized (_portAdapters)
+ {
+ removedPort = _portAdapters.remove(portAdapter.getPort());
+ }
+ return removedPort != null;
+ }
+
+ private boolean deleteAuthenticationProvider(AuthenticationProvider authenticationProvider)
+ {
+ AuthenticationProvider removedAuthenticationProvider = null;
+ synchronized (_authenticationProviders)
+ {
+ removedAuthenticationProvider = _authenticationProviders.remove(authenticationProvider.getName());
+ }
+ return removedAuthenticationProvider != null;
+ }
+
+ private void addVirtualHost(VirtualHost virtualHost)
+ {
+ synchronized (_vhostAdapters)
+ {
+ String name = virtualHost.getName();
+ if (_vhostAdapters.containsKey(name))
+ {
+ throw new IllegalConfigurationException("Virtual host with name " + name + " is already specified!");
+ }
+ _vhostAdapters.put(name, virtualHost);
+ }
+ virtualHost.addChangeListener(this);
+ }
+
+ @Override
+ public boolean setState(State currentState, State desiredState)
+ {
+ if (desiredState == State.ACTIVE)
+ {
+ changeState(_groupProviders, currentState, State.ACTIVE, false);
+ changeState(_authenticationProviders, currentState, State.ACTIVE, false);
+
+ CurrentActor.set(new BrokerActor(getRootMessageLogger()));
+ try
+ {
+ changeState(_vhostAdapters, currentState, State.ACTIVE, false);
+ }
+ finally
+ {
+ CurrentActor.remove();
+ }
+
+ changeState(_portAdapters, currentState,State.ACTIVE, false);
+ changeState(_plugins, currentState,State.ACTIVE, false);
+ return true;
+ }
+ else if (desiredState == State.STOPPED)
+ {
+ changeState(_plugins, currentState,State.STOPPED, true);
+ changeState(_portAdapters, currentState, State.STOPPED, true);
+ changeState(_vhostAdapters,currentState, State.STOPPED, true);
+ changeState(_authenticationProviders, currentState, State.STOPPED, true);
+ changeState(_groupProviders, currentState, State.STOPPED, true);
+ return true;
+ }
+ return false;
+ }
+
+ private void changeState(Map<?, ? extends ConfiguredObject> configuredObjectMap, State currentState, State desiredState, boolean swallowException)
+ {
+ synchronized(configuredObjectMap)
+ {
+ Collection<? extends ConfiguredObject> adapters = configuredObjectMap.values();
+ for (ConfiguredObject configuredObject : adapters)
+ {
+ try
+ {
+ configuredObject.setDesiredState(currentState, desiredState);
+ }
+ catch(RuntimeException e)
+ {
+ if (swallowException)
+ {
+ LOGGER.error("Failed to stop " + configuredObject, e);
+ }
+ else
+ {
+ throw e;
+ }
+ }
+ }
+ }
+ }
- return super.getAttribute(name); //TODO - Implement.
+ @Override
+ public void stateChanged(ConfiguredObject object, State oldState, State newState)
+ {
+ if(newState == State.DELETED)
+ {
+ boolean childDeleted = false;
+ if(object instanceof AuthenticationProvider)
+ {
+ childDeleted = deleteAuthenticationProvider((AuthenticationProvider)object);
+ }
+ else if(object instanceof Port)
+ {
+ childDeleted = deletePort((Port)object);
+ }
+ else if(object instanceof VirtualHost)
+ {
+ childDeleted = deleteVirtualHost((VirtualHost)object);
+ }
+ else if(object instanceof GroupProvider)
+ {
+ childDeleted = deleteGroupProvider((GroupProvider)object);
+ }
+ else if(object instanceof KeyStore)
+ {
+ childDeleted = deleteKeyStore((KeyStore)object);
+ }
+ else if(object instanceof TrustStore)
+ {
+ childDeleted = deleteTrustStore((TrustStore)object);
+ }
+ if(childDeleted)
+ {
+ childRemoved(object);
+ }
+ }
}
@Override
- public Object setAttribute(String name, Object expected, Object desired)
- throws IllegalStateException, AccessControlException, IllegalArgumentException
+ public void childAdded(ConfiguredObject object, ConfiguredObject child)
+ {
+ // no-op
+ }
+
+ @Override
+ public void childRemoved(ConfiguredObject object, ConfiguredObject child)
{
- return super.setAttribute(name, expected, desired); //TODO - Implement.
+ // no-op
}
@Override
- public void groupManagerRegistered(GroupManager groupManager)
+ public void attributeSet(ConfiguredObject object, String attributeName, Object oldAttributeValue, Object newAttributeValue)
+ {
+ // no-op
+ }
+
+ private void addPlugin(ConfiguredObject plugin)
{
- GroupProviderAdapter adapter = null;
- synchronized (_groupManagerAdapters)
+ synchronized(_plugins)
{
- if(!_groupManagerAdapters.containsKey(groupManager))
+ if (_plugins.containsKey(plugin.getId()))
{
- adapter = GroupProviderAdapter.createGroupProviderAdapter(this, groupManager);
- _groupManagerAdapters.put(groupManager, adapter);
+ throw new IllegalConfigurationException("Plugin with id '" + plugin.getId() + "' is already registered!");
}
+ _plugins.put(plugin.getId(), plugin);
}
- if(adapter != null)
+ plugin.addChangeListener(this);
+ }
+
+
+ private Collection<ConfiguredObject> getPlugins()
+ {
+ synchronized(_plugins)
{
- childAdded(adapter);
+ return Collections.unmodifiableCollection(_plugins.values());
}
}
+ public void recoverChild(ConfiguredObject object)
+ {
+ if(object instanceof AuthenticationProvider)
+ {
+ addAuthenticationProvider((AuthenticationProvider)object);
+ }
+ else if(object instanceof Port)
+ {
+ addPort((Port)object);
+ }
+ else if(object instanceof VirtualHost)
+ {
+ addVirtualHost((VirtualHost)object);
+ }
+ else if(object instanceof GroupProvider)
+ {
+ addGroupProvider((GroupProvider)object);
+ }
+ else if(object instanceof KeyStore)
+ {
+ addKeyStore((KeyStore)object);
+ }
+ else if(object instanceof TrustStore)
+ {
+ addTrustStore((TrustStore)object);
+ }
+ else if(object instanceof Plugin)
+ {
+ addPlugin(object);
+ }
+ else
+ {
+ throw new IllegalArgumentException("Attempted to recover unexpected type of configured object: " + object.getClass().getName());
+ }
+ }
+
+ @Override
+ public RootMessageLogger getRootMessageLogger()
+ {
+ return _rootMessageLogger;
+ }
+
+ @Override
+ public SecurityManager getSecurityManager()
+ {
+ return _securityManager;
+ }
+
+ @Override
+ public LogRecorder getLogRecorder()
+ {
+ return _logRecorder;
+ }
+
@Override
- public void groupManagerUnregistered(GroupManager groupManager)
+ public VirtualHost findVirtualHostByName(String name)
{
- GroupProviderAdapter adapter;
- synchronized (_groupManagerAdapters)
+ return _vhostAdapters.get(name);
+ }
+
+ @Override
+ public SubjectCreator getSubjectCreator(SocketAddress localAddress)
+ {
+ InetSocketAddress inetSocketAddress = (InetSocketAddress)localAddress;
+ AuthenticationProvider provider = _defaultAuthenticationProvider;
+ Collection<Port> ports = getPorts();
+ for (Port p : ports)
+ {
+ if (inetSocketAddress.getPort() == p.getPort())
+ {
+ provider = p.getAuthenticationProvider();
+ break;
+ }
+ }
+ return provider.getSubjectCreator();
+ }
+
+ @Override
+ public Collection<KeyStore> getKeyStores()
+ {
+ synchronized(_trustStores)
{
- adapter = _groupManagerAdapters.remove(groupManager);
+ return Collections.unmodifiableCollection(_keyStores.values());
}
- if(adapter != null)
+ }
+
+ @Override
+ public Collection<TrustStore> getTrustStores()
+ {
+ synchronized(_trustStores)
{
- childRemoved(adapter);
+ return Collections.unmodifiableCollection(_trustStores.values());
}
}
+
+ @Override
+ public VirtualHostRegistry getVirtualHostRegistry()
+ {
+ return _virtualHostRegistry;
+ }
+
+ @Override
+ public KeyStore getDefaultKeyStore()
+ {
+ return _keyStores.get(_defaultKeyStoreId);
+ }
+
+ @Override
+ public TrustStore getDefaultTrustStore()
+ {
+ return _trustStores.get(_defaultTrustStoreId);
+ }
+
+ @Override
+ public TaskExecutor getTaskExecutor()
+ {
+ return super.getTaskExecutor();
+ }
}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/ConnectionAdapter.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/ConnectionAdapter.java
index 5439f6a560..84f99e1f17 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/ConnectionAdapter.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/ConnectionAdapter.java
@@ -38,6 +38,7 @@ import org.apache.qpid.server.model.Session;
import org.apache.qpid.server.model.State;
import org.apache.qpid.server.model.Statistics;
import org.apache.qpid.server.model.UUIDGenerator;
+import org.apache.qpid.server.configuration.updater.TaskExecutor;
import org.apache.qpid.server.protocol.AMQConnectionModel;
import org.apache.qpid.server.protocol.AMQSessionModel;
import org.apache.qpid.server.stats.StatisticsGatherer;
@@ -50,9 +51,9 @@ final class ConnectionAdapter extends AbstractAdapter implements Connection
new HashMap<AMQSessionModel, SessionAdapter>();
private final Statistics _statistics;
- public ConnectionAdapter(final AMQConnectionModel conn)
+ public ConnectionAdapter(final AMQConnectionModel conn, TaskExecutor taskExecutor)
{
- super(UUIDGenerator.generateRandomUUID());
+ super(UUIDGenerator.generateRandomUUID(), taskExecutor);
_connection = conn;
_statistics = new ConnectionStatisticsAdapter(conn);
}
@@ -74,7 +75,7 @@ final class ConnectionAdapter extends AbstractAdapter implements Connection
{
if(!_sessionAdapters.containsKey(session))
{
- _sessionAdapters.put(session, new SessionAdapter(session));
+ _sessionAdapters.put(session, new SessionAdapter(session, getTaskExecutor()));
}
}
return new ArrayList<Session>(_sessionAdapters.values());
@@ -199,52 +200,6 @@ final class ConnectionAdapter extends AbstractAdapter implements Connection
}
@Override
- public Object setAttribute(String name, Object expected, Object desired) throws IllegalStateException, AccessControlException, IllegalArgumentException
- {
- if(name.equals(CLIENT_ID))
- {
-
- }
- else if(name.equals(CLIENT_VERSION))
- {
-
- }
- else if(name.equals(INCOMING))
- {
-
- }
- else if(name.equals(LOCAL_ADDRESS))
- {
-
- }
- else if(name.equals(PRINCIPAL))
- {
-
- }
- else if(name.equals(PROPERTIES))
- {
-
- }
- else if(name.equals(REMOTE_ADDRESS))
- {
-
- }
- else if(name.equals(REMOTE_PROCESS_NAME))
- {
-
- }
- else if(name.equals(REMOTE_PROCESS_PID))
- {
-
- }
- else if(name.equals(SESSION_COUNT_LIMIT))
- {
-
- }
- return super.setAttribute(name, expected, desired);
- }
-
- @Override
public Collection<String> getAttributeNames()
{
final HashSet<String> attrNames = new HashSet<String>(super.getAttributeNames());
@@ -270,7 +225,8 @@ final class ConnectionAdapter extends AbstractAdapter implements Connection
}
}
- public <C extends ConfiguredObject> C createChild(Class<C> childClass, Map<String, Object> attributes, ConfiguredObject... otherParents)
+ @Override
+ public <C extends ConfiguredObject> C addChild(Class<C> childClass, Map<String, Object> attributes, ConfiguredObject... otherParents)
{
if(childClass == Session.class)
{
@@ -310,4 +266,11 @@ final class ConnectionAdapter extends AbstractAdapter implements Connection
return super.getStatistic(name);
}
}
+
+ @Override
+ protected boolean setState(State currentState, State desiredState)
+ {
+ // TODO: add state management
+ return false;
+ }
}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/ConsumerAdapter.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/ConsumerAdapter.java
index 031d518670..e6d3fab2f8 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/ConsumerAdapter.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/ConsumerAdapter.java
@@ -45,7 +45,7 @@ public class ConsumerAdapter extends AbstractAdapter implements Consumer
queueAdapter.getName(),
subscription.getSessionModel().getConnectionModel().getRemoteAddressString(),
String.valueOf(subscription.getSessionModel().getChannelId()),
- subscription.getConsumerName()));
+ subscription.getConsumerName()), queueAdapter.getTaskExecutor());
_subscription = subscription;
_queue = queueAdapter;
_statistics = new ConsumerStatistics();
@@ -108,13 +108,6 @@ public class ConsumerAdapter extends AbstractAdapter implements Consumer
}
@Override
- public Object setAttribute(final String name, final Object expected, final Object desired)
- throws IllegalStateException, AccessControlException, IllegalArgumentException
- {
- return super.setAttribute(name, expected, desired); //TODO
- }
-
- @Override
public Object getAttribute(final String name)
{
if(ID.equals(name))
@@ -222,4 +215,11 @@ public class ConsumerAdapter extends AbstractAdapter implements Consumer
return null; // TODO - Implement
}
}
+
+ @Override
+ protected boolean setState(State currentState, State desiredState)
+ {
+ // TODO : Add state management
+ return false;
+ }
}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/ExchangeAdapter.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/ExchangeAdapter.java
index 266fdbd1ba..5d5f3f7378 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/ExchangeAdapter.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/ExchangeAdapter.java
@@ -35,14 +35,13 @@ import org.apache.qpid.server.binding.Binding;
import org.apache.qpid.server.exchange.ExchangeRegistry;
import org.apache.qpid.server.model.ConfiguredObject;
import org.apache.qpid.server.model.Exchange;
-import org.apache.qpid.server.model.IllegalStateTransitionException;
import org.apache.qpid.server.model.LifetimePolicy;
import org.apache.qpid.server.model.Publisher;
import org.apache.qpid.server.model.Queue;
import org.apache.qpid.server.model.State;
import org.apache.qpid.server.model.Statistics;
-import org.apache.qpid.server.plugin.ExchangeType;
import org.apache.qpid.server.queue.AMQQueue;
+import org.apache.qpid.server.util.MapValueConverter;
import org.apache.qpid.server.virtualhost.VirtualHost;
final class ExchangeAdapter extends AbstractAdapter implements Exchange, org.apache.qpid.server.exchange.Exchange.BindingListener
@@ -57,7 +56,7 @@ final class ExchangeAdapter extends AbstractAdapter implements Exchange, org.apa
public ExchangeAdapter(final VirtualHostAdapter virtualHostAdapter,
final org.apache.qpid.server.exchange.Exchange exchange)
{
- super(exchange.getId());
+ super(exchange.getId(), virtualHostAdapter.getTaskExecutor());
_statistics = new ExchangeStatistics();
_vhost = virtualHostAdapter;
_exchange = exchange;
@@ -113,8 +112,8 @@ final class ExchangeAdapter extends AbstractAdapter implements Exchange, org.apa
throws AccessControlException, IllegalStateException
{
attributes = new HashMap<String, Object>(attributes);
- String bindingKey = getStringAttribute(org.apache.qpid.server.model.Binding.NAME, attributes, "");
- Map<String, Object> bindingArgs = getMapAttribute(org.apache.qpid.server.model.Binding.ARGUMENTS, attributes, Collections.EMPTY_MAP);
+ String bindingKey = MapValueConverter.getStringAttribute(org.apache.qpid.server.model.Binding.NAME, attributes, "");
+ Map<String, Object> bindingArgs = MapValueConverter.getMapAttribute(org.apache.qpid.server.model.Binding.ARGUMENTS, attributes, Collections.<String,Object>emptyMap());
attributes.remove(org.apache.qpid.server.model.Binding.NAME);
attributes.remove(org.apache.qpid.server.model.Binding.ARGUMENTS);
@@ -257,7 +256,7 @@ final class ExchangeAdapter extends AbstractAdapter implements Exchange, org.apa
}
@Override
- public <C extends ConfiguredObject> C createChild(Class<C> childClass, Map<String, Object> attributes, ConfiguredObject... otherParents)
+ public <C extends ConfiguredObject> C addChild(Class<C> childClass, Map<String, Object> attributes, ConfiguredObject... otherParents)
{
if(childClass == org.apache.qpid.server.model.Binding.class)
{
@@ -369,28 +368,20 @@ final class ExchangeAdapter extends AbstractAdapter implements Exchange, org.apa
}
@Override
- public Object setAttribute(String name, Object expected, Object desired)
- throws IllegalStateException, AccessControlException, IllegalArgumentException
- {
- return super.setAttribute(name, expected, desired); //TODO - Implement
- }
-
- @Override
public Collection<String> getAttributeNames()
{
return AVAILABLE_ATTRIBUTES;
}
@Override
- public State setDesiredState(State currentState, State desiredState) throws IllegalStateTransitionException,
- AccessControlException
+ protected boolean setState(State currentState, State desiredState)
{
if (desiredState == State.DELETED)
{
delete();
- return State.DELETED;
+ return true;
}
- return super.setDesiredState(currentState, desiredState);
+ return false;
}
private class ExchangeStatistics implements Statistics
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/GroupProviderAdapter.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/GroupProviderAdapter.java
index adc98919d5..0fa834bc28 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/GroupProviderAdapter.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/GroupProviderAdapter.java
@@ -26,6 +26,7 @@ import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
+import java.util.UUID;
import org.apache.qpid.server.model.Broker;
import org.apache.qpid.server.model.ConfiguredObject;
@@ -37,33 +38,27 @@ import org.apache.qpid.server.model.LifetimePolicy;
import org.apache.qpid.server.model.State;
import org.apache.qpid.server.model.Statistics;
import org.apache.qpid.server.model.UUIDGenerator;
-import org.apache.qpid.server.registry.ApplicationRegistry;
+import org.apache.qpid.server.configuration.updater.TaskExecutor;
import org.apache.qpid.server.security.access.Operation;
import org.apache.qpid.server.security.group.GroupManager;
+import org.apache.qpid.server.security.SecurityManager;
public class GroupProviderAdapter extends AbstractAdapter implements
GroupProvider
{
private final GroupManager _groupManager;
-
- protected GroupProviderAdapter(GroupManager groupManager)
+ private final Broker _broker;
+ public GroupProviderAdapter(UUID id, GroupManager groupManager, Broker broker)
{
- super(UUIDGenerator.generateRandomUUID());
+ super(id, broker.getTaskExecutor());
if (groupManager == null)
{
throw new IllegalArgumentException("GroupManager must not be null");
}
_groupManager = groupManager;
- }
-
- public static GroupProviderAdapter createGroupProviderAdapter(
- BrokerAdapter brokerAdapter, GroupManager groupManager)
- {
- final GroupProviderAdapter groupProviderAdapter = new GroupProviderAdapter(
- groupManager);
- groupProviderAdapter.addParent(Broker.class, brokerAdapter);
- return groupProviderAdapter;
+ _broker = broker;
+ addParent(Broker.class, broker);
}
@Override
@@ -180,7 +175,7 @@ public class GroupProviderAdapter extends AbstractAdapter implements
}
@Override
- public <C extends ConfiguredObject> C createChild(Class<C> childClass,
+ public <C extends ConfiguredObject> C addChild(Class<C> childClass,
Map<String, Object> attributes, ConfiguredObject... otherParents)
{
if (childClass == Group.class)
@@ -190,7 +185,7 @@ public class GroupProviderAdapter extends AbstractAdapter implements
if (getSecurityManager().authoriseGroupOperation(Operation.CREATE, groupName))
{
_groupManager.createGroup(groupName);
- return (C) new GroupAdapter(groupName);
+ return (C) new GroupAdapter(groupName, getTaskExecutor());
}
else
{
@@ -214,7 +209,7 @@ public class GroupProviderAdapter extends AbstractAdapter implements
Collection<Group> principals = new ArrayList<Group>(groups.size());
for (Principal group : groups)
{
- principals.add(new GroupAdapter(group.getName()));
+ principals.add(new GroupAdapter(group.getName(), getTaskExecutor()));
}
return (Collection<C>) Collections
.unmodifiableCollection(principals);
@@ -225,19 +220,18 @@ public class GroupProviderAdapter extends AbstractAdapter implements
}
}
- private org.apache.qpid.server.security.SecurityManager getSecurityManager()
+ private SecurityManager getSecurityManager()
{
- return ApplicationRegistry.getInstance().getSecurityManager();
+ return _broker.getSecurityManager();
}
private class GroupAdapter extends AbstractAdapter implements Group
{
private final String _group;
- public GroupAdapter(String group)
+ public GroupAdapter(String group, TaskExecutor taskExecutor)
{
- super(UUIDGenerator.generateGroupUUID(
- GroupProviderAdapter.this.getName(), group));
+ super(UUIDGenerator.generateGroupUUID(GroupProviderAdapter.this.getName(), group), taskExecutor);
_group = group;
}
@@ -319,7 +313,7 @@ public class GroupProviderAdapter extends AbstractAdapter implements
Collection<GroupMember> members = new ArrayList<GroupMember>();
for (Principal principal : usersInGroup)
{
- members.add(new GroupMemberAdapter(principal.getName()));
+ members.add(new GroupMemberAdapter(principal.getName(), getTaskExecutor()));
}
return (Collection<C>) Collections
.unmodifiableCollection(members);
@@ -332,7 +326,7 @@ public class GroupProviderAdapter extends AbstractAdapter implements
}
@Override
- public <C extends ConfiguredObject> C createChild(Class<C> childClass,
+ public <C extends ConfiguredObject> C addChild(Class<C> childClass,
Map<String, Object> attributes,
ConfiguredObject... otherParents)
{
@@ -343,7 +337,7 @@ public class GroupProviderAdapter extends AbstractAdapter implements
if (getSecurityManager().authoriseGroupOperation(Operation.UPDATE, _group))
{
_groupManager.addUserToGroup(memberName, _group);
- return (C) new GroupMemberAdapter(memberName);
+ return (C) new GroupMemberAdapter(memberName, getTaskExecutor());
}
else
{
@@ -378,15 +372,7 @@ public class GroupProviderAdapter extends AbstractAdapter implements
}
@Override
- public Object setAttribute(String name, Object expected, Object desired)
- throws IllegalStateException, AccessControlException,
- IllegalArgumentException
- {
- return super.setAttribute(name, expected, desired);
- }
-
- @Override
- public State setDesiredState(State currentState, State desiredState)
+ protected boolean setState(State currentState, State desiredState)
throws IllegalStateTransitionException, AccessControlException
{
if (desiredState == State.DELETED)
@@ -394,16 +380,15 @@ public class GroupProviderAdapter extends AbstractAdapter implements
if (getSecurityManager().authoriseGroupOperation(Operation.DELETE, _group))
{
_groupManager.removeGroup(_group);
- return State.DELETED;
+ return true;
}
else
{
- throw new AccessControlException("Do not have permission" +
- " to delete group");
+ throw new AccessControlException("Do not have permission to delete group");
}
}
- return super.setDesiredState(currentState, desiredState);
+ return false;
}
private class GroupMemberAdapter extends AbstractAdapter implements
@@ -411,12 +396,9 @@ public class GroupProviderAdapter extends AbstractAdapter implements
{
private String _memberName;
- public GroupMemberAdapter(String memberName)
+ public GroupMemberAdapter(String memberName, TaskExecutor taskExecutor)
{
- super(UUIDGenerator
- .generateGroupMemberUUID(
- GroupProviderAdapter.this.getName(), _group,
- memberName));
+ super(UUIDGenerator.generateGroupMemberUUID(GroupProviderAdapter.this.getName(), _group, memberName), taskExecutor);
_memberName = memberName;
}
@@ -522,7 +504,7 @@ public class GroupProviderAdapter extends AbstractAdapter implements
}
@Override
- public State setDesiredState(State currentState, State desiredState)
+ protected boolean setState(State currentState, State desiredState)
throws IllegalStateTransitionException,
AccessControlException
{
@@ -531,18 +513,38 @@ public class GroupProviderAdapter extends AbstractAdapter implements
if (getSecurityManager().authoriseGroupOperation(Operation.UPDATE, _group))
{
_groupManager.removeUserFromGroup(_memberName, _group);
- return State.DELETED;
+ return true;
}
else
{
- throw new AccessControlException("Do not have permission" +
- " to remove group member");
+ throw new AccessControlException("Do not have permission to remove group member");
}
}
-
- return super.setDesiredState(currentState, desiredState);
+ return false;
}
}
}
+
+ @Override
+ protected boolean setState(State currentState, State desiredState)
+ {
+ if (desiredState == State.ACTIVE)
+ {
+ return true;
+ }
+ else if (desiredState == State.STOPPED)
+ {
+ return true;
+ }
+ // TODO: DELETE state is ignored for now
+ // in case if we need to delete group provider, then we need AuthenticationProvider to be a change listener of it
+ // in order to remove deleted group provider from its group provider list
+ return false;
+ }
+
+ public Set<Principal> getGroupPrincipalsForUser(String username)
+ {
+ return _groupManager.getGroupPrincipalsForUser(username);
+ }
}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/HTTPPortAdapter.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/HTTPPortAdapter.java
deleted file mode 100644
index 823d27160b..0000000000
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/HTTPPortAdapter.java
+++ /dev/null
@@ -1,273 +0,0 @@
-/*
- *
- * 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.qpid.server.model.adapter;
-
-import java.security.AccessControlException;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Map;
-import org.apache.qpid.server.model.ConfiguredObject;
-import org.apache.qpid.server.model.Connection;
-import org.apache.qpid.server.model.LifetimePolicy;
-import org.apache.qpid.server.model.Port;
-import org.apache.qpid.server.model.Protocol;
-import org.apache.qpid.server.model.State;
-import org.apache.qpid.server.model.Statistics;
-import org.apache.qpid.server.model.Transport;
-import org.apache.qpid.server.model.UUIDGenerator;
-import org.apache.qpid.server.model.VirtualHostAlias;
-
-public class HTTPPortAdapter extends AbstractAdapter implements Port
-{
- private final BrokerAdapter _broker;
- private final int _port;
- private final Protocol _protocol;
- private final Transport _transport;
-
- public HTTPPortAdapter(BrokerAdapter brokerAdapter, int port)
- {
- this(brokerAdapter, port, Protocol.HTTP, Transport.TCP);
- }
-
- public HTTPPortAdapter(BrokerAdapter brokerAdapter, int port, Protocol protocol, Transport transport)
- {
- super(UUIDGenerator.generateRandomUUID());
- _broker = brokerAdapter;
- _port = port;
- _protocol = protocol;
- _transport = transport;
- }
-
- @Override
- public String getBindingAddress()
- {
- return "0.0.0.0";
- }
-
- @Override
- public int getPort()
- {
- return _port;
- }
-
- @Override
- public Collection<Transport> getTransports()
- {
- return Collections.singleton(_transport);
- }
-
- @Override
- public void addTransport(Transport transport)
- throws IllegalStateException, AccessControlException, IllegalArgumentException
- {
- throw new IllegalStateException(); // TODO - Implement
- }
-
- @Override
- public Transport removeTransport(Transport transport)
- throws IllegalStateException, AccessControlException, IllegalArgumentException
- {
- throw new IllegalStateException(); // TODO - Implement
- }
-
- @Override
- public Collection<Protocol> getProtocols()
- {
- return Collections.singleton(_protocol);
- }
-
- @Override
- public void addProtocol(Protocol protocol)
- throws IllegalStateException, AccessControlException, IllegalArgumentException
- {
- throw new IllegalStateException(); // TODO - Implement
- }
-
- @Override
- public Protocol removeProtocol(Protocol protocol)
- throws IllegalStateException, AccessControlException, IllegalArgumentException
- {
- throw new IllegalStateException(); // TODO - Implement
- }
-
- @Override
- public Collection<VirtualHostAlias> getVirtualHostBindings()
- {
- return Collections.emptySet();
- }
-
- @Override
- public Collection<Connection> getConnections()
- {
- return Collections.emptySet(); // TODO - Implement
- }
-
- @Override
- public String getName()
- {
- return getBindingAddress() + ":" + getPort(); // TODO - Implement
- }
-
- @Override
- public String setName(String currentName, String desiredName) throws IllegalStateException, AccessControlException
- {
- throw new IllegalStateException(); // TODO - Implement
- }
-
- @Override
- public State getActualState()
- {
- return State.ACTIVE;
- }
-
- @Override
- public boolean isDurable()
- {
- return false; // TODO - Implement
- }
-
- @Override
- public void setDurable(boolean durable)
- throws IllegalStateException, AccessControlException, IllegalArgumentException
- {
- throw new IllegalStateException();
- }
-
- @Override
- public LifetimePolicy getLifetimePolicy()
- {
- return LifetimePolicy.PERMANENT;
- }
-
- @Override
- public LifetimePolicy setLifetimePolicy(LifetimePolicy expected, LifetimePolicy desired)
- throws IllegalStateException, AccessControlException, IllegalArgumentException
- {
- throw new IllegalStateException(); // TODO - Implement
- }
-
- @Override
- public long getTimeToLive()
- {
- return 0; // TODO - Implement
- }
-
- @Override
- public long setTimeToLive(long expected, long desired)
- throws IllegalStateException, AccessControlException, IllegalArgumentException
- {
- throw new IllegalStateException(); // TODO - Implement
- }
-
- @Override
- public Statistics getStatistics()
- {
- return NoStatistics.getInstance();
- }
-
- @Override
- public <C extends ConfiguredObject> Collection<C> getChildren(Class<C> clazz)
- {
- if(clazz == Connection.class)
- {
- return (Collection<C>) getConnections();
- }
- else
- {
- return Collections.emptySet();
- }
- }
-
- @Override
- public <C extends ConfiguredObject> C createChild(Class<C> childClass, Map<String, Object> attributes, ConfiguredObject... otherParents)
- {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public Object getAttribute(String name)
- {
- if(ID.equals(name))
- {
- return getId();
- }
- else if(NAME.equals(name))
- {
- return getName();
- }
- else if(STATE.equals(name))
- {
- return getActualState();
- }
- else if(DURABLE.equals(name))
- {
- return isDurable();
- }
- else if(LIFETIME_POLICY.equals(name))
- {
- return getLifetimePolicy();
- }
- else if(TIME_TO_LIVE.equals(name))
- {
- return getTimeToLive();
- }
- else if(CREATED.equals(name))
- {
-
- }
- else if(UPDATED.equals(name))
- {
-
- }
- else if(BINDING_ADDRESS.equals(name))
- {
- return getBindingAddress();
- }
- else if(PORT.equals(name))
- {
- return getPort();
- }
- else if(PROTOCOLS.equals(name))
- {
- return getProtocols();
- }
- else if(TRANSPORTS.equals(name))
- {
- return getTransports();
- }
-
- return super.getAttribute(name); //TODO - Implement
- }
-
- @Override
- public Collection<String> getAttributeNames()
- {
- return AVAILABLE_ATTRIBUTES;
- }
-
- @Override
- public Object setAttribute(String name, Object expected, Object desired)
- throws IllegalStateException, AccessControlException, IllegalArgumentException
- {
- return super.setAttribute(name, expected, desired); //TODO - Implement
- }
-}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/KeyStoreAdapter.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/KeyStoreAdapter.java
new file mode 100644
index 0000000000..113d895e62
--- /dev/null
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/KeyStoreAdapter.java
@@ -0,0 +1,48 @@
+/*
+ *
+ * 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.qpid.server.model.adapter;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.UUID;
+
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.KeyStore;
+
+public class KeyStoreAdapter extends AbstractKeyStoreAdapter implements KeyStore
+{
+
+ public KeyStoreAdapter(UUID id, Broker broker, Map<String, Object> attributes)
+ {
+ super(id, broker, attributes);
+ if (attributes.get(CERTIFICATE_ALIAS) != null)
+ {
+ changeAttribute(CERTIFICATE_ALIAS, null, attributes.get(CERTIFICATE_ALIAS));
+ }
+ }
+
+ @Override
+ public Collection<String> getAttributeNames()
+ {
+ return AVAILABLE_ATTRIBUTES;
+ }
+
+}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/PortAdapter.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/PortAdapter.java
index 7653fcc9b9..cb166d220e 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/PortAdapter.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/PortAdapter.java
@@ -21,7 +21,16 @@
package org.apache.qpid.server.model.adapter;
+import java.security.AccessControlException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
import java.util.Map;
+import java.util.UUID;
+
+import org.apache.qpid.server.model.AuthenticationProvider;
+import org.apache.qpid.server.model.Broker;
import org.apache.qpid.server.model.ConfiguredObject;
import org.apache.qpid.server.model.Connection;
import org.apache.qpid.server.model.LifetimePolicy;
@@ -30,119 +39,82 @@ import org.apache.qpid.server.model.Protocol;
import org.apache.qpid.server.model.State;
import org.apache.qpid.server.model.Statistics;
import org.apache.qpid.server.model.Transport;
-import org.apache.qpid.server.model.UUIDGenerator;
import org.apache.qpid.server.model.VirtualHost;
import org.apache.qpid.server.model.VirtualHostAlias;
-import org.apache.qpid.server.protocol.AmqpProtocolVersion;
-import org.apache.qpid.server.transport.QpidAcceptor;
-
-import java.net.InetSocketAddress;
-import java.security.AccessControlException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
+import org.apache.qpid.server.configuration.updater.TaskExecutor;
public class PortAdapter extends AbstractAdapter implements Port
{
- private final BrokerAdapter _broker;
- private final QpidAcceptor _acceptor;
- private final InetSocketAddress _address;
- private final Collection<Protocol> _protocols;
-
- public PortAdapter(BrokerAdapter brokerAdapter, QpidAcceptor acceptor, InetSocketAddress address)
- {
- super(UUIDGenerator.generateRandomUUID());
- _broker = brokerAdapter;
- _acceptor = acceptor;
- _address = address;
- List<Protocol> protocols = new ArrayList<Protocol>();
+ private final Broker _broker;
+ private AuthenticationProvider _authenticationProvider;
- for(AmqpProtocolVersion pv : _acceptor.getSupported())
- {
- switch(pv)
- {
- case v0_8:
- protocols.add(Protocol.AMQP_0_8);
- break;
- case v0_9:
- protocols.add(Protocol.AMQP_0_9);
- break;
- case v0_9_1:
- protocols.add(Protocol.AMQP_0_9_1);
- break;
- case v0_10:
- protocols.add(Protocol.AMQP_0_10);
- break;
- case v1_0_0:
- protocols.add(Protocol.AMQP_1_0);
- break;
- }
- }
+ /*
+ * TODO register PortAceptor as a listener. For supporting multiple
+ * protocols on the same port we need to introduce a special entity like
+ * PortAceptor which will be responsible for port binding/unbinding
+ */
+ public PortAdapter(UUID id, Broker broker, Map<String, Object> attributes, Map<String, Object> defaults, TaskExecutor taskExecutor)
+ {
+ super(id, defaults, attributes, taskExecutor);
+ _broker = broker;
- _protocols = Collections.unmodifiableCollection(protocols);
+ addParent(Broker.class, broker);
}
@Override
public String getBindingAddress()
{
- return _address.getHostName();
+ return (String)getAttribute(BINDING_ADDRESS);
}
@Override
public int getPort()
{
- return _address.getPort();
+ return (Integer)getAttribute(PORT);
}
+ @SuppressWarnings("unchecked")
@Override
public Collection<Transport> getTransports()
{
- switch (_acceptor.getTransport())
- {
- case TCP:
- return Collections.singleton(Transport.TCP);
- case SSL:
- return Collections.singleton(Transport.SSL);
- }
-
- return null; // TODO - Implement
+ return (Collection<Transport>)getAttribute(TRANSPORTS);
}
@Override
public void addTransport(Transport transport)
throws IllegalStateException, AccessControlException, IllegalArgumentException
{
- throw new IllegalStateException(); // TODO - Implement
+ throw new IllegalStateException();
}
@Override
public Transport removeTransport(Transport transport)
throws IllegalStateException, AccessControlException, IllegalArgumentException
{
- throw new IllegalStateException(); // TODO - Implement
+ throw new IllegalStateException();
}
+ @SuppressWarnings("unchecked")
@Override
public Collection<Protocol> getProtocols()
{
- return _protocols;
+ return (Collection<Protocol>)getAttribute(PROTOCOLS);
}
@Override
public void addProtocol(Protocol protocol)
throws IllegalStateException, AccessControlException, IllegalArgumentException
{
- throw new IllegalStateException(); // TODO - Implement
+ throw new IllegalStateException();
}
@Override
public Protocol removeProtocol(Protocol protocol)
throws IllegalStateException, AccessControlException, IllegalArgumentException
{
- throw new IllegalStateException(); // TODO - Implement
+ throw new IllegalStateException();
}
@Override
@@ -165,19 +137,19 @@ public class PortAdapter extends AbstractAdapter implements Port
@Override
public Collection<Connection> getConnections()
{
- return null; // TODO - Implement
+ return null;
}
@Override
public String getName()
{
- return getBindingAddress() + ":" + getPort(); // TODO - Implement
+ return (String)getAttribute(NAME);
}
@Override
public String setName(String currentName, String desiredName) throws IllegalStateException, AccessControlException
{
- throw new IllegalStateException(); // TODO - Implement
+ throw new IllegalStateException();
}
@Override
@@ -189,7 +161,7 @@ public class PortAdapter extends AbstractAdapter implements Port
@Override
public boolean isDurable()
{
- return false; // TODO - Implement
+ return false;
}
@Override
@@ -209,20 +181,20 @@ public class PortAdapter extends AbstractAdapter implements Port
public LifetimePolicy setLifetimePolicy(LifetimePolicy expected, LifetimePolicy desired)
throws IllegalStateException, AccessControlException, IllegalArgumentException
{
- throw new IllegalStateException(); // TODO - Implement
+ throw new IllegalStateException();
}
@Override
public long getTimeToLive()
{
- return 0; // TODO - Implement
+ return 0;
}
@Override
public long setTimeToLive(long expected, long desired)
throws IllegalStateException, AccessControlException, IllegalArgumentException
{
- throw new IllegalStateException(); // TODO - Implement
+ throw new IllegalStateException();
}
@Override
@@ -257,10 +229,6 @@ public class PortAdapter extends AbstractAdapter implements Port
{
return getId();
}
- else if(NAME.equals(name))
- {
- return getName();
- }
else if(STATE.equals(name))
{
return getActualState();
@@ -285,36 +253,54 @@ public class PortAdapter extends AbstractAdapter implements Port
{
}
- else if(BINDING_ADDRESS.equals(name))
- {
- return getBindingAddress();
- }
- else if(PORT.equals(name))
+ return super.getAttribute(name);
+ }
+
+ @Override
+ public Collection<String> getAttributeNames()
+ {
+ return AVAILABLE_ATTRIBUTES;
+ }
+
+ @Override
+ public boolean setState(State currentState, State desiredState)
+ {
+ if (desiredState == State.DELETED)
{
- return getPort();
+ return true;
}
- else if(PROTOCOLS.equals(name))
+ else if (desiredState == State.ACTIVE)
{
- return getProtocols();
+ onActivate();
+ return true;
}
- else if(TRANSPORTS.equals(name))
+ else if (desiredState == State.STOPPED)
{
- return getTransports();
+ onStop();
+ return true;
}
+ return false;
+ }
- return super.getAttribute(name); //TODO - Implement
+ protected void onActivate()
+ {
+ // no-op: expected to be overridden by subclass
}
- @Override
- public Collection<String> getAttributeNames()
+ protected void onStop()
{
- return AVAILABLE_ATTRIBUTES;
+ // no-op: expected to be overridden by subclass
}
@Override
- public Object setAttribute(String name, Object expected, Object desired)
- throws IllegalStateException, AccessControlException, IllegalArgumentException
+ public AuthenticationProvider getAuthenticationProvider()
+ {
+ return _authenticationProvider;
+ }
+
+ public void setAuthenticationProvider(AuthenticationProvider authenticationProvider)
{
- return super.setAttribute(name, expected, desired); //TODO - Implement
+ _authenticationProvider = authenticationProvider;
}
+
}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/PortFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/PortFactory.java
new file mode 100644
index 0000000000..a1f72c8119
--- /dev/null
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/PortFactory.java
@@ -0,0 +1,215 @@
+/*
+ *
+ * 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.qpid.server.model.adapter;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.EnumSet;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+
+import org.apache.qpid.server.configuration.BrokerProperties;
+import org.apache.qpid.server.configuration.IllegalConfigurationException;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.Port;
+import org.apache.qpid.server.model.Protocol;
+import org.apache.qpid.server.model.Protocol.ProtocolType;
+import org.apache.qpid.server.model.Transport;
+import org.apache.qpid.server.util.MapValueConverter;
+
+public class PortFactory
+{
+ public static final int DEFAULT_AMQP_SEND_BUFFER_SIZE = 262144;
+ public static final int DEFAULT_AMQP_RECEIVE_BUFFER_SIZE = 262144;
+ public static final boolean DEFAULT_AMQP_NEED_CLIENT_AUTH = false;
+ public static final boolean DEFAULT_AMQP_WANT_CLIENT_AUTH = false;
+ public static final boolean DEFAULT_AMQP_TCP_NO_DELAY = true;
+ public static final String DEFAULT_AMQP_BINDING = "*";
+ public static final Transport DEFAULT_TRANSPORT = Transport.TCP;
+
+ private final Collection<Protocol> _defaultProtocols;
+
+ public PortFactory()
+ {
+ Set<Protocol> defaultProtocols = EnumSet.of(Protocol.AMQP_0_8, Protocol.AMQP_0_9, Protocol.AMQP_0_9_1,
+ Protocol.AMQP_0_10, Protocol.AMQP_1_0);
+ String excludedProtocols = System.getProperty(BrokerProperties.PROPERTY_BROKER_DEFAULT_AMQP_PROTOCOL_EXCLUDES);
+ if (excludedProtocols != null)
+ {
+ String[] excludes = excludedProtocols.split(",");
+ for (String exclude : excludes)
+ {
+ Protocol protocol = Protocol.valueOf(exclude);
+ defaultProtocols.remove(protocol);
+ }
+ }
+ String includedProtocols = System.getProperty(BrokerProperties.PROPERTY_BROKER_DEFAULT_AMQP_PROTOCOL_INCLUDES);
+ if (includedProtocols != null)
+ {
+ String[] includes = includedProtocols.split(",");
+ for (String include : includes)
+ {
+ Protocol protocol = Protocol.valueOf(include);
+ defaultProtocols.add(protocol);
+ }
+ }
+ _defaultProtocols = Collections.unmodifiableCollection(defaultProtocols);
+ }
+
+ public Port createPort(UUID id, Broker broker, Map<String, Object> objectAttributes)
+ {
+ Map<String, Object> attributes = retrieveAttributes(objectAttributes);
+
+ final Port port;
+ Map<String, Object> defaults = new HashMap<String, Object>();
+ defaults.put(Port.TRANSPORTS, Collections.singleton(DEFAULT_TRANSPORT));
+ Object portValue = attributes.get(Port.PORT);
+ if (portValue == null)
+ {
+ throw new IllegalConfigurationException("Port attribute is not specified for port: " + attributes);
+ }
+ if (isAmqpProtocol(attributes))
+ {
+ Object binding = attributes.get(Port.BINDING_ADDRESS);
+ if (binding == null)
+ {
+ binding = DEFAULT_AMQP_BINDING;
+ defaults.put(Port.BINDING_ADDRESS, DEFAULT_AMQP_BINDING);
+ }
+ defaults.put(Port.NAME, binding + ":" + portValue);
+ defaults.put(Port.PROTOCOLS, _defaultProtocols);
+ defaults.put(Port.TCP_NO_DELAY, DEFAULT_AMQP_TCP_NO_DELAY);
+ defaults.put(Port.WANT_CLIENT_AUTH, DEFAULT_AMQP_WANT_CLIENT_AUTH);
+ defaults.put(Port.NEED_CLIENT_AUTH, DEFAULT_AMQP_NEED_CLIENT_AUTH);
+ defaults.put(Port.RECEIVE_BUFFER_SIZE, DEFAULT_AMQP_RECEIVE_BUFFER_SIZE);
+ defaults.put(Port.SEND_BUFFER_SIZE, DEFAULT_AMQP_SEND_BUFFER_SIZE);
+ port = new AmqpPortAdapter(id, broker, attributes, defaults, broker.getTaskExecutor());
+ }
+ else
+ {
+ @SuppressWarnings("unchecked")
+ Collection<Protocol> protocols = (Collection<Protocol>)attributes.get(Port.PROTOCOLS);
+ if (protocols.size() > 1)
+ {
+ throw new IllegalConfigurationException("Only one protocol can be used on non AMQP port");
+ }
+ Protocol protocol = protocols.iterator().next();
+ defaults.put(Port.NAME, portValue + "-" + protocol.name());
+ port = new PortAdapter(id, broker, attributes, defaults, broker.getTaskExecutor());
+ }
+ return port;
+ }
+
+ private Map<String, Object> retrieveAttributes(Map<String, Object> objectAttributes)
+ {
+ Map<String, Object> attributes = new HashMap<String, Object>(objectAttributes);
+
+ if (objectAttributes.containsKey(Port.PROTOCOLS))
+ {
+ final Set<Protocol> protocolSet = MapValueConverter.getEnumSetAttribute(Port.PROTOCOLS, objectAttributes, Protocol.class);
+ attributes.put(Port.PROTOCOLS, protocolSet);
+ }
+
+ if (objectAttributes.containsKey(Port.TRANSPORTS))
+ {
+ final Set<Transport> transportSet = MapValueConverter.getEnumSetAttribute(Port.TRANSPORTS, objectAttributes,
+ Transport.class);
+ attributes.put(Port.TRANSPORTS, transportSet);
+ }
+
+ if (objectAttributes.containsKey(Port.PORT))
+ {
+ Integer port = MapValueConverter.getIntegerAttribute(Port.PORT, objectAttributes);
+ attributes.put(Port.PORT, port);
+ }
+
+ if (objectAttributes.containsKey(Port.TCP_NO_DELAY))
+ {
+ boolean tcpNoDelay = MapValueConverter.getBooleanAttribute(Port.TCP_NO_DELAY, objectAttributes);
+ attributes.put(Port.TCP_NO_DELAY, tcpNoDelay);
+ }
+
+ if (objectAttributes.containsKey(Port.RECEIVE_BUFFER_SIZE))
+ {
+ int receiveBufferSize = MapValueConverter.getIntegerAttribute(Port.RECEIVE_BUFFER_SIZE, objectAttributes);
+ attributes.put(Port.RECEIVE_BUFFER_SIZE, receiveBufferSize);
+ }
+
+ if (objectAttributes.containsKey(Port.SEND_BUFFER_SIZE))
+ {
+ int sendBufferSize = MapValueConverter.getIntegerAttribute(Port.SEND_BUFFER_SIZE, objectAttributes);
+ attributes.put(Port.SEND_BUFFER_SIZE, sendBufferSize);
+ }
+
+ if (objectAttributes.containsKey(Port.NEED_CLIENT_AUTH))
+ {
+ boolean needClientAuth = MapValueConverter.getBooleanAttribute(Port.NEED_CLIENT_AUTH, objectAttributes);
+ attributes.put(Port.NEED_CLIENT_AUTH, needClientAuth);
+ }
+
+ if (objectAttributes.containsKey(Port.WANT_CLIENT_AUTH))
+ {
+ boolean wantClientAuth = MapValueConverter.getBooleanAttribute(Port.WANT_CLIENT_AUTH, objectAttributes);
+ attributes.put(Port.WANT_CLIENT_AUTH, wantClientAuth);
+ }
+
+ if (objectAttributes.containsKey(Port.BINDING_ADDRESS))
+ {
+ String binding = MapValueConverter.getStringAttribute(Port.BINDING_ADDRESS, objectAttributes);
+ attributes.put(Port.BINDING_ADDRESS, binding);
+ }
+ return attributes;
+ }
+
+ private boolean isAmqpProtocol(Map<String, Object> portAttributes)
+ {
+ @SuppressWarnings("unchecked")
+ Set<Protocol> protocols = (Set<Protocol>) portAttributes.get(Port.PROTOCOLS);
+ if (protocols == null || protocols.isEmpty())
+ {
+ // defaulting to AMQP if protocol is not specified
+ return true;
+ }
+
+ Set<ProtocolType> protocolTypes = new HashSet<ProtocolType>();
+ for (Protocol protocolObject : protocols)
+ {
+ protocolTypes.add(protocolObject.getProtocolType());
+ }
+
+ if (protocolTypes.size() > 1)
+ {
+ throw new IllegalConfigurationException("Found different protocol types '" + protocolTypes
+ + "' on port configuration: " + portAttributes);
+ }
+
+ return protocolTypes.contains(ProtocolType.AMQP);
+ }
+
+ public Collection<Protocol> getDefaultProtocols()
+ {
+ return _defaultProtocols;
+ }
+
+}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/QueueAdapter.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/QueueAdapter.java
index b907d4177a..f3ddf32e5a 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/QueueAdapter.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/QueueAdapter.java
@@ -43,6 +43,7 @@ import org.apache.qpid.server.model.State;
import org.apache.qpid.server.model.Statistics;
import org.apache.qpid.server.queue.*;
import org.apache.qpid.server.subscription.Subscription;
+import org.apache.qpid.server.util.MapValueConverter;
final class QueueAdapter extends AbstractAdapter implements Queue, AMQQueue.SubscriptionRegistrationListener, AMQQueue.NotificationListener
{
@@ -79,7 +80,7 @@ final class QueueAdapter extends AbstractAdapter implements Queue, AMQQueue.Subs
public QueueAdapter(final VirtualHostAdapter virtualHostAdapter, final AMQQueue queue)
{
- super(queue.getId());
+ super(queue.getId(), virtualHostAdapter.getTaskExecutor());
_vhost = virtualHostAdapter;
addParent(org.apache.qpid.server.model.VirtualHost.class, virtualHostAdapter);
@@ -206,47 +207,47 @@ final class QueueAdapter extends AbstractAdapter implements Queue, AMQQueue.Subs
}
@Override
- public Object setAttribute(String name, Object expected, Object desired) throws IllegalStateException, AccessControlException, IllegalArgumentException
+ public boolean changeAttribute(String name, Object expected, Object desired) throws IllegalStateException, AccessControlException, IllegalArgumentException
{
try
{
if(ALERT_REPEAT_GAP.equals(name))
{
_queue.setMinimumAlertRepeatGap((Long)desired);
- return desired;
+ return true;
}
else if(ALERT_THRESHOLD_MESSAGE_AGE.equals(name))
{
_queue.setMaximumMessageAge((Long)desired);
- return desired;
+ return true;
}
else if(ALERT_THRESHOLD_MESSAGE_SIZE.equals(name))
{
_queue.setMaximumMessageSize((Long)desired);
- return desired;
+ return true;
}
else if(ALERT_THRESHOLD_QUEUE_DEPTH_BYTES.equals(name))
{
_queue.setMaximumQueueDepth((Long)desired);
- return desired;
+ return true;
}
else if(ALERT_THRESHOLD_QUEUE_DEPTH_MESSAGES.equals(name))
{
_queue.setMaximumMessageCount((Long)desired);
- return desired;
+ return true;
}
else if(ALTERNATE_EXCHANGE.equals(name))
{
// In future we may want to accept a UUID as an alternative way to identifying the exchange
ExchangeAdapter alternateExchange = (ExchangeAdapter) desired;
_queue.setAlternateExchange(alternateExchange == null ? null : alternateExchange.getExchange());
- return desired;
+ return true;
}
else if(EXCLUSIVE.equals(name))
{
Boolean exclusiveFlag = (Boolean) desired;
_queue.setExclusive(exclusiveFlag);
- return desired;
+ return true;
}
else if(MESSAGE_GROUP_KEY.equals(name))
{
@@ -267,7 +268,7 @@ final class QueueAdapter extends AbstractAdapter implements Queue, AMQQueue.Subs
else if(MAXIMUM_DELIVERY_ATTEMPTS.equals(name))
{
_queue.setMaximumDeliveryCount((Integer)desired);
- return desired;
+ return true;
}
else if(NO_LOCAL.equals(name))
{
@@ -280,12 +281,12 @@ final class QueueAdapter extends AbstractAdapter implements Queue, AMQQueue.Subs
else if(QUEUE_FLOW_CONTROL_SIZE_BYTES.equals(name))
{
_queue.setCapacity((Long)desired);
- return desired;
+ return true;
}
else if(QUEUE_FLOW_RESUME_SIZE_BYTES.equals(name))
{
_queue.setFlowResumeCapacity((Long)desired);
- return desired;
+ return true;
}
else if(QUEUE_FLOW_STOPPED.equals(name))
{
@@ -302,10 +303,10 @@ final class QueueAdapter extends AbstractAdapter implements Queue, AMQQueue.Subs
else if (DESCRIPTION.equals(name))
{
_queue.setDescription((String) desired);
- return desired;
+ return true;
}
- return super.setAttribute(name, expected, desired);
+ return super.changeAttribute(name, expected, desired);
}
finally
{
@@ -496,8 +497,8 @@ final class QueueAdapter extends AbstractAdapter implements Queue, AMQQueue.Subs
throws AccessControlException, IllegalStateException
{
attributes = new HashMap<String, Object>(attributes);
- String bindingKey = getStringAttribute(org.apache.qpid.server.model.Binding.NAME, attributes, "");
- Map<String, Object> bindingArgs = getMapAttribute(org.apache.qpid.server.model.Binding.ARGUMENTS, attributes, Collections.EMPTY_MAP);
+ String bindingKey = MapValueConverter.getStringAttribute(org.apache.qpid.server.model.Binding.NAME, attributes, "");
+ Map<String, Object> bindingArgs = MapValueConverter.getMapAttribute(org.apache.qpid.server.model.Binding.ARGUMENTS, attributes, Collections.<String,Object>emptyMap());
attributes.remove(org.apache.qpid.server.model.Binding.NAME);
attributes.remove(org.apache.qpid.server.model.Binding.ARGUMENTS);
@@ -509,7 +510,7 @@ final class QueueAdapter extends AbstractAdapter implements Queue, AMQQueue.Subs
@Override
- public <C extends ConfiguredObject> C createChild(Class<C> childClass, Map<String, Object> attributes, ConfiguredObject... otherParents)
+ public <C extends ConfiguredObject> C addChild(Class<C> childClass, Map<String, Object> attributes, ConfiguredObject... otherParents)
{
if(childClass == org.apache.qpid.server.model.Binding.class)
{
@@ -713,15 +714,15 @@ final class QueueAdapter extends AbstractAdapter implements Queue, AMQQueue.Subs
}
@Override
- public State setDesiredState(State currentState, State desiredState) throws IllegalStateTransitionException,
+ protected boolean setState(State currentState, State desiredState) throws IllegalStateTransitionException,
AccessControlException
{
if (desiredState == State.DELETED)
{
delete();
- return State.DELETED;
+ return true;
}
- return super.setDesiredState(currentState, desiredState);
+ return false;
}
}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/SessionAdapter.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/SessionAdapter.java
index d802697d67..2fffdb32f8 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/SessionAdapter.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/SessionAdapter.java
@@ -34,6 +34,7 @@ import org.apache.qpid.server.model.State;
import org.apache.qpid.server.model.Statistics;
import org.apache.qpid.server.model.Consumer;
import org.apache.qpid.server.model.UUIDGenerator;
+import org.apache.qpid.server.configuration.updater.TaskExecutor;
import org.apache.qpid.server.protocol.AMQSessionModel;
final class SessionAdapter extends AbstractAdapter implements Session
@@ -44,9 +45,9 @@ final class SessionAdapter extends AbstractAdapter implements Session
private AMQSessionModel _session;
private SessionStatistics _statistics;
- public SessionAdapter(final AMQSessionModel session)
+ public SessionAdapter(final AMQSessionModel session, TaskExecutor taskExecutor)
{
- super(UUIDGenerator.generateRandomUUID());
+ super(UUIDGenerator.generateRandomUUID(), taskExecutor);
_session = session;
_statistics = new SessionStatistics();
}
@@ -141,13 +142,6 @@ final class SessionAdapter extends AbstractAdapter implements Session
return super.getAttribute(name); //TODO - Implement
}
- @Override
- public Object setAttribute(String name, Object expected, Object desired)
- throws IllegalStateException, AccessControlException, IllegalArgumentException
- {
- return super.setAttribute(name, expected, desired); //TODO - Implement
- }
-
public Statistics getStatistics()
{
return _statistics;
@@ -237,4 +231,11 @@ final class SessionAdapter extends AbstractAdapter implements Session
return null; // TODO - Implement
}
}
+
+ @Override
+ protected boolean setState(State currentState, State desiredState)
+ {
+ // TODO : add state management
+ return false;
+ }
}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/TrustStoreAdapter.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/TrustStoreAdapter.java
new file mode 100644
index 0000000000..bdffe605ec
--- /dev/null
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/TrustStoreAdapter.java
@@ -0,0 +1,43 @@
+/*
+ *
+ * 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.qpid.server.model.adapter;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.UUID;
+
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.TrustStore;
+
+public class TrustStoreAdapter extends AbstractKeyStoreAdapter implements TrustStore
+{
+ public TrustStoreAdapter(UUID id, Broker broker, Map<String, Object> attributes)
+ {
+ super(id, broker, attributes);
+ }
+
+ @Override
+ public Collection<String> getAttributeNames()
+ {
+ return AVAILABLE_ATTRIBUTES;
+ }
+
+}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/VirtualHostAdapter.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/VirtualHostAdapter.java
index e564eabcdd..3e6f73d23e 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/VirtualHostAdapter.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/VirtualHostAdapter.java
@@ -20,6 +20,7 @@
*/
package org.apache.qpid.server.model.adapter;
+import java.io.File;
import java.security.AccessControlException;
import java.security.Principal;
import java.util.ArrayList;
@@ -31,16 +32,27 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.UUID;
+
+import org.apache.commons.configuration.CompositeConfiguration;
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.PropertiesConfiguration;
+import org.apache.commons.configuration.SystemConfiguration;
import org.apache.qpid.AMQException;
import org.apache.qpid.framing.FieldTable;
+import org.apache.qpid.server.configuration.IllegalConfigurationException;
+import org.apache.qpid.server.configuration.VirtualHostConfiguration;
+import org.apache.qpid.server.configuration.XmlConfigurationUtilities.MyConfiguration;
import org.apache.qpid.server.connection.IConnectionRegistry;
import org.apache.qpid.server.exchange.ExchangeRegistry;
import org.apache.qpid.server.message.ServerMessage;
+import org.apache.qpid.server.model.Broker;
import org.apache.qpid.server.model.ConfiguredObject;
import org.apache.qpid.server.model.Connection;
import org.apache.qpid.server.model.Exchange;
import org.apache.qpid.server.model.LifetimePolicy;
import org.apache.qpid.server.model.Port;
+import org.apache.qpid.server.model.Protocol;
import org.apache.qpid.server.model.Queue;
import org.apache.qpid.server.model.QueueType;
import org.apache.qpid.server.model.State;
@@ -48,6 +60,7 @@ import org.apache.qpid.server.model.Statistics;
import org.apache.qpid.server.model.UUIDGenerator;
import org.apache.qpid.server.model.VirtualHost;
import org.apache.qpid.server.model.VirtualHostAlias;
+import org.apache.qpid.server.configuration.updater.TaskExecutor;
import org.apache.qpid.server.plugin.ExchangeType;
import org.apache.qpid.server.protocol.AMQConnectionModel;
import org.apache.qpid.server.queue.AMQQueue;
@@ -56,16 +69,28 @@ import org.apache.qpid.server.queue.QueueEntry;
import org.apache.qpid.server.queue.QueueRegistry;
import org.apache.qpid.server.security.SecurityManager;
import org.apache.qpid.server.security.auth.AuthenticatedPrincipal;
+import org.apache.qpid.server.stats.StatisticsGatherer;
import org.apache.qpid.server.store.MessageStore;
import org.apache.qpid.server.txn.LocalTransaction;
import org.apache.qpid.server.txn.ServerTransaction;
+import org.apache.qpid.server.util.MapValueConverter;
+import org.apache.qpid.server.virtualhost.VirtualHostImpl;
+import org.apache.qpid.server.virtualhost.VirtualHostRegistry;
-final class VirtualHostAdapter extends AbstractAdapter implements VirtualHost, ExchangeRegistry.RegistryChangeListener,
+public final class VirtualHostAdapter extends AbstractAdapter implements VirtualHost, ExchangeRegistry.RegistryChangeListener,
QueueRegistry.RegistryChangeListener,
IConnectionRegistry.RegistryChangeListener
{
- private final org.apache.qpid.server.virtualhost.VirtualHost _virtualHost;
+ @SuppressWarnings("serial")
+ public static final Map<String, Class<?>> ATTRIBUTE_TYPES = Collections.unmodifiableMap(new HashMap<String, Class<?>>(){{
+ put(NAME, String.class);
+ put(STORE_PATH, String.class);
+ put(STORE_TYPE, String.class);
+ put(CONFIG_PATH, String.class);
+ }});
+
+ private org.apache.qpid.server.virtualhost.VirtualHost _virtualHost;
private final Map<AMQConnectionModel, ConnectionAdapter> _connectionAdapters =
new HashMap<AMQConnectionModel, ConnectionAdapter>();
@@ -75,37 +100,52 @@ final class VirtualHostAdapter extends AbstractAdapter implements VirtualHost, E
private final Map<org.apache.qpid.server.exchange.Exchange, ExchangeAdapter> _exchangeAdapters =
new HashMap<org.apache.qpid.server.exchange.Exchange, ExchangeAdapter>();
-
- private final StatisticsAdapter _statistics;
-
- private final BrokerAdapter _broker;
-
+ private StatisticsAdapter _statistics;
+ private final Broker _broker;
private final List<VirtualHostAlias> _aliases = new ArrayList<VirtualHostAlias>();
+ private StatisticsGatherer _brokerStatisticsGatherer;
-
- VirtualHostAdapter(BrokerAdapter brokerAdapter,
- final org.apache.qpid.server.virtualhost.VirtualHost virtualHost)
+ public VirtualHostAdapter(UUID id, Map<String, Object> attributes, Broker broker, StatisticsGatherer brokerStatisticsGatherer, TaskExecutor taskExecutor)
{
- super(virtualHost.getId());
- _broker = brokerAdapter;
- _virtualHost = virtualHost;
- _statistics = new VirtualHostStatisticsAdapter(virtualHost);
- virtualHost.getQueueRegistry().addRegistryChangeListener(this);
- populateQueues();
- virtualHost.getExchangeRegistry().addRegistryChangeListener(this);
- populateExchanges();
- virtualHost.getConnectionRegistry().addRegistryChangeListener(this);
- populateConnections();
-
+ super(id, null, MapValueConverter.convert(attributes, ATTRIBUTE_TYPES), taskExecutor);
+ validateAttributes();
+ _broker = broker;
+ _brokerStatisticsGatherer = brokerStatisticsGatherer;
+ addParent(Broker.class, broker);
+ }
+ private void validateAttributes()
+ {
+ String name = getName();
+ if (name == null || "".equals(name.trim()))
+ {
+ throw new IllegalConfigurationException("Virtual host name must be specified");
+ }
- for(Port port :_broker.getPorts())
+ String configurationFile = (String) getAttribute(CONFIG_PATH);
+ String storePath = (String) getAttribute(STORE_PATH);
+ String storeType = (String) getAttribute(STORE_TYPE);
+ boolean invalidAttributes = false;
+ if (configurationFile == null)
{
- _aliases.add(new VirtualHostAliasAdapter(this, port));
+ if (storePath == null || storeType == null)
+ {
+ invalidAttributes = true;
+ }
+ }
+ else
+ {
+ if (storePath != null || storeType != null)
+ {
+ invalidAttributes = true;
+ }
+ }
+ if (invalidAttributes)
+ {
+ throw new IllegalConfigurationException("Please specify either the 'configPath' attribute or both 'storePath' and 'storeType' attributes");
}
}
-
private void populateExchanges()
{
Collection<org.apache.qpid.server.exchange.Exchange> actualExchanges =
@@ -127,37 +167,22 @@ final class VirtualHostAdapter extends AbstractAdapter implements VirtualHost, E
private void populateQueues()
{
Collection<AMQQueue> actualQueues = _virtualHost.getQueueRegistry().getQueues();
-
- synchronized(_queueAdapters)
- {
- for(AMQQueue queue : actualQueues)
- {
- if(!_queueAdapters.containsKey(queue))
- {
- _queueAdapters.put(queue, new QueueAdapter(this,queue));
- }
- }
- }
- }
-
- private void populateConnections()
- {
-
- List<AMQConnectionModel> actualConnections = _virtualHost.getConnectionRegistry().getConnections();
-
- synchronized(_connectionAdapters)
+ if ( actualQueues != null )
{
- for(AMQConnectionModel conn : actualConnections)
+ synchronized(_queueAdapters)
{
- if(!_connectionAdapters.containsKey(conn))
+ for(AMQQueue queue : actualQueues)
{
- _connectionAdapters.put(conn, new ConnectionAdapter(conn));
+ if(!_queueAdapters.containsKey(queue))
+ {
+ _queueAdapters.put(queue, new QueueAdapter(this, queue));
+ }
}
}
}
-
}
+ @Override
public String getReplicationGroupName()
{
return null; //TODO
@@ -199,12 +224,12 @@ final class VirtualHostAdapter extends AbstractAdapter implements VirtualHost, E
{
attributes = new HashMap<String, Object>(attributes);
- String name = getStringAttribute(Exchange.NAME, attributes, null);
- State state = getEnumAttribute(State.class, Exchange.STATE, attributes, State.ACTIVE);
- boolean durable = getBooleanAttribute(Exchange.DURABLE, attributes, false);
- LifetimePolicy lifetime = getEnumAttribute(LifetimePolicy.class, Exchange.LIFETIME_POLICY, attributes, LifetimePolicy.PERMANENT);
- String type = getStringAttribute(Exchange.TYPE, attributes, null);
- long ttl = getLongAttribute(Exchange.TIME_TO_LIVE, attributes, 0l);
+ String name = MapValueConverter.getStringAttribute(Exchange.NAME, attributes, null);
+ State state = MapValueConverter.getEnumAttribute(State.class, Exchange.STATE, attributes, State.ACTIVE);
+ boolean durable = MapValueConverter.getBooleanAttribute(Exchange.DURABLE, attributes, false);
+ LifetimePolicy lifetime = MapValueConverter.getEnumAttribute(LifetimePolicy.class, Exchange.LIFETIME_POLICY, attributes, LifetimePolicy.PERMANENT);
+ String type = MapValueConverter.getStringAttribute(Exchange.TYPE, attributes, null);
+ long ttl = MapValueConverter.getLongAttribute(Exchange.TIME_TO_LIVE, attributes, 0l);
attributes.remove(Exchange.NAME);
attributes.remove(Exchange.STATE);
@@ -267,7 +292,7 @@ final class VirtualHostAdapter extends AbstractAdapter implements VirtualHost, E
if (attributes.containsKey(Queue.TYPE))
{
- String typeAttribute = getStringAttribute(Queue.TYPE, attributes, null);
+ String typeAttribute = MapValueConverter.getStringAttribute(Queue.TYPE, attributes, null);
QueueType queueType = null;
try
{
@@ -290,12 +315,12 @@ final class VirtualHostAdapter extends AbstractAdapter implements VirtualHost, E
throw new IllegalArgumentException("Sort key is not specified for sorted queue");
}
}
- String name = getStringAttribute(Queue.NAME, attributes, null);
- State state = getEnumAttribute(State.class, Queue.STATE, attributes, State.ACTIVE);
- boolean durable = getBooleanAttribute(Queue.DURABLE, attributes, false);
- LifetimePolicy lifetime = getEnumAttribute(LifetimePolicy.class, Queue.LIFETIME_POLICY, attributes, LifetimePolicy.PERMANENT);
- long ttl = getLongAttribute(Queue.TIME_TO_LIVE, attributes, 0l);
- boolean exclusive= getBooleanAttribute(Queue.EXCLUSIVE, attributes, false);
+ String name = MapValueConverter.getStringAttribute(Queue.NAME, attributes, null);
+ State state = MapValueConverter.getEnumAttribute(State.class, Queue.STATE, attributes, State.ACTIVE);
+ boolean durable = MapValueConverter.getBooleanAttribute(Queue.DURABLE, attributes, false);
+ LifetimePolicy lifetime = MapValueConverter.getEnumAttribute(LifetimePolicy.class, Queue.LIFETIME_POLICY, attributes, LifetimePolicy.PERMANENT);
+ long ttl = MapValueConverter.getLongAttribute(Queue.TIME_TO_LIVE, attributes, 0l);
+ boolean exclusive= MapValueConverter.getBooleanAttribute(Queue.EXCLUSIVE, attributes, false);
attributes.remove(Queue.NAME);
attributes.remove(Queue.STATE);
@@ -370,7 +395,7 @@ final class VirtualHostAdapter extends AbstractAdapter implements VirtualHost, E
public String getName()
{
- return _virtualHost.getName();
+ return (String)getAttribute(NAME);
}
public String setName(final String currentName, final String desiredName)
@@ -381,7 +406,28 @@ final class VirtualHostAdapter extends AbstractAdapter implements VirtualHost, E
public State getActualState()
{
- return getDesiredState();
+ if (_virtualHost == null)
+ {
+ return State.INITIALISING;
+ }
+ else
+ {
+ org.apache.qpid.server.virtualhost.State implementationState = _virtualHost.getState();
+ switch(implementationState)
+ {
+ case INITIALISING:
+ return State.INITIALISING;
+ case ACTIVE:
+ return State.ACTIVE;
+ case PASSIVE:
+ return State.QUIESCED;
+ case STOPPED:
+ return State.STOPPED;
+ default:
+ // unexpected state
+ return null;
+ }
+ }
}
public boolean isDurable()
@@ -448,7 +494,7 @@ final class VirtualHostAdapter extends AbstractAdapter implements VirtualHost, E
}
@Override
- public <C extends ConfiguredObject> C createChild(Class<C> childClass, Map<String, Object> attributes, ConfiguredObject... otherParents)
+ public <C extends ConfiguredObject> C addChild(Class<C> childClass, Map<String, Object> attributes, ConfiguredObject... otherParents)
{
if(childClass == Exchange.class)
{
@@ -548,7 +594,7 @@ final class VirtualHostAdapter extends AbstractAdapter implements VirtualHost, E
{
if(!_connectionAdapters.containsKey(connection))
{
- adapter = new ConnectionAdapter(connection);
+ adapter = new ConnectionAdapter(connection, getTaskExecutor());
_connectionAdapters.put(connection, adapter);
}
@@ -709,10 +755,6 @@ final class VirtualHostAdapter extends AbstractAdapter implements VirtualHost, E
{
return getId();
}
- else if(NAME.equals(name))
- {
- return getName();
- }
else if(STATE.equals(name))
{
return State.ACTIVE;
@@ -737,10 +779,19 @@ final class VirtualHostAdapter extends AbstractAdapter implements VirtualHost, E
{
// TODO
}
- else if(SUPPORTED_EXCHANGE_TYPES.equals(name))
+ else if (_virtualHost != null)
+ {
+ return getAttributeFromVirtualHostImplementation(name);
+ }
+ return super.getAttribute(name);
+ }
+
+ private Object getAttributeFromVirtualHostImplementation(String name)
+ {
+ if(SUPPORTED_EXCHANGE_TYPES.equals(name))
{
List<String> types = new ArrayList<String>();
- for(ExchangeType type : _virtualHost.getExchangeFactory().getRegisteredTypes())
+ for(@SuppressWarnings("rawtypes") ExchangeType type : _virtualHost.getExchangeFactory().getRegisteredTypes())
{
types.add(type.getName().asString());
}
@@ -774,9 +825,9 @@ final class VirtualHostAdapter extends AbstractAdapter implements VirtualHost, E
{
return _virtualHost.getMessageStore().getStoreType();
}
- else if(STORE_CONFIGURATION.equals(name))
+ else if(STORE_PATH.equals(name))
{
- // TODO
+ return _virtualHost.getMessageStore().getStoreLocation();
}
else if(STORE_TRANSACTION_IDLE_TIMEOUT_CLOSE.equals(name))
{
@@ -818,13 +869,6 @@ final class VirtualHostAdapter extends AbstractAdapter implements VirtualHost, E
}
@Override
- public Object setAttribute(String name, Object expected, Object desired)
- throws IllegalStateException, AccessControlException, IllegalArgumentException
- {
- return super.setAttribute(name, expected, desired); //TODO - Implement
- }
-
- @Override
public Collection<String> getAttributeNames()
{
return AVAILABLE_ATTRIBUTES;
@@ -885,4 +929,111 @@ final class VirtualHostAdapter extends AbstractAdapter implements VirtualHost, E
}
}
+
+ @Override
+ protected boolean setState(State currentState, State desiredState)
+ {
+ if (desiredState == State.ACTIVE)
+ {
+ activate();
+ return true;
+ }
+ else if (desiredState == State.STOPPED)
+ {
+ if (_virtualHost != null)
+ {
+ try
+ {
+ _virtualHost.close();
+ }
+ finally
+ {
+ _broker.getVirtualHostRegistry().unregisterVirtualHost(_virtualHost);
+ }
+ }
+ return true;
+ }
+ else if (desiredState == State.DELETED)
+ {
+ //TODO: add ACL check to authorize the operation
+ if (_virtualHost != null && _virtualHost.getState() == org.apache.qpid.server.virtualhost.State.ACTIVE)
+ {
+ setDesiredState(currentState, State.STOPPED);
+ }
+ return true;
+ }
+ return false;
+ }
+
+ private void activate()
+ {
+ VirtualHostRegistry virtualHostRegistry = _broker.getVirtualHostRegistry();
+ String virtualHostName = getName();
+ try
+ {
+ VirtualHostConfiguration configuration = createVirtualHostConfiguration(virtualHostName);
+ _virtualHost = new VirtualHostImpl(_broker.getVirtualHostRegistry(), _brokerStatisticsGatherer, _broker.getSecurityManager(), configuration);
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Failed to create virtual host " + virtualHostName, e);
+ }
+
+ virtualHostRegistry.registerVirtualHost(_virtualHost);
+
+ _statistics = new VirtualHostStatisticsAdapter(_virtualHost);
+ _virtualHost.getQueueRegistry().addRegistryChangeListener(this);
+ populateQueues();
+ _virtualHost.getExchangeRegistry().addRegistryChangeListener(this);
+ populateExchanges();
+ _virtualHost.getConnectionRegistry().addRegistryChangeListener(this);
+
+ synchronized(_aliases)
+ {
+ for(Port port :_broker.getPorts())
+ {
+ if (Protocol.hasAmqpProtocol(port.getProtocols()))
+ {
+ _aliases.add(new VirtualHostAliasAdapter(this, port));
+ }
+ }
+ }
+ }
+
+ private VirtualHostConfiguration createVirtualHostConfiguration(String virtualHostName) throws ConfigurationException
+ {
+ VirtualHostConfiguration configuration;
+ String configurationFile = (String)getAttribute(CONFIG_PATH);
+ if (configurationFile == null)
+ {
+ final MyConfiguration basicConfiguration = new MyConfiguration();
+ PropertiesConfiguration config = new PropertiesConfiguration();
+ config.addProperty("store.type", (String)getAttribute(STORE_TYPE));
+ config.addProperty("store.environment-path", (String)getAttribute(STORE_PATH));
+ basicConfiguration.addConfiguration(config);
+
+ CompositeConfiguration compositeConfiguration = new CompositeConfiguration();
+ compositeConfiguration.addConfiguration(new SystemConfiguration());
+ compositeConfiguration.addConfiguration(basicConfiguration);
+ configuration = new VirtualHostConfiguration(virtualHostName, compositeConfiguration , _broker);
+ }
+ else
+ {
+ configuration = new VirtualHostConfiguration(virtualHostName, new File(configurationFile) , _broker);
+ }
+ return configuration;
+ }
+
+ @Override
+ public SecurityManager getSecurityManager()
+ {
+ return _virtualHost.getSecurityManager();
+ }
+
+ @Override
+ public MessageStore getMessageStore()
+ {
+ return _virtualHost.getMessageStore();
+ }
+
}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/VirtualHostAliasAdapter.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/VirtualHostAliasAdapter.java
index 367d1ff518..91b705b004 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/VirtualHostAliasAdapter.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/VirtualHostAliasAdapter.java
@@ -43,7 +43,7 @@ public class VirtualHostAliasAdapter extends AbstractAdapter implements Virtual
public VirtualHostAliasAdapter(VirtualHostAdapter virtualHostAdapter, Port port)
{
- super(UUIDGenerator.generateVhostAliasUUID(virtualHostAdapter.getName(), port.getName()));
+ super(UUIDGenerator.generateVhostAliasUUID(virtualHostAdapter.getName(), port.getName()), virtualHostAdapter.getTaskExecutor());
_vhost = virtualHostAdapter;
_port = port;
}
@@ -140,4 +140,11 @@ public class VirtualHostAliasAdapter extends AbstractAdapter implements Virtual
{
throw new UnsupportedOperationException();
}
+
+ @Override
+ protected boolean setState(State currentState, State desiredState)
+ {
+ // TODO: state is not supported at the moment
+ return false;
+ }
}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/AccessControlFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/AccessControlFactory.java
index 82f57c707b..7708b90efc 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/AccessControlFactory.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/AccessControlFactory.java
@@ -18,10 +18,11 @@
*/
package org.apache.qpid.server.plugin;
-import org.apache.commons.configuration.Configuration;
+import java.util.Map;
+
import org.apache.qpid.server.security.AccessControl;
public interface AccessControlFactory
{
- AccessControl createInstance(Configuration securityConfig);
+ AccessControl createInstance(Map<String, Object> attributes);
}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/AuthenticationManagerFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/AuthenticationManagerFactory.java
index 014b9fb28f..95e6b4feb0 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/AuthenticationManagerFactory.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/AuthenticationManagerFactory.java
@@ -18,11 +18,14 @@
*/
package org.apache.qpid.server.plugin;
-import org.apache.commons.configuration.Configuration;
+import java.util.Map;
+
import org.apache.qpid.server.security.auth.manager.AuthenticationManager;
public interface AuthenticationManagerFactory
{
- AuthenticationManager createInstance(Configuration securityConfiguration);
+ public static final String ATTRIBUTE_TYPE = "authenticationProviderType";
+
+ AuthenticationManager createInstance(Map<String, Object> attributes);
}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/GroupManagerFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/GroupManagerFactory.java
index b7f1eeaf29..5d80ca24fd 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/GroupManagerFactory.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/GroupManagerFactory.java
@@ -18,10 +18,11 @@
*/
package org.apache.qpid.server.plugin;
-import org.apache.commons.configuration.Configuration;
+import java.util.Map;
+
import org.apache.qpid.server.security.group.GroupManager;
public interface GroupManagerFactory
{
- GroupManager createInstance(Configuration securityConfiguration);
+ GroupManager createInstance(Map<String, Object> attributes);
}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/ManagementFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/PluginFactory.java
index 92414b7127..af24f62e28 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/ManagementFactory.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/PluginFactory.java
@@ -18,11 +18,15 @@
*/
package org.apache.qpid.server.plugin;
-import org.apache.qpid.server.configuration.ServerConfiguration;
-import org.apache.qpid.server.management.plugin.ManagementPlugin;
+import java.util.Map;
+import java.util.UUID;
+
import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.Plugin;
-public interface ManagementFactory
+public interface PluginFactory
{
- ManagementPlugin createInstance(ServerConfiguration configuration, Broker broker);
+ static final String PLUGIN_TYPE = "pluginType";
+
+ Plugin createInstance(UUID id, Map<String, Object> attributes, Broker broker);
}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQProtocolEngine.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQProtocolEngine.java
index f77f3a764a..ee1ef2418a 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQProtocolEngine.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQProtocolEngine.java
@@ -52,6 +52,7 @@ import org.apache.qpid.protocol.AMQMethodEvent;
import org.apache.qpid.protocol.AMQMethodListener;
import org.apache.qpid.protocol.ServerProtocolEngine;
import org.apache.qpid.server.AMQChannel;
+import org.apache.qpid.server.configuration.BrokerProperties;
import org.apache.qpid.server.handler.ServerMethodDispatcherImpl;
import org.apache.qpid.server.logging.LogActor;
import org.apache.qpid.server.logging.LogSubject;
@@ -60,10 +61,10 @@ import org.apache.qpid.server.logging.actors.CurrentActor;
import org.apache.qpid.server.logging.actors.ManagementActor;
import org.apache.qpid.server.logging.messages.ConnectionMessages;
import org.apache.qpid.server.logging.subjects.ConnectionLogSubject;
+import org.apache.qpid.server.model.Broker;
import org.apache.qpid.server.output.ProtocolOutputConverter;
import org.apache.qpid.server.output.ProtocolOutputConverterRegistry;
import org.apache.qpid.server.queue.QueueEntry;
-import org.apache.qpid.server.registry.ApplicationRegistry;
import org.apache.qpid.server.security.auth.AuthenticatedPrincipal;
import org.apache.qpid.server.state.AMQState;
import org.apache.qpid.server.state.AMQStateManager;
@@ -72,7 +73,6 @@ import org.apache.qpid.server.subscription.ClientDeliveryMethod;
import org.apache.qpid.server.subscription.Subscription;
import org.apache.qpid.server.subscription.SubscriptionImpl;
import org.apache.qpid.server.virtualhost.VirtualHost;
-import org.apache.qpid.server.virtualhost.VirtualHostRegistry;
import org.apache.qpid.transport.Sender;
import org.apache.qpid.transport.TransportException;
import org.apache.qpid.transport.network.NetworkConnection;
@@ -112,7 +112,7 @@ public class AMQProtocolEngine implements ServerProtocolEngine, AMQProtocolSessi
private volatile boolean _closed;
// maximum number of channels this session should have
- private long _maxNoOfChannels = ApplicationRegistry.getInstance().getConfiguration().getMaxChannelCount();
+ private long _maxNoOfChannels;
/* AMQP Version for this session */
private ProtocolVersion _protocolVersion = ProtocolVersion.getLatestSupportedVersion();
@@ -152,18 +152,21 @@ public class AMQProtocolEngine implements ServerProtocolEngine, AMQProtocolSessi
private final Lock _receivedLock;
private AtomicLong _lastWriteTime = new AtomicLong(System.currentTimeMillis());
+ private final Broker _broker;
- public AMQProtocolEngine(VirtualHostRegistry virtualHostRegistry, NetworkConnection network, final long connectionId)
+ public AMQProtocolEngine(Broker broker, NetworkConnection network, final long connectionId)
{
+ _broker = broker;
+ _maxNoOfChannels = (Integer)broker.getAttribute(Broker.SESSION_COUNT_LIMIT);
_receivedLock = new ReentrantLock();
- _stateManager = new AMQStateManager(virtualHostRegistry, this);
+ _stateManager = new AMQStateManager(broker, this);
_codecFactory = new AMQCodecFactory(true, this);
setNetworkConnection(network);
_connectionID = connectionId;
- _actor = new AMQPConnectionActor(this, virtualHostRegistry.getApplicationRegistry().getRootMessageLogger());
+ _actor = new AMQPConnectionActor(this, _broker.getRootMessageLogger());
_logSubject = new ConnectionLogSubject(this);
@@ -370,7 +373,7 @@ public class AMQProtocolEngine implements ServerProtocolEngine, AMQProtocolSessi
// This sets the protocol version (and hence framing classes) for this session.
setProtocolVersion(pv);
- String mechanisms = ApplicationRegistry.getInstance().getSubjectCreator(getLocalAddress()).getMechanisms();
+ String mechanisms = _broker.getSubjectCreator(getLocalAddress()).getMechanisms();
String locales = "en_US";
@@ -761,7 +764,7 @@ public class AMQProtocolEngine implements ServerProtocolEngine, AMQProtocolSessi
if (delay > 0)
{
_network.setMaxWriteIdle(delay);
- _network.setMaxReadIdle((int) (ApplicationRegistry.getInstance().getConfiguration().getHeartBeatTimeout() * delay));
+ _network.setMaxReadIdle(BrokerProperties.DEFAULT_HEART_BEAT_TIMEOUT_FACTOR * delay);
}
}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/MultiVersionProtocolEngine.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/MultiVersionProtocolEngine.java
index b0465c731e..d9e5e1c473 100755
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/MultiVersionProtocolEngine.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/MultiVersionProtocolEngine.java
@@ -28,7 +28,7 @@ import java.util.Set;
import org.apache.log4j.Logger;
import org.apache.qpid.protocol.ServerProtocolEngine;
-import org.apache.qpid.server.registry.IApplicationRegistry;
+import org.apache.qpid.server.model.Broker;
import org.apache.qpid.server.transport.ServerConnection;
import org.apache.qpid.transport.ConnectionDelegate;
import org.apache.qpid.transport.Sender;
@@ -42,24 +42,24 @@ public class MultiVersionProtocolEngine implements ServerProtocolEngine
private Set<AmqpProtocolVersion> _supported;
private String _fqdn;
- private IApplicationRegistry _appRegistry;
+ private final Broker _broker;
private NetworkConnection _network;
private Sender<ByteBuffer> _sender;
private final AmqpProtocolVersion _defaultSupportedReply;
private volatile ServerProtocolEngine _delegate = new SelfDelegateProtocolEngine();
- public MultiVersionProtocolEngine(final IApplicationRegistry appRegistry,
+ public MultiVersionProtocolEngine(final Broker broker,
final Set<AmqpProtocolVersion> supported,
final AmqpProtocolVersion defaultSupportedReply,
final long id,
final NetworkConnection network)
{
- this(appRegistry, supported, defaultSupportedReply, id);
+ this(broker, supported, defaultSupportedReply, id);
setNetworkConnection(network);
}
- public MultiVersionProtocolEngine(final IApplicationRegistry appRegistry,
+ public MultiVersionProtocolEngine(final Broker broker,
final Set<AmqpProtocolVersion> supported,
final AmqpProtocolVersion defaultSupportedReply,
final long id)
@@ -71,7 +71,7 @@ public class MultiVersionProtocolEngine implements ServerProtocolEngine
}
_id = id;
- _appRegistry = appRegistry;
+ _broker = broker;
_supported = supported;
_defaultSupportedReply = defaultSupportedReply;
}
@@ -252,7 +252,7 @@ public class MultiVersionProtocolEngine implements ServerProtocolEngine
public ServerProtocolEngine getProtocolEngine()
{
- return new AMQProtocolEngine(_appRegistry.getVirtualHostRegistry(), _network, _id);
+ return new AMQProtocolEngine(_broker, _network, _id);
}
};
@@ -272,7 +272,7 @@ public class MultiVersionProtocolEngine implements ServerProtocolEngine
public ServerProtocolEngine getProtocolEngine()
{
- return new AMQProtocolEngine(_appRegistry.getVirtualHostRegistry(), _network, _id);
+ return new AMQProtocolEngine(_broker, _network, _id);
}
};
@@ -292,7 +292,7 @@ public class MultiVersionProtocolEngine implements ServerProtocolEngine
public ServerProtocolEngine getProtocolEngine()
{
- return new AMQProtocolEngine(_appRegistry.getVirtualHostRegistry(), _network, _id);
+ return new AMQProtocolEngine(_broker, _network, _id);
}
};
@@ -313,15 +313,15 @@ public class MultiVersionProtocolEngine implements ServerProtocolEngine
public ServerProtocolEngine getProtocolEngine()
{
- final ConnectionDelegate connDelegate =
- new org.apache.qpid.server.transport.ServerConnectionDelegate(_appRegistry, _fqdn, _appRegistry.getSubjectCreator(getLocalAddress()));
+ final ConnectionDelegate connDelegate = new org.apache.qpid.server.transport.ServerConnectionDelegate(_broker,
+ _fqdn, _broker.getSubjectCreator(getLocalAddress()));
ServerConnection conn = new ServerConnection(_id);
conn.setConnectionDelegate(connDelegate);
conn.setRemoteAddress(_network.getRemoteAddress());
conn.setLocalAddress(_network.getLocalAddress());
- return new ProtocolEngine_0_10( conn, _network, _appRegistry);
+ return new ProtocolEngine_0_10( conn, _network);
}
};
@@ -341,7 +341,7 @@ public class MultiVersionProtocolEngine implements ServerProtocolEngine
public ServerProtocolEngine getProtocolEngine()
{
- return new ProtocolEngine_1_0_0(_network, _appRegistry,_id);
+ return new ProtocolEngine_1_0_0(_network, _broker, _id);
}
};
@@ -361,7 +361,7 @@ public class MultiVersionProtocolEngine implements ServerProtocolEngine
public ServerProtocolEngine getProtocolEngine()
{
- return new ProtocolEngine_1_0_0_SASL(_network, _appRegistry, _id);
+ return new ProtocolEngine_1_0_0_SASL(_network, _broker, _id);
}
};
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/MultiVersionProtocolEngineFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/MultiVersionProtocolEngineFactory.java
index 552b1c7054..9f078c8999 100755
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/MultiVersionProtocolEngineFactory.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/MultiVersionProtocolEngineFactory.java
@@ -22,8 +22,7 @@ package org.apache.qpid.server.protocol;
import org.apache.qpid.protocol.ProtocolEngineFactory;
import org.apache.qpid.protocol.ServerProtocolEngine;
-import org.apache.qpid.server.registry.ApplicationRegistry;
-import org.apache.qpid.server.registry.IApplicationRegistry;
+import org.apache.qpid.server.model.Broker;
import java.util.Set;
import java.util.concurrent.atomic.AtomicLong;
@@ -32,11 +31,12 @@ public class MultiVersionProtocolEngineFactory implements ProtocolEngineFactory
{
private static final AtomicLong ID_GENERATOR = new AtomicLong(0);
- private final IApplicationRegistry _appRegistry;
+ private final Broker _broker;
private final Set<AmqpProtocolVersion> _supported;
private final AmqpProtocolVersion _defaultSupportedReply;
- public MultiVersionProtocolEngineFactory(final Set<AmqpProtocolVersion> supportedVersions, final AmqpProtocolVersion defaultSupportedReply)
+ public MultiVersionProtocolEngineFactory(Broker broker,
+ final Set<AmqpProtocolVersion> supportedVersions, final AmqpProtocolVersion defaultSupportedReply)
{
if(defaultSupportedReply != null && !supportedVersions.contains(defaultSupportedReply))
{
@@ -44,14 +44,14 @@ public class MultiVersionProtocolEngineFactory implements ProtocolEngineFactory
+ ") to an unsupported protocol version initiation is itself not supported!");
}
- _appRegistry = ApplicationRegistry.getInstance();
+ _broker = broker;
_supported = supportedVersions;
_defaultSupportedReply = defaultSupportedReply;
}
public ServerProtocolEngine newProtocolEngine()
{
- return new MultiVersionProtocolEngine(_appRegistry, _supported, _defaultSupportedReply, ID_GENERATOR.getAndIncrement());
+ return new MultiVersionProtocolEngine(_broker, _supported, _defaultSupportedReply, ID_GENERATOR.getAndIncrement());
}
}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/ProtocolEngine_0_10.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/ProtocolEngine_0_10.java
index 7d263b517c..d5f7fe486c 100755
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/ProtocolEngine_0_10.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/ProtocolEngine_0_10.java
@@ -22,7 +22,6 @@ package org.apache.qpid.server.protocol;
import org.apache.qpid.protocol.ServerProtocolEngine;
import org.apache.qpid.server.logging.messages.ConnectionMessages;
-import org.apache.qpid.server.registry.IApplicationRegistry;
import org.apache.qpid.server.transport.ServerConnection;
import org.apache.qpid.transport.Sender;
import org.apache.qpid.transport.network.Assembler;
@@ -32,7 +31,7 @@ import org.apache.qpid.transport.network.NetworkConnection;
import java.net.SocketAddress;
import java.nio.ByteBuffer;
-import java.util.UUID;
+
public class ProtocolEngine_0_10 extends InputHandler implements ServerProtocolEngine
{
@@ -42,19 +41,17 @@ public class ProtocolEngine_0_10 extends InputHandler implements ServerProtocol
private long _readBytes;
private long _writtenBytes;
private ServerConnection _connection;
- private final IApplicationRegistry _appRegistry;
+
private long _createTime = System.currentTimeMillis();
private long _lastReadTime;
private long _lastWriteTime;
public ProtocolEngine_0_10(ServerConnection conn,
- NetworkConnection network,
- final IApplicationRegistry appRegistry)
+ NetworkConnection network)
{
super(new Assembler(conn));
_connection = conn;
- _appRegistry = appRegistry;
if(network != null)
{
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/ProtocolEngine_1_0_0.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/ProtocolEngine_1_0_0.java
index 4dbb98cc4a..f6b8e1e5c9 100755
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/ProtocolEngine_1_0_0.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/ProtocolEngine_1_0_0.java
@@ -22,7 +22,6 @@ package org.apache.qpid.server.protocol;
import java.net.SocketAddress;
import java.nio.ByteBuffer;
-import java.util.UUID;
import java.util.concurrent.atomic.AtomicLong;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -39,10 +38,10 @@ import org.apache.qpid.amqp_1_0.transport.FrameOutputHandler;
import org.apache.qpid.amqp_1_0.type.Binary;
import org.apache.qpid.amqp_1_0.type.FrameBody;
import org.apache.qpid.protocol.ServerProtocolEngine;
+import org.apache.qpid.server.model.Broker;
import org.apache.qpid.server.protocol.v1_0.Connection_1_0;
-import org.apache.qpid.server.registry.IApplicationRegistry;
import org.apache.qpid.server.security.SubjectCreator;
-import org.apache.qpid.server.security.auth.manager.AuthenticationManager;
+import org.apache.qpid.server.virtualhost.VirtualHost;
import org.apache.qpid.transport.Sender;
import org.apache.qpid.transport.network.NetworkConnection;
@@ -55,7 +54,7 @@ public class ProtocolEngine_1_0_0 implements ServerProtocolEngine, FrameOutputHa
private long _writtenBytes;
private long _lastReadTime;
private long _lastWriteTime;
- private final IApplicationRegistry _appRegistry;
+ private final Broker _broker;
private long _createTime = System.currentTimeMillis();
private ConnectionEndpoint _conn;
private final long _connectionId;
@@ -99,9 +98,9 @@ public class ProtocolEngine_1_0_0 implements ServerProtocolEngine, FrameOutputHa
- public ProtocolEngine_1_0_0(final NetworkConnection networkDriver, final IApplicationRegistry appRegistry, long id)
+ public ProtocolEngine_1_0_0(final NetworkConnection networkDriver, final Broker broker, long id)
{
- _appRegistry = appRegistry;
+ _broker = broker;
_connectionId = id;
if(networkDriver != null)
{
@@ -145,12 +144,14 @@ public class ProtocolEngine_1_0_0 implements ServerProtocolEngine, FrameOutputHa
_network = network;
_sender = sender;
- Container container = new Container(_appRegistry.getBrokerId().toString());
+ Container container = new Container(_broker.getId().toString());
- _conn = new ConnectionEndpoint(container, asSaslServerProvider(_appRegistry.getSubjectCreator(
+ VirtualHost virtualHost = _broker.getVirtualHostRegistry().getVirtualHost((String)_broker.getAttribute(Broker.DEFAULT_VIRTUAL_HOST));
+
+ _conn = new ConnectionEndpoint(container, asSaslServerProvider(_broker.getSubjectCreator(
getLocalAddress())));
_conn.setRemoteAddress(_network.getRemoteAddress());
- _conn.setConnectionEventListener(new Connection_1_0(_appRegistry, _conn, _connectionId));
+ _conn.setConnectionEventListener(new Connection_1_0(virtualHost, _conn, _connectionId));
_conn.setFrameOutputHandler(this);
_frameWriter = new FrameWriter(_conn.getDescribedTypeRegistry());
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/ProtocolEngine_1_0_0_SASL.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/ProtocolEngine_1_0_0_SASL.java
index 8e671a016f..3b02ef2e5b 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/ProtocolEngine_1_0_0_SASL.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/ProtocolEngine_1_0_0_SASL.java
@@ -23,7 +23,6 @@ package org.apache.qpid.server.protocol;
import java.io.PrintWriter;
import java.net.SocketAddress;
import java.nio.ByteBuffer;
-import java.util.UUID;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.security.sasl.SaslException;
@@ -40,10 +39,10 @@ import org.apache.qpid.amqp_1_0.transport.FrameOutputHandler;
import org.apache.qpid.amqp_1_0.type.Binary;
import org.apache.qpid.amqp_1_0.type.FrameBody;
import org.apache.qpid.protocol.ServerProtocolEngine;
+import org.apache.qpid.server.model.Broker;
import org.apache.qpid.server.protocol.v1_0.Connection_1_0;
-import org.apache.qpid.server.registry.ApplicationRegistry;
-import org.apache.qpid.server.registry.IApplicationRegistry;
import org.apache.qpid.server.security.SubjectCreator;
+import org.apache.qpid.server.virtualhost.VirtualHost;
import org.apache.qpid.transport.Sender;
import org.apache.qpid.transport.network.NetworkConnection;
@@ -54,7 +53,7 @@ public class ProtocolEngine_1_0_0_SASL implements ServerProtocolEngine, FrameOut
private long _lastReadTime;
private long _lastWriteTime;
- private final IApplicationRegistry _appRegistry;
+ private final Broker _broker;
private long _createTime = System.currentTimeMillis();
private ConnectionEndpoint _conn;
private long _connectionId;
@@ -113,12 +112,11 @@ public class ProtocolEngine_1_0_0_SASL implements ServerProtocolEngine, FrameOut
private State _state = State.A;
- public ProtocolEngine_1_0_0_SASL(final NetworkConnection networkDriver, final IApplicationRegistry appRegistry,
+ public ProtocolEngine_1_0_0_SASL(final NetworkConnection networkDriver, final Broker broker,
long id)
{
_connectionId = id;
- _appRegistry = appRegistry;
-
+ _broker = broker;
if(networkDriver != null)
{
setNetworkConnection(networkDriver, networkDriver.getSender());
@@ -161,15 +159,12 @@ public class ProtocolEngine_1_0_0_SASL implements ServerProtocolEngine, FrameOut
_network = network;
_sender = sender;
- Container container = new Container(_appRegistry.getBrokerId().toString());
+ Container container = new Container(_broker.getId().toString());
- _conn = new ConnectionEndpoint(container, asSaslServerProvider(ApplicationRegistry.getInstance()
- .getSubjectCreator(getLocalAddress())));
+ VirtualHost virtualHost = _broker.getVirtualHostRegistry().getVirtualHost((String)_broker.getAttribute(Broker.DEFAULT_VIRTUAL_HOST));
+ _conn = new ConnectionEndpoint(container, asSaslServerProvider(_broker.getSubjectCreator(getLocalAddress())));
_conn.setRemoteAddress(getRemoteAddress());
- _conn.setConnectionEventListener(new Connection_1_0(_appRegistry, _conn, _connectionId));
-
-
-
+ _conn.setConnectionEventListener(new Connection_1_0(virtualHost, _conn, _connectionId));
_conn.setFrameOutputHandler(this);
_conn.setSaslFrameOutput(this);
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/v1_0/Connection_1_0.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/v1_0/Connection_1_0.java
index f429d8ba9f..cf4164c244 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/v1_0/Connection_1_0.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/v1_0/Connection_1_0.java
@@ -31,7 +31,6 @@ import org.apache.qpid.protocol.AMQConstant;
import org.apache.qpid.server.logging.LogSubject;
import org.apache.qpid.server.protocol.AMQConnectionModel;
import org.apache.qpid.server.protocol.AMQSessionModel;
-import org.apache.qpid.server.registry.IApplicationRegistry;
import org.apache.qpid.server.stats.StatisticsCounter;
import org.apache.qpid.server.virtualhost.VirtualHost;
@@ -44,7 +43,6 @@ import static org.apache.qpid.server.logging.subjects.LogSubjectFormat.CONNECTIO
public class Connection_1_0 implements ConnectionEventListener
{
- private IApplicationRegistry _appRegistry;
private VirtualHost _vhost;
private final ConnectionEndpoint _conn;
private final long _connectionId;
@@ -62,10 +60,9 @@ public class Connection_1_0 implements ConnectionEventListener
- public Connection_1_0(IApplicationRegistry appRegistry, ConnectionEndpoint conn, long connectionId)
+ public Connection_1_0(VirtualHost virtualHost, ConnectionEndpoint conn, long connectionId)
{
- _appRegistry = appRegistry;
- _vhost = _appRegistry.getVirtualHostRegistry().getDefaultVirtualHost();
+ _vhost = virtualHost;
_conn = conn;
_connectionId = connectionId;
_vhost.getConnectionRegistry().registerConnection(_model);
@@ -74,7 +71,7 @@ public class Connection_1_0 implements ConnectionEventListener
public void remoteSessionCreation(SessionEndpoint endpoint)
{
- Session_1_0 session = new Session_1_0(_vhost, _appRegistry, this);
+ Session_1_0 session = new Session_1_0(_vhost, this);
_sessions.add(session);
endpoint.setSessionEventListener(session);
}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/v1_0/Session_1_0.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/v1_0/Session_1_0.java
index a019a4b78d..a0ed824c58 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/v1_0/Session_1_0.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/v1_0/Session_1_0.java
@@ -36,7 +36,6 @@ import org.apache.qpid.amqp_1_0.type.transport.*;
import org.apache.qpid.amqp_1_0.type.transport.Error;
import org.apache.qpid.AMQException;
import org.apache.qpid.AMQSecurityException;
-import org.apache.qpid.protocol.ProtocolEngine;
import org.apache.qpid.server.exchange.Exchange;
import org.apache.qpid.server.logging.LogSubject;
import org.apache.qpid.server.message.InboundMessage;
@@ -45,8 +44,6 @@ import org.apache.qpid.server.protocol.AMQConnectionModel;
import org.apache.qpid.server.protocol.AMQSessionModel;
import org.apache.qpid.server.queue.AMQQueue;
import org.apache.qpid.server.queue.AMQQueueFactory;
-import org.apache.qpid.server.registry.IApplicationRegistry;
-import org.apache.qpid.server.transport.ServerConnection;
import org.apache.qpid.server.txn.AutoCommitTransaction;
import org.apache.qpid.server.txn.ServerTransaction;
import org.apache.qpid.server.virtualhost.VirtualHost;
@@ -58,7 +55,6 @@ import static org.apache.qpid.server.logging.subjects.LogSubjectFormat.CHANNEL_F
public class Session_1_0 implements SessionEventListener, AMQSessionModel, LogSubject
{
private static final Symbol LIFETIME_POLICY = Symbol.valueOf("lifetime-policy");
- private IApplicationRegistry _appRegistry;
private VirtualHost _vhost;
private AutoCommitTransaction _transaction;
@@ -68,9 +64,8 @@ public class Session_1_0 implements SessionEventListener, AMQSessionModel, LogSu
private UUID _id = UUID.randomUUID();
- public Session_1_0(VirtualHost vhost, IApplicationRegistry appRegistry, final Connection_1_0 connection)
+ public Session_1_0(VirtualHost vhost, final Connection_1_0 connection)
{
- _appRegistry = appRegistry;
_vhost = vhost;
_transaction = new AutoCommitTransaction(vhost.getMessageStore());
_connection = connection;
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/AMQQueueFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/AMQQueueFactory.java
index 6a1c3bd893..a65a6a8eb2 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/AMQQueueFactory.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/AMQQueueFactory.java
@@ -30,13 +30,13 @@ import org.apache.qpid.AMQSecurityException;
import org.apache.qpid.exchange.ExchangeDefaults;
import org.apache.qpid.framing.AMQShortString;
import org.apache.qpid.framing.FieldTable;
+import org.apache.qpid.server.configuration.BrokerProperties;
import org.apache.qpid.server.configuration.QueueConfiguration;
-import org.apache.qpid.server.configuration.ServerConfiguration;
+import org.apache.qpid.server.exchange.DefaultExchangeFactory;
import org.apache.qpid.server.exchange.Exchange;
import org.apache.qpid.server.exchange.ExchangeFactory;
import org.apache.qpid.server.exchange.ExchangeRegistry;
import org.apache.qpid.server.model.UUIDGenerator;
-import org.apache.qpid.server.registry.ApplicationRegistry;
import org.apache.qpid.server.virtualhost.VirtualHost;
public class AMQQueueFactory
@@ -426,9 +426,7 @@ public class AMQQueueFactory
*/
protected static String getDeadLetterQueueName(String name)
{
- ServerConfiguration serverConfig = ApplicationRegistry.getInstance().getConfiguration();
- String dlQueueName = name + serverConfig.getDeadLetterQueueSuffix();
- return dlQueueName;
+ return name + System.getProperty(BrokerProperties.PROPERTY_DEAD_LETTER_QUEUE_SUFFIX, DEFAULT_DLQ_NAME_SUFFIX);
}
/**
@@ -440,9 +438,7 @@ public class AMQQueueFactory
*/
protected static String getDeadLetterExchangeName(String name)
{
- ServerConfiguration serverConfig = ApplicationRegistry.getInstance().getConfiguration();
- String dlExchangeName = name + serverConfig.getDeadLetterExchangeSuffix();
- return dlExchangeName;
+ return name + System.getProperty(BrokerProperties.PROPERTY_DEAD_LETTER_EXCHANGE_SUFFIX, DefaultExchangeFactory.DEFAULT_DLE_NAME_SUFFIX);
}
private static Map<String, Object> createQueueArgumentsFromConfig(QueueConfiguration config)
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/IncomingMessage.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/IncomingMessage.java
index c5a610c7b6..18affc7161 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/IncomingMessage.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/IncomingMessage.java
@@ -34,7 +34,6 @@ import org.apache.qpid.server.message.EnqueableMessage;
import org.apache.qpid.server.message.InboundMessage;
import org.apache.qpid.server.message.MessageContentSource;
import org.apache.qpid.server.message.MessageMetaData;
-import org.apache.qpid.server.registry.ApplicationRegistry;
import org.apache.qpid.server.store.StoredMessage;
import java.nio.ByteBuffer;
@@ -47,9 +46,6 @@ public class IncomingMessage implements Filterable, InboundMessage, EnqueableMes
/** Used for debugging purposes. */
private static final Logger _logger = Logger.getLogger(IncomingMessage.class);
- private static final boolean SYNCHED_CLOCKS =
- ApplicationRegistry.getInstance().getConfiguration().getSynchedClocks();
-
private final MessagePublishInfo _messagePublishInfo;
private ContentHeaderBody _contentHeaderBody;
@@ -101,33 +97,7 @@ public class IncomingMessage implements Filterable, InboundMessage, EnqueableMes
public void setExpiration()
{
- long expiration =
- ((BasicContentHeaderProperties) _contentHeaderBody.getProperties()).getExpiration();
- long timestamp =
- ((BasicContentHeaderProperties) _contentHeaderBody.getProperties()).getTimestamp();
-
- if (SYNCHED_CLOCKS)
- {
- _expiration = expiration;
- }
- else
- {
- // Update TTL to be in broker time.
- if (expiration != 0L)
- {
- if (timestamp != 0L)
- {
- // todo perhaps use arrival time
- long diff = (System.currentTimeMillis() - timestamp);
-
- if ((diff > 1000L) || (diff < 1000L))
- {
- _expiration = expiration + diff;
- }
- }
- }
- }
-
+ _expiration = ((BasicContentHeaderProperties) _contentHeaderBody.getProperties()).getExpiration();
}
public MessageMetaData headersReceived(long currentTime)
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/SimpleAMQQueue.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/SimpleAMQQueue.java
index beb566f622..73c2870b9b 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/SimpleAMQQueue.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/SimpleAMQQueue.java
@@ -52,7 +52,6 @@ import org.apache.qpid.server.logging.messages.QueueMessages;
import org.apache.qpid.server.logging.subjects.QueueLogSubject;
import org.apache.qpid.server.message.ServerMessage;
import org.apache.qpid.server.protocol.AMQSessionModel;
-import org.apache.qpid.server.registry.ApplicationRegistry;
import org.apache.qpid.server.security.AuthorizationHolder;
import org.apache.qpid.server.subscription.AssignedSubscriptionMessageGroupManager;
import org.apache.qpid.server.subscription.DefinedGroupMessageGroupManager;
@@ -132,23 +131,23 @@ public class SimpleAMQQueue implements AMQQueue, Subscription.StateListener, Mes
private final AtomicInteger _bindingCountHigh = new AtomicInteger();
/** max allowed size(KB) of a single message */
- private long _maximumMessageSize = ApplicationRegistry.getInstance().getConfiguration().getMaximumMessageSize();
+ private long _maximumMessageSize;
/** max allowed number of messages on a queue. */
- private long _maximumMessageCount = ApplicationRegistry.getInstance().getConfiguration().getMaximumMessageCount();
+ private long _maximumMessageCount;
/** max queue depth for the queue */
- private long _maximumQueueDepth = ApplicationRegistry.getInstance().getConfiguration().getMaximumQueueDepth();
+ private long _maximumQueueDepth;
/** maximum message age before alerts occur */
- private long _maximumMessageAge = ApplicationRegistry.getInstance().getConfiguration().getMaximumMessageAge();
+ private long _maximumMessageAge;
/** the minimum interval between sending out consecutive alerts of the same type */
- private long _minimumAlertRepeatGap = ApplicationRegistry.getInstance().getConfiguration().getMinimumAlertRepeatGap();
+ private long _minimumAlertRepeatGap;
- private long _capacity = ApplicationRegistry.getInstance().getConfiguration().getCapacity();
+ private long _capacity;
- private long _flowResumeCapacity = ApplicationRegistry.getInstance().getConfiguration().getFlowResumeCapacity();
+ private long _flowResumeCapacity;
private final Set<NotificationCheck> _notificationChecks = EnumSet.noneOf(NotificationCheck.class);
@@ -185,7 +184,7 @@ public class SimpleAMQQueue implements AMQQueue, Subscription.StateListener, Mes
private AbstractConfiguration _queueConfiguration;
/** the maximum delivery count for each message on this queue or 0 if maximum delivery count is not to be enforced. */
- private int _maximumDeliveryCount = ApplicationRegistry.getInstance().getConfiguration().getMaxDeliveryCount();
+ private int _maximumDeliveryCount;
private final MessageGroupManager _messageGroupManager;
private final Collection<SubscriptionRegistrationListener> _subscriptionListeners =
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/registry/ApplicationRegistry.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/registry/ApplicationRegistry.java
index c32e85b293..995951a462 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/registry/ApplicationRegistry.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/registry/ApplicationRegistry.java
@@ -20,44 +20,39 @@
*/
package org.apache.qpid.server.registry;
-import org.apache.commons.configuration.Configuration;
-import org.apache.commons.configuration.ConfigurationException;
-import org.apache.log4j.Logger;
-import org.apache.qpid.server.logging.*;
+import java.util.Collection;
+import java.util.Timer;
+import java.util.TimerTask;
+import org.apache.log4j.Logger;
import org.apache.qpid.common.Closeable;
import org.apache.qpid.common.QpidProperties;
-import org.apache.qpid.server.configuration.ServerConfiguration;
-import org.apache.qpid.server.configuration.VirtualHostConfiguration;
+import org.apache.qpid.server.configuration.BrokerProperties;
+import org.apache.qpid.server.configuration.ConfigurationEntryStore;
+import org.apache.qpid.server.configuration.ConfiguredObjectRecoverer;
+import org.apache.qpid.server.configuration.RecovererProvider;
+import org.apache.qpid.server.configuration.startup.DefaultRecovererProvider;
+import org.apache.qpid.server.logging.CompositeStartupMessageLogger;
+import org.apache.qpid.server.logging.Log4jMessageLogger;
+import org.apache.qpid.server.logging.LogActor;
+import org.apache.qpid.server.logging.LogRecorder;
+import org.apache.qpid.server.logging.RootMessageLogger;
+import org.apache.qpid.server.logging.SystemOutMessageLogger;
import org.apache.qpid.server.logging.actors.AbstractActor;
import org.apache.qpid.server.logging.actors.BrokerActor;
import org.apache.qpid.server.logging.actors.CurrentActor;
+import org.apache.qpid.server.logging.actors.GenericActor;
import org.apache.qpid.server.logging.messages.BrokerMessages;
import org.apache.qpid.server.logging.messages.VirtualHostMessages;
-import org.apache.qpid.server.management.plugin.ManagementPlugin;
import org.apache.qpid.server.model.Broker;
-import org.apache.qpid.server.model.adapter.BrokerAdapter;
-import org.apache.qpid.server.plugin.GroupManagerFactory;
-import org.apache.qpid.server.plugin.ManagementFactory;
-import org.apache.qpid.server.plugin.QpidServiceLoader;
-import org.apache.qpid.server.security.SecurityManager;
-import org.apache.qpid.server.security.SubjectCreator;
-import org.apache.qpid.server.security.auth.manager.AuthenticationManager;
-import org.apache.qpid.server.security.auth.manager.AuthenticationManagerRegistry;
-import org.apache.qpid.server.security.auth.manager.IAuthenticationManagerRegistry;
-import org.apache.qpid.server.security.group.GroupManager;
-import org.apache.qpid.server.security.group.GroupPrincipalAccessor;
+import org.apache.qpid.server.model.ConfiguredObject;
+import org.apache.qpid.server.model.State;
+import org.apache.qpid.server.configuration.updater.TaskExecutor;
import org.apache.qpid.server.stats.StatisticsCounter;
-import org.apache.qpid.server.transport.QpidAcceptor;
+import org.apache.qpid.server.stats.StatisticsGatherer;
import org.apache.qpid.server.virtualhost.VirtualHost;
-import org.apache.qpid.server.virtualhost.VirtualHostImpl;
import org.apache.qpid.server.virtualhost.VirtualHostRegistry;
-import java.net.InetSocketAddress;
-import java.net.SocketAddress;
-import java.util.*;
-import java.util.concurrent.atomic.AtomicReference;
-
/**
* An abstract application registry that provides access to configuration information and handles the
@@ -69,307 +64,86 @@ public class ApplicationRegistry implements IApplicationRegistry
{
private static final Logger _logger = Logger.getLogger(ApplicationRegistry.class);
- private static AtomicReference<IApplicationRegistry> _instance = new AtomicReference<IApplicationRegistry>(null);
-
- private final ServerConfiguration _configuration;
-
- private final Map<InetSocketAddress, QpidAcceptor> _acceptors =
- Collections.synchronizedMap(new HashMap<InetSocketAddress, QpidAcceptor>());
-
- private IAuthenticationManagerRegistry _authenticationManagerRegistry;
-
- private final VirtualHostRegistry _virtualHostRegistry = new VirtualHostRegistry(this);
-
- private SecurityManager _securityManager;
+ private final VirtualHostRegistry _virtualHostRegistry = new VirtualHostRegistry();
private volatile RootMessageLogger _rootMessageLogger;
- private CompositeStartupMessageLogger _startupMessageLogger;
-
private Broker _broker;
private Timer _reportingTimer;
private StatisticsCounter _messagesDelivered, _dataDelivered, _messagesReceived, _dataReceived;
- private final List<PortBindingListener> _portBindingListeners = new ArrayList<PortBindingListener>();
-
- private int _httpManagementPort = -1, _httpsManagementPort = -1;
-
private LogRecorder _logRecorder;
- private List<IAuthenticationManagerRegistry.RegistryChangeListener> _authManagerChangeListeners =
- new ArrayList<IAuthenticationManagerRegistry.RegistryChangeListener>();
-
- private List<GroupManagerChangeListener> _groupManagerChangeListeners =
- new ArrayList<GroupManagerChangeListener>();
-
- private List<GroupManager> _groupManagerList = new ArrayList<GroupManager>();
-
- private QpidServiceLoader<GroupManagerFactory> _groupManagerServiceLoader = new QpidServiceLoader<GroupManagerFactory>();
-
- private final List<ManagementPlugin> _managmentInstanceList = new ArrayList<ManagementPlugin>();
-
- public Map<InetSocketAddress, QpidAcceptor> getAcceptors()
- {
- synchronized (_acceptors)
- {
- return new HashMap<InetSocketAddress, QpidAcceptor>(_acceptors);
- }
- }
-
- protected void setSecurityManager(SecurityManager securityManager)
- {
- _securityManager = securityManager;
- }
+ private ConfigurationEntryStore _store;
+ private TaskExecutor _taskExecutor;
protected void setRootMessageLogger(RootMessageLogger rootMessageLogger)
{
_rootMessageLogger = rootMessageLogger;
}
- protected CompositeStartupMessageLogger getStartupMessageLogger()
- {
- return _startupMessageLogger;
- }
-
- protected void setStartupMessageLogger(CompositeStartupMessageLogger startupMessageLogger)
+ public ApplicationRegistry(ConfigurationEntryStore store)
{
- _startupMessageLogger = startupMessageLogger;
- }
-
- public static void initialise(IApplicationRegistry instance) throws Exception
- {
- if(instance == null)
- {
- throw new IllegalArgumentException("ApplicationRegistry instance must not be null");
- }
-
- if(!_instance.compareAndSet(null, instance))
- {
- throw new IllegalStateException("An ApplicationRegistry is already initialised");
- }
-
- _logger.info("Initialising Application Registry(" + instance + ")");
-
-
- try
- {
- instance.initialise();
- }
- catch (Exception e)
- {
- _instance.set(null);
-
- //remove the Broker instance, then re-throw
-
- throw e;
- }
- }
-
- public static boolean isConfigured()
- {
- return _instance.get() != null;
- }
-
- public static void remove()
- {
- IApplicationRegistry instance = _instance.getAndSet(null);
- try
- {
- if (instance != null)
- {
- if (_logger.isInfoEnabled())
- {
- _logger.info("Shutting down ApplicationRegistry(" + instance + ")");
- }
- instance.close();
- }
- }
- catch (Exception e)
- {
- _logger.error("Error shutting down Application Registry(" + instance + "): " + e, e);
- }
- }
-
- public ApplicationRegistry(ServerConfiguration configuration)
- {
- _configuration = configuration;
+ _store = store;
+ initialiseStatistics();
}
public void initialise() throws Exception
{
+ // Create the RootLogger to be used during broker operation
+ boolean statusUpdatesEnabled = Boolean.parseBoolean(System.getProperty(BrokerProperties.PROPERTY_STATUS_UPDATES, "true"));
+ _rootMessageLogger = new Log4jMessageLogger(statusUpdatesEnabled);
+
_logRecorder = new LogRecorder();
- //Create the RootLogger to be used during broker operation
- _rootMessageLogger = new Log4jMessageLogger(_configuration);
//Create the composite (log4j+SystemOut MessageLogger to be used during startup
RootMessageLogger[] messageLoggers = {new SystemOutMessageLogger(), _rootMessageLogger};
- _startupMessageLogger = new CompositeStartupMessageLogger(messageLoggers);
+ CompositeStartupMessageLogger startupMessageLogger = new CompositeStartupMessageLogger(messageLoggers);
- BrokerActor actor = new BrokerActor(_startupMessageLogger);
- CurrentActor.setDefault(actor);
+ BrokerActor actor = new BrokerActor(startupMessageLogger);
CurrentActor.set(actor);
-
+ CurrentActor.setDefault(actor);
+ GenericActor.setDefaultMessageLogger(_rootMessageLogger);
try
{
- initialiseStatistics();
-
- if(_configuration.getHTTPManagementEnabled())
- {
- _httpManagementPort = _configuration.getHTTPManagementPort();
- }
- if (_configuration.getHTTPSManagementEnabled())
- {
- _httpsManagementPort = _configuration.getHTTPSManagementPort();
- }
-
- _broker = new BrokerAdapter(this);
-
- _configuration.initialise();
logStartupMessages(CurrentActor.get());
- // Management needs to be registered so that JMXManagement.childAdded can create optional management objects
- createAndStartManagementPlugins(_configuration, _broker);
+ _taskExecutor = new TaskExecutor();
+ _taskExecutor.start();
- _securityManager = new SecurityManager(_configuration.getConfig());
+ RecovererProvider provider = new DefaultRecovererProvider((StatisticsGatherer)this, _virtualHostRegistry, _logRecorder, _rootMessageLogger, _taskExecutor);
+ ConfiguredObjectRecoverer<? extends ConfiguredObject> brokerRecoverer = provider.getRecoverer(Broker.class.getSimpleName());
+ _broker = (Broker) brokerRecoverer.create(provider, _store.getRootEntry());
- _groupManagerList = createGroupManagers(_configuration);
+ _virtualHostRegistry.setDefaultVirtualHostName((String)_broker.getAttribute(Broker.DEFAULT_VIRTUAL_HOST));
- _authenticationManagerRegistry = createAuthenticationManagerRegistry(_configuration, new GroupPrincipalAccessor(_groupManagerList));
+ initialiseStatisticsReporting();
- if(!_authManagerChangeListeners.isEmpty())
- {
- for(IAuthenticationManagerRegistry.RegistryChangeListener listener : _authManagerChangeListeners)
- {
+ // starting the broker
+ _broker.setDesiredState(State.INITIALISING, State.ACTIVE);
- _authenticationManagerRegistry.addRegistryChangeListener(listener);
- for(AuthenticationManager authMgr : _authenticationManagerRegistry.getAvailableAuthenticationManagers().values())
- {
- listener.authenticationManagerRegistered(authMgr);
- }
- }
- _authManagerChangeListeners.clear();
- }
+ CurrentActor.get().message(BrokerMessages.READY());
}
finally
{
CurrentActor.remove();
}
- CurrentActor.set(new BrokerActor(_rootMessageLogger));
- try
- {
- initialiseVirtualHosts();
- initialiseStatisticsReporting();
- }
- finally
- {
- // Startup complete, so pop the current actor
- CurrentActor.remove();
- }
+ CurrentActor.setDefault(new BrokerActor(_rootMessageLogger));
}
- private void createAndStartManagementPlugins(ServerConfiguration configuration, Broker broker) throws Exception
+ private void initialiseStatisticsReporting()
{
- QpidServiceLoader<ManagementFactory> factories = new QpidServiceLoader<ManagementFactory>();
- for (ManagementFactory managementFactory: factories.instancesOf(ManagementFactory.class))
- {
- ManagementPlugin managementPlugin = managementFactory.createInstance(configuration, broker);
- if(managementPlugin != null)
- {
- try
- {
- managementPlugin.start();
- }
- catch(Exception e)
- {
- _logger.error("Management plugin " + managementPlugin.getClass().getSimpleName() + " failed to start normally, stopping it now", e);
- managementPlugin.stop();
- throw e;
- }
-
- _managmentInstanceList.add(managementPlugin);
- }
- }
-
- if (_logger.isDebugEnabled())
- {
- _logger.debug("Configured " + _managmentInstanceList.size() + " management instance(s)");
- }
- }
-
- private void closeAllManagementPlugins()
- {
- for (ManagementPlugin managementPlugin : _managmentInstanceList)
- {
- try
- {
- managementPlugin.stop();
- }
- catch (Exception e)
- {
- _logger.error("Exception thrown whilst stopping management plugin " + managementPlugin.getClass().getSimpleName(), e);
- }
- }
- }
-
- private List<GroupManager> createGroupManagers(ServerConfiguration configuration) throws ConfigurationException
- {
- List<GroupManager> groupManagerList = new ArrayList<GroupManager>();
- Configuration securityConfig = configuration.getConfig().subset("security");
-
- for(GroupManagerFactory factory : _groupManagerServiceLoader.instancesOf(GroupManagerFactory.class))
- {
- GroupManager groupManager = factory.createInstance(securityConfig);
- if (groupManager != null)
- {
- groupManagerList.add(groupManager);
- for(GroupManagerChangeListener listener : _groupManagerChangeListeners)
- {
- listener.groupManagerRegistered(groupManager);
- }
- }
- }
-
- if (_logger.isDebugEnabled())
- {
- _logger.debug("Configured " + groupManagerList.size() + " group manager(s)");
- }
- return groupManagerList;
- }
-
- protected IAuthenticationManagerRegistry createAuthenticationManagerRegistry(ServerConfiguration configuration, GroupPrincipalAccessor groupPrincipalAccessor)
- throws ConfigurationException
- {
- return new AuthenticationManagerRegistry(configuration, groupPrincipalAccessor);
- }
-
- protected void initialiseVirtualHosts() throws Exception
- {
- for (String name : _configuration.getVirtualHosts())
- {
- createVirtualHost(_configuration.getVirtualHostConfig(name));
- }
- getVirtualHostRegistry().setDefaultVirtualHostName(_configuration.getDefaultVirtualHost());
- }
-
- public void initialiseStatisticsReporting()
- {
- long report = _configuration.getStatisticsReportingPeriod() * 1000; // convert to ms
- final boolean broker = _configuration.isStatisticsGenerationBrokerEnabled();
- final boolean virtualhost = _configuration.isStatisticsGenerationVirtualhostsEnabled();
- final boolean reset = _configuration.isStatisticsReportResetEnabled();
+ long report = ((Number)_broker.getAttribute(Broker.STATISTICS_REPORTING_PERIOD)).intValue() * 1000; // convert to ms
+ final boolean reset = (Boolean)_broker.getAttribute(Broker.STATISTICS_REPORTING_RESET_ENABLED);
/* add a timer task to report statistics if generation is enabled for broker or virtualhosts */
- if (report > 0L && (broker || virtualhost))
+ if (report > 0L)
{
_reportingTimer = new Timer("Statistics-Reporting", true);
-
-
-
- _reportingTimer.scheduleAtFixedRate(new StatisticsReportingTask(broker, virtualhost, reset),
- report / 2,
- report);
+ StatisticsReportingTask task = new StatisticsReportingTask(reset, _rootMessageLogger);
+ _reportingTimer.scheduleAtFixedRate(task, report / 2, report);
}
}
@@ -378,76 +152,62 @@ public class ApplicationRegistry implements IApplicationRegistry
private final int DELIVERED = 0;
private final int RECEIVED = 1;
- private boolean _broker;
- private boolean _virtualhost;
- private boolean _reset;
-
+ private final boolean _reset;
+ private final RootMessageLogger _logger;
- public StatisticsReportingTask(boolean broker, boolean virtualhost, boolean reset)
+ public StatisticsReportingTask(boolean reset, RootMessageLogger logger)
{
- _broker = broker;
- _virtualhost = virtualhost;
_reset = reset;
+ _logger = logger;
}
public void run()
{
- CurrentActor.set(new AbstractActor(ApplicationRegistry.getInstance().getRootMessageLogger()) {
+ CurrentActor.set(new AbstractActor(_logger)
+ {
public String getLogMessage()
{
return "[" + Thread.currentThread().getName() + "] ";
}
});
-
- if (_broker)
+ try
{
CurrentActor.get().message(BrokerMessages.STATS_DATA(DELIVERED, _dataDelivered.getPeak() / 1024.0, _dataDelivered.getTotal()));
CurrentActor.get().message(BrokerMessages.STATS_MSGS(DELIVERED, _messagesDelivered.getPeak(), _messagesDelivered.getTotal()));
CurrentActor.get().message(BrokerMessages.STATS_DATA(RECEIVED, _dataReceived.getPeak() / 1024.0, _dataReceived.getTotal()));
CurrentActor.get().message(BrokerMessages.STATS_MSGS(RECEIVED, _messagesReceived.getPeak(), _messagesReceived.getTotal()));
- }
+ Collection<VirtualHost> hosts = _virtualHostRegistry.getVirtualHosts();
- if (_virtualhost)
- {
- for (VirtualHost vhost : getVirtualHostRegistry().getVirtualHosts())
+ if (hosts.size() > 1)
{
- String name = vhost.getName();
- StatisticsCounter dataDelivered = vhost.getDataDeliveryStatistics();
- StatisticsCounter messagesDelivered = vhost.getMessageDeliveryStatistics();
- StatisticsCounter dataReceived = vhost.getDataReceiptStatistics();
- StatisticsCounter messagesReceived = vhost.getMessageReceiptStatistics();
-
- CurrentActor.get().message(VirtualHostMessages.STATS_DATA(name, DELIVERED, dataDelivered.getPeak() / 1024.0, dataDelivered.getTotal()));
- CurrentActor.get().message(VirtualHostMessages.STATS_MSGS(name, DELIVERED, messagesDelivered.getPeak(), messagesDelivered.getTotal()));
- CurrentActor.get().message(VirtualHostMessages.STATS_DATA(name, RECEIVED, dataReceived.getPeak() / 1024.0, dataReceived.getTotal()));
- CurrentActor.get().message(VirtualHostMessages.STATS_MSGS(name, RECEIVED, messagesReceived.getPeak(), messagesReceived.getTotal()));
+ for (VirtualHost vhost : hosts)
+ {
+ String name = vhost.getName();
+ StatisticsCounter dataDelivered = vhost.getDataDeliveryStatistics();
+ StatisticsCounter messagesDelivered = vhost.getMessageDeliveryStatistics();
+ StatisticsCounter dataReceived = vhost.getDataReceiptStatistics();
+ StatisticsCounter messagesReceived = vhost.getMessageReceiptStatistics();
+
+ CurrentActor.get().message(VirtualHostMessages.STATS_DATA(name, DELIVERED, dataDelivered.getPeak() / 1024.0, dataDelivered.getTotal()));
+ CurrentActor.get().message(VirtualHostMessages.STATS_MSGS(name, DELIVERED, messagesDelivered.getPeak(), messagesDelivered.getTotal()));
+ CurrentActor.get().message(VirtualHostMessages.STATS_DATA(name, RECEIVED, dataReceived.getPeak() / 1024.0, dataReceived.getTotal()));
+ CurrentActor.get().message(VirtualHostMessages.STATS_MSGS(name, RECEIVED, messagesReceived.getPeak(), messagesReceived.getTotal()));
+ }
}
- }
- if (_reset)
+ if (_reset)
+ {
+ resetStatistics();
+ }
+ }
+ catch(Exception e)
{
- resetStatistics();
+ ApplicationRegistry._logger.warn("Unexpected exception occured while reporting the statistics", e);
+ }
+ finally
+ {
+ CurrentActor.remove();
}
-
- CurrentActor.remove();
- }
- }
-
- /**
- * Get the ApplicationRegistry
- * @return the IApplicationRegistry instance
- * @throws IllegalStateException if no registry instance has been initialised.
- */
- public static IApplicationRegistry getInstance() throws IllegalStateException
- {
- IApplicationRegistry iApplicationRegistry = _instance.get();
- if (iApplicationRegistry == null)
- {
- throw new IllegalStateException("No ApplicationRegistry has been initialised");
- }
- else
- {
- return iApplicationRegistry;
}
}
@@ -478,7 +238,7 @@ public class ApplicationRegistry implements IApplicationRegistry
}
//Set the Actor for Broker Shutdown
- CurrentActor.set(new BrokerActor(getRootMessageLogger()));
+ CurrentActor.set(new BrokerActor(_rootMessageLogger));
try
{
//Stop Statistics Reporting
@@ -487,128 +247,34 @@ public class ApplicationRegistry implements IApplicationRegistry
_reportingTimer.cancel();
}
- //Stop incoming connections
- unbind();
+ if (_broker != null)
+ {
+ _broker.setDesiredState(_broker.getActualState(), State.STOPPED);
+ }
//Shutdown virtualhosts
close(_virtualHostRegistry);
- close(_authenticationManagerRegistry);
+ if (_taskExecutor != null)
+ {
+ _taskExecutor.stop();
+ }
CurrentActor.get().message(BrokerMessages.STOPPED());
_logRecorder.closeLogRecorder();
- closeAllManagementPlugins();
}
finally
{
- CurrentActor.remove();
- }
- }
-
- private void unbind()
- {
- List<QpidAcceptor> removedAcceptors = new ArrayList<QpidAcceptor>();
- synchronized (_acceptors)
- {
- for (InetSocketAddress bindAddress : _acceptors.keySet())
- {
- QpidAcceptor acceptor = _acceptors.get(bindAddress);
-
- removedAcceptors.add(acceptor);
- try
- {
- acceptor.getNetworkTransport().close();
- }
- catch (Throwable e)
- {
- _logger.error("Unable to close network driver due to:" + e.getMessage());
- }
-
- CurrentActor.get().message(BrokerMessages.SHUTTING_DOWN(acceptor.toString(), bindAddress.getPort()));
- }
- }
- synchronized (_portBindingListeners)
- {
- for(QpidAcceptor acceptor : removedAcceptors)
+ if (_taskExecutor != null)
{
- for(PortBindingListener listener : _portBindingListeners)
- {
- listener.unbound(acceptor);
- }
- }
- }
- }
-
- public ServerConfiguration getConfiguration()
- {
- return _configuration;
- }
-
- public void addAcceptor(InetSocketAddress bindAddress, QpidAcceptor acceptor)
- {
- synchronized (_acceptors)
- {
- _acceptors.put(bindAddress, acceptor);
- }
- synchronized (_portBindingListeners)
- {
- for(PortBindingListener listener : _portBindingListeners)
- {
- listener.bound(acceptor, bindAddress);
+ _taskExecutor.stopImmediately();
}
+ CurrentActor.remove();
}
- }
-
- public VirtualHostRegistry getVirtualHostRegistry()
- {
- return _virtualHostRegistry;
- }
-
- public SecurityManager getSecurityManager()
- {
- return _securityManager;
- }
-
- @Override
- public SubjectCreator getSubjectCreator(SocketAddress localAddress)
- {
- return _authenticationManagerRegistry.getSubjectCreator(localAddress);
- }
-
- @Override
- public IAuthenticationManagerRegistry getAuthenticationManagerRegistry()
- {
- return _authenticationManagerRegistry;
- }
-
- @Override
- public List<GroupManager> getGroupManagers()
- {
- return _groupManagerList;
- }
-
- public RootMessageLogger getRootMessageLogger()
- {
- return _rootMessageLogger;
- }
-
- public RootMessageLogger getCompositeStartupMessageLogger()
- {
- return _startupMessageLogger;
- }
-
- public UUID getBrokerId()
- {
- return getBroker().getId();
- }
-
- public VirtualHost createVirtualHost(final VirtualHostConfiguration vhostConfig) throws Exception
- {
- VirtualHostImpl virtualHost = new VirtualHostImpl(this, vhostConfig);
- _virtualHostRegistry.registerVirtualHost(virtualHost);
- return virtualHost;
+ _store = null;
+ _broker = null;
}
public void registerMessageDelivered(long messageSize)
@@ -677,66 +343,4 @@ public class ApplicationRegistry implements IApplicationRegistry
logActor.message(BrokerMessages.MAX_MEMORY(Runtime.getRuntime().maxMemory()));
}
- public Broker getBroker()
- {
- return _broker;
- }
-
- @Override
- public void addPortBindingListener(PortBindingListener listener)
- {
- synchronized (_portBindingListeners)
- {
- _portBindingListeners.add(listener);
- }
- }
-
-
- @Override
- public boolean useHTTPManagement()
- {
- return _httpManagementPort != -1;
- }
-
- @Override
- public int getHTTPManagementPort()
- {
- return _httpManagementPort;
- }
-
- @Override
- public boolean useHTTPSManagement()
- {
- return _httpsManagementPort != -1;
- }
-
- @Override
- public int getHTTPSManagementPort()
- {
- return _httpsManagementPort;
- }
-
- public LogRecorder getLogRecorder()
- {
- return _logRecorder;
- }
-
- @Override
- public void addAuthenticationManagerRegistryChangeListener(IAuthenticationManagerRegistry.RegistryChangeListener registryChangeListener)
- {
- if(_authenticationManagerRegistry == null)
- {
- _authManagerChangeListeners.add(registryChangeListener);
- }
- else
- {
- _authenticationManagerRegistry.addRegistryChangeListener(registryChangeListener);
- }
- }
-
- @Override
- public void addGroupManagerChangeListener(GroupManagerChangeListener groupManagerChangeListener)
- {
- _groupManagerChangeListeners.add(groupManagerChangeListener);
- }
}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/registry/IApplicationRegistry.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/registry/IApplicationRegistry.java
index 8cdb576f76..0f9ddbfb59 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/registry/IApplicationRegistry.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/registry/IApplicationRegistry.java
@@ -20,25 +20,7 @@
*/
package org.apache.qpid.server.registry;
-import org.apache.qpid.server.configuration.ServerConfiguration;
-import org.apache.qpid.server.configuration.VirtualHostConfiguration;
-import org.apache.qpid.server.logging.RootMessageLogger;
-import org.apache.qpid.server.model.Broker;
-import org.apache.qpid.server.security.SecurityManager;
-import org.apache.qpid.server.security.SubjectCreator;
-import org.apache.qpid.server.security.auth.manager.AuthenticationManager;
-import org.apache.qpid.server.security.auth.manager.IAuthenticationManagerRegistry;
-import org.apache.qpid.server.security.group.GroupManager;
import org.apache.qpid.server.stats.StatisticsGatherer;
-import org.apache.qpid.server.transport.QpidAcceptor;
-import org.apache.qpid.server.virtualhost.VirtualHost;
-import org.apache.qpid.server.virtualhost.VirtualHostRegistry;
-
-import java.net.InetSocketAddress;
-import java.net.SocketAddress;
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
public interface IApplicationRegistry extends StatisticsGatherer
{
@@ -54,71 +36,4 @@ public interface IApplicationRegistry extends StatisticsGatherer
*/
void close();
- /**
- * Get the low level configuration. For use cases where the configured object approach is not required
- * you can get the complete configuration information.
- * @return a Commons Configuration instance
- */
- ServerConfiguration getConfiguration();
-
- /**
- * Get the SubjectCreator for the given socket address.
- *
- * @param address The (listening) socket address for which the AuthenticationManager is required
- */
- SubjectCreator getSubjectCreator(SocketAddress localAddress);
-
- IAuthenticationManagerRegistry getAuthenticationManagerRegistry();
-
- List<GroupManager> getGroupManagers();
-
- VirtualHostRegistry getVirtualHostRegistry();
-
- SecurityManager getSecurityManager();
-
- RootMessageLogger getRootMessageLogger();
-
- /**
- * Register any acceptors for this registry
- * @param bindAddress The address that the acceptor has been bound with
- * @param acceptor The acceptor in use
- */
- void addAcceptor(InetSocketAddress bindAddress, QpidAcceptor acceptor);
-
- public UUID getBrokerId();
-
- Broker getBroker();
-
- VirtualHost createVirtualHost(VirtualHostConfiguration vhostConfig) throws Exception;
-
- void initialiseStatisticsReporting();
-
- Map<InetSocketAddress, QpidAcceptor> getAcceptors();
-
- void addPortBindingListener(PortBindingListener listener);
-
- boolean useHTTPManagement();
-
- int getHTTPManagementPort();
-
- boolean useHTTPSManagement();
-
- int getHTTPSManagementPort();
-
- void addAuthenticationManagerRegistryChangeListener(IAuthenticationManagerRegistry.RegistryChangeListener registryChangeListener);
-
- public interface PortBindingListener
- {
- public void bound(QpidAcceptor acceptor, InetSocketAddress bindAddress);
- public void unbound(QpidAcceptor acceptor);
-
- }
-
- void addGroupManagerChangeListener(GroupManagerChangeListener groupManagerChangeListener);
-
- public static interface GroupManagerChangeListener
- {
- void groupManagerRegistered(GroupManager groupManager);
- void groupManagerUnregistered(GroupManager groupManager);
- }
}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/SecurityManager.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/SecurityManager.java
index 6099d11c46..1a1cce171b 100755
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/SecurityManager.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/SecurityManager.java
@@ -18,8 +18,6 @@
*/
package org.apache.qpid.server.security;
-import org.apache.commons.configuration.Configuration;
-import org.apache.commons.configuration.ConfigurationException;
import org.apache.log4j.Logger;
import org.apache.qpid.framing.AMQShortString;
@@ -122,21 +120,21 @@ public class SecurityManager
/*
* Used by the VirtualHost to allow deferring to the broker level security plugins if required.
*/
- public SecurityManager(SecurityManager parent, Configuration config) throws ConfigurationException
+ public SecurityManager(SecurityManager parent, String aclFile)
{
- this(config);
+ this(aclFile);
// our global plugins are the parent's host plugins
_globalPlugins = parent._hostPlugins;
}
- public SecurityManager(Configuration config) throws ConfigurationException
+ public SecurityManager(String aclFile)
{
- Configuration securityConfig = config.subset("security");
-
+ Map<String, Object> attributes = new HashMap<String, Object>();
+ attributes.put("aclFile", aclFile);
for (AccessControlFactory provider : (new QpidServiceLoader<AccessControlFactory>()).instancesOf(AccessControlFactory.class))
{
- AccessControl accessControl = provider.createInstance(securityConfig);
+ AccessControl accessControl = provider.createInstance(attributes);
if(accessControl != null)
{
addHostPlugin(accessControl);
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/AbstractPrincipalDatabaseAuthManagerFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/AbstractPrincipalDatabaseAuthManagerFactory.java
new file mode 100644
index 0000000000..ff21d63c87
--- /dev/null
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/AbstractPrincipalDatabaseAuthManagerFactory.java
@@ -0,0 +1,71 @@
+/*
+ * 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.qpid.server.security.auth.manager;
+
+import java.io.IOException;
+import java.util.Map;
+
+import org.apache.log4j.Logger;
+import org.apache.qpid.server.plugin.AuthenticationManagerFactory;
+import org.apache.qpid.server.security.auth.database.PrincipalDatabase;
+
+/**
+ * Factory for {@link PrincipalDatabaseAuthenticationManager} objects configured
+ * with either the Plain or Base64MD5 digest {@link PrincipalDatabase}
+ * implementation.
+ */
+public abstract class AbstractPrincipalDatabaseAuthManagerFactory implements AuthenticationManagerFactory
+{
+ public static final String ATTRIBUTE_PATH = "path";
+
+ private static final Logger LOGGER = Logger.getLogger(AbstractPrincipalDatabaseAuthManagerFactory.class);
+
+ @Override
+ public AuthenticationManager createInstance(Map<String, Object> attributes)
+ {
+ if (attributes == null || !getType().equals(attributes.get(ATTRIBUTE_TYPE)))
+ {
+ return null;
+ }
+
+ String passwordFile = (String) attributes.get(ATTRIBUTE_PATH);
+ if (passwordFile == null)
+ {
+ LOGGER.warn("Password file path must not be null");
+ return null;
+ }
+
+ PrincipalDatabase principalDatabase = createPrincipalDatabase();
+ try
+ {
+ principalDatabase.setPasswordFile(passwordFile);
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException(e.getMessage(), e);
+ }
+
+ return new PrincipalDatabaseAuthenticationManager(principalDatabase);
+ }
+
+ abstract String getType();
+
+ abstract PrincipalDatabase createPrincipalDatabase();
+}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/AnonymousAuthenticationManagerFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/AnonymousAuthenticationManagerFactory.java
index 1dabb3d203..1b1995500c 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/AnonymousAuthenticationManagerFactory.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/AnonymousAuthenticationManagerFactory.java
@@ -19,20 +19,22 @@
*/
package org.apache.qpid.server.security.auth.manager;
-import org.apache.commons.configuration.Configuration;
+import java.util.Map;
+
import org.apache.qpid.server.plugin.AuthenticationManagerFactory;
public class AnonymousAuthenticationManagerFactory implements AuthenticationManagerFactory
{
+ public static final String PROVIDER_TYPE = AnonymousAuthenticationManager.class.getSimpleName();
+
@Override
- public AuthenticationManager createInstance(Configuration configuration)
+ public AuthenticationManager createInstance(Map<String, Object> attributes)
{
- if (configuration.subset("anonymous-auth-manager").isEmpty())
+ if (attributes != null && PROVIDER_TYPE.equals(attributes.get(ATTRIBUTE_TYPE)))
{
- return null;
+ return new AnonymousAuthenticationManager();
}
-
- return new AnonymousAuthenticationManager();
+ return null;
}
}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/AuthenticationManagerRegistry.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/AuthenticationManagerRegistry.java
deleted file mode 100644
index 0f311e9aca..0000000000
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/AuthenticationManagerRegistry.java
+++ /dev/null
@@ -1,208 +0,0 @@
-/*
- * 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.qpid.server.security.auth.manager;
-
-import java.net.InetSocketAddress;
-import java.net.SocketAddress;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.commons.configuration.Configuration;
-import org.apache.commons.configuration.ConfigurationException;
-import org.apache.qpid.common.Closeable;
-import org.apache.qpid.server.configuration.ServerConfiguration;
-import org.apache.qpid.server.plugin.AuthenticationManagerFactory;
-import org.apache.qpid.server.plugin.QpidServiceLoader;
-import org.apache.qpid.server.security.SubjectCreator;
-import org.apache.qpid.server.security.group.GroupPrincipalAccessor;
-
-/**
- * A concrete implementation of {@link IAuthenticationManagerRegistry} that registers all {@link AuthenticationManager}
- * instances defined in the configuration, building an optional mapping between port number and AuthenticationManager.
- *
- * <p>The default AuthenticationManager is either the one nominated as default within the configuration with
- * {@link ServerConfiguration#getDefaultAuthenticationManager()}, or if there is only one, it is implicitly
- * the default.</p>
- *
- * <p>It is important to {@link #close()} the registry after use and this allows the AuthenticationManagers
- * to reverse any security registrations they have performed.</p>
- */
-public class AuthenticationManagerRegistry implements Closeable, IAuthenticationManagerRegistry
-{
- private final Map<String,AuthenticationManager> _classToAuthManagerMap = new HashMap<String,AuthenticationManager>();
- private final SubjectCreator _defaultSubjectCreator;
- private final Map<Integer, SubjectCreator> _portToSubjectCreatorMap;
- private final List<RegistryChangeListener> _listeners =
- Collections.synchronizedList(new ArrayList<RegistryChangeListener>());
- private final QpidServiceLoader<AuthenticationManagerFactory> _authManagerFactoryServiceLoader;
-
- public AuthenticationManagerRegistry(ServerConfiguration serverConfiguration, GroupPrincipalAccessor groupPrincipalAccessor)
- throws ConfigurationException
- {
- this(serverConfiguration, groupPrincipalAccessor, new QpidServiceLoader<AuthenticationManagerFactory>());
- }
-
- // Exists as separate constructor for unit testing purposes
- AuthenticationManagerRegistry(ServerConfiguration serverConfiguration, GroupPrincipalAccessor groupPrincipalAccessor, QpidServiceLoader<AuthenticationManagerFactory> authManagerFactoryServiceLoader)
- throws ConfigurationException
- {
- _authManagerFactoryServiceLoader = authManagerFactoryServiceLoader;
-
- boolean willClose = true;
- try
- {
- createAuthManagers(serverConfiguration.getConfig());
-
- if(_classToAuthManagerMap.isEmpty())
- {
- throw new ConfigurationException("No authentication managers configured within the configuration file.");
- }
-
- _defaultSubjectCreator = createDefaultSubectCreator(serverConfiguration, groupPrincipalAccessor);
-
- _portToSubjectCreatorMap = createPortToSubjectCreatorMap(serverConfiguration, groupPrincipalAccessor);
- willClose = false;
- }
- finally
- {
- // if anyConfigurationExceptionthing went wrong whilst configuring the registry, try to close all the AuthentcationManagers instantiated so far.
- // This is done to allow the AuthenticationManager to undo any security registrations that they have performed.
- if (willClose)
- {
- close();
- }
- }
- }
-
- @Override
- public SubjectCreator getSubjectCreator(SocketAddress address)
- {
- SubjectCreator subjectCreator =
- address instanceof InetSocketAddress
- ? _portToSubjectCreatorMap.get(((InetSocketAddress)address).getPort())
- : null;
-
- return subjectCreator == null ? _defaultSubjectCreator : subjectCreator;
- }
-
- @Override
- public void close()
- {
- for (AuthenticationManager authManager : _classToAuthManagerMap.values())
- {
- authManager.close();
- }
- }
-
- private void createAuthManagers(Configuration config)
- {
- Configuration securityConfiguration = config.subset("security");
-
- for(AuthenticationManagerFactory factory : _authManagerFactoryServiceLoader.atLeastOneInstanceOf(AuthenticationManagerFactory.class))
- {
- AuthenticationManager plugin = factory.createInstance(securityConfiguration);
- if(plugin != null)
- {
- validateAndInitialiseAuthenticationManager(plugin);
- }
- }
- }
-
- private void validateAndInitialiseAuthenticationManager(AuthenticationManager authenticationManager)
- {
- // TODO Should be a user-defined name rather than the classname.
- final String authManagerName = authenticationManager.getClass().getSimpleName();
- if (_classToAuthManagerMap.containsKey(authManagerName))
- {
- throw new RuntimeException("Cannot configure more than one authentication manager with name "
- + authManagerName + ".");
- }
-
- authenticationManager.initialise();
-
- _classToAuthManagerMap.put(authManagerName, authenticationManager);
- }
-
- private SubjectCreator createDefaultSubectCreator(
- ServerConfiguration serverConfiguration, GroupPrincipalAccessor groupAccessor)
- throws ConfigurationException
- {
- final AuthenticationManager defaultAuthenticationManager;
- if(_classToAuthManagerMap.size() == 1)
- {
- defaultAuthenticationManager = _classToAuthManagerMap.values().iterator().next();
- }
- else if(serverConfiguration.getDefaultAuthenticationManager() != null)
- {
- defaultAuthenticationManager = _classToAuthManagerMap.get(serverConfiguration.getDefaultAuthenticationManager());
- if(defaultAuthenticationManager == null)
- {
- throw new ConfigurationException("No authentication managers configured of type "
- + serverConfiguration.getDefaultAuthenticationManager()
- + " which is specified as the default. Available managers are: "
- + _classToAuthManagerMap.keySet());
- }
- }
- else
- {
- throw new ConfigurationException("If more than one authentication manager is configured a default MUST be specified.");
- }
- return new SubjectCreator(defaultAuthenticationManager, groupAccessor);
- }
-
- private Map<Integer, SubjectCreator> createPortToSubjectCreatorMap(
- ServerConfiguration serverConfiguration, GroupPrincipalAccessor groupPrincipalAccessor)
- throws ConfigurationException
- {
- Map<Integer,SubjectCreator> portToSubjectCreatorMap = new HashMap<Integer, SubjectCreator>();
-
- for(Map.Entry<Integer,String> portMapping : serverConfiguration.getPortAuthenticationMappings().entrySet())
- {
-
- AuthenticationManager authenticationManager = _classToAuthManagerMap.get(portMapping.getValue());
- if(authenticationManager == null)
- {
- throw new ConfigurationException("Unknown authentication manager class " + portMapping.getValue() +
- " configured for port " + portMapping.getKey());
- }
-
- SubjectCreator subjectCreator = new SubjectCreator(authenticationManager, groupPrincipalAccessor);
- portToSubjectCreatorMap.put(portMapping.getKey(), subjectCreator);
- }
-
- return portToSubjectCreatorMap;
- }
-
- @Override
- public Map<String, AuthenticationManager> getAvailableAuthenticationManagers()
- {
- return Collections.unmodifiableMap(new HashMap<String, AuthenticationManager>(_classToAuthManagerMap));
- }
-
- @Override
- public void addRegistryChangeListener(RegistryChangeListener listener)
- {
- _listeners.add(listener);
- }
-
-}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/Base64MD5PasswordFileAuthenticationManagerFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/Base64MD5PasswordFileAuthenticationManagerFactory.java
new file mode 100644
index 0000000000..c61567ef77
--- /dev/null
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/Base64MD5PasswordFileAuthenticationManagerFactory.java
@@ -0,0 +1,42 @@
+/*
+ *
+ * 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.qpid.server.security.auth.manager;
+
+import org.apache.qpid.server.security.auth.database.Base64MD5PasswordFilePrincipalDatabase;
+import org.apache.qpid.server.security.auth.database.PrincipalDatabase;
+
+public class Base64MD5PasswordFileAuthenticationManagerFactory extends AbstractPrincipalDatabaseAuthManagerFactory
+{
+ public static final String PROVIDER_TYPE = "Base64MD5PasswordFileAuthenticationProvider";
+
+ @Override
+ String getType()
+ {
+ return PROVIDER_TYPE;
+ }
+
+ @Override
+ PrincipalDatabase createPrincipalDatabase()
+ {
+ return new Base64MD5PasswordFilePrincipalDatabase();
+ }
+
+}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/ExternalAuthenticationManagerFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/ExternalAuthenticationManagerFactory.java
index 686f084c93..3c3628e9db 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/ExternalAuthenticationManagerFactory.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/ExternalAuthenticationManagerFactory.java
@@ -19,20 +19,22 @@
*/
package org.apache.qpid.server.security.auth.manager;
-import org.apache.commons.configuration.Configuration;
+import java.util.Map;
+
import org.apache.qpid.server.plugin.AuthenticationManagerFactory;
public class ExternalAuthenticationManagerFactory implements AuthenticationManagerFactory
{
+ public static final String PROVIDER_TYPE = ExternalAuthenticationManager.class.getSimpleName();
+
@Override
- public AuthenticationManager createInstance(Configuration configuration)
+ public AuthenticationManager createInstance(Map<String, Object> attributes)
{
- if (configuration.subset("external-auth-manager").isEmpty())
+ if (attributes != null && PROVIDER_TYPE.equals(attributes.get(ATTRIBUTE_TYPE)))
{
- return null;
+ return new ExternalAuthenticationManager();
}
-
- return new ExternalAuthenticationManager();
+ return null;
}
}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/IAuthenticationManagerRegistry.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/IAuthenticationManagerRegistry.java
deleted file mode 100644
index 6ed8f95512..0000000000
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/IAuthenticationManagerRegistry.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * 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.qpid.server.security.auth.manager;
-
-import java.net.SocketAddress;
-
-import java.util.Map;
-import org.apache.qpid.common.Closeable;
-import org.apache.qpid.server.security.SubjectCreator;
-
-/**
- * Registry for {@link AuthenticationManager} instances, also exposing them wrapped in {@link SubjectCreator}'s
- * as a convenience.
- *
- * <p>It is important to {@link #close()} the registry after use and this allows the AuthenticationManagers
- * to reverse any security registrations they have performed.</p>
- */
-public interface IAuthenticationManagerRegistry extends Closeable
-{
- /**
- * Returns the {@link SubjectCreator} associated with a particular {@link SocketAddress}.
- * If no subject creator is associated with this address, a default will be
- * returned. Null is never returned.
- */
- public SubjectCreator getSubjectCreator(SocketAddress address);
-
- Map<String, AuthenticationManager> getAvailableAuthenticationManagers();
-
- public static interface RegistryChangeListener
- {
- void authenticationManagerRegistered(AuthenticationManager authenticationManager);
- void authenticationManagerUnregistered(AuthenticationManager authenticationManager);
- }
-
- public void addRegistryChangeListener(RegistryChangeListener listener);
-} \ No newline at end of file
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/KerberosAuthenticationManagerFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/KerberosAuthenticationManagerFactory.java
index 470a51b6a6..7af6727280 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/KerberosAuthenticationManagerFactory.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/KerberosAuthenticationManagerFactory.java
@@ -19,19 +19,21 @@
*/
package org.apache.qpid.server.security.auth.manager;
-import org.apache.commons.configuration.Configuration;
+import java.util.Map;
+
import org.apache.qpid.server.plugin.AuthenticationManagerFactory;
public class KerberosAuthenticationManagerFactory implements AuthenticationManagerFactory
{
+ public static final String PROVIDER_TYPE = KerberosAuthenticationManager.class.getSimpleName();
+
@Override
- public AuthenticationManager createInstance(Configuration configuration)
+ public AuthenticationManager createInstance(Map<String, Object> attributes)
{
- if (configuration.subset("kerberos-auth-manager").isEmpty())
+ if (attributes != null && PROVIDER_TYPE.equals(attributes.get(ATTRIBUTE_TYPE)))
{
- return null;
+ return new KerberosAuthenticationManager();
}
-
- return new KerberosAuthenticationManager();
+ return null;
}
}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/PlainPasswordFileAuthenticationManagerFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/PlainPasswordFileAuthenticationManagerFactory.java
new file mode 100644
index 0000000000..43b92735f1
--- /dev/null
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/PlainPasswordFileAuthenticationManagerFactory.java
@@ -0,0 +1,42 @@
+/*
+ *
+ * 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.qpid.server.security.auth.manager;
+
+import org.apache.qpid.server.security.auth.database.PlainPasswordFilePrincipalDatabase;
+import org.apache.qpid.server.security.auth.database.PrincipalDatabase;
+
+public class PlainPasswordFileAuthenticationManagerFactory extends AbstractPrincipalDatabaseAuthManagerFactory
+{
+ public static final String PROVIDER_TYPE = "PlainPasswordFileAuthenticationProvider";
+
+ @Override
+ String getType()
+ {
+ return PROVIDER_TYPE;
+ }
+
+ @Override
+ PrincipalDatabase createPrincipalDatabase()
+ {
+ return new PlainPasswordFilePrincipalDatabase();
+ }
+
+}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthManagerFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthManagerFactory.java
deleted file mode 100644
index d616bbb7ae..0000000000
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthManagerFactory.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * 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.qpid.server.security.auth.manager;
-
-import java.io.IOException;
-
-import org.apache.commons.configuration.Configuration;
-import org.apache.log4j.Logger;
-import org.apache.qpid.server.plugin.AuthenticationManagerFactory;
-import org.apache.qpid.server.security.auth.database.Base64MD5PasswordFilePrincipalDatabase;
-import org.apache.qpid.server.security.auth.database.PlainPasswordFilePrincipalDatabase;
-import org.apache.qpid.server.security.auth.database.PrincipalDatabase;
-
-/**
- * Factory for {@link PrincipalDatabaseAuthenticationManager} objects configured with either the
- * Plain or Base64MD5 digest {@link PrincipalDatabase} implementation.
- */
-public class PrincipalDatabaseAuthManagerFactory implements AuthenticationManagerFactory
-{
- private static final Logger LOGGER = Logger.getLogger(PrincipalDatabaseAuthManagerFactory.class);
-
- @Override
- public AuthenticationManager createInstance(Configuration configuration)
- {
- if(configuration.subset("pd-auth-manager").isEmpty())
- {
- return null;
- }
-
- String clazz = configuration.getString("pd-auth-manager.principal-database.class");
- String passwordArgumentName = configuration.getString("pd-auth-manager.principal-database.attributes.attribute.name");
- String passwordFile = configuration.getString("pd-auth-manager.principal-database.attributes.attribute.value");
-
- PrincipalDatabase principalDatabase = createKnownImplementation(clazz);
- if (principalDatabase == null)
- {
- LOGGER.warn("Config for pd-auth-manager found but principal-database class specified in config " + clazz +
- " not recognised.");
- return null;
- }
-
- if (!"passwordFile".equals(passwordArgumentName) || passwordFile == null)
- {
- LOGGER.warn("Config for pd-auth-manager found but config incomplete - expected attributes not found.");
- return null;
- }
-
- try
- {
- principalDatabase.setPasswordFile(passwordFile);
- }
- catch (IOException e)
- {
- throw new RuntimeException(e.getMessage(), e);
- }
-
- return new PrincipalDatabaseAuthenticationManager(principalDatabase);
- }
-
- private PrincipalDatabase createKnownImplementation(String clazz)
- {
- if (PlainPasswordFilePrincipalDatabase.class.getName().equals(clazz))
- {
- return new PlainPasswordFilePrincipalDatabase();
- }
- else if (Base64MD5PasswordFilePrincipalDatabase.class.getName().equals(clazz))
- {
- return new Base64MD5PasswordFilePrincipalDatabase();
- }
- else
- {
- return null;
- }
- }
-}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthenticationManager.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthenticationManager.java
index 8f84732f36..f4c834810d 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthenticationManager.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthenticationManager.java
@@ -50,8 +50,6 @@ import java.util.TreeMap;
*/
public class PrincipalDatabaseAuthenticationManager implements AuthenticationManager
{
- public static final String PD_CLASS = "pd.class";
- public static final String PD_PASSWORD_FILE = "pd.passwordFile";
private static final Logger _logger = Logger.getLogger(PrincipalDatabaseAuthenticationManager.class);
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/SimpleLDAPAuthenticationManagerFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/SimpleLDAPAuthenticationManagerFactory.java
index 8a1d23ffb1..05a692fb0e 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/SimpleLDAPAuthenticationManagerFactory.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/SimpleLDAPAuthenticationManagerFactory.java
@@ -19,32 +19,51 @@
*/
package org.apache.qpid.server.security.auth.manager;
-import org.apache.commons.configuration.Configuration;
+import java.util.Map;
+
import org.apache.qpid.server.plugin.AuthenticationManagerFactory;
public class SimpleLDAPAuthenticationManagerFactory implements AuthenticationManagerFactory
{
-
private static final String DEFAULT_LDAP_CONTEXT_FACTORY = "com.sun.jndi.ldap.LdapCtxFactory";
+ public static final String PROVIDER_TYPE = SimpleLDAPAuthenticationManager.class.getSimpleName();
+
+ public static final String ATTRIBUTE_LDAP_CONTEXT_FACTORY = "ldapContextFactory";
+ public static final String ATTRIBUTE_SEARCH_FILTER = "searchFilter";
+ public static final String ATTRIBUTE_SEARCH_CONTEXT = "searchContext";
+ public static final String ATTRIBUTE_PROVIDER_AUTH_URL = "providerAuthUrl";
+ public static final String ATTRIBUTE_PROVIDER_SEARCH_URL = "providerSearchUrl";
+ public static final String ATTRIBUTE_PROVIDER_URL = "providerUrl";
+
@Override
- public AuthenticationManager createInstance(Configuration configuration)
+ public AuthenticationManager createInstance(Map<String, Object> attributes)
{
-
- final Configuration subset = configuration.subset("simple-ldap-auth-manager");
- if(subset.isEmpty())
+ if (attributes == null || !PROVIDER_TYPE.equals(attributes.get(ATTRIBUTE_TYPE)))
{
return null;
}
+ String providerUrl = (String) attributes.get(ATTRIBUTE_PROVIDER_URL);
+ String providerSearchUrl = (String) attributes.get(ATTRIBUTE_PROVIDER_SEARCH_URL);
+ if (providerSearchUrl == null)
+ {
+ providerSearchUrl = providerUrl;
+ }
+ String providerAuthUrl = (String) attributes.get(ATTRIBUTE_PROVIDER_AUTH_URL);
+ if (providerAuthUrl == null)
+ {
+ providerAuthUrl = providerUrl;
+ }
+ String searchContext = (String) attributes.get(ATTRIBUTE_SEARCH_CONTEXT);
+ String searchFilter = (String) attributes.get(ATTRIBUTE_SEARCH_FILTER);
+ String ldapContextFactory = (String) attributes.get(ATTRIBUTE_LDAP_CONTEXT_FACTORY);
+ if (ldapContextFactory == null)
+ {
+ ldapContextFactory = DEFAULT_LDAP_CONTEXT_FACTORY;
+ }
- String providerUrl = configuration.getString("simple-ldap-auth-manager.provider-url");
- String providerSearchUrl = configuration.getString("simple-ldap-auth-manager.provider-search-url", providerUrl);
- String providerAuthUrl = configuration.getString("simple-ldap-auth-manager.provider-auth-url", providerUrl);
- String searchContext = configuration.getString("simple-ldap-auth-manager.search-context");
- String searchFilter = configuration.getString("simple-ldap-auth-manager.search-filter");
- String ldapContextFactory = configuration.getString("simple-ldap-auth-manager.ldap-context-factory", DEFAULT_LDAP_CONTEXT_FACTORY);
-
- return new SimpleLDAPAuthenticationManager(providerSearchUrl, providerAuthUrl, searchContext, searchFilter, ldapContextFactory);
+ return new SimpleLDAPAuthenticationManager(providerSearchUrl, providerAuthUrl, searchContext, searchFilter,
+ ldapContextFactory);
}
}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/rmi/RMIPasswordAuthenticator.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/rmi/RMIPasswordAuthenticator.java
index 9f5d87bf62..abb8677e90 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/rmi/RMIPasswordAuthenticator.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/rmi/RMIPasswordAuthenticator.java
@@ -22,7 +22,7 @@ package org.apache.qpid.server.security.auth.rmi;
import java.net.SocketAddress;
-import org.apache.qpid.server.registry.IApplicationRegistry;
+import org.apache.qpid.server.model.Broker;
import org.apache.qpid.server.security.SecurityManager;
import org.apache.qpid.server.security.SubjectCreator;
import org.apache.qpid.server.security.auth.AuthenticationResult.AuthenticationStatus;
@@ -42,13 +42,13 @@ public class RMIPasswordAuthenticator implements JMXAuthenticator
static final String CREDENTIALS_REQUIRED = "User details are required. " +
"Please ensure you are using an up to date management console to connect.";
- private final IApplicationRegistry _appRegistry;
- private final SocketAddress _socketAddress;
+ private final Broker _broker;
+ private final SocketAddress _address;
- public RMIPasswordAuthenticator(IApplicationRegistry appRegistry, SocketAddress socketAddress)
+ public RMIPasswordAuthenticator(Broker broker, SocketAddress address)
{
- _appRegistry = appRegistry;
- _socketAddress = socketAddress;
+ _broker = broker;
+ _address = address;
}
public Subject authenticate(Object credentials) throws SecurityException
@@ -94,10 +94,10 @@ public class RMIPasswordAuthenticator implements JMXAuthenticator
throw new SecurityException(SHOULD_BE_NON_NULL);
}
- SubjectCreator subjectCreator = _appRegistry.getSubjectCreator(_socketAddress);
+ SubjectCreator subjectCreator = _broker.getSubjectCreator(_address);
if (subjectCreator == null)
{
- throw new SecurityException("Can't get subject creator for " + _socketAddress);
+ throw new SecurityException("Can't get subject creator for " + _address);
}
final SubjectAuthenticationResult result = subjectCreator.authenticate(username, password);
@@ -121,7 +121,7 @@ public class RMIPasswordAuthenticator implements JMXAuthenticator
SecurityManager.setThreadSubject(authenticatedSubject);
try
{
- if (!_appRegistry.getSecurityManager().accessManagement())
+ if (!_broker.getSecurityManager().accessManagement())
{
throw new SecurityException(USER_NOT_AUTHORISED_FOR_MANAGEMENT);
}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/group/FileGroupManager.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/group/FileGroupManager.java
index 5cc1085a0d..8295f28f9e 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/group/FileGroupManager.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/group/FileGroupManager.java
@@ -25,7 +25,7 @@ import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
-import org.apache.commons.configuration.ConfigurationException;
+import org.apache.qpid.server.configuration.IllegalConfigurationException;
import org.apache.qpid.server.security.auth.UsernamePrincipal;
/**
@@ -49,7 +49,7 @@ public class FileGroupManager implements GroupManager
private final FileGroupDatabase _groupDatabase;
- public FileGroupManager(String groupFile) throws ConfigurationException
+ public FileGroupManager(String groupFile)
{
_groupDatabase = new FileGroupDatabase();
try
@@ -58,7 +58,7 @@ public class FileGroupManager implements GroupManager
}
catch (IOException e)
{
- throw new ConfigurationException("Unable to set group file " + groupFile, e);
+ throw new IllegalConfigurationException("Unable to set group file " + groupFile, e);
}
}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/group/FileGroupManagerFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/group/FileGroupManagerFactory.java
index a55cdbf602..5c4730a9c8 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/group/FileGroupManagerFactory.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/group/FileGroupManagerFactory.java
@@ -18,48 +18,34 @@
*/
package org.apache.qpid.server.security.group;
-import org.apache.commons.configuration.Configuration;
-import org.apache.commons.configuration.ConfigurationException;
+import static org.apache.qpid.server.util.MapValueConverter.getStringAttribute;
+
+import java.util.Map;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.qpid.server.configuration.IllegalConfigurationException;
+import org.apache.qpid.server.model.GroupProvider;
import org.apache.qpid.server.plugin.GroupManagerFactory;
public class FileGroupManagerFactory implements GroupManagerFactory
{
- private static final String GROUP_FILE_MARKER = "groupFile";
- private static final String FILE_ATTRIBUTE_VALUE = "file-group-manager.attributes.attribute.value";
- private static final String FILE_ATTRIBUTE_NAME = "file-group-manager.attributes.attribute.name";
+ static final String FILE_GROUP_MANAGER_TYPE = "file-group-manager";
+ static final String FILE = "file";
@Override
- public GroupManager createInstance(Configuration configuration)
+ public GroupManager createInstance(Map<String, Object> attributes)
{
- if(configuration.subset("file-group-manager").isEmpty())
+ if(!FILE_GROUP_MANAGER_TYPE.equals(getStringAttribute(GroupProvider.TYPE, attributes, null)))
{
return null;
}
- String groupFileArgumentName = configuration.getString(FILE_ATTRIBUTE_NAME);
- String groupFile = configuration.getString(FILE_ATTRIBUTE_VALUE);
-
- if (!GROUP_FILE_MARKER.equals(groupFileArgumentName))
- {
- throw new RuntimeException("Config for file-group-manager found but " + FILE_ATTRIBUTE_NAME
- + " has no value or " + groupFileArgumentName
- + " does not equal " + GROUP_FILE_MARKER);
- }
-
- if (groupFile == null)
- {
- throw new RuntimeException("Config for file-group-manager found but " + FILE_ATTRIBUTE_VALUE + " has no value."
- + " Filename expected.");
- }
-
- try
- {
- return new FileGroupManager(groupFile);
- }
- catch (ConfigurationException e)
+ String groupFile = getStringAttribute(FILE, attributes, null);
+ if (StringUtils.isBlank(groupFile))
{
- throw new RuntimeException(e);
+ throw new IllegalConfigurationException("Path to file containing groups is not specified!");
}
+ return new FileGroupManager(groupFile);
}
}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/group/GroupPrincipalAccessor.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/group/GroupPrincipalAccessor.java
index 9ab8ee586c..d549b76aab 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/group/GroupPrincipalAccessor.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/group/GroupPrincipalAccessor.java
@@ -19,27 +19,30 @@
package org.apache.qpid.server.security.group;
import java.security.Principal;
+import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
-import java.util.List;
import java.util.Set;
+import org.apache.qpid.server.model.GroupProvider;
+import org.apache.qpid.server.model.adapter.GroupProviderAdapter;
+
public class GroupPrincipalAccessor
{
- private final List<GroupManager> _groupManagerList;
+ private final Collection<GroupProvider> _groupProviders;
- public GroupPrincipalAccessor(List<GroupManager> groupManagerList)
+ public GroupPrincipalAccessor(Collection<GroupProvider> groupProviders)
{
- _groupManagerList = groupManagerList;
+ _groupProviders = groupProviders;
}
public Set<Principal> getGroupPrincipals(String username)
{
Set<Principal> principals = new HashSet<Principal>();
- for (GroupManager groupManager : _groupManagerList)
+ for (GroupProvider groupProvider : _groupProviders)
{
- Set<Principal> groups = groupManager.getGroupPrincipalsForUser(username);
+ Set<Principal> groups = groupProvider.getGroupPrincipalsForUser(username);
if (groups != null)
{
principals.addAll(groups);
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/state/AMQStateManager.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/state/AMQStateManager.java
index f8b8d14abf..ff41536a23 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/state/AMQStateManager.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/state/AMQStateManager.java
@@ -31,11 +31,10 @@ import org.apache.qpid.framing.MethodDispatcher;
import org.apache.qpid.protocol.AMQConstant;
import org.apache.qpid.protocol.AMQMethodEvent;
import org.apache.qpid.protocol.AMQMethodListener;
+import org.apache.qpid.server.model.Broker;
import org.apache.qpid.server.protocol.AMQProtocolSession;
-import org.apache.qpid.server.registry.IApplicationRegistry;
import org.apache.qpid.server.security.SecurityManager;
import org.apache.qpid.server.security.SubjectCreator;
-import org.apache.qpid.server.security.auth.manager.AuthenticationManager;
import org.apache.qpid.server.virtualhost.VirtualHostRegistry;
import java.util.concurrent.CopyOnWriteArraySet;
@@ -48,32 +47,29 @@ public class AMQStateManager implements AMQMethodListener
{
private static final Logger _logger = Logger.getLogger(AMQStateManager.class);
- private final VirtualHostRegistry _virtualHostRegistry;
+ private final Broker _broker;
private final AMQProtocolSession _protocolSession;
/** The current state */
private AMQState _currentState;
private CopyOnWriteArraySet<StateListener> _stateListeners = new CopyOnWriteArraySet<StateListener>();
- public AMQStateManager(VirtualHostRegistry virtualHostRegistry, AMQProtocolSession protocolSession)
+ public AMQStateManager(Broker broker, AMQProtocolSession protocolSession)
{
-
- _virtualHostRegistry = virtualHostRegistry;
+ _broker = broker;
_protocolSession = protocolSession;
_currentState = AMQState.CONNECTION_NOT_STARTED;
}
/**
- * Get the ApplicationRegistry associated with this AMQStateManager
- *
- * returns the application registry associated with the VirtualHostRegistry of the AMQStateManager
+ * Get the Broker instance
*
- * @return the ApplicationRegistry
+ * @return the Broker
*/
- public IApplicationRegistry getApplicationRegistry()
+ public Broker getBroker()
{
- return _virtualHostRegistry.getApplicationRegistry();
+ return _broker;
}
public AMQState getCurrentState()
@@ -149,7 +145,7 @@ public class AMQStateManager implements AMQMethodListener
public VirtualHostRegistry getVirtualHostRegistry()
{
- return _virtualHostRegistry;
+ return _broker.getVirtualHostRegistry();
}
public AMQProtocolSession getProtocolSession()
@@ -161,6 +157,6 @@ public class AMQStateManager implements AMQMethodListener
public SubjectCreator getSubjectCreator()
{
- return getApplicationRegistry().getSubjectCreator(getProtocolSession().getLocalAddress());
+ return _broker.getSubjectCreator(getProtocolSession().getLocalAddress());
}
}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/MemoryMessageStore.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/store/MemoryMessageStore.java
index 262d7d0213..3f1d1b9530 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/MemoryMessageStore.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/store/MemoryMessageStore.java
@@ -30,6 +30,7 @@ import java.util.concurrent.atomic.AtomicLong;
/** A simple message store that stores the messages in a thread-safe structure in memory. */
public class MemoryMessageStore extends NullMessageStore
{
+ public static final String TYPE = "Memory";
private final AtomicLong _messageId = new AtomicLong(1);
private final AtomicBoolean _closed = new AtomicBoolean(false);
@@ -138,6 +139,6 @@ public class MemoryMessageStore extends NullMessageStore
@Override
public String getStoreType()
{
- return "Memory";
+ return TYPE;
}
}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/MemoryMessageStoreFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/store/MemoryMessageStoreFactory.java
new file mode 100644
index 0000000000..20b6b7a8a6
--- /dev/null
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/store/MemoryMessageStoreFactory.java
@@ -0,0 +1,39 @@
+/*
+ *
+ * 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.qpid.server.store;
+
+
+public class MemoryMessageStoreFactory implements MessageStoreFactory
+{
+
+ @Override
+ public String getType()
+ {
+ return MemoryMessageStore.TYPE;
+ }
+
+ @Override
+ public MessageStore createMessageStore()
+ {
+ return new MemoryMessageStore();
+ }
+
+}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/MessageStoreCreator.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/store/MessageStoreCreator.java
new file mode 100644
index 0000000000..0d5a4850f6
--- /dev/null
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/store/MessageStoreCreator.java
@@ -0,0 +1,66 @@
+/*
+ *
+ * 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.qpid.server.store;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.qpid.server.configuration.IllegalConfigurationException;
+import org.apache.qpid.server.plugin.QpidServiceLoader;
+
+public class MessageStoreCreator
+{
+ private Map<String, MessageStoreFactory> _factories = new HashMap<String, MessageStoreFactory>();
+
+ public MessageStoreCreator()
+ {
+ QpidServiceLoader<MessageStoreFactory> qpidServiceLoader = new QpidServiceLoader<MessageStoreFactory>();
+ Iterable<MessageStoreFactory> factories = qpidServiceLoader.atLeastOneInstanceOf(MessageStoreFactory.class);
+ for (MessageStoreFactory messageStoreFactory : factories)
+ {
+ String type = messageStoreFactory.getType();
+ MessageStoreFactory factory = _factories.put(type.toLowerCase(), messageStoreFactory);
+ if (factory != null)
+ {
+ throw new IllegalStateException("MessageStoreFactory with type name '" + type
+ + "' is already registered using class '" + factory.getClass().getName() + "', can not register class '"
+ + messageStoreFactory.getClass().getName() + "'");
+ }
+ }
+ }
+
+ public MessageStore createMessageStore(String storeType)
+ {
+ MessageStoreFactory factory = _factories.get(storeType.toLowerCase());
+ if (factory == null)
+ {
+ throw new IllegalConfigurationException("Unknown store type: " + storeType);
+ }
+ return factory.createMessageStore();
+ }
+
+ public Collection<MessageStoreFactory> getFactories()
+ {
+ return Collections.unmodifiableCollection(_factories.values());
+ }
+}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/MessageStoreFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/store/MessageStoreFactory.java
new file mode 100644
index 0000000000..a1afd02f12
--- /dev/null
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/store/MessageStoreFactory.java
@@ -0,0 +1,28 @@
+/*
+ *
+ * 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.qpid.server.store;
+
+public interface MessageStoreFactory
+{
+ String getType();
+
+ MessageStore createMessageStore();
+}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/derby/DerbyMessageStore.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/store/derby/DerbyMessageStore.java
index 2f6ad96fb1..e9946d1860 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/derby/DerbyMessageStore.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/store/derby/DerbyMessageStore.java
@@ -231,7 +231,7 @@ public class DerbyMessageStore implements MessageStore
private static final String DERBY_SINGLE_DB_SHUTDOWN_CODE = "08006";
- private static final String DERBY_STORE_TYPE = "DERBY";
+ public static final String TYPE = "DERBY";
private final StateManager _stateManager;
@@ -2333,7 +2333,7 @@ public class DerbyMessageStore implements MessageStore
@Override
public String getStoreType()
{
- return DERBY_STORE_TYPE;
+ return TYPE;
}
} \ No newline at end of file
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/derby/DerbyMessageStoreFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/store/derby/DerbyMessageStoreFactory.java
new file mode 100644
index 0000000000..046b503d8a
--- /dev/null
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/store/derby/DerbyMessageStoreFactory.java
@@ -0,0 +1,41 @@
+/*
+ *
+ * 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.qpid.server.store.derby;
+
+import org.apache.qpid.server.store.MessageStore;
+import org.apache.qpid.server.store.MessageStoreFactory;
+
+public class DerbyMessageStoreFactory implements MessageStoreFactory
+{
+
+ @Override
+ public String getType()
+ {
+ return DerbyMessageStore.TYPE;
+ }
+
+ @Override
+ public MessageStore createMessageStore()
+ {
+ return new DerbyMessageStore();
+ }
+
+}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/transport/QpidAcceptor.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/transport/QpidAcceptor.java
deleted file mode 100644
index 7c4188bfcd..0000000000
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/transport/QpidAcceptor.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- *
- * 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.qpid.server.transport;
-
-import org.apache.qpid.server.protocol.AmqpProtocolVersion;
-import org.apache.qpid.transport.network.NetworkTransport;
-
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Set;
-
-public class QpidAcceptor
-{
- public enum Transport
- {
- TCP("TCP"),
- SSL("TCP/SSL");
-
- private final String _asString;
-
- Transport(String asString)
- {
- _asString = asString;
- }
-
- public String toString()
- {
- return _asString;
- }
- }
-
- private NetworkTransport _networkTransport;
- private Transport _transport;
- private Set<AmqpProtocolVersion> _supported;
-
-
- public QpidAcceptor(NetworkTransport transport, Transport protocol, Set<AmqpProtocolVersion> supported)
- {
- _networkTransport = transport;
- _transport = protocol;
- _supported = Collections.unmodifiableSet(new HashSet<AmqpProtocolVersion>(supported));
- }
-
- public NetworkTransport getNetworkTransport()
- {
- return _networkTransport;
- }
-
- public Transport getTransport()
- {
- return _transport;
- }
-
- public Set<AmqpProtocolVersion> getSupported()
- {
- return _supported;
- }
-
- public String toString()
- {
- return _transport.toString();
- }
-}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/transport/ServerConnectionDelegate.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/transport/ServerConnectionDelegate.java
index f48121f9f0..f3153fde62 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/transport/ServerConnectionDelegate.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/transport/ServerConnectionDelegate.java
@@ -28,13 +28,13 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;
-import java.util.UUID;
import javax.security.sasl.SaslException;
import javax.security.sasl.SaslServer;
import org.apache.qpid.common.ServerPropertyNames;
import org.apache.qpid.properties.ConnectionStartProperties;
+import org.apache.qpid.server.configuration.BrokerProperties;
+import org.apache.qpid.server.model.Broker;
import org.apache.qpid.server.protocol.AMQConnectionModel;
-import org.apache.qpid.server.registry.IApplicationRegistry;
import org.apache.qpid.server.security.SecurityManager;
import org.apache.qpid.server.security.SubjectCreator;
import org.apache.qpid.server.security.auth.AuthenticationResult.AuthenticationStatus;
@@ -54,35 +54,36 @@ public class ServerConnectionDelegate extends ServerDelegate
{
private static final Logger LOGGER = LoggerFactory.getLogger(ServerConnectionDelegate.class);
+ private final Broker _broker;
private final String _localFQDN;
- private final IApplicationRegistry _appRegistry;
private int _maxNoOfChannels;
private Map<String,Object> _clientProperties;
private final SubjectCreator _subjectCreator;
- public ServerConnectionDelegate(IApplicationRegistry appRegistry, String localFQDN, SubjectCreator subjectCreator)
+ public ServerConnectionDelegate(Broker broker, String localFQDN, SubjectCreator subjectCreator)
{
- this(createConnectionProperties(appRegistry), Collections.singletonList((Object)"en_US"), appRegistry, localFQDN, subjectCreator);
+ this(createConnectionProperties(broker), Collections.singletonList((Object)"en_US"), broker, localFQDN, subjectCreator);
}
private ServerConnectionDelegate(Map<String, Object> properties,
List<Object> locales,
- IApplicationRegistry appRegistry,
+ Broker broker,
String localFQDN,
SubjectCreator subjectCreator)
{
super(properties, parseToList(subjectCreator.getMechanisms()), locales);
- _appRegistry = appRegistry;
+ _broker = broker;
_localFQDN = localFQDN;
- _maxNoOfChannels = appRegistry.getConfiguration().getMaxChannelCount();
+ _maxNoOfChannels = (Integer)broker.getAttribute(Broker.SESSION_COUNT_LIMIT);
_subjectCreator = subjectCreator;
}
- private static List<String> getFeatures(IApplicationRegistry appRegistry)
+ private static List<String> getFeatures(Broker broker)
{
+ String brokerDisabledFeatures = System.getProperty(BrokerProperties.PROPERTY_DISABLED_FEATURES);
final List<String> features = new ArrayList<String>();
- if (!appRegistry.getConfiguration().getDisabledFeatures().contains(ServerPropertyNames.FEATURE_QPID_JMS_SELECTOR))
+ if (brokerDisabledFeatures == null || !brokerDisabledFeatures.contains(ServerPropertyNames.FEATURE_QPID_JMS_SELECTOR))
{
features.add(ServerPropertyNames.FEATURE_QPID_JMS_SELECTOR);
}
@@ -90,12 +91,12 @@ public class ServerConnectionDelegate extends ServerDelegate
return Collections.unmodifiableList(features);
}
- private static Map<String, Object> createConnectionProperties(final IApplicationRegistry applicationRegistry)
+ private static Map<String, Object> createConnectionProperties(final Broker broker)
{
final Map<String,Object> map = new HashMap<String,Object>(2);
// Federation tag is used by the client to identify the broker instance
- map.put(ServerPropertyNames.FEDERATION_TAG, applicationRegistry.getBrokerId().toString());
- final List<String> features = getFeatures(applicationRegistry);
+ map.put(ServerPropertyNames.FEDERATION_TAG, broker.getId().toString());
+ final List<String> features = getFeatures(broker);
if (features != null && features.size() > 0)
{
map.put(ServerPropertyNames.QPID_FEATURES, features);
@@ -179,7 +180,7 @@ public class ServerConnectionDelegate extends ServerDelegate
{
vhostName = "";
}
- vhost = _appRegistry.getVirtualHostRegistry().getVirtualHost(vhostName);
+ vhost = _broker.getVirtualHostRegistry().getVirtualHost(vhostName);
SecurityManager.setThreadSubject(sconn.getAuthorizedSubject());
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/transport/ServerSessionDelegate.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/transport/ServerSessionDelegate.java
index 2c9edb4ffe..d83bd1c4dc 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/transport/ServerSessionDelegate.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/transport/ServerSessionDelegate.java
@@ -45,7 +45,6 @@ import org.apache.qpid.server.queue.AMQQueue;
import org.apache.qpid.server.queue.AMQQueueFactory;
import org.apache.qpid.server.queue.BaseQueue;
import org.apache.qpid.server.queue.QueueRegistry;
-import org.apache.qpid.server.registry.ApplicationRegistry;
import org.apache.qpid.server.security.SecurityManager;
import org.apache.qpid.server.store.DurableConfigurationStore;
import org.apache.qpid.server.store.MessageStore;
@@ -1266,18 +1265,12 @@ public class ServerSessionDelegate extends SessionDelegate
}
}
queueRegistry.registerQueue(queue);
- boolean autoRegister = ApplicationRegistry.getInstance().getConfiguration().getQueueAutoRegister();
- if (autoRegister)
- {
-
- ExchangeRegistry exchangeRegistry = getExchangeRegistry(session);
+ ExchangeRegistry exchangeRegistry = getExchangeRegistry(session);
- Exchange defaultExchange = exchangeRegistry.getDefaultExchange();
+ Exchange defaultExchange = exchangeRegistry.getDefaultExchange();
- virtualHost.getBindingFactory().addBinding(queueName, queue, defaultExchange, null);
-
- }
+ virtualHost.getBindingFactory().addBinding(queueName, queue, defaultExchange, null);
if (method.hasAutoDelete()
&& method.getAutoDelete()
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/util/MapValueConverter.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/util/MapValueConverter.java
new file mode 100644
index 0000000000..4732900c60
--- /dev/null
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/util/MapValueConverter.java
@@ -0,0 +1,335 @@
+/*
+ *
+ * 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.qpid.server.util;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+public class MapValueConverter
+{
+
+ public static String getStringAttribute(String name, Map<String,Object> attributes, String defaultVal)
+ {
+ final Object value = attributes.get(name);
+ return toString(value, defaultVal);
+ }
+
+ public static String toString(final Object value)
+ {
+ return toString(value, null);
+ }
+
+ public static String toString(final Object value, String defaultVal)
+ {
+ if (value == null)
+ {
+ return defaultVal;
+ }
+ else if (value instanceof String)
+ {
+ return (String)value;
+ }
+ return String.valueOf(value);
+ }
+
+ public static String getStringAttribute(String name, Map<String, Object> attributes)
+ {
+ assertMandatoryAttribute(name, attributes);
+ return getStringAttribute(name, attributes, null);
+ }
+
+ private static void assertMandatoryAttribute(String name, Map<String, Object> attributes)
+ {
+ if (!attributes.containsKey(name))
+ {
+ throw new IllegalArgumentException("Value for attribute " + name + " is not found");
+ }
+ }
+
+ public static Map<String,Object> getMapAttribute(String name, Map<String,Object> attributes, Map<String,Object> defaultVal)
+ {
+ final Object value = attributes.get(name);
+ if(value == null)
+ {
+ return defaultVal;
+ }
+ else if(value instanceof Map)
+ {
+ @SuppressWarnings("unchecked")
+ Map<String,Object> retVal = (Map<String,Object>) value;
+ return retVal;
+ }
+ else
+ {
+ throw new IllegalArgumentException("Value for attribute " + name + " is not of required type Map");
+ }
+ }
+
+
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ public static <E extends Enum> E getEnumAttribute(Class<E> clazz, String name, Map<String,Object> attributes, E defaultVal)
+ {
+ Object obj = attributes.get(name);
+ if(obj == null)
+ {
+ return defaultVal;
+ }
+ else if(clazz.isInstance(obj))
+ {
+ return (E) obj;
+ }
+ else if(obj instanceof String)
+ {
+ return (E) Enum.valueOf(clazz, (String)obj);
+ }
+ else
+ {
+ throw new IllegalArgumentException("Value for attribute " + name + " is not of required type " + clazz.getSimpleName());
+ }
+ }
+
+ public static <E extends Enum<?>> E getEnumAttribute(Class<E> clazz, String name, Map<String,Object> attributes)
+ {
+ assertMandatoryAttribute(name, attributes);
+ return getEnumAttribute(clazz, name, attributes, null);
+ }
+
+ public static Boolean getBooleanAttribute(String name, Map<String,Object> attributes, Boolean defaultValue)
+ {
+ Object obj = attributes.get(name);
+ return toBoolean(name, obj, defaultValue);
+ }
+
+ public static Boolean toBoolean(String name, Object obj)
+ {
+ return toBoolean(name, obj, null);
+ }
+
+ public static Boolean toBoolean(String name, Object obj, Boolean defaultValue)
+ {
+ if(obj == null)
+ {
+ return defaultValue;
+ }
+ else if(obj instanceof Boolean)
+ {
+ return (Boolean) obj;
+ }
+ else if(obj instanceof String)
+ {
+ return Boolean.parseBoolean((String) obj);
+ }
+ else
+ {
+ throw new IllegalArgumentException("Value for attribute " + name + " is not of required type Boolean");
+ }
+ }
+
+
+ public static boolean getBooleanAttribute(String name, Map<String, Object> attributes)
+ {
+ assertMandatoryAttribute(name, attributes);
+ return getBooleanAttribute(name, attributes, null);
+ }
+
+ public static Integer getIntegerAttribute(String name, Map<String,Object> attributes, Integer defaultValue)
+ {
+ Object obj = attributes.get(name);
+ return toInteger(name, obj, defaultValue);
+ }
+
+ public static Integer toInteger(String name, Object obj)
+ {
+ return toInteger(name, obj, null);
+ }
+
+ public static Integer toInteger(String name, Object obj, Integer defaultValue)
+ {
+ if(obj == null)
+ {
+ return defaultValue;
+ }
+ else if(obj instanceof Number)
+ {
+ return ((Number) obj).intValue();
+ }
+ else if(obj instanceof String)
+ {
+ return Integer.valueOf((String) obj);
+ }
+ else
+ {
+ throw new IllegalArgumentException("Value for attribute " + name + " is not of required type Integer");
+ }
+ }
+
+ public static Integer getIntegerAttribute(String name, Map<String,Object> attributes)
+ {
+ assertMandatoryAttribute(name, attributes);
+ return getIntegerAttribute(name, attributes, null);
+ }
+
+ public static Long getLongAttribute(String name, Map<String,Object> attributes, Long defaultValue)
+ {
+ Object obj = attributes.get(name);
+ return toLong(name, obj, defaultValue);
+ }
+
+ public static Long toLong(String name, Object obj)
+ {
+ return toLong(name, obj, null);
+ }
+
+ public static Long toLong(String name, Object obj, Long defaultValue)
+ {
+ if(obj == null)
+ {
+ return defaultValue;
+ }
+ else if(obj instanceof Number)
+ {
+ return ((Number) obj).longValue();
+ }
+ else if(obj instanceof String)
+ {
+ return Long.valueOf((String) obj);
+ }
+ else
+ {
+ throw new IllegalArgumentException("Value for attribute " + name + " is not of required type Long");
+ }
+ }
+
+ public static <T> Set<T> getSetAttribute(String name, Map<String,Object> attributes)
+ {
+ assertMandatoryAttribute(name, attributes);
+ return getSetAttribute(name, attributes, Collections.<T>emptySet());
+ }
+
+ @SuppressWarnings("unchecked")
+ public static <T> Set<T> getSetAttribute(String name, Map<String,Object> attributes, Set<T> defaultValue)
+ {
+ Object obj = attributes.get(name);
+ if(obj == null)
+ {
+ return defaultValue;
+ }
+ else if(obj instanceof Set)
+ {
+ return (Set<T>) obj;
+ }
+ else
+ {
+ throw new IllegalArgumentException("Value for attribute " + name + " is not of required type Set");
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ public static <T extends Enum<T>> Set<T> getEnumSetAttribute(String name, Map<String, Object> attributes, Class<T> clazz)
+ {
+ Object obj = attributes.get(name);
+ Object[] items = null;
+ if (obj == null)
+ {
+ return null;
+ }
+ else if (obj instanceof Collection)
+ {
+ Collection<?> data = (Collection<?>) obj;
+ items = data.toArray(new Object[data.size()]);
+ }
+ else if (obj instanceof String[])
+ {
+ items = (String[]) obj;
+ }
+ else if (obj instanceof Object[])
+ {
+ items = (Object[]) obj;
+ }
+ else
+ {
+ throw new IllegalArgumentException("Value for attribute " + name + "[" + obj
+ + "] cannot be converted into set of enum of " + clazz);
+ }
+ Set<T> set = new HashSet<T>();
+ for (int i = 0; i < items.length; i++)
+ {
+ T item = null;
+ Object value = items[i];
+ if (value instanceof String)
+ {
+ item = (T) Enum.valueOf(clazz, (String) value);
+ }
+ else if (clazz.isInstance(value))
+ {
+ item = (T) value;
+ }
+ else
+ {
+ throw new IllegalArgumentException("Cannot convert " + value + " from [" + obj + "] into enum of " + clazz
+ + " for attribute " + name);
+ }
+ set.add(item);
+ }
+ return set;
+ }
+
+ public static Map<String, Object> convert(Map<String, Object> configurationAttributes, Map<String, Class<?>> attributeTypes)
+ {
+ Map<String, Object> attributes = new HashMap<String, Object>();
+ for (Map.Entry<String, Class<?>> attributeEntry : attributeTypes.entrySet())
+ {
+ String attributeName = attributeEntry.getKey();
+ if (configurationAttributes.containsKey(attributeName))
+ {
+ Class<?> classObject = attributeEntry.getValue();
+ Object rawValue = configurationAttributes.get(attributeName);
+ Object value = null;
+ if (classObject == Long.class || classObject == long.class)
+ {
+ value = toLong(attributeName, rawValue);
+ }
+ else if (classObject == Integer.class || classObject == int.class)
+ {
+ value = toInteger(attributeName, rawValue);
+ }
+ else if (classObject == Boolean.class || classObject == boolean.class)
+ {
+ value = toBoolean(attributeName, rawValue);
+ }
+ else if (classObject == String.class)
+ {
+ value = toString(rawValue);
+ }
+ else
+ {
+ throw new IllegalArgumentException("Cannot convert '" + rawValue + "' into " + classObject);
+ }
+ attributes.put(attributeName, value);
+ }
+ }
+ return attributes;
+ }
+}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHost.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHost.java
index ff39e7ae0d..d24f79c56c 100755
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHost.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHost.java
@@ -58,8 +58,6 @@ public interface VirtualHost extends DurableConfigurationStore.Source, Closeable
void close();
- UUID getBrokerId();
-
UUID getId();
void scheduleHouseKeepingTask(long period, HouseKeepingTask task);
@@ -74,7 +72,7 @@ public interface VirtualHost extends DurableConfigurationStore.Source, Closeable
int getHouseKeepingActiveCount();
- IApplicationRegistry getApplicationRegistry();
+ VirtualHostRegistry getVirtualHostRegistry();
BindingFactory getBindingFactory();
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHostImpl.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHostImpl.java
index caff2b11d2..dd3610373f 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHostImpl.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHostImpl.java
@@ -55,13 +55,14 @@ import org.apache.qpid.server.queue.AMQQueue;
import org.apache.qpid.server.queue.AMQQueueFactory;
import org.apache.qpid.server.queue.DefaultQueueRegistry;
import org.apache.qpid.server.queue.QueueRegistry;
-import org.apache.qpid.server.registry.IApplicationRegistry;
import org.apache.qpid.server.security.SecurityManager;
import org.apache.qpid.server.stats.StatisticsCounter;
+import org.apache.qpid.server.stats.StatisticsGatherer;
import org.apache.qpid.server.store.Event;
import org.apache.qpid.server.store.EventListener;
import org.apache.qpid.server.store.HAMessageStore;
import org.apache.qpid.server.store.MessageStore;
+import org.apache.qpid.server.store.MessageStoreCreator;
import org.apache.qpid.server.store.OperationalLoggingListener;
import org.apache.qpid.server.txn.DtxRegistry;
@@ -79,7 +80,9 @@ public class VirtualHostImpl implements VirtualHost, IConnectionRegistry.Registr
private final ScheduledThreadPoolExecutor _houseKeepingTasks;
- private final IApplicationRegistry _appRegistry;
+ private final VirtualHostRegistry _virtualHostRegistry;
+
+ private final StatisticsGatherer _brokerStatisticsGatherer;
private final SecurityManager _securityManager;
@@ -106,7 +109,7 @@ public class VirtualHostImpl implements VirtualHost, IConnectionRegistry.Registr
private final Map<String, LinkRegistry> _linkRegistry = new HashMap<String, LinkRegistry>();
private boolean _blocked;
- public VirtualHostImpl(IApplicationRegistry appRegistry, VirtualHostConfiguration hostConfig) throws Exception
+ public VirtualHostImpl(VirtualHostRegistry virtualHostRegistry, StatisticsGatherer brokerStatisticsGatherer, SecurityManager parentSecurityManager, VirtualHostConfiguration hostConfig) throws Exception
{
if (hostConfig == null)
{
@@ -118,7 +121,8 @@ public class VirtualHostImpl implements VirtualHost, IConnectionRegistry.Registr
throw new IllegalArgumentException("Illegal name (" + hostConfig.getName() + ") for virtualhost.");
}
- _appRegistry = appRegistry;
+ _virtualHostRegistry = virtualHostRegistry;
+ _brokerStatisticsGatherer = brokerStatisticsGatherer;
_vhostConfig = hostConfig;
_name = _vhostConfig.getName();
_dtxRegistry = new DtxRegistry();
@@ -127,7 +131,7 @@ public class VirtualHostImpl implements VirtualHost, IConnectionRegistry.Registr
CurrentActor.get().message(VirtualHostMessages.CREATED(_name));
- _securityManager = new SecurityManager(_appRegistry.getSecurityManager(), _vhostConfig.getConfig());
+ _securityManager = new SecurityManager(parentSecurityManager, _vhostConfig.getConfig().getString("security.acl"));
_connectionRegistry = new ConnectionRegistry();
_connectionRegistry.addRegistryChangeListener(this);
@@ -142,7 +146,7 @@ public class VirtualHostImpl implements VirtualHost, IConnectionRegistry.Registr
_bindingFactory = new BindingFactory(this);
- _messageStore = initialiseMessageStore(hostConfig.getMessageStoreClass());
+ _messageStore = initialiseMessageStore(hostConfig);
configureMessageStore(hostConfig);
@@ -266,19 +270,34 @@ public class VirtualHostImpl implements VirtualHost, IConnectionRegistry.Registr
if (!(o instanceof MessageStore))
{
- throw new ClassCastException("Message store factory class must implement " + MessageStore.class +
+ throw new ClassCastException("Message store class must implement " + MessageStore.class +
". Class " + clazz + " does not.");
}
final MessageStore messageStore = (MessageStore) o;
- final MessageStoreLogSubject storeLogSubject = new MessageStoreLogSubject(this, clazz.getSimpleName());
+ return messageStore;
+ }
+
+ private MessageStore initialiseMessageStore(VirtualHostConfiguration hostConfig) throws Exception
+ {
+ String storeType = hostConfig.getConfig().getString("store.type");
+ MessageStore messageStore = null;
+ if (storeType == null)
+ {
+ messageStore = initialiseMessageStore(hostConfig.getMessageStoreClass());
+ }
+ else
+ {
+ messageStore = new MessageStoreCreator().createMessageStore(storeType);
+ }
+
+ final MessageStoreLogSubject storeLogSubject = new MessageStoreLogSubject(this, messageStore.getClass().getSimpleName());
OperationalLoggingListener.listen(messageStore, storeLogSubject);
messageStore.addEventListener(new BeforeActivationListener(), Event.BEFORE_ACTIVATE);
messageStore.addEventListener(new AfterActivationListener(), Event.AFTER_ACTIVATE);
messageStore.addEventListener(new BeforeCloseListener(), Event.BEFORE_CLOSE);
messageStore.addEventListener(new BeforePassivationListener(), Event.BEFORE_PASSIVATE);
-
return messageStore;
}
@@ -461,14 +480,9 @@ public class VirtualHostImpl implements VirtualHost, IConnectionRegistry.Registr
CurrentActor.get().message(VirtualHostMessages.CLOSED());
}
- public UUID getBrokerId()
- {
- return _appRegistry.getBrokerId();
- }
-
- public IApplicationRegistry getApplicationRegistry()
+ public VirtualHostRegistry getVirtualHostRegistry()
{
- return _appRegistry;
+ return _virtualHostRegistry;
}
public BindingFactory getBindingFactory()
@@ -480,14 +494,14 @@ public class VirtualHostImpl implements VirtualHost, IConnectionRegistry.Registr
{
_messagesDelivered.registerEvent(1L);
_dataDelivered.registerEvent(messageSize);
- _appRegistry.registerMessageDelivered(messageSize);
+ _brokerStatisticsGatherer.registerMessageDelivered(messageSize);
}
public void registerMessageReceived(long messageSize, long timestamp)
{
_messagesReceived.registerEvent(1L, timestamp);
_dataReceived.registerEvent(messageSize, timestamp);
- _appRegistry.registerMessageReceived(messageSize, timestamp);
+ _brokerStatisticsGatherer.registerMessageReceived(messageSize, timestamp);
}
public StatisticsCounter getMessageReceiptStatistics()
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHostRegistry.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHostRegistry.java
index 9f26c00841..483e11942b 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHostRegistry.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHostRegistry.java
@@ -21,12 +21,9 @@
package org.apache.qpid.server.virtualhost;
import org.apache.qpid.common.Closeable;
-import org.apache.qpid.server.exchange.ExchangeRegistry;
-import org.apache.qpid.server.registry.ApplicationRegistry;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.Collections;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@@ -34,44 +31,26 @@ import java.util.concurrent.ConcurrentHashMap;
public class VirtualHostRegistry implements Closeable
{
private final Map<String, VirtualHost> _registry = new ConcurrentHashMap<String, VirtualHost>();
-
-
private String _defaultVirtualHostName;
- private ApplicationRegistry _applicationRegistry;
- private final Collection<RegistryChangeListener> _listeners =
- Collections.synchronizedCollection(new ArrayList<RegistryChangeListener>());
- public VirtualHostRegistry(ApplicationRegistry applicationRegistry)
+
+ public VirtualHostRegistry()
{
- _applicationRegistry = applicationRegistry;
+ super();
}
- public synchronized void registerVirtualHost(VirtualHost host) throws Exception
+ public synchronized void registerVirtualHost(VirtualHost host)
{
if(_registry.containsKey(host.getName()))
{
- throw new Exception("Virtual Host with name " + host.getName() + " already registered.");
+ throw new IllegalArgumentException("Virtual Host with name " + host.getName() + " already registered.");
}
_registry.put(host.getName(),host);
- synchronized (_listeners)
- {
- for(RegistryChangeListener listener : _listeners)
- {
- listener.virtualHostRegistered(host);
- }
- }
}
-
+
public synchronized void unregisterVirtualHost(VirtualHost host)
{
_registry.remove(host.getName());
- synchronized (_listeners)
- {
- for(RegistryChangeListener listener : _listeners)
- {
- listener.virtualHostUnregistered(host);
- }
- }
}
public VirtualHost getVirtualHost(String name)
@@ -105,30 +84,12 @@ public class VirtualHostRegistry implements Closeable
return new ArrayList<VirtualHost>(_registry.values());
}
- public ApplicationRegistry getApplicationRegistry()
- {
- return _applicationRegistry;
- }
-
public void close()
{
for (VirtualHost virtualHost : getVirtualHosts())
{
virtualHost.close();
}
-
- }
-
- public static interface RegistryChangeListener
- {
- void virtualHostRegistered(VirtualHost virtualHost);
- void virtualHostUnregistered(VirtualHost virtualHost);
-
- }
-
- public void addRegistryChangeListener(RegistryChangeListener listener)
- {
- _listeners.add(listener);
}
}
diff --git a/qpid/java/broker/src/main/resources/META-INF/services/org.apache.qpid.server.configuration.ConfigurationStoreFactory b/qpid/java/broker/src/main/resources/META-INF/services/org.apache.qpid.server.configuration.ConfigurationStoreFactory
new file mode 100644
index 0000000000..5f75a8c4c9
--- /dev/null
+++ b/qpid/java/broker/src/main/resources/META-INF/services/org.apache.qpid.server.configuration.ConfigurationStoreFactory
@@ -0,0 +1,19 @@
+#
+# 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.
+#
+org.apache.qpid.server.configuration.store.factory.JsonConfigurationStoreFactory
diff --git a/qpid/java/broker/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.AuthenticationManagerFactory b/qpid/java/broker/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.AuthenticationManagerFactory
index ee41fe966d..8ff67030ef 100644
--- a/qpid/java/broker/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.AuthenticationManagerFactory
+++ b/qpid/java/broker/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.AuthenticationManagerFactory
@@ -17,7 +17,8 @@
# under the License.
#
org.apache.qpid.server.security.auth.manager.AnonymousAuthenticationManagerFactory
+org.apache.qpid.server.security.auth.manager.Base64MD5PasswordFileAuthenticationManagerFactory
org.apache.qpid.server.security.auth.manager.ExternalAuthenticationManagerFactory
org.apache.qpid.server.security.auth.manager.KerberosAuthenticationManagerFactory
-org.apache.qpid.server.security.auth.manager.PrincipalDatabaseAuthManagerFactory
+org.apache.qpid.server.security.auth.manager.PlainPasswordFileAuthenticationManagerFactory
org.apache.qpid.server.security.auth.manager.SimpleLDAPAuthenticationManagerFactory
diff --git a/qpid/java/broker/src/main/resources/META-INF/services/org.apache.qpid.server.store.MessageStoreFactory b/qpid/java/broker/src/main/resources/META-INF/services/org.apache.qpid.server.store.MessageStoreFactory
new file mode 100644
index 0000000000..1357f816b7
--- /dev/null
+++ b/qpid/java/broker/src/main/resources/META-INF/services/org.apache.qpid.server.store.MessageStoreFactory
@@ -0,0 +1,20 @@
+#
+# 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.
+#
+org.apache.qpid.server.store.derby.DerbyMessageStoreFactory
+org.apache.qpid.server.store.MemoryMessageStoreFactory \ No newline at end of file
diff --git a/qpid/java/broker/src/main/resources/initial-store.json b/qpid/java/broker/src/main/resources/initial-store.json
new file mode 100644
index 0000000000..a80ad95bd4
--- /dev/null
+++ b/qpid/java/broker/src/main/resources/initial-store.json
@@ -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.
+ *
+ */
+{
+ "name": "QpidBroker",
+ "defaultAuthenticationProvider" : "defaultAuthenticationProvider",
+ "defaultVirtualHost" : "default",
+ "authenticationproviders" : [ {
+ "name" : "defaultAuthenticationProvider",
+ "authenticationProviderType" : "PlainPasswordFileAuthenticationProvider",
+ "path" : "${QPID_HOME}/etc/passwd"
+ } ],
+ "ports" : [ {
+ "name" : "5672-AMQP",
+ "port" : 5672
+ }, {
+ "name" : "8080-HTTP",
+ "port" : 8080,
+ "protocols" : [ "HTTP" ]
+ }, {
+ "name" : "8999-RMI",
+ "port" : 8999,
+ "protocols" : [ "RMI" ]
+ }, {
+ "name" : "9099-JMX_RMI",
+ "port" : 9099,
+ "protocols" : [ "JMX_RMI" ]
+ }],
+ "virtualhosts" : [ {
+ "name" : "default",
+ "storeType" : "DERBY",
+ "storePath" : "${QPID_WORK}/store"
+ } ],
+ "plugins" : [ {
+ "pluginType" : "MANAGEMENT-HTTP",
+ "name" : "httpManagement"
+ }, {
+ "pluginType" : "MANAGEMENT-JMX",
+ "name" : "jmxManagement"
+ } ]
+} \ No newline at end of file
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/AMQChannelTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/AMQChannelTest.java
index fc6cbcb248..e10bdbbb35 100644
--- a/qpid/java/broker/src/test/java/org/apache/qpid/server/AMQChannelTest.java
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/AMQChannelTest.java
@@ -20,23 +20,69 @@
*/
package org.apache.qpid.server;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.qpid.AMQException;
+import org.apache.qpid.framing.AMQShortString;
+import org.apache.qpid.framing.BasicContentHeaderProperties;
+import org.apache.qpid.framing.ContentHeaderBody;
+import org.apache.qpid.framing.abstraction.MessagePublishInfo;
+import org.apache.qpid.server.configuration.BrokerProperties;
+import org.apache.qpid.server.exchange.Exchange;
+import org.apache.qpid.server.message.MessageContentSource;
+import org.apache.qpid.server.model.Broker;
import org.apache.qpid.server.protocol.AMQProtocolSession;
import org.apache.qpid.server.protocol.InternalTestProtocolSession;
-import org.apache.qpid.server.registry.ApplicationRegistry;
-import org.apache.qpid.server.util.InternalBrokerBaseCase;
+import org.apache.qpid.server.util.BrokerTestHelper;
import org.apache.qpid.server.virtualhost.VirtualHost;
+import org.apache.qpid.test.utils.QpidTestCase;
-public class AMQChannelTest extends InternalBrokerBaseCase
+public class AMQChannelTest extends QpidTestCase
{
private VirtualHost _virtualHost;
private AMQProtocolSession _protocolSession;
+ private Map<Integer,String> _replies;
+ private Broker _broker;
@Override
public void setUp() throws Exception
{
super.setUp();
- _virtualHost = ApplicationRegistry.getInstance().getVirtualHostRegistry().getVirtualHosts().iterator().next();
- _protocolSession = new InternalTestProtocolSession(_virtualHost);
+ BrokerTestHelper.setUp();
+ _virtualHost = BrokerTestHelper.createVirtualHost(getTestName());
+ _broker = BrokerTestHelper.createBrokerMock();
+ _protocolSession = new InternalTestProtocolSession(_virtualHost, _broker)
+ {
+ @Override
+ public void writeReturn(MessagePublishInfo messagePublishInfo,
+ ContentHeaderBody header,
+ MessageContentSource msgContent,
+ int channelId,
+ int replyCode,
+ AMQShortString replyText) throws AMQException
+ {
+ _replies.put(replyCode, replyText.asString());
+ }
+ };
+ _replies = new HashMap<Integer, String>();
+ }
+
+ @Override
+ public void tearDown() throws Exception
+ {
+ try
+ {
+ _virtualHost.close();
+ }
+ finally
+ {
+ BrokerTestHelper.tearDown();
+ super.tearDown();
+ }
}
public void testCompareTo() throws Exception
@@ -44,9 +90,54 @@ public class AMQChannelTest extends InternalBrokerBaseCase
AMQChannel channel1 = new AMQChannel(_protocolSession, 1, _virtualHost.getMessageStore());
// create a channel with the same channelId but on a different session
- AMQChannel channel2 = new AMQChannel(new InternalTestProtocolSession(_virtualHost), 1, _virtualHost.getMessageStore());
+ AMQChannel channel2 = new AMQChannel(new InternalTestProtocolSession(_virtualHost, _broker), 1, _virtualHost.getMessageStore());
assertFalse("Unexpected compare result", channel1.compareTo(channel2) == 0);
assertEquals("Unexpected compare result", 0, channel1.compareTo(channel1));
}
+ public void testPublishContentHeaderWhenMessageAuthorizationFails() throws Exception
+ {
+ setTestSystemProperty(BrokerProperties.PROPERTY_MSG_AUTH, "true");
+ AMQChannel channel = new AMQChannel(_protocolSession, 1, _virtualHost.getMessageStore());
+ channel.setLocalTransactional();
+
+ MessagePublishInfo info = mock(MessagePublishInfo.class);
+ Exchange e = mock(Exchange.class);
+ ContentHeaderBody contentHeaderBody= mock(ContentHeaderBody.class);
+ BasicContentHeaderProperties properties = mock(BasicContentHeaderProperties.class);
+
+ when(contentHeaderBody.getProperties()).thenReturn(properties);
+ when(info.getExchange()).thenReturn(new AMQShortString("test"));
+ when(properties.getUserId()).thenReturn(new AMQShortString(_protocolSession.getAuthorizedPrincipal().getName() + "_incorrect"));
+
+ channel.setPublishFrame(info, e);
+ channel.publishContentHeader(contentHeaderBody);
+ channel.commit();
+
+ assertEquals("Unexpected number of replies", 1, _replies.size());
+ assertEquals("Message authorization passed", "Access Refused", _replies.get(403));
+ }
+
+ public void testPublishContentHeaderWhenMessageAuthorizationPasses() throws Exception
+ {
+ setTestSystemProperty(BrokerProperties.PROPERTY_MSG_AUTH, "true");
+ AMQChannel channel = new AMQChannel(_protocolSession, 1, _virtualHost.getMessageStore());
+ channel.setLocalTransactional();
+
+ MessagePublishInfo info = mock(MessagePublishInfo.class);
+ Exchange e = mock(Exchange.class);
+ ContentHeaderBody contentHeaderBody= mock(ContentHeaderBody.class);
+ BasicContentHeaderProperties properties = mock(BasicContentHeaderProperties.class);
+
+ when(contentHeaderBody.getProperties()).thenReturn(properties);
+ when(info.getExchange()).thenReturn(new AMQShortString("test"));
+ when(properties.getUserId()).thenReturn(new AMQShortString(_protocolSession.getAuthorizedPrincipal().getName()));
+
+ channel.setPublishFrame(info, e);
+ channel.publishContentHeader(contentHeaderBody);
+ channel.commit();
+
+ assertEquals("Unexpected number of replies", 0, _replies.size());
+ }
+
}
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/BrokerOptionsTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/BrokerOptionsTest.java
index 43824e713f..9b7e3794d0 100644
--- a/qpid/java/broker/src/test/java/org/apache/qpid/server/BrokerOptionsTest.java
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/BrokerOptionsTest.java
@@ -22,91 +22,36 @@ package org.apache.qpid.server;
import org.apache.qpid.test.utils.QpidTestCase;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Set;
-
-
public class BrokerOptionsTest extends QpidTestCase
{
private BrokerOptions _options;
-
- private static final int TEST_PORT1 = 6789;
- private static final int TEST_PORT2 = 6790;
-
protected void setUp()
{
_options = new BrokerOptions();
}
-
- public void testDefaultPort()
- {
- assertEquals(Collections.<Integer>emptySet(), _options.getPorts());
- }
-
- public void testOverriddenPort()
- {
- _options.addPort(TEST_PORT1);
- assertEquals(Collections.singleton(TEST_PORT1), _options.getPorts());
- }
-
- public void testManyOverriddenPorts()
- {
- _options.addPort(TEST_PORT1);
- _options.addPort(TEST_PORT2);
- final Set<Integer> expectedPorts = new HashSet<Integer>(Arrays.asList(new Integer[] {TEST_PORT1, TEST_PORT2}));
- assertEquals(expectedPorts, _options.getPorts());
- }
-
- public void testDuplicateOverriddenPortsAreSilentlyIgnored()
- {
- _options.addPort(TEST_PORT1);
- _options.addPort(TEST_PORT2);
- _options.addPort(TEST_PORT1); // duplicate - should be silently ignored
- final Set<Integer> expectedPorts = new HashSet<Integer>(Arrays.asList(new Integer[] {TEST_PORT1, TEST_PORT2}));
- assertEquals(expectedPorts, _options.getPorts());
- }
-
- public void testDefaultSSLPort()
- {
- assertEquals(Collections.<Integer>emptySet(), _options.getSSLPorts());
- }
- public void testOverriddenSSLPort()
+ public void testDefaultConfigurationStoreType()
{
- _options.addSSLPort(TEST_PORT1);
- assertEquals(Collections.singleton(TEST_PORT1), _options.getSSLPorts());
+ assertEquals("json", _options.getConfigurationStoreType());
}
- public void testManyOverriddenSSLPorts()
+ public void testOverriddenConfigurationStoreType()
{
- _options.addSSLPort(TEST_PORT1);
- _options.addSSLPort(TEST_PORT2);
- final Set<Integer> expectedPorts = new HashSet<Integer>(Arrays.asList(new Integer[] {TEST_PORT1, TEST_PORT2}));
- assertEquals(expectedPorts, _options.getSSLPorts());
+ _options.setConfigurationStoreType("dby");
+ assertEquals("dby", _options.getConfigurationStoreType());
}
- public void testDuplicateOverriddenSSLPortsAreSilentlyIgnored()
+ public void testDefaultConfigurationStoreLocation()
{
- _options.addSSLPort(TEST_PORT1);
- _options.addSSLPort(TEST_PORT2);
- _options.addSSLPort(TEST_PORT1); // duplicate - should be silently ignored
- final Set<Integer> expectedPorts = new HashSet<Integer>(Arrays.asList(new Integer[] {TEST_PORT1, TEST_PORT2}));
- assertEquals(expectedPorts, _options.getSSLPorts());
+ assertNull(_options.getConfigurationStoreLocation());
}
- public void testDefaultConfigFile()
- {
- assertNull(_options.getConfigFile());
- }
-
- public void testOverriddenConfigFile()
+ public void testOverriddenConfigurationStoreLocation()
{
final String testConfigFile = "etc/mytestconfig.xml";
- _options.setConfigFile(testConfigFile);
- assertEquals(testConfigFile, _options.getConfigFile());
+ _options.setConfigurationStoreLocation(testConfigFile);
+ assertEquals(testConfigFile, _options.getConfigurationStoreLocation());
}
public void testDefaultLogConfigFile()
@@ -121,72 +66,6 @@ public class BrokerOptionsTest extends QpidTestCase
assertEquals(testLogConfigFile, _options.getLogConfigFile());
}
- public void testDefaultJmxPortRegistryServer()
- {
- assertNull(_options.getJmxPortRegistryServer());
- }
-
- public void testJmxPortRegistryServer()
- {
- _options.setJmxPortRegistryServer(TEST_PORT1);
- assertEquals(Integer.valueOf(TEST_PORT1), _options.getJmxPortRegistryServer());
- }
-
- public void testDefaultJmxPortConnectorServer()
- {
- assertNull(_options.getJmxPortConnectorServer());
- }
-
- public void testJmxPortConnectorServer()
- {
- _options.setJmxPortConnectorServer(TEST_PORT1);
- assertEquals(Integer.valueOf(TEST_PORT1), _options.getJmxPortConnectorServer());
- }
-
- public void testQpidHomeExposesSysProperty()
- {
- assertEquals(System.getProperty("QPID_HOME"), _options.getQpidHome());
- }
-
- public void testDefaultExcludesPortFor0_10()
- {
- assertEquals(Collections.EMPTY_SET, _options.getExcludedPorts(ProtocolExclusion.v0_10));
- }
-
- public void testOverriddenExcludesPortFor0_10()
- {
- _options.addExcludedPort(ProtocolExclusion.v0_10, TEST_PORT1);
- assertEquals(Collections.singleton(TEST_PORT1), _options.getExcludedPorts(ProtocolExclusion.v0_10));
- }
-
- public void testManyOverriddenExcludedPortFor0_10()
- {
- _options.addExcludedPort(ProtocolExclusion.v0_10, TEST_PORT1);
- _options.addExcludedPort(ProtocolExclusion.v0_10, TEST_PORT2);
- final Set<Integer> expectedPorts = new HashSet<Integer>(Arrays.asList(new Integer[] {TEST_PORT1, TEST_PORT2}));
- assertEquals(expectedPorts, _options.getExcludedPorts(ProtocolExclusion.v0_10));
- }
-
- public void testDuplicatedOverriddenExcludedPortFor0_10AreSilentlyIgnored()
- {
- _options.addExcludedPort(ProtocolExclusion.v0_10, TEST_PORT1);
- _options.addExcludedPort(ProtocolExclusion.v0_10, TEST_PORT2);
- final Set<Integer> expectedPorts = new HashSet<Integer>(Arrays.asList(new Integer[] {TEST_PORT1, TEST_PORT2}));
- assertEquals(expectedPorts, _options.getExcludedPorts(ProtocolExclusion.v0_10));
- }
-
- public void testDefaultBind()
- {
- assertNull(_options.getBind());
- }
-
- public void testOverriddenBind()
- {
- final String bind = "192.168.0.1";
- _options.setBind(bind);
- assertEquals(bind, _options.getBind());
- }
-
public void testDefaultLogWatchFrequency()
{
assertEquals(0L, _options.getLogWatchFrequency());
@@ -199,31 +78,4 @@ public class BrokerOptionsTest extends QpidTestCase
_options.setLogWatchFrequency(myFreq);
assertEquals(myFreq, _options.getLogWatchFrequency());
}
-
- public void testDefaultIncludesPortFor0_10()
- {
- assertEquals(Collections.EMPTY_SET, _options.getIncludedPorts(ProtocolInclusion.v0_10));
- }
-
- public void testOverriddenIncludesPortFor0_10()
- {
- _options.addIncludedPort(ProtocolInclusion.v0_10, TEST_PORT1);
- assertEquals(Collections.singleton(TEST_PORT1), _options.getIncludedPorts(ProtocolInclusion.v0_10));
- }
-
- public void testManyOverriddenIncludedPortFor0_10()
- {
- _options.addIncludedPort(ProtocolInclusion.v0_10, TEST_PORT1);
- _options.addIncludedPort(ProtocolInclusion.v0_10, TEST_PORT2);
- final Set<Integer> expectedPorts = new HashSet<Integer>(Arrays.asList(new Integer[] {TEST_PORT1, TEST_PORT2}));
- assertEquals(expectedPorts, _options.getIncludedPorts(ProtocolInclusion.v0_10));
- }
-
- public void testDuplicatedOverriddenIncludedPortFor0_10AreSilentlyIgnored()
- {
- _options.addIncludedPort(ProtocolInclusion.v0_10, TEST_PORT1);
- _options.addIncludedPort(ProtocolInclusion.v0_10, TEST_PORT2);
- final Set<Integer> expectedPorts = new HashSet<Integer>(Arrays.asList(new Integer[] {TEST_PORT1, TEST_PORT2}));
- assertEquals(expectedPorts, _options.getIncludedPorts(ProtocolInclusion.v0_10));
- }
}
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/MainTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/MainTest.java
index ffd607574e..b0533080a5 100644
--- a/qpid/java/broker/src/test/java/org/apache/qpid/server/MainTest.java
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/MainTest.java
@@ -23,8 +23,6 @@ package org.apache.qpid.server;
import org.apache.commons.cli.CommandLine;
import org.apache.qpid.test.utils.QpidTestCase;
-import java.util.EnumSet;
-
/**
* Test to verify the command line parsing within the Main class, by
* providing it a series of command line arguments and verifying the
@@ -36,105 +34,24 @@ public class MainTest extends QpidTestCase
{
BrokerOptions options = startDummyMain("");
- assertTrue(options.getPorts().isEmpty());
- assertTrue(options.getSSLPorts().isEmpty());
- assertEquals(null, options.getJmxPortRegistryServer());
- assertEquals(null, options.getConfigFile());
+ assertEquals("json", options.getConfigurationStoreType());
+ assertEquals(null, options.getConfigurationStoreLocation());
assertEquals(null, options.getLogConfigFile());
- assertEquals(null, options.getBind());
-
- for(ProtocolExclusion pe : EnumSet.allOf(ProtocolExclusion.class))
- {
- assertEquals(0, options.getExcludedPorts(pe).size());
- }
-
- for(ProtocolInclusion pe : EnumSet.allOf(ProtocolInclusion.class))
- {
- assertEquals(0, options.getIncludedPorts(pe).size());
- }
- }
-
- public void testPortOverriddenSingle()
- {
- BrokerOptions options = startDummyMain("-p 1234");
-
- assertTrue(options.getPorts().contains(1234));
- assertEquals(1, options.getPorts().size());
- assertTrue(options.getSSLPorts().isEmpty());
- }
-
- public void testPortOverriddenMultiple()
- {
- BrokerOptions options = startDummyMain("-p 1234 -p 4321");
-
- assertTrue(options.getPorts().contains(1234));
- assertTrue(options.getPorts().contains(4321));
- assertEquals(2, options.getPorts().size());
- assertTrue(options.getSSLPorts().isEmpty());
+ assertEquals(0, options.getLogWatchFrequency());
}
- public void testSSLPortOverriddenSingle()
+ public void testConfigurationStoreLocation()
{
- BrokerOptions options = startDummyMain("-s 5678");
+ BrokerOptions options = startDummyMain("-sp abcd/config.xml");
- assertTrue(options.getSSLPorts().contains(5678));
- assertEquals(1, options.getSSLPorts().size());
- assertTrue(options.getPorts().isEmpty());
+ assertEquals("abcd/config.xml", options.getConfigurationStoreLocation());
}
- public void testSSLPortOverriddenMultiple()
+ public void testConfigurationStoreType()
{
- BrokerOptions options = startDummyMain("-s 5678 -s 8765");
+ BrokerOptions options = startDummyMain("-st dby");
- assertTrue(options.getSSLPorts().contains(5678));
- assertTrue(options.getSSLPorts().contains(8765));
- assertEquals(2, options.getSSLPorts().size());
- assertTrue(options.getPorts().isEmpty());
- }
-
- public void testNonSSLandSSLPortsOverridden()
- {
- BrokerOptions options = startDummyMain("-p 5678 -s 8765");
-
- assertTrue(options.getPorts().contains(5678));
- assertTrue(options.getSSLPorts().contains(8765));
- assertEquals(1, options.getPorts().size());
- assertEquals(1, options.getSSLPorts().size());
- }
-
- public void testJmxPortRegistryServerOverridden()
- {
- BrokerOptions options = startDummyMain("--jmxregistryport 3456");
-
- assertEquals(Integer.valueOf(3456), options.getJmxPortRegistryServer());
-
- options = startDummyMain("-m 3457");
- assertEquals(Integer.valueOf(3457), options.getJmxPortRegistryServer());
- }
-
- public void testJmxPortConnectorServerOverridden()
- {
- BrokerOptions options = startDummyMain("--jmxconnectorport 3456");
-
- assertEquals(Integer.valueOf(3456), options.getJmxPortConnectorServer());
- }
-
- public void testExclude0_10()
- {
- BrokerOptions options = startDummyMain("-p 3456 --exclude-0-10 3456");
-
- assertTrue(options.getPorts().contains(3456));
- assertEquals(1, options.getPorts().size());
- assertTrue(options.getExcludedPorts(ProtocolExclusion.v0_10).contains(3456));
- assertEquals(1, options.getExcludedPorts(ProtocolExclusion.v0_10).size());
- assertEquals(0, options.getExcludedPorts(ProtocolExclusion.v0_9_1).size());
- }
-
- public void testConfig()
- {
- BrokerOptions options = startDummyMain("-c abcd/config.xml");
-
- assertEquals("abcd/config.xml", options.getConfigFile());
+ assertEquals("dby", options.getConfigurationStoreType());
}
public void testLogConfig()
@@ -167,20 +84,6 @@ public class MainTest extends QpidTestCase
assertTrue("Parsed command line didnt pick up help option", main.getCommandLine().hasOption("h"));
}
- public void testInclude010()
- {
- BrokerOptions options = startDummyMain("-p 5678 --include-0-10 5678");
-
- assertTrue(options.getPorts().contains(5678));
- assertEquals(1, options.getPorts().size());
- assertTrue(options.getIncludedPorts(ProtocolInclusion.v0_10).contains(5678));
- assertEquals(1, options.getIncludedPorts(ProtocolInclusion.v0_10).size());
- assertEquals(0, options.getIncludedPorts(ProtocolInclusion.v0_9_1).size());
- assertEquals(0, options.getIncludedPorts(ProtocolInclusion.v0_9).size());
- assertEquals(0, options.getIncludedPorts(ProtocolInclusion.v0_8).size());
- assertEquals(0, options.getIncludedPorts(ProtocolInclusion.v1_0).size());
- }
-
private BrokerOptions startDummyMain(String commandLine)
{
return (new TestMain(commandLine.split("\\s"))).getOptions();
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/ack/AcknowledgeTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/ack/AcknowledgeTest.java
index b3223f16c4..4d6d60906d 100644
--- a/qpid/java/broker/src/test/java/org/apache/qpid/server/ack/AcknowledgeTest.java
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/ack/AcknowledgeTest.java
@@ -22,14 +22,72 @@ package org.apache.qpid.server.ack;
import org.apache.qpid.AMQException;
+import org.apache.qpid.exchange.ExchangeDefaults;
import org.apache.qpid.framing.AMQShortString;
+import org.apache.qpid.server.AMQChannel;
+import org.apache.qpid.server.exchange.Exchange;
import org.apache.qpid.server.protocol.InternalTestProtocolSession;
-import org.apache.qpid.server.util.InternalBrokerBaseCase;
+import org.apache.qpid.server.queue.SimpleAMQQueue;
+import org.apache.qpid.server.store.MessageStore;
+import org.apache.qpid.server.store.TestableMemoryMessageStore;
+import org.apache.qpid.server.util.BrokerTestHelper;
+import org.apache.qpid.server.virtualhost.VirtualHost;
+import org.apache.qpid.test.utils.QpidTestCase;
import java.util.List;
-public class AcknowledgeTest extends InternalBrokerBaseCase
+public class AcknowledgeTest extends QpidTestCase
{
+ private AMQChannel _channel;
+ private SimpleAMQQueue _queue;
+ private MessageStore _messageStore;
+ private String _queueName;
+
+ @Override
+ public void setUp() throws Exception
+ {
+ super.setUp();
+ BrokerTestHelper.setUp();
+ _channel = BrokerTestHelper.createChannel();
+ VirtualHost virtualHost = _channel.getVirtualHost();
+ _queueName = getTestName();
+ _queue = BrokerTestHelper.createQueue(_queueName, virtualHost);
+ _messageStore = virtualHost.getMessageStore();
+ Exchange defaultExchange = virtualHost.getExchangeRegistry().getDefaultExchange();
+ virtualHost.getBindingFactory().addBinding(_queueName, _queue, defaultExchange, null);
+ }
+
+ @Override
+ public void tearDown() throws Exception
+ {
+ try
+ {
+ if (_channel != null)
+ {
+ _channel.getVirtualHost().close();
+ }
+ }
+ finally
+ {
+ BrokerTestHelper.tearDown();
+ super.tearDown();
+ }
+ }
+
+ private AMQChannel getChannel()
+ {
+ return _channel;
+ }
+
+ private InternalTestProtocolSession getSession()
+ {
+ return (InternalTestProtocolSession)_channel.getProtocolSession();
+ }
+
+ private SimpleAMQQueue getQueue()
+ {
+ return _queue;
+ }
public void testTransactionalSingleAck() throws AMQException
{
@@ -70,7 +128,7 @@ public class AcknowledgeTest extends InternalBrokerBaseCase
checkStoreContents(0);
//Send required messsages to the queue
- publishMessages(getSession(), getChannel(), sendMessageCount);
+ BrokerTestHelper.publishMessages(getChannel(), sendMessageCount, _queueName, ExchangeDefaults.DEFAULT_EXCHANGE_NAME.asString());
if (getChannel().isTransactional())
{
@@ -84,7 +142,7 @@ public class AcknowledgeTest extends InternalBrokerBaseCase
assertEquals("Channel should have no unacked msgs ", 0, getChannel().getUnacknowledgedMessageMap().size());
//Subscribe to the queue
- AMQShortString subscriber = subscribe(getSession(), getChannel(), getQueue());
+ AMQShortString subscriber = _channel.subscribeToQueue(null, _queue, true, null, false, true);
getQueue().deliverAsync();
@@ -117,4 +175,9 @@ public class AcknowledgeTest extends InternalBrokerBaseCase
checkStoreContents(remainingUnackedMessages);
}
+ private void checkStoreContents(int messageCount)
+ {
+ assertEquals("Message header count incorrect in the MetaDataMap", messageCount, ((TestableMemoryMessageStore) _messageStore).getMessageCount());
+ }
+
}
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/BrokerConfigurationStoreCreatorTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/BrokerConfigurationStoreCreatorTest.java
new file mode 100644
index 0000000000..d9bdd444aa
--- /dev/null
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/BrokerConfigurationStoreCreatorTest.java
@@ -0,0 +1,107 @@
+/*
+ *
+ * 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.qpid.server.configuration;
+
+import java.io.File;
+import java.util.Set;
+import java.util.UUID;
+
+import org.apache.qpid.server.BrokerOptions;
+import org.apache.qpid.server.configuration.store.JsonConfigurationEntryStore;
+import org.apache.qpid.test.utils.QpidTestCase;
+import org.apache.qpid.util.FileUtils;
+
+public class BrokerConfigurationStoreCreatorTest extends QpidTestCase
+{
+ private File _userStoreLocation;
+ private BrokerConfigurationStoreCreator _storeCreator;
+ private BrokerOptions _options;
+
+ public void setUp() throws Exception
+ {
+ super.setUp();
+
+ // check whether QPID_HOME JVM system property is set
+ if (QPID_HOME == null)
+ {
+ // set the properties in order to resolve the defaults store settings
+ setTestSystemProperty("QPID_HOME", TMP_FOLDER);
+ }
+ _storeCreator = new BrokerConfigurationStoreCreator();
+ _userStoreLocation = new File(TMP_FOLDER, "_store_" + System.currentTimeMillis() + "_" + getTestName());
+ _options = new BrokerOptions();
+ }
+
+ public void tearDown() throws Exception
+ {
+ try
+ {
+ super.tearDown();
+ }
+ finally
+ {
+ if (_userStoreLocation != null)
+ {
+ FileUtils.delete(_userStoreLocation, true);
+ }
+ }
+ }
+
+ public void testCreateJsonStore()
+ {
+ ConfigurationEntryStore store = _storeCreator.createStore(_userStoreLocation.getAbsolutePath(), "json", _options);
+ assertNotNull("Store was not created", store);
+ assertTrue("File should exists", _userStoreLocation.exists());
+ assertTrue("File size should be greater than 0", _userStoreLocation.length() > 0);
+ JsonConfigurationEntryStore jsonStore = new JsonConfigurationEntryStore();
+ jsonStore.open(_userStoreLocation.getAbsolutePath());
+ Set<UUID> childrenIds = jsonStore.getRootEntry().getChildrenIds();
+ assertFalse("Unexpected children: " + childrenIds, childrenIds.isEmpty());
+ }
+
+ public void testCreateDerbyStore()
+ {
+ //TODO: Implement DERBY store
+ try
+ {
+ _storeCreator.createStore(_userStoreLocation.getAbsolutePath(), "derby", _options);
+ fail("Store is not yet supported");
+ }
+ catch(IllegalConfigurationException e)
+ {
+ // pass
+ }
+ }
+
+ public void testCreateXmlStore() throws Exception
+ {
+ try
+ {
+ _storeCreator.createStore(_userStoreLocation.getAbsolutePath(), "xml", _options);
+ fail("Store is not yet supported");
+ }
+ catch(IllegalConfigurationException e)
+ {
+ // pass
+ }
+ }
+
+}
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/BrokerPropertiesTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/BrokerPropertiesTest.java
new file mode 100644
index 0000000000..5e9e19ffaf
--- /dev/null
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/BrokerPropertiesTest.java
@@ -0,0 +1,51 @@
+/*
+ *
+ * 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.qpid.server.configuration;
+
+import java.util.Locale;
+
+import org.apache.qpid.test.utils.QpidTestCase;
+
+public class BrokerPropertiesTest extends QpidTestCase
+{
+ public void testGetLocaleDefault()
+ {
+ Locale locale = BrokerProperties.getLocale();
+ assertEquals("Unexpected locale", Locale.US, locale);
+ }
+
+ public void testGetLocaleSetWithJVMProperty()
+ {
+ setTestSystemProperty(BrokerProperties.PROPERTY_LOCALE, "en_GB");
+ Locale locale = BrokerProperties.getLocale();
+ assertEquals("Unexpected locale", Locale.UK, locale);
+ }
+
+ public void testGetLocaleSetWithJVMPropertyInUnexpectedFormat()
+ {
+ setTestSystemProperty(BrokerProperties.PROPERTY_LOCALE, "penguins_ANTARCTIC_Moubray_Bay");
+ Locale locale = BrokerProperties.getLocale();
+ assertEquals("Unexpected locale language", "penguins", locale.getLanguage());
+ assertEquals("Unexpected locale country", "ANTARCTIC", locale.getCountry());
+ assertEquals("Unexpected locale country", "Moubray_Bay", locale.getVariant());
+ }
+
+}
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/QueueConfigurationTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/QueueConfigurationTest.java
index 3c5b85cd90..0bb65479ce 100644
--- a/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/QueueConfigurationTest.java
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/QueueConfigurationTest.java
@@ -20,25 +20,31 @@
*/
package org.apache.qpid.server.configuration;
+import static org.mockito.Mockito.when;
+
import junit.framework.TestCase;
import org.apache.commons.configuration.CompositeConfiguration;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.PropertiesConfiguration;
-import org.apache.qpid.server.registry.ApplicationRegistry;
-import org.apache.qpid.server.util.TestApplicationRegistry;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.util.BrokerTestHelper;
public class QueueConfigurationTest extends TestCase
{
-
private VirtualHostConfiguration _emptyConf;
private PropertiesConfiguration _env;
private VirtualHostConfiguration _fullHostConf;
+ private Broker _broker;
+ @Override
public void setUp() throws Exception
{
+ super.setUp();
+ BrokerTestHelper.setUp();
+ _broker = BrokerTestHelper.createBrokerMock();
_env = new PropertiesConfiguration();
- _emptyConf = new VirtualHostConfiguration("test", _env);
+ _emptyConf = new VirtualHostConfiguration("test", _env, _broker);
PropertiesConfiguration fullEnv = new PropertiesConfiguration();
fullEnv.setProperty("queues.maximumMessageAge", 1);
@@ -49,35 +55,41 @@ public class QueueConfigurationTest extends TestCase
fullEnv.setProperty("queues.deadLetterQueues", true);
fullEnv.setProperty("queues.maximumDeliveryCount", 5);
- _fullHostConf = new VirtualHostConfiguration("test", fullEnv);
+ _fullHostConf = new VirtualHostConfiguration("test", fullEnv, _broker);
}
+ @Override
+ public void tearDown() throws Exception
+ {
+ BrokerTestHelper.tearDown();
+ super.tearDown();
+ }
+
public void testMaxDeliveryCount() throws Exception
{
- try
- {
- ApplicationRegistry registry = new TestApplicationRegistry(new ServerConfiguration(_env));
- ApplicationRegistry.initialise(registry);
-
- // Check default value
- QueueConfiguration qConf = new QueueConfiguration("test", _emptyConf);
- assertEquals("Unexpected default server configuration for max delivery count ", 0, qConf.getMaxDeliveryCount());
-
- // Check explicit value
- VirtualHostConfiguration vhostConfig = overrideConfiguration("maximumDeliveryCount", 7);
- qConf = new QueueConfiguration("test", vhostConfig);
- assertEquals("Unexpected host configuration for max delivery count", 7, qConf.getMaxDeliveryCount());
-
- // Check inherited value
- qConf = new QueueConfiguration("test", _fullHostConf);
- assertEquals("Unexpected queue configuration for max delivery count", 5, qConf.getMaxDeliveryCount());
-
- }
- finally
- {
- ApplicationRegistry.remove();
- }
+ // broker MAXIMUM_DELIVERY_ATTEMPTS attribute is not set
+ when(_broker.getAttribute(Broker.MAXIMUM_DELIVERY_ATTEMPTS)).thenReturn(null);
+
+ // Check default value
+ QueueConfiguration qConf = new QueueConfiguration("test", _emptyConf);
+ assertEquals("Unexpected default server configuration for max delivery count ", 0, qConf.getMaxDeliveryCount());
+
+ // set broker MAXIMUM_DELIVERY_ATTEMPTS attribute to 2
+ when(_broker.getAttribute(Broker.MAXIMUM_DELIVERY_ATTEMPTS)).thenReturn(2);
+
+ // Check that queue inherits the MAXIMUM_DELIVERY_ATTEMPTS value from broker
+ qConf = new QueueConfiguration("test", _emptyConf);
+ assertEquals("Unexpected default server configuration for max delivery count ", 2, qConf.getMaxDeliveryCount());
+
+ // Check explicit value
+ VirtualHostConfiguration vhostConfig = overrideConfiguration("maximumDeliveryCount", 7);
+ qConf = new QueueConfiguration("test", vhostConfig);
+ assertEquals("Unexpected host configuration for max delivery count", 7, qConf.getMaxDeliveryCount());
+
+ // Check inherited value
+ qConf = new QueueConfiguration("test", _fullHostConf);
+ assertEquals("Unexpected queue configuration for max delivery count", 5, qConf.getMaxDeliveryCount());
}
/**
@@ -87,28 +99,28 @@ public class QueueConfigurationTest extends TestCase
*/
public void testIsDeadLetterQueueEnabled() throws Exception
{
- try
- {
- ApplicationRegistry registry = new TestApplicationRegistry(new ServerConfiguration(_env));
- ApplicationRegistry.initialise(registry);
-
- // Check default value
- QueueConfiguration qConf = new QueueConfiguration("test", _emptyConf);
- assertFalse("Unexpected queue configuration for dead letter enabled attribute", qConf.isDeadLetterQueueEnabled());
-
- // Check explicit value
- VirtualHostConfiguration vhostConfig = overrideConfiguration("deadLetterQueues", true);
- qConf = new QueueConfiguration("test", vhostConfig);
- assertTrue("Unexpected queue configuration for dead letter enabled attribute", qConf.isDeadLetterQueueEnabled());
-
- // Check inherited value
- qConf = new QueueConfiguration("test", _fullHostConf);
- assertTrue("Unexpected queue configuration for dead letter enabled attribute", qConf.isDeadLetterQueueEnabled());
- }
- finally
- {
- ApplicationRegistry.remove();
- }
+ // enable dead letter queues broker wide
+ when(_broker.getAttribute(Broker.DEAD_LETTER_QUEUE_ENABLED)).thenReturn(true);
+
+ // Check that queue inherits the broker setting
+ QueueConfiguration qConf = new QueueConfiguration("test", _emptyConf);
+ assertTrue("Unexpected queue configuration for dead letter enabled attribute", qConf.isDeadLetterQueueEnabled());
+
+ // broker DEAD_LETTER_QUEUE_ENABLED is not set
+ when(_broker.getAttribute(Broker.DEAD_LETTER_QUEUE_ENABLED)).thenReturn(null);
+
+ // Check that queue dead letter queue is not enabled
+ qConf = new QueueConfiguration("test", _emptyConf);
+ assertFalse("Unexpected queue configuration for dead letter enabled attribute", qConf.isDeadLetterQueueEnabled());
+
+ // Check explicit value
+ VirtualHostConfiguration vhostConfig = overrideConfiguration("deadLetterQueues", true);
+ qConf = new QueueConfiguration("test", vhostConfig);
+ assertTrue("Unexpected queue configuration for dead letter enabled attribute", qConf.isDeadLetterQueueEnabled());
+
+ // Check inherited value
+ qConf = new QueueConfiguration("test", _fullHostConf);
+ assertTrue("Unexpected queue configuration for dead letter enabled attribute", qConf.isDeadLetterQueueEnabled());
}
public void testGetMaximumMessageAge() throws ConfigurationException
@@ -178,27 +190,28 @@ public class QueueConfigurationTest extends TestCase
public void testGetMinimumAlertRepeatGap() throws Exception
{
- try
- {
- ApplicationRegistry registry = new TestApplicationRegistry(new ServerConfiguration(_env));
- ApplicationRegistry.initialise(registry);
- // Check default value
- QueueConfiguration qConf = new QueueConfiguration("test", _emptyConf);
- assertEquals(ServerConfiguration.DEFAULT_MINIMUM_ALERT_REPEAT_GAP, qConf.getMinimumAlertRepeatGap());
-
- // Check explicit value
- VirtualHostConfiguration vhostConfig = overrideConfiguration("minimumAlertRepeatGap", 2);
- qConf = new QueueConfiguration("test", vhostConfig);
- assertEquals(2, qConf.getMinimumAlertRepeatGap());
-
- // Check inherited value
- qConf = new QueueConfiguration("test", _fullHostConf);
- assertEquals(1, qConf.getMinimumAlertRepeatGap());
- }
- finally
- {
- ApplicationRegistry.remove();
- }
+ // set broker attribute ALERT_REPEAT_GAP to 10
+ when(_broker.getAttribute(Broker.ALERT_REPEAT_GAP)).thenReturn(10);
+
+ // check that broker level setting is available on queue configuration
+ QueueConfiguration qConf = new QueueConfiguration("test", _emptyConf);
+ assertEquals(10, qConf.getMinimumAlertRepeatGap());
+
+ // remove configuration for ALERT_REPEAT_GAP on broker level
+ when(_broker.getAttribute(Broker.ALERT_REPEAT_GAP)).thenReturn(null);
+
+ // Check default value
+ qConf = new QueueConfiguration("test", _emptyConf);
+ assertEquals(0, qConf.getMinimumAlertRepeatGap());
+
+ // Check explicit value
+ VirtualHostConfiguration vhostConfig = overrideConfiguration("minimumAlertRepeatGap", 2);
+ qConf = new QueueConfiguration("test", vhostConfig);
+ assertEquals(2, qConf.getMinimumAlertRepeatGap());
+
+ // Check inherited value
+ qConf = new QueueConfiguration("test", _fullHostConf);
+ assertEquals(1, qConf.getMinimumAlertRepeatGap());
}
public void testSortQueueConfiguration() throws ConfigurationException
@@ -235,6 +248,6 @@ public class QueueConfigurationTest extends TestCase
config.addConfiguration(_fullHostConf.getConfig());
config.addConfiguration(queueConfig);
- return new VirtualHostConfiguration("test", config);
+ return new VirtualHostConfiguration("test", config, _broker);
}
}
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/ServerConfigurationTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/ServerConfigurationTest.java
deleted file mode 100644
index c77732e356..0000000000
--- a/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/ServerConfigurationTest.java
+++ /dev/null
@@ -1,1791 +0,0 @@
-/*
- *
- * 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.qpid.server.configuration;
-
-import org.apache.commons.configuration.ConfigurationException;
-import org.apache.commons.configuration.XMLConfiguration;
-
-import org.apache.qpid.framing.AMQShortString;
-import org.apache.qpid.server.exchange.Exchange;
-import org.apache.qpid.server.protocol.AmqpProtocolVersion;
-import org.apache.qpid.server.registry.ApplicationRegistry;
-import org.apache.qpid.server.util.TestApplicationRegistry;
-import org.apache.qpid.server.virtualhost.VirtualHost;
-import org.apache.qpid.server.virtualhost.VirtualHostRegistry;
-import org.apache.qpid.test.utils.QpidTestCase;
-
-import static org.apache.qpid.transport.ConnectionSettings.WILDCARD_ADDRESS;
-
-import java.io.File;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.Writer;
-import java.util.Locale;
-
-import javax.net.ssl.KeyManagerFactory;
-
-public class ServerConfigurationTest extends QpidTestCase
-{
- private XMLConfiguration _config = new XMLConfiguration();
- private ServerConfiguration _serverConfig = null;
-
- @Override
- protected void setUp() throws Exception
- {
- super.setUp();
- _serverConfig = new ServerConfiguration(_config);
- ApplicationRegistry.initialise(new TestApplicationRegistry(_serverConfig));
- }
-
- @Override
- protected void tearDown() throws Exception
- {
- super.tearDown();
- ApplicationRegistry.remove();
- }
-
- public void testSetJMXPortRegistryServer() throws ConfigurationException
- {
- _serverConfig.initialise();
- _serverConfig.setJMXPortRegistryServer(23);
- assertEquals(23, _serverConfig.getJMXPortRegistryServer());
- }
-
- public void testGetJMXPortRegistryServer() throws ConfigurationException
- {
- _config.setProperty(ServerConfiguration.MGMT_JMXPORT_REGISTRYSERVER, 42);
- _serverConfig.initialise();
- assertEquals(42, _serverConfig.getJMXPortRegistryServer());
- }
-
- public void testDefaultJMXPortRegistryServer() throws ConfigurationException
- {
- _serverConfig.initialise();
- assertEquals(8999, _serverConfig.getJMXPortRegistryServer());
- }
-
- public void testSetJMXPortConnectorServer() throws ConfigurationException
- {
- ServerConfiguration serverConfig = new ServerConfiguration(_config);
- serverConfig.setJMXPortConnectorServer(67);
- assertEquals(67, serverConfig.getJMXConnectorServerPort());
- }
-
- public void testGetJMXPortConnectorServer() throws ConfigurationException
- {
- _config.setProperty(ServerConfiguration.MGMT_JMXPORT_CONNECTORSERVER, 67);
- ServerConfiguration serverConfig = new ServerConfiguration(_config);
- assertEquals(67, serverConfig.getJMXConnectorServerPort());
- }
-
- public void testDefaultJMXPortConnectorServer() throws ConfigurationException
- {
- ServerConfiguration serverConfig = new ServerConfiguration(_config);
- assertEquals(ServerConfiguration.DEFAULT_JMXPORT_REGISTRYSERVER + ServerConfiguration.JMXPORT_CONNECTORSERVER_OFFSET,
- serverConfig.getJMXConnectorServerPort());
- }
-
- public void testGetPlatformMbeanserver() throws ConfigurationException
- {
- _serverConfig.initialise();
- assertEquals(true, _serverConfig.getPlatformMbeanserver());
-
- // Check value we set
- _config.setProperty("management.platform-mbeanserver", false);
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals(false, _serverConfig.getPlatformMbeanserver());
- }
-
- public void testGetFrameSize() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
- assertEquals(65536, _serverConfig.getFrameSize());
-
- // Check value we set
- _config.setProperty("advanced.framesize", "23");
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals(23, _serverConfig.getFrameSize());
- }
-
- public void testGetStatusEnabled() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
- assertEquals(ServerConfiguration.DEFAULT_STATUS_UPDATES.equalsIgnoreCase("on"),
- _serverConfig.getStatusUpdatesEnabled());
-
- // Check disabling we set
- _config.setProperty(ServerConfiguration.STATUS_UPDATES, "off");
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals(false, _serverConfig.getStatusUpdatesEnabled());
-
- // Check invalid values don't cause error but result in disabled
- _config.setProperty(ServerConfiguration.STATUS_UPDATES, "Yes Please");
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals(false, _serverConfig.getStatusUpdatesEnabled());
-
- }
- public void testGetSynchedClocks() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
- assertEquals(false, _serverConfig.getSynchedClocks());
-
- // Check value we set
- _config.setProperty("advanced.synced-clocks", true);
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals(true, _serverConfig.getSynchedClocks());
- }
-
- public void testGetLocale() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
-
- // The Default is what ever the VMs default is
- Locale defaultLocale = Locale.getDefault();
-
- assertEquals(defaultLocale, _serverConfig.getLocale());
-
-
- //Test Language only
- Locale update = new Locale("es");
- _config.setProperty(ServerConfiguration.ADVANCED_LOCALE, "es");
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals(update, _serverConfig.getLocale());
-
- //Test Language and Country
- update = new Locale("es","ES");
- _config.setProperty(ServerConfiguration.ADVANCED_LOCALE, "es_ES");
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals(update, _serverConfig.getLocale());
-
- //Test Language and Country and Variant
- update = new Locale("es","ES", "Traditional_WIN");
- _config.setProperty(ServerConfiguration.ADVANCED_LOCALE, "es_ES_Traditional_WIN");
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals(update, _serverConfig.getLocale());
- }
-
-
- public void testGetMsgAuth() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
- assertEquals(false, _serverConfig.getMsgAuth());
-
- // Check value we set
- _config.setProperty("security.msg-auth", true);
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals(true, _serverConfig.getMsgAuth());
- }
-
- public void testGetManagementKeyStorePath() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
- assertEquals(null, _serverConfig.getManagementKeyStorePath());
-
- // Check value we set
- _config.setProperty("management.ssl.keyStorePath", "a");
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals("a", _serverConfig.getManagementKeyStorePath());
- }
-
- public void testGetManagementSSLEnabled() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
- assertEquals(false, _serverConfig.getManagementSSLEnabled());
-
- // Check value we set
- _config.setProperty("management.ssl.enabled", true);
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals(true, _serverConfig.getManagementSSLEnabled());
- }
-
- public void testGetManagementKeystorePassword() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
- assertEquals(null, _serverConfig.getManagementKeyStorePassword());
-
- // Check value we set
- _config.setProperty("management.ssl.keyStorePassword", "a");
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals("a", _serverConfig.getManagementKeyStorePassword());
- }
-
- public void testGetQueueAutoRegister() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
- assertEquals(true, _serverConfig.getQueueAutoRegister());
-
- // Check value we set
- _config.setProperty("queue.auto_register", false);
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals(false, _serverConfig.getQueueAutoRegister());
- }
-
- public void testGetJMXManagementEnabled() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
- assertEquals(true, _serverConfig.getJMXManagementEnabled());
-
- // Check value we set
- _config.setProperty("management.enabled", false);
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals(false, _serverConfig.getJMXManagementEnabled());
- }
-
- public void testGetHTTPManagementEnabled() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
- assertEquals(true, _serverConfig.getHTTPManagementEnabled());
-
- // Check value we set
- _config.setProperty("management.http.enabled", false);
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals(false, _serverConfig.getHTTPManagementEnabled());
- }
-
- public void testGetHTTPManagementSessionTimeout() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
- assertEquals(60 * 15, _serverConfig.getHTTPManagementSessionTimeout());
-
- // Check value we set
- _config.setProperty("management.http.session-timeout", 60);
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals(60, _serverConfig.getHTTPManagementSessionTimeout());
- }
-
- public void testGetHTTPManagementSaslAuthEnabled() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
- assertEquals(true, _serverConfig.getHTTPManagementSaslAuthEnabled());
-
- // Check value we set
- _config.setProperty("management.http.sasl-auth", false);
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals(false, _serverConfig.getHTTPManagementSaslAuthEnabled());
- }
-
- public void testGetHTTPSManagementSaslAuthEnabled() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
- assertEquals(true, _serverConfig.getHTTPSManagementSaslAuthEnabled());
-
- // Check value we set
- _config.setProperty("management.https.sasl-auth", false);
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals(false, _serverConfig.getHTTPSManagementSaslAuthEnabled());
- }
-
- public void testGetManagementRightsInferAllAccess() throws Exception
- {
- _serverConfig.initialise();
-
- //check default
- assertTrue("default should be true", _serverConfig.getManagementRightsInferAllAccess());
-
- //update it
- _config.setProperty("management.managementRightsInferAllAccess", "false");
- assertFalse("New value should be false", _serverConfig.getManagementRightsInferAllAccess());
- }
-
- public void testGetHeartBeatDelay() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
- assertEquals(5, _serverConfig.getHeartBeatDelay());
-
- // Check value we set
- _config.setProperty("heartbeat.delay", 23);
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals(23, _serverConfig.getHeartBeatDelay());
- }
-
- public void testGetHeartBeatTimeout() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
- assertEquals(2.0, _serverConfig.getHeartBeatTimeout());
-
- // Check value we set
- _config.setProperty("heartbeat.timeoutFactor", 2.3);
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals(2.3, _serverConfig.getHeartBeatTimeout());
- }
-
- public void testGetMaximumMessageAge() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
- assertEquals(0, _serverConfig.getMaximumMessageAge());
-
- // Check value we set
- _config.setProperty("maximumMessageAge", 10L);
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals(10, _serverConfig.getMaximumMessageAge());
- }
-
- public void testGetMaximumMessageCount() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
- assertEquals(0, _serverConfig.getMaximumMessageCount());
-
- // Check value we set
- _config.setProperty("maximumMessageCount", 10L);
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals(10, _serverConfig.getMaximumMessageCount());
- }
-
- public void testGetMaximumQueueDepth() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
- assertEquals(0, _serverConfig.getMaximumQueueDepth());
-
- // Check value we set
- _config.setProperty("maximumQueueDepth", 10L);
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals(10, _serverConfig.getMaximumQueueDepth());
- }
-
- public void testGetMaximumMessageSize() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
- assertEquals(0, _serverConfig.getMaximumMessageSize());
-
- // Check value we set
- _config.setProperty("maximumMessageSize", 10L);
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals(10, _serverConfig.getMaximumMessageSize());
- }
-
- public void testGetMinimumAlertRepeatGap() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
- assertEquals(30000l, _serverConfig.getMinimumAlertRepeatGap());
-
- // Check value we set
- _config.setProperty("minimumAlertRepeatGap", 10L);
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals(10, _serverConfig.getMinimumAlertRepeatGap());
- }
-
- public void testGetProcessors() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
- assertEquals(4, _serverConfig.getConnectorProcessors());
-
- // Check value we set
- _config.setProperty("connector.processors", 10);
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals(10, _serverConfig.getConnectorProcessors());
- }
-
- public void testGetPorts() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
- assertNotNull(_serverConfig.getPorts());
- assertEquals(1, _serverConfig.getPorts().size());
- assertEquals(5672, _serverConfig.getPorts().get(0));
-
-
- // Check value we set
- _config.setProperty("connector.port", "10");
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertNotNull(_serverConfig.getPorts());
- assertEquals(1, _serverConfig.getPorts().size());
- assertEquals("10", _serverConfig.getPorts().get(0));
- }
-
- public void testGetBind() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
- assertEquals(WILDCARD_ADDRESS, _serverConfig.getBind());
-
- // Check value we set
- _config.setProperty("connector.bind", "a");
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals("a", _serverConfig.getBind());
- }
-
- public void testGetReceiveBufferSize() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
- assertEquals(ServerConfiguration.DEFAULT_BUFFER_SIZE, _serverConfig.getReceiveBufferSize());
-
- // Check value we set
- _config.setProperty("connector.socketReceiveBuffer", "23");
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals(23, _serverConfig.getReceiveBufferSize());
- }
-
- public void testGetWriteBufferSize() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
- assertEquals(ServerConfiguration.DEFAULT_BUFFER_SIZE, _serverConfig.getWriteBufferSize());
-
- // Check value we set
- _config.setProperty("connector.socketWriteBuffer", "23");
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals(23, _serverConfig.getWriteBufferSize());
- }
-
- public void testGetTcpNoDelay() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
- assertEquals(true, _serverConfig.getTcpNoDelay());
-
- // Check value we set
- _config.setProperty("connector.tcpNoDelay", false);
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals(false, _serverConfig.getTcpNoDelay());
- }
-
- public void testGetEnableSSL() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
- assertEquals(false, _serverConfig.getEnableSSL());
-
- // Check value we set
- _config.setProperty("connector.ssl.enabled", true);
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals(true, _serverConfig.getEnableSSL());
- }
-
- public void testGetSSLOnly() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
- assertEquals(false, _serverConfig.getSSLOnly());
-
- // Check value we set
- _config.setProperty("connector.ssl.sslOnly", true);
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals(true, _serverConfig.getSSLOnly());
- }
-
- public void testGetSSLPorts() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
- assertNotNull(_serverConfig.getSSLPorts());
- assertEquals(1, _serverConfig.getSSLPorts().size());
- assertEquals(ServerConfiguration.DEFAULT_SSL_PORT, _serverConfig.getSSLPorts().get(0));
-
-
- // Check value we set
- _config.setProperty("connector.ssl.port", "10");
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertNotNull(_serverConfig.getSSLPorts());
- assertEquals(1, _serverConfig.getSSLPorts().size());
- assertEquals("10", _serverConfig.getSSLPorts().get(0));
- }
-
- public void testGetConnectorKeystorePath() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
- assertNull(_serverConfig.getConnectorKeyStorePath());
-
- // Check value we set
- _config.setProperty("connector.ssl.keyStorePath", "a");
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals("a", _serverConfig.getConnectorKeyStorePath());
-
- // Ensure we continue to support the old name keystorePath
- _config.clearProperty("connector.ssl.keyStorePath");
- _config.setProperty("connector.ssl.keystorePath", "b");
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals("b", _serverConfig.getConnectorKeyStorePath());
- }
-
- public void testGetConnectorKeystorePassword() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
- assertNull(_serverConfig.getConnectorKeyStorePassword());
-
- // Check value we set
- _config.setProperty("connector.ssl.keyStorePassword", "a");
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals("a", _serverConfig.getConnectorKeyStorePassword());
-
- // Ensure we continue to support the old name keystorePassword
- _config.clearProperty("connector.ssl.keyStorePassword");
- _config.setProperty("connector.ssl.keystorePassword", "b");
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals("b", _serverConfig.getConnectorKeyStorePassword());
- }
-
- public void testConnectorGetKeyManagerAlgorithm() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
- assertEquals(KeyManagerFactory.getDefaultAlgorithm(), _serverConfig.getConnectorKeyManagerFactoryAlgorithm());
-
- // Check value we set
- _config.setProperty("connector.ssl.keyManagerFactoryAlgorithm", "a");
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals("a", _serverConfig.getConnectorKeyManagerFactoryAlgorithm());
-
- // Ensure we continue to support the old name certType
- _config.clearProperty("connector.ssl.keyManagerFactoryAlgorithm");
- _config.setProperty("connector.ssl.certType", "b");
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals("b", _serverConfig.getConnectorKeyManagerFactoryAlgorithm());
- }
-
- public void testGetHousekeepingCheckPeriod() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
- assertEquals(30000, _serverConfig.getHousekeepingCheckPeriod());
-
- // Check value we set
- _config.setProperty("housekeeping.checkPeriod", 23L);
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- _serverConfig.setHousekeepingCheckPeriod(42L);
- assertEquals(42, _serverConfig.getHousekeepingCheckPeriod());
- }
-
- public void testSingleConfiguration() throws IOException, ConfigurationException
- {
- File fileA = File.createTempFile(getClass().getName(), null);
- fileA.deleteOnExit();
- FileWriter out = new FileWriter(fileA);
- out.write("<broker><connector><port>2342</port><ssl><port>4235</port></ssl></connector></broker>");
- out.close();
- ServerConfiguration conf = new ServerConfiguration(fileA);
- conf.initialise();
- assertEquals("4235", conf.getSSLPorts().get(0));
- }
-
- public void testCombinedConfiguration() throws IOException, ConfigurationException
- {
- File mainFile = File.createTempFile(getClass().getName(), null);
- File fileA = File.createTempFile(getClass().getName(), null);
- File fileB = File.createTempFile(getClass().getName(), null);
-
- mainFile.deleteOnExit();
- fileA.deleteOnExit();
- fileB.deleteOnExit();
-
- FileWriter out = new FileWriter(mainFile);
- out.write("<configuration><system/>");
- out.write("<xml fileName=\"" + fileA.getAbsolutePath() + "\"/>");
- out.write("<xml fileName=\"" + fileB.getAbsolutePath() + "\"/>");
- out.write("</configuration>");
- out.close();
-
- out = new FileWriter(fileA);
- out.write("<broker><connector><port>2342</port><ssl><port>4235</port></ssl></connector></broker>");
- out.close();
-
- out = new FileWriter(fileB);
- out.write("<broker><connector><ssl><port>2345</port></ssl></connector></broker>");
- out.close();
-
- ServerConfiguration config = new ServerConfiguration(mainFile.getAbsoluteFile());
- config.initialise();
- assertEquals("4235", config.getSSLPorts().get(0)); // From first file, not
- // overriden by second
- assertNotNull(config.getPorts());
- assertEquals(1, config.getPorts().size());
- assertEquals("2342", config.getPorts().get(0)); // From the first file, not
- // present in the second
- }
-
- public void testVariableInterpolation() throws Exception
- {
- File mainFile = File.createTempFile(getClass().getName(), null);
-
- mainFile.deleteOnExit();
-
- FileWriter out = new FileWriter(mainFile);
- out.write("<broker>\n");
- out.write("\t<work>foo</work>\n");
- out.write("\t<management><ssl><keyStorePath>${work}</keyStorePath></ssl></management>\n");
- out.write("</broker>\n");
- out.close();
-
- ServerConfiguration config = new ServerConfiguration(mainFile.getAbsoluteFile());
- config.initialise();
- assertEquals("Did not get correct interpolated value",
- "foo", config.getManagementKeyStorePath());
- }
-
- private void writeConfigFile(File mainFile, boolean allow) throws IOException {
- writeConfigFile(mainFile, allow, true, null, "test");
- }
-
- private void writeConfigFile(File mainFile, boolean allow, boolean includeVhosts, File vhostsFile, String name) throws IOException {
- FileWriter out = new FileWriter(mainFile);
- out.write("<broker>\n");
- out.write("\t<management><enabled>false</enabled></management>\n");
- out.write("\t<security>\n");
- out.write("\t\t<pd-auth-manager>\n");
- out.write("\t\t\t<principal-database>\n");
- out.write("\t\t\t\t<class>org.apache.qpid.server.security.auth.database.PlainPasswordFilePrincipalDatabase</class>\n");
- out.write("\t\t\t\t<attributes>\n");
- out.write("\t\t\t\t\t<attribute>\n");
- out.write("\t\t\t\t\t\t<name>passwordFile</name>\n");
- out.write("\t\t\t\t\t\t<value>/dev/null</value>\n");
- out.write("\t\t\t\t\t</attribute>\n");
- out.write("\t\t\t\t</attributes>\n");
- out.write("\t\t\t</principal-database>\n");
- out.write("\t\t</pd-auth-manager>\n");
- out.write("\t\t<firewall>\n");
- out.write("\t\t\t<rule access=\""+ ((allow) ? "allow" : "deny") +"\" network=\"127.0.0.1\"/>");
- out.write("\t\t</firewall>\n");
- out.write("\t</security>\n");
- if (includeVhosts)
- {
- out.write("\t<virtualhosts>\n");
- out.write("\t\t<default>test</default>\n");
- out.write("\t\t<virtualhost>\n");
- out.write(String.format("\t\t\t<name>%s</name>\n", name));
- out.write(String.format("\t\t<%s> \n", name));
- out.write("\t\t\t<exchanges>\n");
- out.write("\t\t\t\t<exchange>\n");
- out.write("\t\t\t\t\t<type>topic</type>\n");
- out.write(String.format("\t\t\t\t\t<name>%s.topic</name>\n", name));
- out.write("\t\t\t\t\t<durable>true</durable>\n");
- out.write("\t\t\t\t</exchange>\n");
- out.write("\t\tt</exchanges>\n");
- out.write(String.format("\t\t</%s> \n", name));
- out.write("\t\t</virtualhost>\n");
- out.write("\t</virtualhosts>\n");
- }
- if (vhostsFile != null)
- {
- out.write("\t<virtualhosts>"+vhostsFile.getAbsolutePath()+"</virtualhosts>\n");
- }
- out.write("</broker>\n");
- out.close();
- }
-
- private void writeTestFishConfigFile(File mainFile) throws IOException {
- FileWriter out = new FileWriter(mainFile);
- out.write("<broker>\n");
- out.write("\t<management><enabled>false</enabled></management>\n");
- out.write("\t<security>\n");
- out.write("\t\t<pd-auth-manager>\n");
- out.write("\t\t\t<principal-database>\n");
- out.write("\t\t\t\t<class>org.apache.qpid.server.security.auth.database.PlainPasswordFilePrincipalDatabase</class>\n");
- out.write("\t\t\t\t<attributes>\n");
- out.write("\t\t\t\t\t<attribute>\n");
- out.write("\t\t\t\t\t\t<name>passwordFile</name>\n");
- out.write("\t\t\t\t\t\t<value>/dev/null</value>\n");
- out.write("\t\t\t\t\t</attribute>\n");
- out.write("\t\t\t\t</attributes>\n");
- out.write("\t\t\t</principal-database>\n");
- out.write("\t\t</pd-auth-manager>\n");
- out.write("\t\t<firewall>\n");
- out.write("\t\t\t<rule access=\"allow\" network=\"127.0.0.1\"/>");
- out.write("\t\t</firewall>\n");
- out.write("\t</security>\n");
- out.write("\t<virtualhosts>\n");
- out.write("\t\t<virtualhost>\n");
- out.write("\t\t\t<name>test</name>\n");
- out.write("\t\t<test> \n");
- out.write("\t\t\t<exchanges>\n");
- out.write("\t\t\t\t<exchange>\n");
- out.write("\t\t\t\t\t<type>topic</type>\n");
- out.write("\t\t\t\t\t<name>test.topic</name>\n");
- out.write("\t\t\t\t\t<durable>true</durable>\n");
- out.write("\t\t\t\t</exchange>\n");
- out.write("\t\tt</exchanges>\n");
- out.write("\t\t</test> \n");
- out.write("\t\t</virtualhost>\n");
- out.write("\t\t<virtualhost>\n");
- out.write("\t\t\t<name>fish</name>\n");
- out.write("\t\t<fish> \n");
- out.write("\t\t\t<exchanges>\n");
- out.write("\t\t\t\t<exchange>\n");
- out.write("\t\t\t\t\t<type>topic</type>\n");
- out.write("\t\t\t\t\t<name>fish.topic</name>\n");
- out.write("\t\t\t\t\t<durable>false</durable>\n");
- out.write("\t\t\t\t</exchange>\n");
- out.write("\t\tt</exchanges>\n");
- out.write("\t\t</fish> \n");
- out.write("\t\t</virtualhost>\n");
- out.write("\t</virtualhosts>\n");
- out.write("</broker>\n");
- out.close();
- }
-
- private void writeVirtualHostsFile(File vhostsFile, String name) throws IOException {
- FileWriter out = new FileWriter(vhostsFile);
- out.write("<virtualhosts>\n");
- out.write(String.format("\t\t<default>%s</default>\n", name));
- out.write("\t<virtualhost>\n");
- out.write(String.format("\t\t<name>%s</name>\n", name));
- out.write(String.format("\t\t<%s>\n", name));
- out.write("\t\t\t<exchanges>\n");
- out.write("\t\t\t\t<exchange>\n");
- out.write("\t\t\t\t\t<type>topic</type>\n");
- out.write("\t\t\t\t\t<name>test.topic</name>\n");
- out.write("\t\t\t\t\t<durable>true</durable>\n");
- out.write("\t\t\t\t</exchange>\n");
- out.write("\t\tt</exchanges>\n");
- out.write(String.format("\t\t</%s>\n", name));
- out.write("\t</virtualhost>\n");
- out.write("</virtualhosts>\n");
- out.close();
- }
-
- private void writeMultiVirtualHostsFile(File vhostsFile) throws IOException {
- FileWriter out = new FileWriter(vhostsFile);
- out.write("<virtualhosts>\n");
- out.write("\t<virtualhost>\n");
- out.write("\t\t<name>topic</name>\n");
- out.write("\t\t<topic>\n");
- out.write("\t\t\t<exchanges>\n");
- out.write("\t\t\t\t<exchange>\n");
- out.write("\t\t\t\t\t<type>topic</type>\n");
- out.write("\t\t\t\t\t<name>test.topic</name>\n");
- out.write("\t\t\t\t\t<durable>true</durable>\n");
- out.write("\t\t\t\t</exchange>\n");
- out.write("\t\tt</exchanges>\n");
- out.write("\t\t</topic>\n");
- out.write("\t</virtualhost>\n");
- out.write("\t<virtualhost>\n");
- out.write("\t\t<name>fanout</name>\n");
- out.write("\t\t<fanout>\n");
- out.write("\t\t\t<exchanges>\n");
- out.write("\t\t\t\t<exchange>\n");
- out.write("\t\t\t\t\t<type>fanout</type>\n");
- out.write("\t\t\t\t\t<name>test.fanout</name>\n");
- out.write("\t\t\t\t\t<durable>true</durable>\n");
- out.write("\t\t\t\t</exchange>\n");
- out.write("\t\tt</exchanges>\n");
- out.write("\t\t</fanout>\n");
- out.write("\t</virtualhost>\n");
- out.write("</virtualhosts>\n");
- out.close();
- }
-
- private void writeMultipleVhostsConfigFile(File mainFile, File[] vhostsFileArray) throws IOException {
- FileWriter out = new FileWriter(mainFile);
- out.write("<broker>\n");
- out.write("\t<management><enabled>false</enabled></management>\n");
- out.write("\t<security>\n");
- out.write("\t\t<pd-auth-manager>\n");
- out.write("\t\t\t<principal-database>\n");
- out.write("\t\t\t\t<class>org.apache.qpid.server.security.auth.database.PlainPasswordFilePrincipalDatabase</class>\n");
- out.write("\t\t\t\t<attributes>\n");
- out.write("\t\t\t\t\t<attribute>\n");
- out.write("\t\t\t\t\t\t<name>passwordFile</name>\n");
- out.write("\t\t\t\t\t\t<value>/dev/null</value>\n");
- out.write("\t\t\t\t\t</attribute>\n");
- out.write("\t\t\t\t</attributes>\n");
- out.write("\t\t\t</principal-database>\n");
- out.write("\t\t</pd-auth-manager>\n");
- out.write("\t\t<firewall>\n");
- out.write("\t\t\t<rule access=\"allow\" network=\"127.0.0.1\"/>");
- out.write("\t\t</firewall>\n");
- out.write("\t</security>\n");
- for (File vhostsFile : vhostsFileArray)
- {
- out.write("\t<virtualhosts>"+vhostsFile.getAbsolutePath()+"</virtualhosts>\n");
- }
- out.write("</broker>\n");
- out.close();
- }
-
- private void writeCombinedConfigFile(File mainFile, File fileA, File fileB) throws Exception
- {
- FileWriter out = new FileWriter(mainFile);
- out.write("<configuration><system/>");
- out.write("<xml fileName=\"" + fileA.getAbsolutePath() + "\"/>");
- out.write("<xml fileName=\"" + fileB.getAbsolutePath() + "\"/>");
- out.write("</configuration>");
- out.close();
- }
-
- /**
- * Test that configuration loads correctly when virtual hosts are specified in the main
- * configuration file only.
- * <p>
- * Test for QPID-2361
- */
- public void testInternalVirtualhostConfigFile() throws Exception
- {
- // Write out config
- File mainFile = File.createTempFile(getClass().getName(), "config");
- mainFile.deleteOnExit();
- writeConfigFile(mainFile, false, true, null, "test");
-
- // Load config
- ApplicationRegistry.remove();
- ApplicationRegistry reg = new ApplicationRegistry(new ServerConfiguration(mainFile));
- ApplicationRegistry.initialise(reg);
-
- // Test config
- VirtualHostRegistry virtualHostRegistry = reg.getVirtualHostRegistry();
- String defaultVirtualHost = reg.getConfiguration().getDefaultVirtualHost();
- VirtualHost virtualHost = virtualHostRegistry.getVirtualHost("test");
- Exchange exchange = virtualHost.getExchangeRegistry().getExchange(new AMQShortString("test.topic"));
-
- assertEquals("Incorrect default host", "test", defaultVirtualHost);
- assertEquals("Incorrect virtualhost count", 1, virtualHostRegistry.getVirtualHosts().size());
- assertEquals("Incorrect virtualhost name", "test", virtualHost.getName());
- assertEquals("Incorrect exchange type", "topic", exchange.getType().getName().toString());
- }
-
- /**
- * Test that configuration loads correctly when virtual hosts are specified in an external
- * configuration file only.
- * <p>
- * Test for QPID-2361
- */
- public void testExternalVirtualhostXMLFile() throws Exception
- {
- // Write out config
- File mainFile = File.createTempFile(getClass().getName(), "config");
- mainFile.deleteOnExit();
- File vhostsFile = File.createTempFile(getClass().getName(), "vhosts");
- vhostsFile.deleteOnExit();
- writeConfigFile(mainFile, false, false, vhostsFile, null);
- writeVirtualHostsFile(vhostsFile, "test");
-
- // Load config
- ApplicationRegistry.remove();
- ApplicationRegistry reg = new ApplicationRegistry(new ServerConfiguration(mainFile));
- ApplicationRegistry.initialise(reg);
-
- // Test config
- VirtualHostRegistry virtualHostRegistry = reg.getVirtualHostRegistry();
- String defaultVirtualHost = reg.getConfiguration().getDefaultVirtualHost();
- VirtualHost virtualHost = virtualHostRegistry.getVirtualHost("test");
- Exchange exchange = virtualHost.getExchangeRegistry().getExchange(new AMQShortString("test.topic"));
-
- assertEquals("Incorrect default host", "test", defaultVirtualHost);
- assertEquals("Incorrect virtualhost count", 1, virtualHostRegistry.getVirtualHosts().size());
- assertEquals("Incorrect virtualhost name", "test", virtualHost.getName());
- assertEquals("Incorrect exchange type", "topic", exchange.getType().getName().toString());
- }
-
- /**
- * Test that configuration loads correctly when virtual hosts are specified in an external
- * configuration file only, with two vhosts that have different properties.
- * <p>
- * Test for QPID-2361
- */
- public void testExternalMultiVirtualhostXMLFile() throws Exception
- {
- // Write out vhosts
- File vhostsFile = File.createTempFile(getClass().getName(), "vhosts-multi");
- vhostsFile.deleteOnExit();
- writeMultiVirtualHostsFile(vhostsFile);
-
- // Write out config
- File mainFile = File.createTempFile(getClass().getName(), "config");
- mainFile.deleteOnExit();
- writeConfigFile(mainFile, false, false, vhostsFile, null);
-
- // Load config
- ApplicationRegistry.remove();
- ApplicationRegistry reg = new ApplicationRegistry(new ServerConfiguration(mainFile));
- ApplicationRegistry.initialise(reg);
-
- // Test config
- VirtualHostRegistry virtualHostRegistry = reg.getVirtualHostRegistry();
-
- assertEquals("Incorrect virtualhost count", 2, virtualHostRegistry.getVirtualHosts().size());
-
- // test topic host
- VirtualHost topicVirtualHost = virtualHostRegistry.getVirtualHost("topic");
- Exchange topicExchange = topicVirtualHost.getExchangeRegistry().getExchange(new AMQShortString("test.topic"));
-
- assertEquals("Incorrect topic virtualhost name", "topic", topicVirtualHost.getName());
- assertEquals("Incorrect topic exchange type", "topic", topicExchange.getType().getName().toString());
-
- // Test fanout host
- VirtualHost fanoutVirtualHost = virtualHostRegistry.getVirtualHost("fanout");
- Exchange fanoutExchange = fanoutVirtualHost.getExchangeRegistry().getExchange(new AMQShortString("test.fanout"));
-
- assertEquals("Incorrect fanout virtualhost name", "fanout", fanoutVirtualHost.getName());
- assertEquals("Incorrect fanout exchange type", "fanout", fanoutExchange.getType().getName().toString());
- }
-
- /**
- * Test that configuration does not load when virtual hosts are specified in both the main
- * configuration file and an external file. Should throw a {@link ConfigurationException}.
- * <p>
- * Test for QPID-2361
- */
- public void testInternalAndExternalVirtualhostXMLFile() throws Exception
- {
- // Write out vhosts
- File vhostsFile = File.createTempFile(getClass().getName(), "vhosts");
- vhostsFile.deleteOnExit();
- writeVirtualHostsFile(vhostsFile, "test");
-
- // Write out config
- File mainFile = File.createTempFile(getClass().getName(), "config");
- mainFile.deleteOnExit();
- writeConfigFile(mainFile, false, true, vhostsFile, "test");
-
- // Load config
- try
- {
- ApplicationRegistry.remove();
- ApplicationRegistry reg = new ApplicationRegistry(new ServerConfiguration(mainFile));
- ApplicationRegistry.initialise(reg);
- fail("Different virtualhost XML configurations not allowed");
- }
- catch (ConfigurationException ce)
- {
- assertEquals("Incorrect error message", "Only one of external or embedded virtualhosts configuration allowed.", ce.getMessage());
- }
- }
-
- /**
- * Test that configuration does not load when virtual hosts are specified in multiple external
- * files. Should throw a {@link ConfigurationException}.
- * <p>
- * Test for QPID-2361
- */
- public void testMultipleInternalVirtualhostXMLFile() throws Exception
- {
- // Write out vhosts
- File vhostsFileOne = File.createTempFile(getClass().getName(), "vhosts-one");
- vhostsFileOne.deleteOnExit();
- writeVirtualHostsFile(vhostsFileOne, "one");
- File vhostsFileTwo = File.createTempFile(getClass().getName(), "vhosts-two");
- vhostsFileTwo.deleteOnExit();
- writeVirtualHostsFile(vhostsFileTwo, "two");
-
- // Write out config
- File mainFile = File.createTempFile(getClass().getName(), "config");
- mainFile.deleteOnExit();
- writeMultipleVhostsConfigFile(mainFile, new File[] { vhostsFileOne, vhostsFileTwo });
-
- // Load config
- try
- {
- ApplicationRegistry.remove();
- ApplicationRegistry reg = new ApplicationRegistry(new ServerConfiguration(mainFile));
- ApplicationRegistry.initialise(reg);
- fail("Multiple virtualhost XML configurations not allowed");
- }
- catch (ConfigurationException ce)
- {
- assertEquals("Incorrect error message",
- "Only one external virtualhosts configuration file allowed, multiple filenames found.",
- ce.getMessage());
- }
- }
-
- /**
- * Test that configuration loads correctly when virtual hosts are specified in an external
- * configuration file in the first of two configurations and embedded in the second. This
- * will throe a {@link ConfigurationException} since the configurations have different
- * types.
- * <p>
- * Test for QPID-2361
- */
- public void testCombinedDifferentVirtualhostConfig() throws Exception
- {
- // Write out vhosts config
- File vhostsFile = File.createTempFile(getClass().getName(), "vhosts");
- vhostsFile.deleteOnExit();
- writeVirtualHostsFile(vhostsFile, "external");
-
- // Write out combined config file
- File mainFile = File.createTempFile(getClass().getName(), "main");
- File fileA = File.createTempFile(getClass().getName(), "a");
- File fileB = File.createTempFile(getClass().getName(), "b");
- mainFile.deleteOnExit();
- fileA.deleteOnExit();
- fileB.deleteOnExit();
- writeCombinedConfigFile(mainFile, fileA, fileB);
- writeConfigFile(fileA, false, false, vhostsFile, null);
- writeConfigFile(fileB, false);
-
- // Load config
- try
- {
- ServerConfiguration config = new ServerConfiguration(mainFile.getAbsoluteFile());
- config.initialise();
- fail("Different virtualhost XML configurations not allowed");
- }
- catch (ConfigurationException ce)
- {
- assertEquals("Incorrect error message", "Only one of external or embedded virtualhosts configuration allowed.", ce.getMessage());
- }
- }
-
- /**
- * Test that configuration loads correctly when virtual hosts are specified two overriding configurations
- * each with an embedded virtualhost section. The first configuration section should be used.
- * <p>
- * Test for QPID-2361
- */
- public void testCombinedConfigEmbeddedVirtualhost() throws Exception
- {
- // Write out combined config file
- File mainFile = File.createTempFile(getClass().getName(), "main");
- File fileA = File.createTempFile(getClass().getName(), "a");
- File fileB = File.createTempFile(getClass().getName(), "b");
- mainFile.deleteOnExit();
- fileA.deleteOnExit();
- fileB.deleteOnExit();
- writeCombinedConfigFile(mainFile, fileA, fileB);
- writeConfigFile(fileA, false, true, null, "a");
- writeConfigFile(fileB, false, true, null, "b");
-
- // Load config
- ServerConfiguration config = new ServerConfiguration(mainFile.getAbsoluteFile());
- config.initialise();
-
- // Test config
- VirtualHostConfiguration virtualHost = config.getVirtualHostConfig("a");
-
- assertEquals("Incorrect virtualhost count", 1, config.getVirtualHosts().length);
- assertEquals("Incorrect virtualhost name", "a", virtualHost.getName());
- }
-
- /**
- * Test that configuration loads correctly when virtual hosts are specified two overriding configurations
- * each with an external virtualhost XML file. The first configuration file should be used.
- * <p>
- * Test for QPID-2361
- */
- public void testCombinedConfigExternalVirtualhost() throws Exception
- {
- // Write out vhosts config
- File vhostsOne = File.createTempFile(getClass().getName(), "vhosts-one");
- vhostsOne.deleteOnExit();
- writeVirtualHostsFile(vhostsOne, "one");
- File vhostsTwo = File.createTempFile(getClass().getName(), "vhosts-two");
- vhostsTwo.deleteOnExit();
- writeVirtualHostsFile(vhostsTwo, "two");
-
- // Write out combined config file
- File mainFile = File.createTempFile(getClass().getName(), "main");
- File fileA = File.createTempFile(getClass().getName(), "a");
- File fileB = File.createTempFile(getClass().getName(), "b");
- mainFile.deleteOnExit();
- fileA.deleteOnExit();
- fileB.deleteOnExit();
- writeCombinedConfigFile(mainFile, fileA, fileB);
- writeConfigFile(fileA, false, false, vhostsOne, null);
- writeConfigFile(fileB, false, false, vhostsTwo, null);
-
- // Load config
- ServerConfiguration config = new ServerConfiguration(mainFile.getAbsoluteFile());
- config.initialise();
-
- // Test config
- VirtualHostConfiguration virtualHost = config.getVirtualHostConfig("one");
-
- assertEquals("Incorrect virtualhost count", 1, config.getVirtualHosts().length);
- assertEquals("Incorrect virtualhost name", "one", virtualHost.getName());
- }
-
- /**
- * Test that configuration loads correctly when an overriding virtualhost configuration resets
- * a property of an embedded virtualhost section. The overriding configuration property value
- * should be used.
- * <p>
- * Test for QPID-2361
- */
- public void testCombinedConfigEmbeddedVirtualhostOverride() throws Exception
- {
- // Write out combined config file
- File mainFile = File.createTempFile(getClass().getName(), "main");
- File fileA = File.createTempFile(getClass().getName(), "override");
- File fileB = File.createTempFile(getClass().getName(), "config");
- mainFile.deleteOnExit();
- fileA.deleteOnExit();
- fileB.deleteOnExit();
- writeCombinedConfigFile(mainFile, fileA, fileB);
- writeTestFishConfigFile(fileB);
-
- // Write out overriding virtualhosts section
- FileWriter out = new FileWriter(fileA);
- out.write("<broker>\n");
- out.write("<virtualhosts>\n");
- out.write("\t<virtualhost>\n");
- out.write("\t\t<test>\n");
- out.write("\t\t\t<exchanges>\n");
- out.write("\t\t\t\t<exchange>\n");
- out.write("\t\t\t\t\t<durable>false</durable>\n");
- out.write("\t\t\t\t</exchange>\n");
- out.write("\t\tt</exchanges>\n");
- out.write("\t\t</test>\n");
- out.write("\t\t<fish>\n");
- out.write("\t\t\t<exchanges>\n");
- out.write("\t\t\t\t<exchange>\n");
- out.write("\t\t\t\t\t<durable>true</durable>\n");
- out.write("\t\t\t\t</exchange>\n");
- out.write("\t\tt</exchanges>\n");
- out.write("\t\t</fish>\n");
- out.write("\t</virtualhost>\n");
- out.write("</virtualhosts>\n");
- out.write("</broker>\n");
- out.close();
-
- // Load config
- ServerConfiguration config = new ServerConfiguration(mainFile.getAbsoluteFile());
- config.initialise();
-
- // Test config
- VirtualHostConfiguration testHost = config.getVirtualHostConfig("test");
- ExchangeConfiguration testExchange = testHost.getExchangeConfiguration("test.topic");
- VirtualHostConfiguration fishHost = config.getVirtualHostConfig("fish");
- ExchangeConfiguration fishExchange = fishHost.getExchangeConfiguration("fish.topic");
-
- assertEquals("Incorrect virtualhost count", 2, config.getVirtualHosts().length);
- assertEquals("Incorrect virtualhost name", "test", testHost.getName());
- assertFalse("Incorrect exchange durable property", testExchange.getDurable());
- assertEquals("Incorrect virtualhost name", "fish", fishHost.getName());
- assertTrue("Incorrect exchange durable property", fishExchange.getDurable());
- }
-
- /**
- * Test that configuration loads correctly when the virtualhost configuration is a set of overriding
- * configuration files that resets a property of a virtualhost. The opmost overriding configuration
- * property value should be used.
- * <p>
- * Test for QPID-2361
- */
- public void testCombinedVirtualhostOverride() throws Exception
- {
- // Write out combined config file
- File mainFile = File.createTempFile(getClass().getName(), "main");
- File vhostsFile = File.createTempFile(getClass().getName(), "vhosts");
- File fileA = File.createTempFile(getClass().getName(), "vhosts-override");
- File fileB = File.createTempFile(getClass().getName(), "vhosts-base");
- mainFile.deleteOnExit();
- vhostsFile.deleteOnExit();
- fileA.deleteOnExit();
- fileB.deleteOnExit();
- writeConfigFile(mainFile, true, false, vhostsFile, null);
- writeCombinedConfigFile(vhostsFile, fileA, fileB);
-
- // Write out overriding virtualhosts sections
- FileWriter out = new FileWriter(fileA);
- out.write("<virtualhosts>\n");
- out.write("\t<virtualhost>\n");
- out.write("\t\t<test>\n");
- out.write("\t\t\t<exchanges>\n");
- out.write("\t\t\t\t<exchange>\n");
- out.write("\t\t\t\t\t<durable>false</durable>\n");
- out.write("\t\t\t\t</exchange>\n");
- out.write("\t\tt</exchanges>\n");
- out.write("\t\t</test>\n");
- out.write("\t</virtualhost>\n");
- out.write("</virtualhosts>\n");
- out.close();
- writeVirtualHostsFile(fileB, "test");
-
- // Load config
- ServerConfiguration config = new ServerConfiguration(mainFile.getAbsoluteFile());
- config.initialise();
-
- // Test config
- VirtualHostConfiguration testHost = config.getVirtualHostConfig("test");
- ExchangeConfiguration testExchange = testHost.getExchangeConfiguration("test.topic");
-
- assertEquals("Incorrect virtualhost count", 1, config.getVirtualHosts().length);
- assertEquals("Incorrect virtualhost name", "test", testHost.getName());
- assertFalse("Incorrect exchange durable property", testExchange.getDurable());
- }
-
- /**
- * Test that configuration loads correctly when the virtualhost configuration is a set of overriding
- * configuration files that define multiple virtualhosts, one per file. Only the virtualhosts defined in
- * the topmost file should be used.
- * <p>
- * Test for QPID-2361
- */
- public void testCombinedMultipleVirtualhosts() throws Exception
- {
- // Write out combined config file
- File mainFile = File.createTempFile(getClass().getName(), "main");
- File vhostsFile = File.createTempFile(getClass().getName(), "vhosts");
- File fileA = File.createTempFile(getClass().getName(), "vhosts-one");
- File fileB = File.createTempFile(getClass().getName(), "vhosts-two");
- mainFile.deleteOnExit();
- vhostsFile.deleteOnExit();
- fileA.deleteOnExit();
- fileB.deleteOnExit();
- writeConfigFile(mainFile, true, false, vhostsFile, null);
- writeCombinedConfigFile(vhostsFile, fileA, fileB);
-
- // Write both virtualhosts definitions
- writeVirtualHostsFile(fileA, "test-one");
- writeVirtualHostsFile(fileB, "test-two");
-
- // Load config
- ServerConfiguration config = new ServerConfiguration(mainFile.getAbsoluteFile());
- config.initialise();
-
- // Test config
- VirtualHostConfiguration oneHost = config.getVirtualHostConfig("test-one");
-
- assertEquals("Incorrect virtualhost count", 1, config.getVirtualHosts().length);
- assertEquals("Incorrect virtualhost name", "test-one", oneHost.getName());
- }
-
- /**
- * Test that a non-existent virtualhost file throws a {@link ConfigurationException}.
- * <p>
- * Test for QPID-2624
- */
- public void testNonExistantVirtualhosts() throws Exception
- {
- // Write out combined config file
- File mainFile = File.createTempFile(getClass().getName(), "main");
- File vhostsFile = new File("doesnotexist");
- mainFile.deleteOnExit();
- writeConfigFile(mainFile, true, false, vhostsFile, null);
-
- // Load config
- try
- {
- ServerConfiguration config = new ServerConfiguration(mainFile.getAbsoluteFile());
- config.initialise();
- }
- catch (ConfigurationException ce)
- {
- assertEquals("Virtualhosts file does not exist", ce.getMessage());
- }
- catch (Exception e)
- {
- fail("Should throw a ConfigurationException");
- }
- }
-
- /**
- * Tests that element disabledFeatures allows features that would
- * otherwise be advertised by the broker to be turned off.
- */
- public void testDisabledFeatures() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
- _serverConfig = new ServerConfiguration(_config);
- assertEquals("Unexpected size", 0, _serverConfig.getDisabledFeatures().size());
-
- // Check value we set
- _config.addProperty("disabledFeatures", "qpid.feature1");
- _config.addProperty("disabledFeatures", "qpid.feature2");
- _serverConfig = new ServerConfiguration(_config);
-
- assertEquals("Unexpected size",2, _serverConfig.getDisabledFeatures().size());
- assertTrue("Unexpected contents", _serverConfig.getDisabledFeatures().contains("qpid.feature1"));
- }
-
- /**
- * Tests that the old element security.jmx.access (that used to be used
- * to define JMX access rights) is rejected.
- */
- public void testManagementAccessRejected() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
-
- // Check value we set
- _config.setProperty("security.jmx.access(0)", "jmxremote.access");
- _serverConfig = new ServerConfiguration(_config);
-
- try
- {
- _serverConfig.initialise();
- fail("Exception not thrown");
- }
- catch (ConfigurationException ce)
- {
- assertEquals("Incorrect error message",
- "Validation error : security/jmx/access is no longer a supported element within the configuration xml.",
- ce.getMessage());
- }
- }
-
- /**
- * Tests that the old element security.jmx.principal-database (that used to define the
- * principal database used for JMX authentication) is rejected.
- */
- public void testManagementPrincipalDatabaseRejected() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
-
- // Check value we set
- _config.setProperty("security.jmx.principal-database(0)", "mydb");
- _serverConfig = new ServerConfiguration(_config);
-
- try
- {
- _serverConfig.initialise();
- fail("Exception not thrown");
- }
- catch (ConfigurationException ce)
- {
- assertEquals("Incorrect error message",
- "Validation error : security/jmx/principal-database is no longer a supported element within the configuration xml.",
- ce.getMessage());
- }
- }
-
- /**
- * Tests that the old element security.principal-databases. ... (that used to define
- * principal databases) is rejected.
- */
- public void testPrincipalDatabasesRejected() throws ConfigurationException
- {
- _serverConfig.initialise();
-
- // Check value we set
- _config.setProperty("security.principal-databases.principal-database.class", "myclass");
- _serverConfig = new ServerConfiguration(_config);
-
- try
- {
- _serverConfig.initialise();
- fail("Exception not thrown");
- }
- catch (ConfigurationException ce)
- {
- assertEquals("Incorrect error message",
- "Validation error : security/principal-databases is no longer supported within the configuration xml.",
- ce.getMessage());
- }
- }
-
- /**
- * Tests that the old element housekeeping.expiredMessageCheckPeriod. ... (that was
- * replaced by housekeeping.checkPeriod) is rejected.
- */
- public void testExpiredMessageCheckPeriodRejected() throws ConfigurationException
- {
- _serverConfig.initialise();
-
- // Check value we set
- _config.setProperty("housekeeping.expiredMessageCheckPeriod", 23L);
- _serverConfig = new ServerConfiguration(_config);
-
- try
- {
- _serverConfig.initialise();
- fail("Exception not thrown");
- }
- catch (ConfigurationException ce)
- {
- assertEquals("Incorrect error message",
- "Validation error : housekeeping/expiredMessageCheckPeriod must be replaced by housekeeping/checkPeriod.",
- ce.getMessage());
- }
- }
-
- public void testMaxDeliveryCountDefault() throws Exception
- {
- final ServerConfiguration serverConfig = new ServerConfiguration(_config);
- assertEquals(0, serverConfig.getMaxDeliveryCount());
- }
-
- public void testMaxDeliveryCount() throws Exception
- {
- _config.setProperty("maximumDeliveryCount", 5);
- final ServerConfiguration serverConfig = new ServerConfiguration(_config);
- assertEquals(5, serverConfig.getMaxDeliveryCount());
- }
-
- /**
- * Test XML configuration file correctly enables dead letter queues
- */
- public void testDeadLetterQueueConfigurationFile() throws Exception
- {
- // Write config
- File xml = File.createTempFile(getClass().getName(), "xml");
- xml.deleteOnExit();
- FileWriter config = new FileWriter(xml);
- config.write("<broker>\n");
- writeSecurity(config);
- config.write("<deadLetterQueues>true</deadLetterQueues>\n");
- config.write("<virtualhosts>\n");
- config.write("<virtualhost>\n");
- config.write("<name>test</name>\n");
- config.write("<test>\n");
- config.write("<queues>\n");
- config.write("<deadLetterQueues>false</deadLetterQueues>\n");
- config.write("<queue>\n");
- config.write("<name>biggles</name>\n");
- config.write("<biggles>\n");
- config.write("<deadLetterQueues>true</deadLetterQueues>\n");
- config.write("</biggles>\n");
- config.write("</queue>\n");
- config.write("<queue>\n");
- config.write("<name>beetle</name>\n");
- config.write("<beetle />\n");
- config.write("</queue>\n");
- config.write("</queues>\n");
- config.write("</test>\n");
- config.write("</virtualhost>\n");
- config.write("<virtualhost>\n");
- config.write("<name>extra</name>\n");
- config.write("<extra>\n");
- config.write("<queues>\n");
- config.write("<queue>\n");
- config.write("<name>r2d2</name>\n");
- config.write("<r2d2>\n");
- config.write("<deadLetterQueues>false</deadLetterQueues>\n");
- config.write("</r2d2>\n");
- config.write("</queue>\n");
- config.write("<queue>\n");
- config.write("<name>c3p0</name>\n");
- config.write("<c3p0 />\n");
- config.write("</queue>\n");
- config.write("</queues>\n");
- config.write("</extra>\n");
- config.write("</virtualhost>\n");
- config.write("</virtualhosts>\n");
- config.write("</broker>\n");
- config.close();
-
- // Load config
- ApplicationRegistry.remove();
- ApplicationRegistry registry = new ApplicationRegistry(new ServerConfiguration(xml));
- ApplicationRegistry.initialise(registry);
- ServerConfiguration serverConfiguration = ApplicationRegistry.getInstance().getConfiguration();
-
- VirtualHostConfiguration test = serverConfiguration.getVirtualHostConfig("test");
- assertNotNull("Host 'test' is not found", test);
- VirtualHostConfiguration extra = serverConfiguration.getVirtualHostConfig("extra");
- assertNotNull("Host 'extra' is not found", test);
-
- QueueConfiguration biggles = test.getQueueConfiguration("biggles");
- QueueConfiguration beetle = test.getQueueConfiguration("beetle");
- QueueConfiguration r2d2 = extra.getQueueConfiguration("r2d2");
- QueueConfiguration c3p0 = extra.getQueueConfiguration("c3p0");
-
- // Validate config
- assertTrue("Broker DLQ should be configured as enabled", serverConfiguration.isDeadLetterQueueEnabled());
- assertFalse("Test vhost DLQ should be configured as disabled", test.isDeadLetterQueueEnabled());
- assertTrue("Extra vhost DLQ should be enabled, using broker default", extra.isDeadLetterQueueEnabled());
- assertTrue("Biggles queue DLQ should be configured as enabled", biggles.isDeadLetterQueueEnabled());
- assertFalse("Beetle queue DLQ should be disabled, using test vhost default", beetle.isDeadLetterQueueEnabled());
- assertFalse("R2D2 queue DLQ should be configured as disabled", r2d2.isDeadLetterQueueEnabled());
- assertTrue("C3P0 queue DLQ should be enabled, using broker default", c3p0.isDeadLetterQueueEnabled());
- }
-
- public void testIsAmqp010enabled() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
- assertEquals(true, _serverConfig.isAmqp010enabled());
-
- // Check value we set
- _config.setProperty(ServerConfiguration.CONNECTOR_AMQP010ENABLED, false);
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals(false, _serverConfig.isAmqp010enabled());
- }
-
- public void testIsAmqp091enabled() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
- assertEquals(true, _serverConfig.isAmqp091enabled());
-
- // Check value we set
- _config.setProperty(ServerConfiguration.CONNECTOR_AMQP091ENABLED, false);
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals(false, _serverConfig.isAmqp091enabled());
- }
-
- public void testIsAmqp09enabled() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
- assertEquals(true, _serverConfig.isAmqp09enabled());
-
- // Check value we set
- _config.setProperty(ServerConfiguration.CONNECTOR_AMQP09ENABLED, false);
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals(false, _serverConfig.isAmqp09enabled());
- }
-
- public void testIsAmqp08enabled() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
- assertEquals(true, _serverConfig.isAmqp08enabled());
-
- // Check value we set
- _config.setProperty(ServerConfiguration.CONNECTOR_AMQP08ENABLED, false);
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals(false, _serverConfig.isAmqp08enabled());
- }
-
- public void testPortInclude08() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
- assertEquals(true, _serverConfig.getPortInclude08().isEmpty());
-
- // Check values we set
- _config.addProperty(ServerConfiguration.CONNECTOR_INCLUDE_08, "1");
- _config.addProperty(ServerConfiguration.CONNECTOR_INCLUDE_08, "2");
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals(2, _serverConfig.getPortInclude08().size());
- assertTrue(_serverConfig.getPortInclude08().contains("1"));
- assertTrue(_serverConfig.getPortInclude08().contains("2"));
- }
-
- public void testPortInclude09() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
- assertEquals(true, _serverConfig.getPortInclude09().isEmpty());
-
- // Check values we set
- _config.addProperty(ServerConfiguration.CONNECTOR_INCLUDE_09, "3");
- _config.addProperty(ServerConfiguration.CONNECTOR_INCLUDE_09, "4");
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals(2, _serverConfig.getPortInclude09().size());
- assertTrue(_serverConfig.getPortInclude09().contains("3"));
- assertTrue(_serverConfig.getPortInclude09().contains("4"));
- }
-
- public void testPortInclude091() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
- assertEquals(true, _serverConfig.getPortInclude091().isEmpty());
-
- // Check values we set
- _config.addProperty(ServerConfiguration.CONNECTOR_INCLUDE_091, "5");
- _config.addProperty(ServerConfiguration.CONNECTOR_INCLUDE_091, "6");
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals(2, _serverConfig.getPortInclude091().size());
- assertTrue(_serverConfig.getPortInclude091().contains("5"));
- assertTrue(_serverConfig.getPortInclude091().contains("6"));
- }
-
- public void testPortInclude010() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
- assertEquals(true, _serverConfig.getPortInclude010().isEmpty());
-
- // Check values we set
- _config.addProperty(ServerConfiguration.CONNECTOR_INCLUDE_010, "7");
- _config.addProperty(ServerConfiguration.CONNECTOR_INCLUDE_010, "8");
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals(2, _serverConfig.getPortInclude010().size());
- assertTrue(_serverConfig.getPortInclude010().contains("7"));
- assertTrue(_serverConfig.getPortInclude010().contains("8"));
- }
-
- public void testPortInclude10() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
- assertEquals(true, _serverConfig.getPortInclude10().isEmpty());
-
- // Check values we set
- _config.addProperty(ServerConfiguration.CONNECTOR_INCLUDE_10, "9");
- _config.addProperty(ServerConfiguration.CONNECTOR_INCLUDE_10, "10");
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals(2, _serverConfig.getPortInclude10().size());
- assertTrue(_serverConfig.getPortInclude10().contains("9"));
- assertTrue(_serverConfig.getPortInclude10().contains("10"));
- }
-
- public void testGetDefaultSupportedProtocolReply() throws Exception
- {
- // Check default
- _serverConfig.initialise();
- assertNull("unexpected default value", _serverConfig.getDefaultSupportedProtocolReply());
-
- // Check values we set
- _config.addProperty(ServerConfiguration.CONNECTOR_AMQP_SUPPORTED_REPLY, "v0_10");
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals(AmqpProtocolVersion.v0_10, _serverConfig.getDefaultSupportedProtocolReply());
- }
-
- public void testDefaultAuthenticationManager() throws Exception
- {
- // Check default
- _serverConfig.initialise();
- assertNull("unexpected default value", _serverConfig.getDefaultAuthenticationManager());
-
- // Check values we set
- String testAuthManager = "myauthmanager";
- _config.addProperty("security.default-auth-manager", testAuthManager);
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals(testAuthManager, _serverConfig.getDefaultAuthenticationManager());
- }
-
- public void testPortAuthenticationMappingsDefault() throws Exception
- {
- _serverConfig.initialise();
- assertEquals("unexpected default number of port/authmanager mappings", 0, _serverConfig.getPortAuthenticationMappings().size());
- }
-
- public void testPortAuthenticationMappingsWithSingleMapping() throws Exception
- {
- String testAuthManager = "myauthmanager";
- _config.addProperty("security.port-mappings.port-mapping.port", 1234);
- _config.addProperty("security.port-mappings.port-mapping.auth-manager", testAuthManager);
-
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals("unexpected number of port/authmanager mappings", 1, _serverConfig.getPortAuthenticationMappings().size());
- assertEquals("unexpected mapping for port", testAuthManager, _serverConfig.getPortAuthenticationMappings().get(1234));
- }
-
- public void testPortAuthenticationMappingsWithManyMapping() throws Exception
- {
- String testAuthManager1 = "myauthmanager1";
- String testAuthManager2 = "myauthmanager2";
- _config.addProperty("security.port-mappings.port-mapping(-1).port", 1234);
- _config.addProperty("security.port-mappings.port-mapping.auth-manager", testAuthManager1);
-
- _config.addProperty("security.port-mappings.port-mapping(-1).port", 2345);
- _config.addProperty("security.port-mappings.port-mapping.auth-manager", testAuthManager2);
-
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
-
- assertEquals("unexpected number of port/authmanager mappings", 2, _serverConfig.getPortAuthenticationMappings().size());
- assertEquals("unexpected mapping for port", testAuthManager1, _serverConfig.getPortAuthenticationMappings().get(1234));
- assertEquals("unexpected mapping for port", testAuthManager2, _serverConfig.getPortAuthenticationMappings().get(2345));
- }
-
- public void testPortAuthenticationMappingWithMissingAuthManager() throws Exception
- {
- _config.addProperty("security.port-mappings.port-mapping(-1).port", 1234);
- // no auth manager defined for port
- _serverConfig = new ServerConfiguration(_config);
- try
- {
- _serverConfig.initialise();
- fail("Exception not thrown");
- }
- catch(ConfigurationException ce)
- {
- // PASS
- assertEquals("Incorrect error message",
- "Validation error: Each port-mapping must have exactly one port and exactly one auth-manager.",
- ce.getMessage());
- }
- }
-
- /**
- * Convenience method to output required security preamble for broker config
- */
- private void writeSecurity(Writer out) throws Exception
- {
- out.write("\t<management><enabled>false</enabled></management>\n");
- out.write("\t<security>\n");
- out.write("\t\t<pd-auth-manager>\n");
- out.write("\t\t\t<principal-database>\n");
- out.write("\t\t\t\t<class>org.apache.qpid.server.security.auth.database.PlainPasswordFilePrincipalDatabase</class>\n");
- out.write("\t\t\t\t<attributes>\n");
- out.write("\t\t\t\t\t<attribute>\n");
- out.write("\t\t\t\t\t\t<name>passwordFile</name>\n");
- out.write("\t\t\t\t\t\t<value>/dev/null</value>\n");
- out.write("\t\t\t\t\t</attribute>\n");
- out.write("\t\t\t\t</attributes>\n");
- out.write("\t\t\t</principal-database>\n");
- out.write("\t\t</pd-auth-manager>\n");
- out.write("\t</security>\n");
- }
-}
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/VirtualHostConfigurationTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/VirtualHostConfigurationTest.java
index 25e066de76..570bd004c5 100644
--- a/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/VirtualHostConfigurationTest.java
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/VirtualHostConfigurationTest.java
@@ -19,24 +19,69 @@
*/
package org.apache.qpid.server.configuration;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.XMLConfiguration;
import org.apache.qpid.framing.AMQShortString;
+import org.apache.qpid.server.model.Broker;
import org.apache.qpid.server.queue.AMQPriorityQueue;
import org.apache.qpid.server.queue.AMQQueue;
-import org.apache.qpid.server.registry.ApplicationRegistry;
import org.apache.qpid.server.store.TestableMemoryMessageStore;
-import org.apache.qpid.server.util.InternalBrokerBaseCase;
+import org.apache.qpid.server.util.BrokerTestHelper;
import org.apache.qpid.server.virtualhost.VirtualHost;
+import org.apache.qpid.server.virtualhost.VirtualHostRegistry;
+import org.apache.qpid.test.utils.QpidTestCase;
-public class VirtualHostConfigurationTest extends InternalBrokerBaseCase
+public class VirtualHostConfigurationTest extends QpidTestCase
{
+ private VirtualHostRegistry _virtualHostRegistry;
+ private XMLConfiguration _configXml;
+ private Broker _broker;
@Override
- public void createBroker()
+ public void setUp() throws Exception
{
- // Prevent auto broker startup
+ super.setUp();
+ BrokerTestHelper.setUp();
+ _configXml = new XMLConfiguration();
+ _configXml.addProperty("virtualhosts.virtualhost(-1).name", getName());
+ _configXml.addProperty("virtualhosts.virtualhost(-1)."+getName()+".store.class", TestableMemoryMessageStore.class.getName());
+ _virtualHostRegistry = new VirtualHostRegistry();
+ _broker = mock(Broker.class);
+ when(_broker.getAttribute(Broker.HOUSEKEEPING_CHECK_PERIOD)).thenReturn(30000l);
+ }
+
+ @Override
+ public void tearDown() throws Exception
+ {
+ try
+ {
+ if (_virtualHostRegistry != null)
+ {
+ _virtualHostRegistry.close();
+ }
+ }
+ finally
+ {
+ BrokerTestHelper.tearDown();
+ super.tearDown();
+ }
+ }
+
+ private XMLConfiguration getConfigXml()
+ {
+ return _configXml;
+ }
+
+ private VirtualHost createVirtualHost(String hostName) throws Exception
+ {
+ Configuration config = getConfigXml().subset("virtualhosts.virtualhost." + XmlConfigurationUtilities.escapeTagName(hostName));
+ VirtualHostConfiguration virtualHostConfiguration = new VirtualHostConfiguration(hostName, config, _broker);
+ return BrokerTestHelper.createVirtualHost(virtualHostConfiguration, _virtualHostRegistry);
}
public void testQueuePriority() throws Exception
@@ -65,11 +110,7 @@ public class VirtualHostConfigurationTest extends InternalBrokerBaseCase
getConfigXml().addProperty("virtualhosts.virtualhost.testQueuePriority.queues.queue.ntest.priority",
"false");
- // Start the broker now.
- super.createBroker();
-
- VirtualHost vhost =
- ApplicationRegistry.getInstance().getVirtualHostRegistry().getVirtualHost(getName());
+ VirtualHost vhost = createVirtualHost(getName());
// Check that atest was a priority queue with 5 priorities
AMQQueue atest = vhost.getQueueRegistry().getQueue(new AMQShortString("atest"));
@@ -102,11 +143,7 @@ public class VirtualHostConfigurationTest extends InternalBrokerBaseCase
getConfigXml().addProperty("virtualhosts.virtualhost.testQueueAlerts.queues(-1).queue(-1).name(-1)", "btest");
- // Start the broker now.
- super.createBroker();
-
- VirtualHost vhost =
- ApplicationRegistry.getInstance().getVirtualHostRegistry().getVirtualHost(getName());
+ VirtualHost vhost = createVirtualHost(getName());
// Check specifically configured values
AMQQueue aTest = vhost.getQueueRegistry().getQueue(new AMQShortString("atest"));
@@ -129,11 +166,7 @@ public class VirtualHostConfigurationTest extends InternalBrokerBaseCase
getConfigXml().addProperty("virtualhosts.virtualhost." + getName() + ".queues.queue.biggles.maximumDeliveryCount", 4);
getConfigXml().addProperty("virtualhosts.virtualhost." + getName() + ".queues(-1).queue(-1).name", "beetle");
- // Start the broker now.
- super.createBroker();
-
- // Get vhosts
- VirtualHost test = ApplicationRegistry.getInstance().getVirtualHostRegistry().getVirtualHost(getName());
+ VirtualHost test = createVirtualHost(getName());
// Enabled specifically
assertEquals("Test vhost MDC was configured as enabled", 5 ,test.getConfiguration().getMaxDeliveryCount());
@@ -163,12 +196,8 @@ public class VirtualHostConfigurationTest extends InternalBrokerBaseCase
getConfigXml().addProperty("virtualhosts.virtualhost." + getName() + "Extra.queues(-1).queue(-1).name", "c3p0");
getConfigXml().addProperty("virtualhosts.virtualhost." + getName() + "Extra.store.class", TestableMemoryMessageStore.class.getName());
- // Start the broker now.
- super.createBroker();
-
- // Get vhosts
- VirtualHost test = ApplicationRegistry.getInstance().getVirtualHostRegistry().getVirtualHost(getName());
- VirtualHost extra = ApplicationRegistry.getInstance().getVirtualHostRegistry().getVirtualHost(getName() + "Extra");
+ VirtualHost test = createVirtualHost(getName());
+ VirtualHost extra = createVirtualHost(getName() + "Extra");
// Enabled specifically
assertTrue("Test vhost DLQ was configured as enabled", test.getConfiguration().isDeadLetterQueueEnabled());
@@ -215,37 +244,13 @@ public class VirtualHostConfigurationTest extends InternalBrokerBaseCase
getConfigXml().addProperty("virtualhosts.virtualhost.testHouseKeepingThreadCount.housekeeping.poolSize",
initialPoolSize);
- // Start the broker now.
- super.createBroker();
-
- VirtualHost vhost =
- ApplicationRegistry.getInstance().getVirtualHostRegistry().getVirtualHost(getName());
+ VirtualHost vhost = createVirtualHost(getName());
assertEquals("HouseKeeping PoolSize not set correctly.",
initialPoolSize, vhost.getHouseKeepingPoolSize());
}
/**
- * Test default house keeping tasks
- *
- * @throws Exception
- */
- public void testDefaultHouseKeepingTasks() throws Exception
- {
- // Start the broker now.
- super.createBroker();
-
- VirtualHost vhost =
- ApplicationRegistry.getInstance().getVirtualHostRegistry().getVirtualHost(getName());
-
- assertEquals("Default houseKeeping task count incorrect.", 1,
- vhost.getHouseKeepingTaskCount());
-
- // Currently the task is:
- // ExpiredMessageTask from VirtualHostC
- }
-
- /**
* Test that we can dynamically change the thread pool size
*
* @throws Exception
@@ -257,11 +262,7 @@ public class VirtualHostConfigurationTest extends InternalBrokerBaseCase
getConfigXml().addProperty("virtualhosts.virtualhost.testDynamicHouseKeepingPoolSizeChange.housekeeping.poolSize",
initialPoolSize);
- // Start the broker now.
- super.createBroker();
-
- VirtualHost vhost =
- ApplicationRegistry.getInstance().getVirtualHostRegistry().getVirtualHost(getName());
+ VirtualHost vhost = createVirtualHost(getName());
assertEquals("HouseKeeping PoolSize not set correctly.",
initialPoolSize, vhost.getHouseKeepingPoolSize());
@@ -285,7 +286,7 @@ public class VirtualHostConfigurationTest extends InternalBrokerBaseCase
try
{
- super.createBroker();
+ createVirtualHost(getName());
fail("Exception not thrown");
}
catch(ConfigurationException ce)
@@ -308,7 +309,7 @@ public class VirtualHostConfigurationTest extends InternalBrokerBaseCase
try
{
- super.createBroker();
+ createVirtualHost(getName());
fail("Exception not thrown");
}
catch (ConfigurationException ce)
@@ -332,11 +333,7 @@ public class VirtualHostConfigurationTest extends InternalBrokerBaseCase
// Add a single property which is inside the <dot.in.a.name> queue tag - the maximum delivery count
getConfigXml().addProperty("virtualhosts.virtualhost." + getName() + ".queues.queue.dot..in..a..name.maximumDeliveryCount", 5);
- // Start the broker now.
- super.createBroker();
-
- // Get vhosts
- VirtualHost test = ApplicationRegistry.getInstance().getVirtualHostRegistry().getVirtualHost(getName());
+ VirtualHost test = createVirtualHost(getName());
// Check, that the property stored within the <dot.in.a.name> tag has been properly loaded
assertEquals("queue with dots in its name has been properly loaded", 5, test.getConfiguration().getQueueConfiguration("dot.in.a.name").getMaxDeliveryCount());
@@ -355,11 +352,7 @@ public class VirtualHostConfigurationTest extends InternalBrokerBaseCase
// Add a single property which is inside the <dot.in.a.name> virtual host tag - the message store
getConfigXml().addProperty("virtualhosts.virtualhost.dot..in..a..name.store.class", TestableMemoryMessageStore.class.getName());
- // Start the broker now.
- super.createBroker();
-
- // Get vhosts
- VirtualHost test = ApplicationRegistry.getInstance().getVirtualHostRegistry().getVirtualHost("dot.in.a.name");
+ VirtualHost test = createVirtualHost("dot.in.a.name");
// Check, that the property stored within the <dot.in.a.name> tag has been properly loaded
assertEquals("virtual host with dots in the name has been properly loaded", TestableMemoryMessageStore.class.getName(), test.getMessageStore().getClass().getName());
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/plugins/AbstractConfigurationTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/plugins/AbstractConfigurationTest.java
index 164e54ac3e..674abbfeb7 100644
--- a/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/plugins/AbstractConfigurationTest.java
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/plugins/AbstractConfigurationTest.java
@@ -24,7 +24,7 @@ import org.apache.commons.configuration.CompositeConfiguration;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.XMLConfiguration;
-import org.apache.qpid.server.util.InternalBrokerBaseCase;
+import org.apache.qpid.test.utils.QpidTestCase;
import java.util.List;
@@ -32,7 +32,7 @@ import java.util.List;
* Test that verifies that given a Configuration a ConfigurationPlugin can
* process and validate that data.
*/
-public class AbstractConfigurationTest extends InternalBrokerBaseCase
+public class AbstractConfigurationTest extends QpidTestCase
{
private static final double DOUBLE = 3.14;
private static final long POSITIVE_LONG = 1000;
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/BrokerRecovererTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/BrokerRecovererTest.java
new file mode 100644
index 0000000000..c1ebe26f52
--- /dev/null
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/BrokerRecovererTest.java
@@ -0,0 +1,405 @@
+/*
+ *
+ * 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.qpid.server.configuration.startup;
+
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.verify;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.UUID;
+
+import junit.framework.TestCase;
+
+import org.apache.qpid.server.configuration.ConfigurationEntry;
+import org.apache.qpid.server.configuration.ConfiguredObjectRecoverer;
+import org.apache.qpid.server.configuration.IllegalConfigurationException;
+import org.apache.qpid.server.configuration.RecovererProvider;
+import org.apache.qpid.server.logging.LogRecorder;
+import org.apache.qpid.server.logging.RootMessageLogger;
+import org.apache.qpid.server.model.AuthenticationProvider;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.ConfiguredObject;
+import org.apache.qpid.server.model.GroupProvider;
+import org.apache.qpid.server.model.KeyStore;
+import org.apache.qpid.server.model.Plugin;
+import org.apache.qpid.server.model.Port;
+import org.apache.qpid.server.model.TrustStore;
+import org.apache.qpid.server.model.VirtualHost;
+import org.apache.qpid.server.model.adapter.AuthenticationProviderFactory;
+import org.apache.qpid.server.model.adapter.PortFactory;
+import org.apache.qpid.server.configuration.updater.TaskExecutor;
+import org.apache.qpid.server.security.group.GroupPrincipalAccessor;
+import org.apache.qpid.server.stats.StatisticsGatherer;
+import org.apache.qpid.server.virtualhost.VirtualHostRegistry;
+
+public class BrokerRecovererTest extends TestCase
+{
+ private BrokerRecoverer _brokerRecoverer;
+ private ConfigurationEntry _brokerEntry = mock(ConfigurationEntry.class);
+
+ private UUID _brokerId = UUID.randomUUID();
+ private Map<String, Collection<ConfigurationEntry>> _brokerEntryChildren = new HashMap<String, Collection<ConfigurationEntry>>();
+ private ConfigurationEntry _authenticationProviderEntry1;
+ private AuthenticationProvider _authenticationProvider1;
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+
+ _brokerRecoverer = new BrokerRecoverer(mock(AuthenticationProviderFactory.class), mock(PortFactory.class), mock(StatisticsGatherer.class),
+ mock(VirtualHostRegistry.class), mock(LogRecorder.class), mock(RootMessageLogger.class), mock(TaskExecutor.class));
+ when(_brokerEntry.getId()).thenReturn(_brokerId);
+ when(_brokerEntry.getChildren()).thenReturn(_brokerEntryChildren);
+
+ //Add a base AuthenticationProvider for all tests
+ _authenticationProvider1 = mock(AuthenticationProvider.class);
+ when(_authenticationProvider1.getName()).thenReturn("authenticationProvider1");
+ _authenticationProviderEntry1 = mock(ConfigurationEntry.class);
+ _brokerEntryChildren.put(AuthenticationProvider.class.getSimpleName(), Arrays.asList(_authenticationProviderEntry1));
+ }
+
+ public void testCreateBrokerAttributes()
+ {
+ Map<String, Object> attributes = new HashMap<String, Object>();
+ attributes.put(Broker.DEFAULT_VIRTUAL_HOST, "test");
+ attributes.put(Broker.DEFAULT_AUTHENTICATION_PROVIDER, "authenticationProvider1");
+ attributes.put(Broker.ALERT_THRESHOLD_MESSAGE_AGE, 9l);
+ attributes.put(Broker.ALERT_THRESHOLD_MESSAGE_COUNT, 8l);
+ attributes.put(Broker.ALERT_THRESHOLD_QUEUE_DEPTH, 7l);
+ attributes.put(Broker.ALERT_THRESHOLD_MESSAGE_SIZE, 6l);
+ attributes.put(Broker.ALERT_REPEAT_GAP, 5l);
+ attributes.put(Broker.FLOW_CONTROL_SIZE_BYTES, 5l);
+ attributes.put(Broker.FLOW_CONTROL_RESUME_SIZE_BYTES, 3l);
+ attributes.put(Broker.MAXIMUM_DELIVERY_ATTEMPTS, 2);
+ attributes.put(Broker.DEAD_LETTER_QUEUE_ENABLED, true);
+ attributes.put(Broker.HOUSEKEEPING_CHECK_PERIOD, 1l);
+ attributes.put(Broker.ACL_FILE, "/path/to/acl");
+ attributes.put(Broker.SESSION_COUNT_LIMIT, 1000);
+ attributes.put(Broker.HEART_BEAT_DELAY, 2000);
+ attributes.put(Broker.STATISTICS_REPORTING_PERIOD, 4000);
+ attributes.put(Broker.STATISTICS_REPORTING_RESET_ENABLED, true);
+
+ Map<String, Object> entryAttributes = new HashMap<String, Object>();
+ for (Map.Entry<String, Object> attribute : attributes.entrySet())
+ {
+ String value = convertToString(attribute.getValue());
+ entryAttributes.put(attribute.getKey(), value);
+ }
+
+ when(_brokerEntry.getAttributes()).thenReturn(entryAttributes);
+
+ final ConfigurationEntry virtualHostEntry = mock(ConfigurationEntry.class);
+ String typeName = VirtualHost.class.getSimpleName();
+ when(virtualHostEntry.getType()).thenReturn(typeName);
+ _brokerEntryChildren.put(typeName, Arrays.asList(virtualHostEntry));
+ final VirtualHost virtualHost = mock(VirtualHost.class);
+ when(virtualHost.getName()).thenReturn("test");
+
+ RecovererProvider recovererProvider = createRecoveryProvider(new ConfigurationEntry[] { virtualHostEntry, _authenticationProviderEntry1 },
+ new ConfiguredObject[] { virtualHost, _authenticationProvider1 });
+ Broker broker = _brokerRecoverer.create(recovererProvider, _brokerEntry);
+ assertNotNull(broker);
+ assertEquals(_brokerId, broker.getId());
+
+ for (Map.Entry<String, Object> attribute : attributes.entrySet())
+ {
+ Object attributeValue = broker.getAttribute(attribute.getKey());
+ assertEquals("Unexpected value of attribute '" + attribute.getKey() + "'", attribute.getValue(), attributeValue);
+ }
+ }
+
+ public void testCreateBrokerWithVirtualHost()
+ {
+ final ConfigurationEntry virtualHostEntry = mock(ConfigurationEntry.class);
+
+ String typeName = VirtualHost.class.getSimpleName();
+ when(virtualHostEntry.getType()).thenReturn(typeName);
+ _brokerEntryChildren.put(typeName, Arrays.asList(virtualHostEntry));
+
+ final VirtualHost virtualHost = mock(VirtualHost.class);
+
+ RecovererProvider recovererProvider = createRecoveryProvider(new ConfigurationEntry[]{virtualHostEntry, _authenticationProviderEntry1},
+ new ConfiguredObject[]{virtualHost, _authenticationProvider1});
+
+ Broker broker = _brokerRecoverer.create(recovererProvider, _brokerEntry);
+
+ assertNotNull(broker);
+ assertEquals(_brokerId, broker.getId());
+ assertEquals(1, broker.getVirtualHosts().size());
+ assertEquals(virtualHost, broker.getVirtualHosts().iterator().next());
+ }
+
+ public void testCreateBrokerWithPorts()
+ {
+ ConfigurationEntry portEntry = mock(ConfigurationEntry.class);
+ Port port = mock(Port.class);
+ _brokerEntryChildren.put(Port.class.getSimpleName(), Arrays.asList(portEntry));
+
+ RecovererProvider recovererProvider = createRecoveryProvider(new ConfigurationEntry[]{portEntry, _authenticationProviderEntry1},
+ new ConfiguredObject[]{port, _authenticationProvider1});
+
+ Broker broker = _brokerRecoverer.create(recovererProvider, _brokerEntry);
+
+ assertNotNull(broker);
+ assertEquals(_brokerId, broker.getId());
+ assertEquals(Collections.singletonList(port), broker.getPorts());
+ }
+
+ public void testCreateBrokerWithoutAuthenticationProviderThrowsException()
+ {
+ assertNotNull("expected to remove the base entry", _brokerEntryChildren.remove(AuthenticationProvider.class.getSimpleName()));
+ assertTrue("should be empty", _brokerEntryChildren.isEmpty());
+
+ RecovererProvider recovererProvider = createRecoveryProvider(new ConfigurationEntry[0], new ConfiguredObject[0]);
+
+ try
+ {
+ _brokerRecoverer.create(recovererProvider, _brokerEntry);
+ fail("should have thrown an exception due to missing authentication provider configuration");
+ }
+ catch(IllegalConfigurationException e)
+ {
+ //expected
+ }
+ }
+
+ public void testCreateBrokerWithOneAuthenticationProvider()
+ {
+ RecovererProvider recovererProvider = createRecoveryProvider(new ConfigurationEntry[]{_authenticationProviderEntry1},
+ new ConfiguredObject[]{_authenticationProvider1});
+
+ Broker broker = _brokerRecoverer.create(recovererProvider, _brokerEntry);
+
+ assertNotNull(broker);
+ assertEquals(_brokerId, broker.getId());
+ assertEquals(Collections.singletonList(_authenticationProvider1), broker.getAuthenticationProviders());
+ }
+
+ public void testCreateBrokerWithMultipleAuthenticationProvidersAndNoDefaultThrowsException()
+ {
+ AuthenticationProvider authenticationProvider2 = mock(AuthenticationProvider.class);
+ when(authenticationProvider2.getName()).thenReturn("authenticationProvider2");
+ ConfigurationEntry authenticationProviderEntry2 = mock(ConfigurationEntry.class);
+ _brokerEntryChildren.put(AuthenticationProvider.class.getSimpleName(), Arrays.asList(_authenticationProviderEntry1, authenticationProviderEntry2));
+
+ Map<String,Object> emptyBrokerAttributes = new HashMap<String,Object>();
+ when(_brokerEntry.getAttributes()).thenReturn(emptyBrokerAttributes);
+
+ RecovererProvider recovererProvider = createRecoveryProvider(new ConfigurationEntry[]{authenticationProviderEntry2, _authenticationProviderEntry1},
+ new ConfiguredObject[]{authenticationProvider2, _authenticationProvider1});
+ try
+ {
+ _brokerRecoverer.create(recovererProvider, _brokerEntry);
+ fail("should have thrown an exception due to missing authentication provider default");
+ }
+ catch(IllegalConfigurationException e)
+ {
+ //expected
+ }
+ }
+
+ public void testCreateBrokerWithMultipleAuthenticationProvidersAndPorts()
+ {
+ //Create a second authentication provider
+ AuthenticationProvider authenticationProvider2 = mock(AuthenticationProvider.class);
+ when(authenticationProvider2.getName()).thenReturn("authenticationProvider2");
+ ConfigurationEntry authenticationProviderEntry2 = mock(ConfigurationEntry.class);
+ _brokerEntryChildren.put(AuthenticationProvider.class.getSimpleName(), Arrays.asList(_authenticationProviderEntry1, authenticationProviderEntry2));
+
+ //Set the default authentication provider
+ Map<String,Object> brokerAtttributes = new HashMap<String,Object>();
+ when(_brokerEntry.getAttributes()).thenReturn(brokerAtttributes);
+ brokerAtttributes.put(Broker.DEFAULT_AUTHENTICATION_PROVIDER, "authenticationProvider2");
+
+ //Add a couple ports, one with a defined authentication provider and
+ //one without (which should then use the default)
+ ConfigurationEntry portEntry1 = mock(ConfigurationEntry.class);
+ Port port1 = mock(Port.class);
+ when(port1.getName()).thenReturn("port1");
+ when(port1.getPort()).thenReturn(5671);
+ when(port1.getAttribute(Port.AUTHENTICATION_MANAGER)).thenReturn("authenticationProvider1");
+ ConfigurationEntry portEntry2 = mock(ConfigurationEntry.class);
+ Port port2 = mock(Port.class);
+ when(port2.getName()).thenReturn("port2");
+ when(port2.getPort()).thenReturn(5672);
+ _brokerEntryChildren.put(Port.class.getSimpleName(), Arrays.asList(portEntry1, portEntry2));
+
+ RecovererProvider recovererProvider = createRecoveryProvider(
+ new ConfigurationEntry[]{portEntry1, portEntry2, authenticationProviderEntry2, _authenticationProviderEntry1},
+ new ConfiguredObject[]{port1, port2, authenticationProvider2, _authenticationProvider1});
+
+ Broker broker = _brokerRecoverer.create(recovererProvider, _brokerEntry);
+
+ assertNotNull(broker);
+ assertEquals("Unexpected number of authentication providers", 2,broker.getAuthenticationProviders().size());
+
+ Collection<Port> ports = broker.getPorts();
+ assertEquals("Unexpected number of ports", 2, ports.size());
+ assertTrue(ports.contains(port1));
+ assertTrue(ports.contains(port2));
+
+ verify(port1).setAuthenticationProvider(any(AuthenticationProvider.class));
+ verify(port1).setAuthenticationProvider(_authenticationProvider1);
+
+ verify(port2).setAuthenticationProvider(any(AuthenticationProvider.class));
+ verify(port2).setAuthenticationProvider(authenticationProvider2);
+ }
+
+ public void testCreateBrokerAssignsGroupAccessorToAuthenticationProviders()
+ {
+ //Create a second authentication provider
+ AuthenticationProvider authenticationProvider2 = mock(AuthenticationProvider.class);
+ when(authenticationProvider2.getName()).thenReturn("authenticationProvider2");
+ ConfigurationEntry authenticationProviderEntry2 = mock(ConfigurationEntry.class);
+ _brokerEntryChildren.put(AuthenticationProvider.class.getSimpleName(), Arrays.asList(_authenticationProviderEntry1, authenticationProviderEntry2));
+
+ //Set the default authentication provider
+ Map<String,Object> brokerAtttributes = new HashMap<String,Object>();
+ when(_brokerEntry.getAttributes()).thenReturn(brokerAtttributes);
+ brokerAtttributes.put(Broker.DEFAULT_AUTHENTICATION_PROVIDER, "authenticationProvider2");
+
+ //Create a group provider
+ ConfigurationEntry groupProviderEntry = mock(ConfigurationEntry.class);
+ GroupProvider groupProvider = mock(GroupProvider.class);
+ _brokerEntryChildren.put(GroupProvider.class.getSimpleName(), Arrays.asList(groupProviderEntry));
+
+ RecovererProvider recovererProvider = createRecoveryProvider(
+ new ConfigurationEntry[]{groupProviderEntry, authenticationProviderEntry2, _authenticationProviderEntry1},
+ new ConfiguredObject[]{groupProvider, authenticationProvider2, _authenticationProvider1});
+
+ Broker broker = _brokerRecoverer.create(recovererProvider, _brokerEntry);
+
+ assertNotNull(broker);
+ assertEquals("Unexpected number of authentication providers", 2, broker.getAuthenticationProviders().size());
+
+ //verify that a GroupAcessor was added to the AuthenticationProviders
+ verify(_authenticationProvider1).setGroupAccessor(any(GroupPrincipalAccessor.class));
+ verify(authenticationProvider2).setGroupAccessor(any(GroupPrincipalAccessor.class));
+ }
+
+ public void testCreateBrokerWithGroupProvider()
+ {
+ ConfigurationEntry groupProviderEntry = mock(ConfigurationEntry.class);
+ GroupProvider groupProvider = mock(GroupProvider.class);
+ _brokerEntryChildren.put(GroupProvider.class.getSimpleName(), Arrays.asList(groupProviderEntry));
+
+ RecovererProvider recovererProvider = createRecoveryProvider(new ConfigurationEntry[]{groupProviderEntry, _authenticationProviderEntry1},
+ new ConfiguredObject[]{groupProvider, _authenticationProvider1});
+
+ Broker broker = _brokerRecoverer.create(recovererProvider, _brokerEntry);
+
+ assertNotNull(broker);
+ assertEquals(_brokerId, broker.getId());
+ assertEquals(Collections.singletonList(groupProvider), broker.getGroupProviders());
+ }
+
+ public void testCreateBrokerWithPlugins()
+ {
+ ConfigurationEntry pluginEntry = mock(ConfigurationEntry.class);
+ Plugin plugin = mock(Plugin.class);
+ _brokerEntryChildren.put(Plugin.class.getSimpleName(), Arrays.asList(pluginEntry));
+
+ RecovererProvider recovererProvider = createRecoveryProvider(new ConfigurationEntry[]{pluginEntry, _authenticationProviderEntry1},
+ new ConfiguredObject[]{plugin, _authenticationProvider1});
+
+ Broker broker = _brokerRecoverer.create(recovererProvider, _brokerEntry);
+
+ assertNotNull(broker);
+ assertEquals(_brokerId, broker.getId());
+ assertEquals(Collections.singleton(plugin), new HashSet<ConfiguredObject>(broker.getChildren(Plugin.class)));
+ }
+
+ public void testCreateBrokerWithKeyStores()
+ {
+ ConfigurationEntry pluginEntry = mock(ConfigurationEntry.class);
+ KeyStore keyStore = mock(KeyStore.class);
+ _brokerEntryChildren.put(KeyStore.class.getSimpleName(), Arrays.asList(pluginEntry));
+
+ RecovererProvider recovererProvider = createRecoveryProvider(new ConfigurationEntry[]{pluginEntry, _authenticationProviderEntry1},
+ new ConfiguredObject[]{keyStore, _authenticationProvider1});
+
+ Broker broker = _brokerRecoverer.create(recovererProvider, _brokerEntry);
+
+ assertNotNull(broker);
+ assertEquals(_brokerId, broker.getId());
+ assertEquals(Collections.singleton(keyStore), new HashSet<ConfiguredObject>(broker.getChildren(KeyStore.class)));
+ }
+
+ public void testCreateBrokerWithTrustStores()
+ {
+ ConfigurationEntry pluginEntry = mock(ConfigurationEntry.class);
+ TrustStore trustStore = mock(TrustStore.class);
+ _brokerEntryChildren.put(TrustStore.class.getSimpleName(), Arrays.asList(pluginEntry));
+
+ RecovererProvider recovererProvider = createRecoveryProvider(new ConfigurationEntry[]{pluginEntry, _authenticationProviderEntry1},
+ new ConfiguredObject[]{trustStore, _authenticationProvider1});
+
+ Broker broker = _brokerRecoverer.create(recovererProvider, _brokerEntry);
+
+ assertNotNull(broker);
+ assertEquals(_brokerId, broker.getId());
+ assertEquals(Collections.singleton(trustStore), new HashSet<ConfiguredObject>(broker.getChildren(TrustStore.class)));
+ }
+
+ private String convertToString(Object attributeValue)
+ {
+ return String.valueOf(attributeValue);
+ }
+
+ private RecovererProvider createRecoveryProvider(final ConfigurationEntry[] entries, final ConfiguredObject[] objectsToRecoverer)
+ {
+ RecovererProvider recovererProvider = new RecovererProvider()
+ {
+ @Override
+ public ConfiguredObjectRecoverer<? extends ConfiguredObject> getRecoverer(String type)
+ {
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ final ConfiguredObjectRecoverer<? extends ConfiguredObject> recovever = new ConfiguredObjectRecoverer()
+ {
+ @Override
+ public ConfiguredObject create(RecovererProvider recovererProvider, ConfigurationEntry entry, ConfiguredObject... parents)
+ {
+ for (int i = 0; i < entries.length; i++)
+ {
+ ConfigurationEntry e = entries[i];
+ if (entry == e)
+ {
+ return objectsToRecoverer[i];
+ }
+ }
+ return null;
+ }
+ };
+
+ return recovever;
+ }
+ };
+ return recovererProvider;
+ }
+}
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/DefaultRecovererProviderTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/DefaultRecovererProviderTest.java
new file mode 100644
index 0000000000..c95f67beb9
--- /dev/null
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/DefaultRecovererProviderTest.java
@@ -0,0 +1,62 @@
+/*
+ *
+ * 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.qpid.server.configuration.startup;
+
+import static org.mockito.Mockito.mock;
+import junit.framework.TestCase;
+
+import org.apache.qpid.server.configuration.ConfiguredObjectRecoverer;
+import org.apache.qpid.server.logging.LogRecorder;
+import org.apache.qpid.server.logging.RootMessageLogger;
+import org.apache.qpid.server.model.AuthenticationProvider;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.GroupProvider;
+import org.apache.qpid.server.model.Plugin;
+import org.apache.qpid.server.model.Port;
+import org.apache.qpid.server.model.VirtualHost;
+import org.apache.qpid.server.configuration.updater.TaskExecutor;
+import org.apache.qpid.server.stats.StatisticsGatherer;
+import org.apache.qpid.server.virtualhost.VirtualHostRegistry;
+
+public class DefaultRecovererProviderTest extends TestCase
+{
+ public void testGetRecoverer()
+ {
+ String[] supportedTypes = {Broker.class.getSimpleName(),
+ VirtualHost.class.getSimpleName(), AuthenticationProvider.class.getSimpleName(),
+ GroupProvider.class.getSimpleName(), Plugin.class.getSimpleName(), Port.class.getSimpleName()};
+
+ // mocking the required object
+ StatisticsGatherer statisticsGatherer = mock(StatisticsGatherer.class);
+ VirtualHostRegistry virtualHostRegistry = mock(VirtualHostRegistry.class);
+ LogRecorder logRecorder = mock(LogRecorder.class);
+ RootMessageLogger rootMessageLogger = mock(RootMessageLogger.class);
+ TaskExecutor taskExecutor = mock(TaskExecutor.class);
+
+ DefaultRecovererProvider provider = new DefaultRecovererProvider(statisticsGatherer, virtualHostRegistry, logRecorder, rootMessageLogger, taskExecutor);
+ for (String configuredObjectType : supportedTypes)
+ {
+ ConfiguredObjectRecoverer<?> recovever = provider.getRecoverer(configuredObjectType);
+ assertNotNull("Null recoverer for type: " + configuredObjectType, recovever);
+ }
+ }
+
+}
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/GroupProviderRecovererTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/GroupProviderRecovererTest.java
new file mode 100644
index 0000000000..6713574e4b
--- /dev/null
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/GroupProviderRecovererTest.java
@@ -0,0 +1,97 @@
+/*
+ *
+ * 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.qpid.server.configuration.startup;
+import static org.mockito.Mockito.*;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+
+import org.apache.qpid.server.configuration.ConfigurationEntry;
+import org.apache.qpid.server.configuration.IllegalConfigurationException;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.GroupProvider;
+import org.apache.qpid.server.plugin.GroupManagerFactory;
+import org.apache.qpid.server.plugin.QpidServiceLoader;
+import org.apache.qpid.server.security.group.GroupManager;
+
+import junit.framework.TestCase;
+
+public class GroupProviderRecovererTest extends TestCase
+{
+
+ private UUID _id;
+ private Map<String, Object> _attributes;
+
+ private GroupManagerFactory _factory;
+ private QpidServiceLoader<GroupManagerFactory> _groupManagerServiceLoader;
+ private Broker _broker;
+ private ConfigurationEntry _configurationEntry;
+
+ @SuppressWarnings("unchecked")
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ _id = UUID.randomUUID();
+ _attributes = new HashMap<String, Object>();
+
+ _factory = mock(GroupManagerFactory.class);
+
+ _groupManagerServiceLoader = mock(QpidServiceLoader.class);
+ when(_groupManagerServiceLoader.instancesOf(GroupManagerFactory.class)).thenReturn(Collections.singletonList(_factory ));
+
+ _broker = mock(Broker.class);
+
+ _configurationEntry = mock(ConfigurationEntry.class);
+ when(_configurationEntry.getId()).thenReturn(_id);
+ when(_configurationEntry.getAttributes()).thenReturn(_attributes);
+ }
+
+ public void testCreate()
+ {
+ GroupManager groupManager = mock(GroupManager.class);
+ String name = groupManager.getClass().getSimpleName();
+ when(_factory.createInstance(_attributes)).thenReturn(groupManager);
+ GroupProviderRecoverer groupProviderRecoverer = new GroupProviderRecoverer(_groupManagerServiceLoader);
+ GroupProvider groupProvider = groupProviderRecoverer.create(null, _configurationEntry, _broker);
+ assertNotNull("Null group provider", groupProvider);
+ assertEquals("Unexpected name", name, groupProvider.getName());
+ assertEquals("Unexpected ID", _id, groupProvider.getId());
+ }
+
+ public void testCreateThrowsExceptionWhenNoGroupManagerIsCreated()
+ {
+ when(_factory.createInstance(_attributes)).thenReturn(null);
+
+ GroupProviderRecoverer groupProviderRecoverer = new GroupProviderRecoverer(_groupManagerServiceLoader);
+ try
+ {
+ groupProviderRecoverer.create(null, _configurationEntry, _broker);
+ fail("Configuration exception should be thrown when group manager is not created");
+ }
+ catch(IllegalConfigurationException e)
+ {
+ // pass
+ }
+ }
+
+}
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/KeyStoreRecovererTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/KeyStoreRecovererTest.java
new file mode 100644
index 0000000000..0d7dc1bb06
--- /dev/null
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/KeyStoreRecovererTest.java
@@ -0,0 +1,111 @@
+/*
+ *
+ * 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.qpid.server.configuration.startup;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+
+import org.apache.qpid.server.configuration.ConfigurationEntry;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.KeyStore;
+import org.apache.qpid.server.model.TrustStore;
+
+import junit.framework.TestCase;
+
+public class KeyStoreRecovererTest extends TestCase
+{
+
+ public void testCreateWithAllAttributesProvided()
+ {
+ Map<String, Object> attributes = getKeyStoreAttributes();
+
+ UUID id = UUID.randomUUID();
+ Broker broker = mock(Broker.class);
+ ConfigurationEntry entry = mock(ConfigurationEntry.class);
+ when(entry.getAttributes()).thenReturn(attributes);
+ when(entry.getId()).thenReturn(id);
+
+ KeyStoreRecoverer recovever = new KeyStoreRecoverer();
+
+ KeyStore KeyStore = recovever.create(null, entry, broker);
+ assertNotNull("Key store configured object is not created", KeyStore);
+ assertEquals(id, KeyStore.getId());
+ assertEquals("my-secret-password", KeyStore.getPassword());
+
+ assertNull("Password was unexpectedly returned from configured object", KeyStore.getAttribute(TrustStore.PASSWORD));
+
+ // password attribute should not be exposed by a key store configured object
+ // so, we should set password value to null in the map being used to create the key store configured object
+ attributes.put(KeyStore.PASSWORD, null);
+ for (Map.Entry<String, Object> attribute : attributes.entrySet())
+ {
+ Object attributeValue = KeyStore.getAttribute(attribute.getKey());
+ assertEquals("Unexpected value of attribute '" + attribute.getKey() + "'", attribute.getValue(), attributeValue);
+ }
+ }
+
+ private Map<String, Object> getKeyStoreAttributes()
+ {
+ Map<String, Object> attributes = new HashMap<String, Object>();
+ attributes.put(KeyStore.NAME, getName());
+ attributes.put(KeyStore.PATH, "/path/to/KeyStore");
+ attributes.put(KeyStore.PASSWORD, "my-secret-password");
+ attributes.put(KeyStore.TYPE, "NON-JKS");
+ attributes.put(KeyStore.KEY_MANAGER_FACTORY_ALGORITHM, "NON-STANDARD");
+ attributes.put(KeyStore.CERTIFICATE_ALIAS, "my-cert-alias");
+ attributes.put(KeyStore.DESCRIPTION, "description");
+ return attributes;
+ }
+
+ public void testCreateWithMissedRequiredAttributes()
+ {
+ Map<String, Object> attributes = getKeyStoreAttributes();
+
+ UUID id = UUID.randomUUID();
+ Broker broker = mock(Broker.class);
+ ConfigurationEntry entry = mock(ConfigurationEntry.class);
+ when(entry.getId()).thenReturn(id);
+
+ KeyStoreRecoverer recovever = new KeyStoreRecoverer();
+
+ String[] mandatoryProperties = {KeyStore.NAME, KeyStore.PATH, KeyStore.PASSWORD};
+ for (int i = 0; i < mandatoryProperties.length; i++)
+ {
+ Map<String, Object> properties = new HashMap<String, Object>(attributes);
+ properties.remove(mandatoryProperties[i]);
+ when(entry.getAttributes()).thenReturn(properties);
+ try
+ {
+ recovever.create(null, entry, broker);
+ fail("Cannot create key store without a " + mandatoryProperties[i]);
+ }
+ catch(IllegalArgumentException e)
+ {
+ // pass
+ }
+ }
+ }
+
+}
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/PluginRecovererTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/PluginRecovererTest.java
new file mode 100644
index 0000000000..42fd742407
--- /dev/null
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/PluginRecovererTest.java
@@ -0,0 +1,117 @@
+/*
+ *
+ * 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.qpid.server.configuration.startup;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+
+import junit.framework.TestCase;
+
+import org.apache.qpid.server.configuration.ConfigurationEntry;
+import org.apache.qpid.server.configuration.IllegalConfigurationException;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.ConfiguredObject;
+import org.apache.qpid.server.model.Plugin;
+import org.apache.qpid.server.plugin.PluginFactory;
+import org.apache.qpid.server.plugin.QpidServiceLoader;
+
+public class PluginRecovererTest extends TestCase
+{
+ private UUID _id;
+ private Map<String, Object> _attributes;
+
+ private PluginFactory _factory;
+ private QpidServiceLoader<PluginFactory> _pluginFactoryServiceLoader;
+ private Broker _broker;
+ private ConfigurationEntry _configurationEntry;
+
+ @SuppressWarnings("unchecked")
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ _id = UUID.randomUUID();
+ _attributes = new HashMap<String, Object>();
+
+ _factory = mock(PluginFactory.class);
+
+ _pluginFactoryServiceLoader = mock(QpidServiceLoader.class);
+ when(_pluginFactoryServiceLoader.instancesOf(PluginFactory.class)).thenReturn(Collections.singletonList(_factory ));
+
+ _broker = mock(Broker.class);
+
+ _configurationEntry = mock(ConfigurationEntry.class);
+ when(_configurationEntry.getId()).thenReturn(_id);
+ when(_configurationEntry.getAttributes()).thenReturn(_attributes);
+ }
+
+ public void testCreate()
+ {
+ Plugin pluginFromFactory = mock(Plugin.class);
+ when(pluginFromFactory.getId()).thenReturn(_id);
+ when(_factory.createInstance(_id, _attributes, _broker)).thenReturn(pluginFromFactory);
+
+ PluginRecoverer pluginRecoverer = new PluginRecoverer(_pluginFactoryServiceLoader);
+ ConfiguredObject pluginFromRecoverer = pluginRecoverer.create(null, _configurationEntry, _broker);
+ assertNotNull("Null group provider", pluginFromRecoverer);
+ assertSame("Unexpected plugin", pluginFromFactory, pluginFromRecoverer);
+ assertEquals("Unexpected ID", _id, pluginFromRecoverer.getId());
+ }
+
+ public void testCreateThrowsExceptionForUnexpectedId()
+ {
+ Plugin pluginFromFactory = mock(Plugin.class);
+ when(pluginFromFactory.getId()).thenReturn(UUID.randomUUID());
+ when(_factory.createInstance(_id, _attributes, _broker)).thenReturn(pluginFromFactory);
+
+ PluginRecoverer pluginRecoverer = new PluginRecoverer(_pluginFactoryServiceLoader);
+ try
+ {
+ pluginRecoverer.create(null, _configurationEntry, _broker);
+ fail("An exception should be thrown for incorrect id");
+ }
+ catch(IllegalStateException e)
+ {
+ //pass
+ }
+ }
+
+ public void testCreateThrowsExceptionWhenNoPluginIsCreated()
+ {
+ when(_factory.createInstance(_id, _attributes, _broker)).thenReturn(null);
+
+ PluginRecoverer pluginRecoverer = new PluginRecoverer(_pluginFactoryServiceLoader);
+ try
+ {
+ pluginRecoverer.create(null, _configurationEntry, _broker);
+ fail("Configuration exception should be thrown when plugin is not created");
+ }
+ catch(IllegalConfigurationException e)
+ {
+ // pass
+ }
+ }
+
+}
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/TrustStoreRecovererTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/TrustStoreRecovererTest.java
new file mode 100644
index 0000000000..3b64f45c80
--- /dev/null
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/TrustStoreRecovererTest.java
@@ -0,0 +1,108 @@
+/*
+ *
+ * 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.qpid.server.configuration.startup;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+
+import org.apache.qpid.server.configuration.ConfigurationEntry;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.TrustStore;
+import org.apache.qpid.test.utils.QpidTestCase;
+
+public class TrustStoreRecovererTest extends QpidTestCase
+{
+ public void testCreateWithAllAttributesProvided()
+ {
+ Map<String, Object> attributes = getTrustStoreAttributes();
+
+ UUID id = UUID.randomUUID();
+ Broker broker = mock(Broker.class);
+ ConfigurationEntry entry = mock(ConfigurationEntry.class);
+ when(entry.getAttributes()).thenReturn(attributes);
+ when(entry.getId()).thenReturn(id);
+
+ TrustStoreRecoverer recovever = new TrustStoreRecoverer();
+
+ TrustStore trustStore = recovever.create(null, entry, broker);
+ assertNotNull("Trust store configured object is not created", trustStore);
+ assertEquals(id, trustStore.getId());
+ assertEquals("my-secret-password", trustStore.getPassword());
+
+ assertNull("Password was unexpectedly returned from configured object", trustStore.getAttribute(TrustStore.PASSWORD));
+
+ // password attribute should not be exposed by a trust store configured object
+ // so, we should set password value to null in the map being used to create the trust store configured object
+ attributes.put(TrustStore.PASSWORD, null);
+ for (Map.Entry<String, Object> attribute : attributes.entrySet())
+ {
+ Object attributeValue = trustStore.getAttribute(attribute.getKey());
+ assertEquals("Unexpected value of attribute '" + attribute.getKey() + "'", attribute.getValue(), attributeValue);
+ }
+ }
+
+ private Map<String, Object> getTrustStoreAttributes()
+ {
+ Map<String, Object> attributes = new HashMap<String, Object>();
+ attributes.put(TrustStore.NAME, getName());
+ attributes.put(TrustStore.PATH, "/path/to/truststore");
+ attributes.put(TrustStore.PASSWORD, "my-secret-password");
+ attributes.put(TrustStore.TYPE, "NON-JKS");
+ attributes.put(TrustStore.KEY_MANAGER_FACTORY_ALGORITHM, "NON-STANDARD");
+ attributes.put(TrustStore.DESCRIPTION, "Description");
+ return attributes;
+ }
+
+ public void testCreateWithMissedRequiredAttributes()
+ {
+ Map<String, Object> attributes = getTrustStoreAttributes();
+
+ UUID id = UUID.randomUUID();
+ Broker broker = mock(Broker.class);
+ ConfigurationEntry entry = mock(ConfigurationEntry.class);
+ when(entry.getAttributes()).thenReturn(attributes);
+ when(entry.getId()).thenReturn(id);
+
+ TrustStoreRecoverer recovever = new TrustStoreRecoverer();
+
+ String[] mandatoryProperties = {TrustStore.NAME, TrustStore.PATH, TrustStore.PASSWORD};
+ for (int i = 0; i < mandatoryProperties.length; i++)
+ {
+ Map<String, Object> properties = new HashMap<String, Object>(attributes);
+ properties.remove(mandatoryProperties[i]);
+ when(entry.getAttributes()).thenReturn(properties);
+ try
+ {
+ recovever.create(null, entry, broker);
+ fail("Cannot create key store without a " + mandatoryProperties[i]);
+ }
+ catch(IllegalArgumentException e)
+ {
+ // pass
+ }
+ }
+ }
+
+}
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/VirtualHostRecovererTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/VirtualHostRecovererTest.java
new file mode 100644
index 0000000000..57d219f85f
--- /dev/null
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/VirtualHostRecovererTest.java
@@ -0,0 +1,124 @@
+/*
+ *
+ * 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.qpid.server.configuration.startup;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+import org.apache.qpid.server.configuration.ConfigurationEntry;
+import org.apache.qpid.server.configuration.IllegalConfigurationException;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.VirtualHost;
+import org.apache.qpid.server.security.SecurityManager;
+import org.apache.qpid.server.stats.StatisticsGatherer;
+
+public class VirtualHostRecovererTest extends TestCase
+{
+ public void testCreate()
+ {
+ StatisticsGatherer statisticsGatherer = mock(StatisticsGatherer.class);
+ SecurityManager securityManager = mock(SecurityManager.class);
+ ConfigurationEntry entry = mock(ConfigurationEntry.class);
+ Broker parent = mock(Broker.class);
+ when(parent.getSecurityManager()).thenReturn(securityManager);
+
+ VirtualHostRecoverer recoverer = new VirtualHostRecoverer(statisticsGatherer);
+ Map<String, Object> attributes = new HashMap<String, Object>();
+ attributes.put(VirtualHost.NAME, getName());
+ attributes.put(VirtualHost.CONFIG_PATH, "/path/to/virtualhost.xml");
+ when(entry.getAttributes()).thenReturn(attributes);
+
+ VirtualHost host = recoverer.create(null, entry, parent);
+
+ assertNotNull("Null is returned", host);
+ assertEquals("Unexpected name", getName(), host.getName());
+ }
+
+ public void testCreateVirtualHostFromStoreConfigAtrributes()
+ {
+ StatisticsGatherer statisticsGatherer = mock(StatisticsGatherer.class);
+ SecurityManager securityManager = mock(SecurityManager.class);
+ ConfigurationEntry entry = mock(ConfigurationEntry.class);
+ Broker parent = mock(Broker.class);
+ when(parent.getSecurityManager()).thenReturn(securityManager);
+
+ VirtualHostRecoverer recoverer = new VirtualHostRecoverer(statisticsGatherer);
+ Map<String, Object> attributes = new HashMap<String, Object>();
+ attributes.put(VirtualHost.NAME, getName());
+ attributes.put(VirtualHost.STORE_PATH, "/path/to/virtualhost/store");
+ attributes.put(VirtualHost.STORE_TYPE, "DERBY");
+ when(entry.getAttributes()).thenReturn(attributes);
+
+ VirtualHost host = recoverer.create(null, entry, parent);
+
+ assertNotNull("Null is returned", host);
+ assertEquals("Unexpected name", getName(), host.getName());
+ }
+
+ public void testCreateWithoutMandatoryAttributesResultsInException()
+ {
+ Map<String, Object> attributes = new HashMap<String, Object>();
+ attributes.put(VirtualHost.NAME, getName());
+ attributes.put(VirtualHost.CONFIG_PATH, "/path/to/virtualhost.xml");
+ String[] mandatoryAttributes = {VirtualHost.NAME, VirtualHost.CONFIG_PATH};
+
+ checkMandatoryAttributesAreValidated(mandatoryAttributes, attributes);
+
+ attributes = new HashMap<String, Object>();
+ attributes.put(VirtualHost.NAME, getName());
+ attributes.put(VirtualHost.STORE_PATH, "/path/to/store");
+ attributes.put(VirtualHost.STORE_TYPE, "DERBY");
+ mandatoryAttributes = new String[]{VirtualHost.NAME, VirtualHost.STORE_PATH, VirtualHost.STORE_TYPE};
+
+ checkMandatoryAttributesAreValidated(mandatoryAttributes, attributes);
+ }
+
+ public void checkMandatoryAttributesAreValidated(String[] mandatoryAttributes, Map<String, Object> attributes)
+ {
+ StatisticsGatherer statisticsGatherer = mock(StatisticsGatherer.class);
+ SecurityManager securityManager = mock(SecurityManager.class);
+ ConfigurationEntry entry = mock(ConfigurationEntry.class);
+ Broker parent = mock(Broker.class);
+ when(parent.getSecurityManager()).thenReturn(securityManager);
+ VirtualHostRecoverer recoverer = new VirtualHostRecoverer(statisticsGatherer);
+
+ for (String name : mandatoryAttributes)
+ {
+ Map<String, Object> copy = new HashMap<String, Object>(attributes);
+ copy.remove(name);
+ when(entry.getAttributes()).thenReturn(copy);
+ try
+ {
+ recoverer.create(null, entry, parent);
+ fail("Cannot create a virtual host without a manadatory attribute " + name);
+ }
+ catch(IllegalConfigurationException e)
+ {
+ // pass
+ }
+ }
+ }
+}
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/store/ConfigurationEntryStoreTestCase.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/store/ConfigurationEntryStoreTestCase.java
new file mode 100644
index 0000000000..b357c0b8e9
--- /dev/null
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/store/ConfigurationEntryStoreTestCase.java
@@ -0,0 +1,392 @@
+/*
+ *
+ * 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.qpid.server.configuration.store;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+
+import org.apache.qpid.server.configuration.ConfigurationEntry;
+import org.apache.qpid.server.configuration.ConfigurationEntryStore;
+import org.apache.qpid.server.model.AuthenticationProvider;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.GroupProvider;
+import org.apache.qpid.server.model.KeyStore;
+import org.apache.qpid.server.model.Port;
+import org.apache.qpid.server.model.Transport;
+import org.apache.qpid.server.model.TrustStore;
+import org.apache.qpid.server.model.VirtualHost;
+import org.apache.qpid.server.plugin.AuthenticationManagerFactory;
+import org.apache.qpid.server.security.auth.manager.AnonymousAuthenticationManager;
+import org.apache.qpid.server.security.auth.manager.ExternalAuthenticationManager;
+import org.apache.qpid.test.utils.QpidTestCase;
+
+public abstract class ConfigurationEntryStoreTestCase extends QpidTestCase
+{
+ private ConfigurationEntryStore _store;
+
+ private UUID _brokerId;
+ private UUID _virtualHostId;
+ private UUID _authenticationProviderId;
+
+ private Map<String, Object> _brokerAttributes;
+ private Map<String, Object> _virtualHostAttributes;
+ private Map<String, Object> _authenticationProviderAttributes;
+
+ public void setUp() throws Exception
+ {
+ super.setUp();
+
+ _brokerId = UUID.randomUUID();
+ _brokerAttributes = new HashMap<String, Object>();
+ _brokerAttributes.put(Broker.DEFAULT_VIRTUAL_HOST, "test");
+ _brokerAttributes.put(Broker.DEFAULT_AUTHENTICATION_PROVIDER, "authenticationProvider1");
+ _brokerAttributes.put(Broker.ALERT_THRESHOLD_MESSAGE_AGE, 9);
+ _brokerAttributes.put(Broker.ALERT_THRESHOLD_MESSAGE_COUNT, 8);
+ _brokerAttributes.put(Broker.ALERT_THRESHOLD_QUEUE_DEPTH, 7);
+ _brokerAttributes.put(Broker.ALERT_THRESHOLD_MESSAGE_SIZE, 6);
+ _brokerAttributes.put(Broker.ALERT_REPEAT_GAP, 5);
+ _brokerAttributes.put(Broker.FLOW_CONTROL_SIZE_BYTES, 5);
+ _brokerAttributes.put(Broker.FLOW_CONTROL_RESUME_SIZE_BYTES, 3);
+ _brokerAttributes.put(Broker.MAXIMUM_DELIVERY_ATTEMPTS, 2);
+ _brokerAttributes.put(Broker.DEAD_LETTER_QUEUE_ENABLED, true);
+ _brokerAttributes.put(Broker.HOUSEKEEPING_CHECK_PERIOD, 1);
+ _brokerAttributes.put(Broker.ACL_FILE, "/path/to/acl");
+ _brokerAttributes.put(Broker.SESSION_COUNT_LIMIT, 1000);
+ _brokerAttributes.put(Broker.HEART_BEAT_DELAY, 2000);
+ _brokerAttributes.put(Broker.STATISTICS_REPORTING_PERIOD, 4000);
+ _brokerAttributes.put(Broker.STATISTICS_REPORTING_RESET_ENABLED, true);
+
+ _virtualHostId = UUID.randomUUID();
+ _virtualHostAttributes = new HashMap<String, Object>();
+ _virtualHostAttributes.put(VirtualHost.NAME, "test");
+ _virtualHostAttributes.put(VirtualHost.CONFIG_PATH, "/path/to/phantom/test");
+
+ _authenticationProviderId = UUID.randomUUID();
+ _authenticationProviderAttributes = new HashMap<String, Object>();
+ _authenticationProviderAttributes.put(AuthenticationProvider.NAME, "authenticationProvider1");
+ _authenticationProviderAttributes.put(AuthenticationManagerFactory.ATTRIBUTE_TYPE, AnonymousAuthenticationManager.class.getSimpleName());
+
+ _store = createStore(_brokerId, _brokerAttributes);
+ addConfiguration(_virtualHostId, VirtualHost.class.getSimpleName(), _virtualHostAttributes);
+ addConfiguration(_authenticationProviderId, AuthenticationProvider.class.getSimpleName(), _authenticationProviderAttributes);
+ }
+
+ // ??? perhaps it should not be abstract
+ protected abstract ConfigurationEntryStore createStore(UUID brokerId, Map<String, Object> brokerAttributes) throws Exception;
+
+ protected abstract void addConfiguration(UUID id, String type, Map<String, Object> attributes);
+
+ protected ConfigurationEntryStore getStore()
+ {
+ return _store;
+ }
+
+ public void testGetRootEntry()
+ {
+ ConfigurationEntry brokerConfigEntry = _store.getRootEntry();
+ assertNotNull("Root entry does not exist", brokerConfigEntry);
+ assertEquals("Unexpected id", _brokerId, brokerConfigEntry.getId());
+ assertEquals("Unexpected type ", Broker.class.getSimpleName(), brokerConfigEntry.getType());
+ Map<String, Object> attributes = brokerConfigEntry.getAttributes();
+ assertNotNull("Attributes cannot be null", attributes);
+ assertEquals("Unexpected attributes", _brokerAttributes, attributes);
+ }
+
+ public void testGetEntry()
+ {
+ ConfigurationEntry authenticationProviderConfigEntry = _store.getEntry(_authenticationProviderId);
+ assertNotNull("Provider with id " + _authenticationProviderId + " should exist", authenticationProviderConfigEntry);
+ assertEquals("Unexpected id", _authenticationProviderId, authenticationProviderConfigEntry.getId());
+ assertEquals("Unexpected type ", AuthenticationProvider.class.getSimpleName(), authenticationProviderConfigEntry.getType());
+ Map<String, Object> attributes = authenticationProviderConfigEntry.getAttributes();
+ assertNotNull("Attributes cannot be null", attributes);
+ assertEquals("Unexpected attributes", _authenticationProviderAttributes, attributes);
+ }
+
+ public void testRemove()
+ {
+ Map<String, Object> virtualHostAttributes = new HashMap<String, Object>();
+ virtualHostAttributes.put(VirtualHost.NAME, getName());
+ virtualHostAttributes.put(VirtualHost.CONFIG_PATH, "/path/to/phantom/virtualhost/config");
+ UUID virtualHostId = UUID.randomUUID();
+ addConfiguration(virtualHostId, VirtualHost.class.getSimpleName(), virtualHostAttributes);
+
+ assertNotNull("Virtual host with id " + virtualHostId + " should exist", _store.getEntry(virtualHostId));
+
+ _store.remove(virtualHostId);
+ assertNull("Authentication provider configuration should be removed", _store.getEntry(virtualHostId));
+ }
+
+ public void testRemoveMultipleEntries()
+ {
+ Map<String, Object> virtualHost1Attributes = new HashMap<String, Object>();
+ virtualHost1Attributes.put(VirtualHost.NAME, "test1");
+ virtualHost1Attributes.put(VirtualHost.CONFIG_PATH, "/path/to/phantom/virtualhost/config1");
+ UUID virtualHost1Id = UUID.randomUUID();
+ addConfiguration(virtualHost1Id, VirtualHost.class.getSimpleName(), virtualHost1Attributes);
+
+ Map<String, Object> virtualHost2Attributes = new HashMap<String, Object>();
+ virtualHost2Attributes.put(VirtualHost.NAME, "test1");
+ virtualHost2Attributes.put(VirtualHost.CONFIG_PATH, "/path/to/phantom/virtualhost/config2");
+ UUID virtualHost2Id = UUID.randomUUID();
+ addConfiguration(virtualHost2Id, VirtualHost.class.getSimpleName(), virtualHost2Attributes);
+
+ assertNotNull("Virtual host with id " + virtualHost1Id + " should exist", _store.getEntry(virtualHost1Id));
+ assertNotNull("Virtual host with id " + virtualHost2Id + " should exist", _store.getEntry(virtualHost2Id));
+
+ UUID[] deletedIds = _store.remove(virtualHost1Id, virtualHost2Id);
+ assertNotNull("Unexpected deleted ids", deletedIds);
+ assertEquals("Unexpected id of first deleted virtual host", virtualHost1Id , deletedIds[0]);
+ assertEquals("Unexpected id of second deleted virtual host", virtualHost2Id , deletedIds[1]);
+ assertNull("First virtual host configuration should be removed", _store.getEntry(virtualHost1Id));
+ assertNull("Second virtual host configuration should be removed", _store.getEntry(virtualHost2Id));
+ }
+
+ public void testSaveBroker()
+ {
+ ConfigurationEntry brokerConfigEntry = _store.getRootEntry();
+ Map<String, Object> attributes = new HashMap<String, Object>();
+ attributes.put(Broker.DEFAULT_VIRTUAL_HOST, "test");
+ attributes.put(Broker.DEFAULT_AUTHENTICATION_PROVIDER, "authenticationProvider1");
+ attributes.put(Broker.ALERT_THRESHOLD_MESSAGE_AGE, 19);
+ attributes.put(Broker.ALERT_THRESHOLD_MESSAGE_COUNT, 18);
+ attributes.put(Broker.ALERT_THRESHOLD_QUEUE_DEPTH, 17);
+ attributes.put(Broker.ALERT_THRESHOLD_MESSAGE_SIZE, 16);
+ attributes.put(Broker.ALERT_REPEAT_GAP, 15);
+ attributes.put(Broker.FLOW_CONTROL_SIZE_BYTES, 15);
+ attributes.put(Broker.FLOW_CONTROL_RESUME_SIZE_BYTES, 13);
+ attributes.put(Broker.MAXIMUM_DELIVERY_ATTEMPTS, 12);
+ attributes.put(Broker.DEAD_LETTER_QUEUE_ENABLED, false);
+ attributes.put(Broker.HOUSEKEEPING_CHECK_PERIOD, 11);
+ attributes.put(Broker.ACL_FILE, "/path/to/acl1");
+ attributes.put(Broker.SESSION_COUNT_LIMIT, 11000);
+ attributes.put(Broker.HEART_BEAT_DELAY, 12000);
+ attributes.put(Broker.STATISTICS_REPORTING_PERIOD, 14000);
+ attributes.put(Broker.STATISTICS_REPORTING_RESET_ENABLED, false);
+ ConfigurationEntry updatedBrokerEntry = new ConfigurationEntry(_brokerId, Broker.class.getSimpleName(), attributes,
+ brokerConfigEntry.getChildrenIds(), _store);
+
+ _store.save(updatedBrokerEntry);
+
+ ConfigurationEntry newBrokerConfigEntry = _store.getRootEntry();
+ assertNotNull("Root entry does not exist", newBrokerConfigEntry);
+ assertEquals("Unexpected id", _brokerId, newBrokerConfigEntry.getId());
+ assertEquals("Unexpected type ", Broker.class.getSimpleName(), newBrokerConfigEntry.getType());
+ Map<String, Object> newBrokerattributes = newBrokerConfigEntry.getAttributes();
+ assertNotNull("Attributes cannot be null", newBrokerattributes);
+ assertEquals("Unexpected attributes", attributes, newBrokerattributes);
+ }
+
+ public void testSaveNewVirtualHost()
+ {
+ Map<String, Object> virtualHostAttributes = new HashMap<String, Object>();
+ virtualHostAttributes.put(VirtualHost.NAME, "test1");
+ virtualHostAttributes.put(VirtualHost.CONFIG_PATH, "/path/to/phantom/virtualhost/config1");
+ UUID virtualHostId = UUID.randomUUID();
+ ConfigurationEntry hostEntry = new ConfigurationEntry(virtualHostId, VirtualHost.class.getSimpleName(), virtualHostAttributes,
+ Collections.<UUID> emptySet(), _store);
+
+ _store.save(hostEntry);
+
+ ConfigurationEntry configurationEntry = _store.getEntry(virtualHostId);
+ assertEquals("Unexpected virtual host configuration", hostEntry, configurationEntry);
+ assertEquals("Unexpected type", VirtualHost.class.getSimpleName(), configurationEntry.getType());
+ assertEquals("Unexpected virtual host attributes", hostEntry.getAttributes(), configurationEntry.getAttributes());
+ assertTrue("Unexpected virtual host children found", hostEntry.getChildrenIds().isEmpty());
+ }
+
+ public void testSaveExistingVirtualHost()
+ {
+ ConfigurationEntry hostEntry = _store.getEntry(_virtualHostId);
+ assertNotNull("Host configuration is not found", hostEntry);
+
+ Map<String, Object> virtualHostAttributes = new HashMap<String, Object>();
+ virtualHostAttributes.put(VirtualHost.NAME, "test");
+ virtualHostAttributes.put(VirtualHost.CONFIG_PATH, "/path/to/new/phantom/test/configuration");
+
+ ConfigurationEntry updatedEntry = new ConfigurationEntry(_virtualHostId, VirtualHost.class.getSimpleName(), virtualHostAttributes,
+ hostEntry.getChildrenIds(), _store);
+ _store.save(updatedEntry);
+
+ ConfigurationEntry newHostEntry = _store.getEntry(_virtualHostId);
+ assertEquals("Unexpected virtual host configuration", updatedEntry, newHostEntry);
+ assertEquals("Unexpected type", VirtualHost.class.getSimpleName(), newHostEntry.getType());
+ assertEquals("Unexpected virtual host attributes", updatedEntry.getAttributes(), newHostEntry.getAttributes());
+ assertEquals("Unexpected virtual host children found", updatedEntry.getChildrenIds(), newHostEntry.getChildrenIds());
+ }
+
+ public void testSaveNewAuthenticationProvider()
+ {
+ UUID authenticationProviderId = UUID.randomUUID();
+ Map<String, Object> authenticationProviderAttributes = new HashMap<String, Object>();
+ authenticationProviderAttributes.put(AuthenticationProvider.NAME, "authenticationProvider1");
+ authenticationProviderAttributes.put(AuthenticationManagerFactory.ATTRIBUTE_TYPE, ExternalAuthenticationManager.class.getSimpleName());
+ ConfigurationEntry providerEntry = new ConfigurationEntry(authenticationProviderId, AuthenticationProvider.class.getSimpleName(),
+ authenticationProviderAttributes, Collections.<UUID> emptySet(), _store);
+
+ _store.save(providerEntry);
+
+ ConfigurationEntry storeEntry = _store.getEntry(authenticationProviderId);
+ assertEquals("Unexpected provider configuration", providerEntry, storeEntry);
+ assertEquals("Unexpected type", AuthenticationProvider.class.getSimpleName(), storeEntry.getType());
+ assertEquals("Unexpected provider attributes", providerEntry.getAttributes(), storeEntry.getAttributes());
+ assertTrue("Unexpected provider children found", storeEntry.getChildrenIds().isEmpty());
+ }
+
+ public void testSaveExistingAuthenticationProvider()
+ {
+ ConfigurationEntry providerEntry = _store.getEntry(_authenticationProviderId);
+ assertNotNull("provider configuration is not found", providerEntry);
+
+ Map<String, Object> authenticationProviderAttributes = new HashMap<String, Object>();
+ authenticationProviderAttributes.put(AuthenticationProvider.NAME, "authenticationProvider1");
+ authenticationProviderAttributes.put(AuthenticationManagerFactory.ATTRIBUTE_TYPE, ExternalAuthenticationManager.class.getSimpleName());
+ ConfigurationEntry updatedEntry = new ConfigurationEntry(_authenticationProviderId, AuthenticationProvider.class.getSimpleName(),
+ authenticationProviderAttributes, Collections.<UUID> emptySet(), _store);
+ _store.save(updatedEntry);
+
+ ConfigurationEntry storeEntry = _store.getEntry(_authenticationProviderId);
+ assertEquals("Unexpected provider configuration", updatedEntry, storeEntry);
+ assertEquals("Unexpected type", AuthenticationProvider.class.getSimpleName(), storeEntry.getType());
+ assertEquals("Unexpected provider attributes", updatedEntry.getAttributes(), storeEntry.getAttributes());
+ assertTrue("Unexpected provider children found", storeEntry.getChildrenIds().isEmpty());
+ }
+
+ public void testSaveTrustStore()
+ {
+ UUID trustStoreId = UUID.randomUUID();
+ Map<String, Object> attributes = new HashMap<String, Object>();
+ attributes.put(TrustStore.NAME, getName());
+ attributes.put(TrustStore.PATH, "/path/to/truststore");
+ attributes.put(TrustStore.PASSWORD, "my-secret-password");
+ attributes.put(TrustStore.TYPE, "NON-JKS");
+ attributes.put(TrustStore.KEY_MANAGER_FACTORY_ALGORITHM, "NON-STANDARD");
+ attributes.put(TrustStore.DESCRIPTION, "Description");
+
+ ConfigurationEntry trustStoreEntry = new ConfigurationEntry(trustStoreId, TrustStore.class.getSimpleName(), attributes,
+ Collections.<UUID> emptySet(), _store);
+
+ _store.save(trustStoreEntry);
+
+ ConfigurationEntry storeEntry = _store.getEntry(trustStoreId);
+ assertEquals("Unexpected trust store configuration", trustStoreEntry, storeEntry);
+ assertEquals("Unexpected type", TrustStore.class.getSimpleName(), storeEntry.getType());
+ assertEquals("Unexpected provider attributes", trustStoreEntry.getAttributes(), storeEntry.getAttributes());
+ assertTrue("Unexpected provider children found", storeEntry.getChildrenIds().isEmpty());
+ }
+
+ public void testSaveKeyStore()
+ {
+ UUID keyStoreId = UUID.randomUUID();
+ Map<String, Object> attributes = new HashMap<String, Object>();
+ attributes.put(KeyStore.NAME, getName());
+ attributes.put(KeyStore.PATH, "/path/to/truststore");
+ attributes.put(KeyStore.PASSWORD, "my-secret-password");
+ attributes.put(KeyStore.TYPE, "NON-JKS");
+ attributes.put(KeyStore.KEY_MANAGER_FACTORY_ALGORITHM, "NON-STANDARD");
+ attributes.put(KeyStore.DESCRIPTION, "Description");
+ attributes.put(KeyStore.CERTIFICATE_ALIAS, "Alias");
+
+ ConfigurationEntry keyStoreEntry = new ConfigurationEntry(keyStoreId, KeyStore.class.getSimpleName(), attributes, Collections.<UUID> emptySet(),
+ _store);
+
+ _store.save(keyStoreEntry);
+
+ ConfigurationEntry storeEntry = _store.getEntry(keyStoreId);
+ assertEquals("Unexpected key store configuration", keyStoreEntry, storeEntry);
+ assertEquals("Unexpected type", KeyStore.class.getSimpleName(), storeEntry.getType());
+ assertEquals("Unexpected provider attributes", keyStoreEntry.getAttributes(), storeEntry.getAttributes());
+ assertTrue("Unexpected provider children found", storeEntry.getChildrenIds().isEmpty());
+ }
+
+ public void testSaveGroupProvider()
+ {
+ UUID groupProviderId = UUID.randomUUID();
+ Map<String, Object> attributes = new HashMap<String, Object>();
+ attributes.put(GroupProvider.NAME, getName());
+
+ ConfigurationEntry groupProviderEntry = new ConfigurationEntry(groupProviderId, GroupProvider.class.getSimpleName(), attributes,
+ Collections.<UUID> emptySet(), _store);
+
+ _store.save(groupProviderEntry);
+
+ ConfigurationEntry storeEntry = _store.getEntry(groupProviderId);
+ assertEquals("Unexpected group provider configuration", groupProviderEntry, storeEntry);
+ assertEquals("Unexpected type", GroupProvider.class.getSimpleName(), storeEntry.getType());
+ assertEquals("Unexpected group provider attributes", groupProviderEntry.getAttributes(), storeEntry.getAttributes());
+ assertTrue("Unexpected provider children found", storeEntry.getChildrenIds().isEmpty());
+ }
+
+ public void testSavePort()
+ {
+ UUID portId = UUID.randomUUID();
+ Map<String, Object> attributes = new HashMap<String, Object>();
+ Set<String> tcpTransportSet = Collections.singleton(Transport.TCP.name());
+ attributes.put(Port.PORT, 9999);
+ attributes.put(Port.TRANSPORTS, tcpTransportSet);
+ attributes.put(Port.TCP_NO_DELAY, true);
+ attributes.put(Port.RECEIVE_BUFFER_SIZE, 1);
+ attributes.put(Port.SEND_BUFFER_SIZE, 2);
+ attributes.put(Port.NEED_CLIENT_AUTH, true);
+ attributes.put(Port.WANT_CLIENT_AUTH, true);
+
+ ConfigurationEntry portEntry = new ConfigurationEntry(portId, Port.class.getSimpleName(), attributes, Collections.<UUID> emptySet(), _store);
+
+ _store.save(portEntry);
+
+ ConfigurationEntry storeEntry = _store.getEntry(portId);
+ assertEquals("Unexpected port configuration", portEntry, storeEntry);
+ assertEquals("Unexpected type", Port.class.getSimpleName(), storeEntry.getType());
+ assertEquals("Unexpected port attributes", portEntry.getAttributes(), storeEntry.getAttributes());
+ assertTrue("Unexpected port children found", storeEntry.getChildrenIds().isEmpty());
+ }
+
+ public void testMultipleSave()
+ {
+ UUID virtualHostId = UUID.randomUUID();
+ Map<String, Object> virtualHostAttributes = new HashMap<String, Object>();
+ virtualHostAttributes.put(VirtualHost.NAME, "test1");
+ virtualHostAttributes.put(VirtualHost.CONFIG_PATH, "/path/to/phantom/virtualhost/config1");
+ ConfigurationEntry hostEntry = new ConfigurationEntry(virtualHostId, VirtualHost.class.getSimpleName(), virtualHostAttributes,
+ Collections.<UUID> emptySet(), _store);
+
+ UUID keyStoreId = UUID.randomUUID();
+ Map<String, Object> attributes = new HashMap<String, Object>();
+ attributes.put(KeyStore.NAME, getName());
+ attributes.put(KeyStore.PATH, "/path/to/truststore");
+ attributes.put(KeyStore.PASSWORD, "my-secret-password");
+ attributes.put(KeyStore.TYPE, "NON-JKS");
+ attributes.put(KeyStore.KEY_MANAGER_FACTORY_ALGORITHM, "NON-STANDARD");
+ attributes.put(KeyStore.DESCRIPTION, "Description");
+ attributes.put(KeyStore.CERTIFICATE_ALIAS, "Alias");
+
+ ConfigurationEntry keyStoreEntry = new ConfigurationEntry(keyStoreId, KeyStore.class.getSimpleName(), attributes, Collections.<UUID> emptySet(),
+ _store);
+
+ _store.save(hostEntry, keyStoreEntry);
+
+ assertNotNull("Virtual host is not found", _store.getEntry(virtualHostId));
+ assertNotNull("Key store is not found", _store.getEntry(keyStoreId));
+ }
+}
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/store/JsonConfigurationEntryStoreTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/store/JsonConfigurationEntryStoreTest.java
new file mode 100644
index 0000000000..a18d5501f0
--- /dev/null
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/store/JsonConfigurationEntryStoreTest.java
@@ -0,0 +1,77 @@
+package org.apache.qpid.server.configuration.store;
+
+import java.io.File;
+import java.io.StringWriter;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+
+import org.apache.qpid.server.configuration.ConfigurationEntry;
+import org.apache.qpid.server.configuration.ConfigurationEntryStore;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.test.utils.TestFileUtils;
+import org.codehaus.jackson.map.ObjectMapper;
+import org.codehaus.jackson.map.SerializationConfig;
+
+public class JsonConfigurationEntryStoreTest extends ConfigurationEntryStoreTestCase
+{
+ private File _storeFile;
+ private ObjectMapper _objectMapper;
+
+ public void tearDown() throws Exception
+ {
+ _storeFile.delete();
+ super.tearDown();
+ }
+
+ @Override
+ protected ConfigurationEntryStore createStore(UUID brokerId, Map<String, Object> brokerAttributes) throws Exception
+ {
+ _objectMapper = new ObjectMapper();
+ _objectMapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, true);
+
+ Map<String, Object> brokerObjectMap = new HashMap<String, Object>();
+ brokerObjectMap.put(Broker.ID, brokerId);
+ brokerObjectMap.put("@type", Broker.class.getSimpleName());
+ brokerObjectMap.putAll(brokerAttributes);
+
+ StringWriter sw = new StringWriter();
+ _objectMapper.writeValue(sw, brokerObjectMap);
+
+ String brokerJson = sw.toString();
+
+ _storeFile = TestFileUtils.createTempFile(this, ".json", brokerJson);
+
+ JsonConfigurationEntryStore store = new JsonConfigurationEntryStore();
+ store.open(_storeFile.getAbsolutePath());
+ return store;
+ }
+
+ @Override
+ protected void addConfiguration(UUID id, String type, Map<String, Object> attributes)
+ {
+ ConfigurationEntryStore store = getStore();
+ store.save(new ConfigurationEntry(id, type, attributes, Collections.<UUID> emptySet(), store));
+ }
+
+ public void testAttributeIsResolvedFromSystemProperties()
+ {
+ String aclLocation = "path/to/acl/" + getTestName();
+ setTestSystemProperty("my.test.property", aclLocation);
+
+ ConfigurationEntryStore store = getStore();
+ ConfigurationEntry brokerConfigEntry = store.getRootEntry();
+ Map<String, Object> attributes = new HashMap<String, Object>(brokerConfigEntry.getAttributes());
+ attributes.put(Broker.ACL_FILE, "${my.test.property}");
+ ConfigurationEntry updatedBrokerEntry = new ConfigurationEntry(brokerConfigEntry.getId(), Broker.class.getSimpleName(),
+ attributes, brokerConfigEntry.getChildrenIds(), store);
+ store.save(updatedBrokerEntry);
+
+ JsonConfigurationEntryStore store2 = new JsonConfigurationEntryStore();
+ store2.open(_storeFile.getAbsolutePath());
+
+ assertEquals("Unresolved ACL value", aclLocation, store2.getRootEntry().getAttributes().get(Broker.ACL_FILE));
+ }
+
+}
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/store/StoreConfigurationChangeListenerTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/store/StoreConfigurationChangeListenerTest.java
new file mode 100644
index 0000000000..a77a0e9fcc
--- /dev/null
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/store/StoreConfigurationChangeListenerTest.java
@@ -0,0 +1,83 @@
+package org.apache.qpid.server.configuration.store;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.when;
+
+import java.util.UUID;
+
+import org.apache.qpid.server.configuration.ConfigurationEntry;
+import org.apache.qpid.server.configuration.ConfigurationEntryStore;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.ConfiguredObject;
+import org.apache.qpid.server.model.Queue;
+import org.apache.qpid.server.model.State;
+import org.apache.qpid.server.model.VirtualHost;
+import org.apache.qpid.test.utils.QpidTestCase;
+
+public class StoreConfigurationChangeListenerTest extends QpidTestCase
+{
+ private ConfigurationEntryStore _store;
+ private StoreConfigurationChangeListener _listener;
+
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ _store = mock(ConfigurationEntryStore.class);
+ _listener = new StoreConfigurationChangeListener(_store);
+ }
+
+ public void testStateChanged()
+ {
+ notifyBrokerStarted();
+ UUID id = UUID.randomUUID();
+ ConfiguredObject object = mock(VirtualHost.class);
+ when(object.getId()).thenReturn(id);
+ _listener.stateChanged(object, State.ACTIVE, State.DELETED);
+ verify(_store).remove(id);
+ }
+
+ public void testChildAdded()
+ {
+ notifyBrokerStarted();
+ Broker broker = mock(Broker.class);
+ VirtualHost child = mock(VirtualHost.class);
+ _listener.childAdded(broker, child);
+ verify(_store).save(any(ConfigurationEntry.class), any(ConfigurationEntry.class));
+ }
+
+ public void testChildRemoved()
+ {
+ notifyBrokerStarted();
+ Broker broker = mock(Broker.class);
+ VirtualHost child = mock(VirtualHost.class);
+ _listener.childRemoved(broker, child);
+ verify(_store).save(any(ConfigurationEntry.class));
+ }
+
+ public void testAttributeSet()
+ {
+ notifyBrokerStarted();
+ Broker broker = mock(Broker.class);
+ _listener.attributeSet(broker, Broker.FLOW_CONTROL_SIZE_BYTES, null, 1);
+ verify(_store).save(any(ConfigurationEntry.class));
+ }
+
+ public void testChildAddedForVirtualHost()
+ {
+ notifyBrokerStarted();
+
+ VirtualHost object = mock(VirtualHost.class);
+ Queue queue = mock(Queue.class);
+ _listener.childAdded(object, queue);
+ verifyNoMoreInteractions(_store);
+ }
+
+ private void notifyBrokerStarted()
+ {
+ Broker broker = mock(Broker.class);
+ _listener.stateChanged(broker, State.INITIALISING, State.ACTIVE);
+ }
+}
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/updater/TaskExecutorTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/updater/TaskExecutorTest.java
new file mode 100644
index 0000000000..cd6302d55b
--- /dev/null
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/updater/TaskExecutorTest.java
@@ -0,0 +1,296 @@
+/*
+ *
+ * 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.qpid.server.configuration.updater;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.Callable;
+import java.util.concurrent.CancellationException;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicReference;
+
+import javax.security.auth.Subject;
+
+import junit.framework.TestCase;
+
+import org.apache.qpid.server.logging.LogActor;
+import org.apache.qpid.server.logging.NullRootMessageLogger;
+import org.apache.qpid.server.logging.actors.CurrentActor;
+import org.apache.qpid.server.logging.actors.TestLogActor;
+import org.apache.qpid.server.model.State;
+import org.apache.qpid.server.security.SecurityManager;
+
+public class TaskExecutorTest extends TestCase
+{
+ private TaskExecutor _executor;
+
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ _executor = new TaskExecutor();
+ }
+
+ protected void tearDown() throws Exception
+ {
+ try
+ {
+ _executor.stopImmediately();
+ }
+ finally
+ {
+ super.tearDown();
+ }
+ }
+
+ public void testGetState()
+ {
+ assertEquals("Unxpected initial state", State.INITIALISING, _executor.getState());
+ }
+
+ public void testStart()
+ {
+ _executor.start();
+ assertEquals("Unxpected started state", State.ACTIVE, _executor.getState());
+ }
+
+ public void testStopImmediately() throws Exception
+ {
+ _executor.start();
+ final CountDownLatch submitLatch = new CountDownLatch(2);
+ final CountDownLatch waitForCallLatch = new CountDownLatch(1);
+ final BlockingQueue<Exception> submitExceptions = new LinkedBlockingQueue<Exception>();
+
+ Runnable runnable = new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ try
+ {
+ Future<?> f = _executor.submit(new NeverEndingCallable(waitForCallLatch));
+ submitLatch.countDown();
+ f.get();
+ }
+ catch (Exception e)
+ {
+ if (e instanceof ExecutionException)
+ {
+ e = (Exception) e.getCause();
+ }
+ submitExceptions.add(e);
+ }
+ }
+ };
+ new Thread(runnable).start();
+ new Thread(runnable).start();
+ assertTrue("Tasks have not been submitted", submitLatch.await(1000, TimeUnit.MILLISECONDS));
+ assertTrue("The first task has not been triggered", waitForCallLatch.await(1000, TimeUnit.MILLISECONDS));
+
+ _executor.stopImmediately();
+ assertEquals("Unxpected stopped state", State.STOPPED, _executor.getState());
+
+ Exception e = submitExceptions.poll(1000l, TimeUnit.MILLISECONDS);
+ assertNotNull("The task execution was not interrupted or cancelled", e);
+ Exception e2 = submitExceptions.poll(1000l, TimeUnit.MILLISECONDS);
+ assertNotNull("The task execution was not interrupted or cancelled", e2);
+
+ assertTrue("One of the exceptions should be CancellationException:", e2 instanceof CancellationException
+ || e instanceof CancellationException);
+ assertTrue("One of the exceptions should be InterruptedException:", e2 instanceof InterruptedException
+ || e instanceof InterruptedException);
+ }
+
+ public void testStop()
+ {
+ _executor.start();
+ _executor.stop();
+ assertEquals("Unxpected stopped state", State.STOPPED, _executor.getState());
+ }
+
+ public void testSubmitAndWait() throws Exception
+ {
+ _executor.start();
+ Object result = _executor.submitAndWait(new Callable<String>()
+ {
+ @Override
+ public String call() throws Exception
+ {
+ return "DONE";
+ }
+ });
+ assertEquals("Unexpected task execution result", "DONE", result);
+ }
+
+ public void testSubmitAndWaitInNotAuthorizedContext()
+ {
+ _executor.start();
+ Object subject = _executor.submitAndWait(new SubjectRetriever());
+ assertNull("Subject must be null", subject);
+ }
+
+ public void testSubmitAndWaitInAuthorizedContext()
+ {
+ _executor.start();
+ Subject subject = new Subject();
+ Object result = Subject.doAs(subject, new PrivilegedAction<Object>()
+ {
+ @Override
+ public Object run()
+ {
+ return _executor.submitAndWait(new SubjectRetriever());
+ }
+ });
+ assertEquals("Unexpected subject", subject, result);
+ }
+
+ public void testSubmitAndWaitInAuthorizedContextWithNullSubject()
+ {
+ _executor.start();
+ Object result = Subject.doAs(null, new PrivilegedAction<Object>()
+ {
+ @Override
+ public Object run()
+ {
+ return _executor.submitAndWait(new SubjectRetriever());
+ }
+ });
+ assertEquals("Unexpected subject", null, result);
+ }
+
+ public void testSubmitAndWaitReThrowsOriginalRuntimeException()
+ {
+ final RuntimeException exception = new RuntimeException();
+ _executor.start();
+ try
+ {
+ _executor.submitAndWait(new Callable<Void>()
+ {
+
+ @Override
+ public Void call() throws Exception
+ {
+ throw exception;
+ }
+ });
+ fail("Exception is expected");
+ }
+ catch (Exception e)
+ {
+ assertEquals("Unexpected exception", exception, e);
+ }
+ }
+
+ public void testSubmitAndWaitPassesOriginalCheckedException()
+ {
+ final Exception exception = new Exception();
+ _executor.start();
+ try
+ {
+ _executor.submitAndWait(new Callable<Void>()
+ {
+
+ @Override
+ public Void call() throws Exception
+ {
+ throw exception;
+ }
+ });
+ fail("Exception is expected");
+ }
+ catch (Exception e)
+ {
+ assertEquals("Unexpected exception", exception, e.getCause());
+ }
+ }
+
+ public void testSubmitAndWaitCurrentActorAndSecurityManagerSubjectAreRespected() throws Exception
+ {
+ _executor.start();
+ LogActor actor = new TestLogActor(new NullRootMessageLogger());
+ Subject subject = new Subject();
+ Subject currentSecurityManagerSubject = SecurityManager.getThreadSubject();
+ final AtomicReference<LogActor> taskLogActor = new AtomicReference<LogActor>();
+ final AtomicReference<Subject> taskSubject = new AtomicReference<Subject>();
+ try
+ {
+ CurrentActor.set(actor);
+ SecurityManager.setThreadSubject(subject);
+ _executor.submitAndWait(new Callable<Void>()
+ {
+ @Override
+ public Void call() throws Exception
+ {
+ taskLogActor.set(CurrentActor.get());
+ taskSubject.set(SecurityManager.getThreadSubject());
+ return null;
+ }
+ });
+ }
+ finally
+ {
+ SecurityManager.setThreadSubject(currentSecurityManagerSubject);
+ CurrentActor.remove();
+ }
+ assertEquals("Unexpected task log actor", actor, taskLogActor.get());
+ assertEquals("Unexpected security manager subject", subject, taskSubject.get());
+ }
+
+ private class SubjectRetriever implements Callable<Subject>
+ {
+ @Override
+ public Subject call() throws Exception
+ {
+ return Subject.getSubject(AccessController.getContext());
+ }
+ }
+
+ private class NeverEndingCallable implements Callable<Void>
+ {
+ private CountDownLatch _waitLatch;
+
+ public NeverEndingCallable(CountDownLatch waitLatch)
+ {
+ super();
+ _waitLatch = waitLatch;
+ }
+
+ @Override
+ public Void call() throws Exception
+ {
+ if (_waitLatch != null)
+ {
+ _waitLatch.countDown();
+ }
+
+ // wait forever
+ synchronized (this)
+ {
+ this.wait();
+ }
+ return null;
+ }
+ }
+}
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/exchange/AbstractHeadersExchangeTestBase.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/exchange/AbstractHeadersExchangeTestBase.java
index 656490c9d8..0bb698a46c 100644
--- a/qpid/java/broker/src/test/java/org/apache/qpid/server/exchange/AbstractHeadersExchangeTestBase.java
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/exchange/AbstractHeadersExchangeTestBase.java
@@ -53,25 +53,56 @@ import org.apache.qpid.server.queue.IncomingMessage;
import org.apache.qpid.server.queue.MockStoredMessage;
import org.apache.qpid.server.queue.QueueEntry;
import org.apache.qpid.server.queue.SimpleAMQQueue;
-import org.apache.qpid.server.registry.ApplicationRegistry;
import org.apache.qpid.server.store.StoredMessage;
import org.apache.qpid.server.subscription.Subscription;
-import org.apache.qpid.server.util.InternalBrokerBaseCase;
+import org.apache.qpid.server.util.BrokerTestHelper;
+import org.apache.qpid.server.virtualhost.VirtualHost;
+import org.apache.qpid.test.utils.QpidTestCase;
-public class AbstractHeadersExchangeTestBase extends InternalBrokerBaseCase
+public class AbstractHeadersExchangeTestBase extends QpidTestCase
{
private static final Logger _log = Logger.getLogger(AbstractHeadersExchangeTestBase.class);
private final HeadersExchange exchange = new HeadersExchange();
- protected final Set<TestQueue> queues = new HashSet<TestQueue>();
-
+ private final Set<TestQueue> queues = new HashSet<TestQueue>();
+ private VirtualHost _virtualHost;
private int count;
+ @Override
+ public void setUp() throws Exception
+ {
+ super.setUp();
+ BrokerTestHelper.setUp();
+ _virtualHost = BrokerTestHelper.createVirtualHost(getClass().getName());
+ }
+
+ @Override
+ public void tearDown() throws Exception
+ {
+ try
+ {
+ if (_virtualHost != null)
+ {
+ _virtualHost.close();
+ }
+ }
+ finally
+ {
+ BrokerTestHelper.tearDown();
+ super.tearDown();
+ }
+ }
+
public void testDoNothing()
{
// this is here only to make junit under Eclipse happy
}
+ public VirtualHost getVirtualHost()
+ {
+ return _virtualHost;
+ }
+
protected TestQueue bindDefault(String... bindings) throws AMQException
{
String queueName = "Queue" + (++count);
@@ -92,7 +123,7 @@ public class AbstractHeadersExchangeTestBase extends InternalBrokerBaseCase
private TestQueue bind(String key, String queueName, Map<String,Object> args) throws AMQException
{
- TestQueue queue = new TestQueue(new AMQShortString(queueName));
+ TestQueue queue = new TestQueue(new AMQShortString(queueName), _virtualHost);
queues.add(queue);
exchange.onBind(new Binding(null, key, queue, exchange, args));
return queue;
@@ -273,10 +304,10 @@ public class AbstractHeadersExchangeTestBase extends InternalBrokerBaseCase
return getNameShortString().toString();
}
- public TestQueue(AMQShortString name) throws AMQException
+ public TestQueue(AMQShortString name, VirtualHost host) throws AMQException
{
- super(UUIDGenerator.generateRandomUUID(), name, false, new AMQShortString("test"), true, false,ApplicationRegistry.getInstance().getVirtualHostRegistry().getVirtualHost("test"), Collections.EMPTY_MAP);
- ApplicationRegistry.getInstance().getVirtualHostRegistry().getVirtualHost("test").getQueueRegistry().registerQueue(this);
+ super(UUIDGenerator.generateRandomUUID(), name, false, new AMQShortString("test"), true, false, host, Collections.EMPTY_MAP);
+ host.getQueueRegistry().registerQueue(this);
}
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/exchange/HeadersExchangeTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/exchange/HeadersExchangeTest.java
index 326d36df05..bd6a02d69b 100644
--- a/qpid/java/broker/src/test/java/org/apache/qpid/server/exchange/HeadersExchangeTest.java
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/exchange/HeadersExchangeTest.java
@@ -23,8 +23,7 @@ package org.apache.qpid.server.exchange;
import org.apache.qpid.AMQException;
import org.apache.qpid.server.protocol.AMQProtocolSession;
import org.apache.qpid.server.protocol.InternalTestProtocolSession;
-import org.apache.qpid.server.registry.ApplicationRegistry;
-import org.apache.qpid.server.virtualhost.VirtualHost;
+import org.apache.qpid.server.util.BrokerTestHelper;
public class HeadersExchangeTest extends AbstractHeadersExchangeTestBase
{
@@ -34,10 +33,15 @@ public class HeadersExchangeTest extends AbstractHeadersExchangeTestBase
public void setUp() throws Exception
{
super.setUp();
- // Just use the first vhost.
- VirtualHost
- virtualHost = ApplicationRegistry.getInstance().getVirtualHostRegistry().getVirtualHosts().iterator().next();
- _protocolSession = new InternalTestProtocolSession(virtualHost);
+ BrokerTestHelper.setUp();
+ _protocolSession = new InternalTestProtocolSession(getVirtualHost(), BrokerTestHelper.createBrokerMock());
+ }
+
+ @Override
+ public void tearDown() throws Exception
+ {
+ BrokerTestHelper.tearDown();
+ super.tearDown();
}
public void testSimple() throws AMQException
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/exchange/TopicExchangeTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/exchange/TopicExchangeTest.java
index d06649a77d..f1bf632235 100644
--- a/qpid/java/broker/src/test/java/org/apache/qpid/server/exchange/TopicExchangeTest.java
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/exchange/TopicExchangeTest.java
@@ -31,36 +31,49 @@ import org.apache.qpid.server.binding.Binding;
import org.apache.qpid.server.message.AMQMessage;
import org.apache.qpid.server.message.MessageMetaData;
import org.apache.qpid.server.model.UUIDGenerator;
-import org.apache.qpid.server.protocol.InternalTestProtocolSession;
import org.apache.qpid.server.queue.AMQQueue;
import org.apache.qpid.server.queue.AMQQueueFactory;
import org.apache.qpid.server.queue.BaseQueue;
import org.apache.qpid.server.queue.IncomingMessage;
-import org.apache.qpid.server.registry.ApplicationRegistry;
import org.apache.qpid.server.store.MemoryMessageStore;
import org.apache.qpid.server.store.MessageStore;
-import org.apache.qpid.server.util.InternalBrokerBaseCase;
+import org.apache.qpid.server.util.BrokerTestHelper;
import org.apache.qpid.server.virtualhost.VirtualHost;
+import org.apache.qpid.test.utils.QpidTestCase;
-public class TopicExchangeTest extends InternalBrokerBaseCase
+public class TopicExchangeTest extends QpidTestCase
{
private TopicExchange _exchange;
-
private VirtualHost _vhost;
private MessageStore _store;
- private InternalTestProtocolSession _protocolSession;
-
@Override
public void setUp() throws Exception
{
super.setUp();
+ BrokerTestHelper.setUp();
_exchange = new TopicExchange();
- _vhost = ApplicationRegistry.getInstance().getVirtualHostRegistry().getVirtualHosts().iterator().next();
+ _vhost = BrokerTestHelper.createVirtualHost(getName());
_store = new MemoryMessageStore();
- _protocolSession = new InternalTestProtocolSession(_vhost);
+ }
+
+ @Override
+ public void tearDown() throws Exception
+ {
+ try
+ {
+ if (_vhost != null)
+ {
+ _vhost.close();
+ }
+ }
+ finally
+ {
+ BrokerTestHelper.tearDown();
+ super.tearDown();
+ }
}
public void testNoRoute() throws AMQException
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/UnitTestMessageLogger.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/UnitTestMessageLogger.java
index fabbe8640e..be31f3d039 100644
--- a/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/UnitTestMessageLogger.java
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/UnitTestMessageLogger.java
@@ -20,7 +20,6 @@
*/
package org.apache.qpid.server.logging;
-import org.apache.qpid.server.configuration.ServerConfiguration;
import java.util.LinkedList;
import java.util.List;
@@ -34,9 +33,9 @@ public class UnitTestMessageLogger extends AbstractRootMessageLogger
}
- public UnitTestMessageLogger(ServerConfiguration config)
+ public UnitTestMessageLogger(boolean statusUpdatesEnabled)
{
- super(config);
+ super(statusUpdatesEnabled);
}
public void rawMessage(String message, String logHierarchy)
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/actors/AMQPChannelActorTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/actors/AMQPChannelActorTest.java
index f739d3fcb9..e2472dbf01 100644
--- a/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/actors/AMQPChannelActorTest.java
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/actors/AMQPChannelActorTest.java
@@ -20,9 +20,8 @@
*/
package org.apache.qpid.server.logging.actors;
-import org.apache.commons.configuration.ConfigurationException;
-
-import org.apache.qpid.AMQException;
+import org.apache.qpid.server.AMQChannel;
+import org.apache.qpid.server.util.BrokerTestHelper;
import java.util.List;
@@ -38,24 +37,17 @@ import java.util.List;
public class AMQPChannelActorTest extends BaseConnectionActorTestCase
{
- @Override
- public void configure()
+ public void setUp()
{
- // Prevent defaulting Logging to ON
+ // do nothing
}
-
- @Override
- public void createBroker() throws Exception
+ private void setUpNow() throws Exception
{
- //prevent auto-broker startup
- }
+ super.setUp();
+ AMQChannel channel = BrokerTestHelper.createChannel(1, getSession());
- private void startBrokerNow() throws Exception
- {
- super.createBroker();
-
- _amqpActor = new AMQPChannelActor(getChannel(), _rootLogger);
+ setAmqpActor(new AMQPChannelActor(channel, getRootLogger()));
}
@@ -68,13 +60,11 @@ public class AMQPChannelActorTest extends BaseConnectionActorTestCase
*/
public void testChannel() throws Exception
{
- getConfigXml().setProperty("status-updates", "ON");
-
- startBrokerNow();
+ setUpNow();
- final String message = sendTestLogMessage(_amqpActor);
+ final String message = sendTestLogMessage(getAmqpActor());
- List<Object> logs = _rawLogger.getLogMessages();
+ List<Object> logs = getRawLogger().getLogMessages();
assertEquals("Message log size not as expected.", 1, logs.size());
@@ -95,128 +85,22 @@ public class AMQPChannelActorTest extends BaseConnectionActorTestCase
// Verify that the logged message contains the 'ch:1' marker
assertTrue("Message was not logged as part of channel 1" + logs.get(0),
logs.get(0).toString().contains("/ch:1"));
-
- }
-
- /**
- * Test that if logging is configured to be off in the configuration that
- * no logging is presented
- * @throws ConfigurationException
- * @throws AMQException
- */
- public void testChannelLoggingOFF() throws Exception, AMQException
- {
- getConfigXml().setProperty("status-updates", "OFF");
-
- // Start the broker now.
- startBrokerNow();
-
- sendTestLogMessage(_amqpActor);
-
- List<Object> logs = _rawLogger.getLogMessages();
-
- assertEquals("Message log size not as expected.", 0, logs.size());
-
- }
-
- /**
- * Test that if logging is configured to be off in the configuration that
- * no logging is presented
- * @throws ConfigurationException
- * @throws AMQException
- */
- public void testChannelLoggingOfF() throws Exception, AMQException
- {
- getConfigXml().setProperty("status-updates", "OfF");
-
- startBrokerNow();
-
- sendTestLogMessage(_amqpActor);
-
- List<Object> logs = _rawLogger.getLogMessages();
-
- assertEquals("Message log size not as expected.", 0, logs.size());
-
- }
-
- /**
- * Test that if logging is configured to be off in the configuration that
- * no logging is presented
- * @throws ConfigurationException
- * @throws AMQException
- */
- public void testChannelLoggingOff() throws Exception, AMQException
- {
- getConfigXml().setProperty("status-updates", "Off");
-
- startBrokerNow();
-
- sendTestLogMessage(_amqpActor);
-
- List<Object> logs = _rawLogger.getLogMessages();
-
- assertEquals("Message log size not as expected.", 0, logs.size());
-
}
/**
- * Test that if logging is configured to be off in the configuration that
+ * Test that if logging is configured to be off via system property that
* no logging is presented
- * @throws ConfigurationException
- * @throws AMQException
*/
- public void testChannelLoggingofF() throws Exception, AMQException
+ public void testChannelLoggingOFF() throws Exception
{
- getConfigXml().setProperty("status-updates", "ofF");
+ setStatusUpdatesEnabled(false);
- startBrokerNow();
+ setUpNow();
- sendTestLogMessage(_amqpActor);
+ sendTestLogMessage(getAmqpActor());
- List<Object> logs = _rawLogger.getLogMessages();
+ List<Object> logs = getRawLogger().getLogMessages();
assertEquals("Message log size not as expected.", 0, logs.size());
-
}
-
- /**
- * Test that if logging is configured to be off in the configuration that
- * no logging is presented
- * @throws ConfigurationException
- * @throws AMQException
- */
- public void testChannelLoggingoff() throws Exception, AMQException
- {
- getConfigXml().setProperty("status-updates", "off");
-
- startBrokerNow();
-
- sendTestLogMessage(_amqpActor);
-
- List<Object> logs = _rawLogger.getLogMessages();
-
- assertEquals("Message log size not as expected.", 0, logs.size());
-
- }
-
- /**
- * Test that if logging is configured to be off in the configuration that
- * no logging is presented
- * @throws ConfigurationException
- * @throws AMQException
- */
- public void testChannelLoggingoFf() throws Exception, AMQException
- {
- getConfigXml().setProperty("status-updates", "oFf");
-
- startBrokerNow();
-
- sendTestLogMessage(_amqpActor);
-
- List<Object> logs = _rawLogger.getLogMessages();
-
- assertEquals("Message log size not as expected.", 0, logs.size());
-
- }
-
}
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/actors/AMQPConnectionActorTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/actors/AMQPConnectionActorTest.java
index 4eda9e9da1..d1cf256563 100644
--- a/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/actors/AMQPConnectionActorTest.java
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/actors/AMQPConnectionActorTest.java
@@ -38,16 +38,9 @@ import java.util.List;
public class AMQPConnectionActorTest extends BaseConnectionActorTestCase
{
@Override
- public void configure()
+ public void setUp()
{
- // Prevent defaulting Logging to ON
- }
-
-
- @Override
- public void createBroker()
- {
- //Prevent auto-broker startup
+ //Prevent logger creation
}
/**
@@ -60,13 +53,11 @@ public class AMQPConnectionActorTest extends BaseConnectionActorTestCase
*/
public void testConnection() throws Exception
{
- getConfigXml().setProperty("status-updates", "ON");
-
- super.createBroker();
+ super.setUp();
final String message = sendLogMessage();
- List<Object> logs = _rawLogger.getLogMessages();
+ List<Object> logs = getRawLogger().getLogMessages();
assertEquals("Message log size not as expected.", 1, logs.size());
@@ -90,14 +81,13 @@ public class AMQPConnectionActorTest extends BaseConnectionActorTestCase
public void testConnectionLoggingOff() throws Exception, AMQException
{
- getConfigXml().setProperty("status-updates", "OFF");
+ setStatusUpdatesEnabled(false);
- // Start the broker now.
- super.createBroker();
+ super.setUp();
sendLogMessage();
- List<Object> logs = _rawLogger.getLogMessages();
+ List<Object> logs = getRawLogger().getLogMessages();
assertEquals("Message log size not as expected.", 0, logs.size());
@@ -107,7 +97,7 @@ public class AMQPConnectionActorTest extends BaseConnectionActorTestCase
{
final String message = "test logging";
- _amqpActor.message(new LogSubject()
+ getAmqpActor().message(new LogSubject()
{
public String toLogString()
{
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/actors/BaseActorTestCase.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/actors/BaseActorTestCase.java
index ec2cdd5585..30c3a51604 100644
--- a/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/actors/BaseActorTestCase.java
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/actors/BaseActorTestCase.java
@@ -20,39 +20,39 @@
*/
package org.apache.qpid.server.logging.actors;
-import org.apache.qpid.server.configuration.ServerConfiguration;
import org.apache.qpid.server.logging.LogActor;
import org.apache.qpid.server.logging.LogMessage;
import org.apache.qpid.server.logging.LogSubject;
import org.apache.qpid.server.logging.RootMessageLogger;
import org.apache.qpid.server.logging.UnitTestMessageLogger;
-import org.apache.qpid.server.util.InternalBrokerBaseCase;
+import org.apache.qpid.test.utils.QpidTestCase;
-public class BaseActorTestCase extends InternalBrokerBaseCase
+public class BaseActorTestCase extends QpidTestCase
{
- protected LogActor _amqpActor;
- protected UnitTestMessageLogger _rawLogger;
- protected RootMessageLogger _rootLogger;
+ private boolean _statusUpdatesEnabled = true;
+ private LogActor _amqpActor;
+ private UnitTestMessageLogger _rawLogger;
+ private RootMessageLogger _rootLogger;
@Override
- public void configure()
+ public void setUp() throws Exception
{
- getConfiguration().getConfig().setProperty(ServerConfiguration.STATUS_UPDATES, "on");
- }
-
- @Override
- public void createBroker() throws Exception
- {
- super.createBroker();
-
- _rawLogger = new UnitTestMessageLogger(getConfiguration());
+ super.setUp();
+ CurrentActor.removeAll();
+ CurrentActor.setDefault(null);
+ _rawLogger = new UnitTestMessageLogger(_statusUpdatesEnabled);
_rootLogger = _rawLogger;
}
+ @Override
public void tearDown() throws Exception
{
- _rawLogger.clearLogMessages();
-
+ if(_rawLogger != null)
+ {
+ _rawLogger.clearLogMessages();
+ }
+ CurrentActor.removeAll();
+ CurrentActor.setDefault(null);
super.tearDown();
}
@@ -87,4 +87,34 @@ public class BaseActorTestCase extends InternalBrokerBaseCase
});
}
+ public boolean isStatusUpdatesEnabled()
+ {
+ return _statusUpdatesEnabled;
+ }
+
+ public void setStatusUpdatesEnabled(boolean statusUpdatesEnabled)
+ {
+ _statusUpdatesEnabled = statusUpdatesEnabled;
+ }
+
+ public LogActor getAmqpActor()
+ {
+ return _amqpActor;
+ }
+
+ public void setAmqpActor(LogActor amqpActor)
+ {
+ _amqpActor = amqpActor;
+ }
+
+ public UnitTestMessageLogger getRawLogger()
+ {
+ return _rawLogger;
+ }
+
+ public RootMessageLogger getRootLogger()
+ {
+ return _rootLogger;
+ }
+
}
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/actors/BaseConnectionActorTestCase.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/actors/BaseConnectionActorTestCase.java
index 956d296dce..09dd48e4d3 100644
--- a/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/actors/BaseConnectionActorTestCase.java
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/actors/BaseConnectionActorTestCase.java
@@ -20,14 +20,43 @@
*/
package org.apache.qpid.server.logging.actors;
+import org.apache.qpid.server.protocol.AMQProtocolSession;
+import org.apache.qpid.server.util.BrokerTestHelper;
+
public class BaseConnectionActorTestCase extends BaseActorTestCase
{
+ private AMQProtocolSession _session;
@Override
- public void createBroker() throws Exception
+ public void setUp() throws Exception
{
- super.createBroker();
+ super.setUp();
+ BrokerTestHelper.setUp();
+ _session = BrokerTestHelper.createSession();
+
+ setAmqpActor(new AMQPConnectionActor(_session, getRootLogger()));
+ }
- _amqpActor = new AMQPConnectionActor(getSession(), _rootLogger);
+ @Override
+ public void tearDown() throws Exception
+ {
+ try
+ {
+ if (_session != null)
+ {
+ _session.getVirtualHost().close();
+ }
+ }
+ finally
+ {
+ BrokerTestHelper.tearDown();
+ super.tearDown();
+ }
}
+
+ public AMQProtocolSession getSession()
+ {
+ return _session;
+ }
+
}
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/actors/CurrentActorTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/actors/CurrentActorTest.java
index f73765f5aa..8ea5510ce6 100644
--- a/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/actors/CurrentActorTest.java
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/actors/CurrentActorTest.java
@@ -70,12 +70,7 @@ public class CurrentActorTest extends BaseConnectionActorTestCase
*/
public void testLIFO() throws AMQException, ConfigurationException
{
- // This test only needs the local objects created, _session etc.
- // So stopping the broker and making them useless will not affect the
- // test, but the extra actors the test broker adds will so by stopping
- // we remove the session actor and so all is good.
- stopBroker();
-
+ assertTrue("Unexpected actor: " + CurrentActor.get(), CurrentActor.get() instanceof TestLogActor);
AMQPConnectionActor connectionActor = new AMQPConnectionActor(getSession(),
new NullRootMessageLogger());
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/actors/HttpManagementActorTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/actors/HttpManagementActorTest.java
index b40405e1f4..905de4b639 100644
--- a/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/actors/HttpManagementActorTest.java
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/actors/HttpManagementActorTest.java
@@ -34,10 +34,10 @@ public class HttpManagementActorTest extends BaseActorTestCase
private static final String SUFFIX = "(" + IP + ":" + PORT + ")] ";
@Override
- public void createBroker() throws Exception
+ public void setUp() throws Exception
{
- super.createBroker();
- _amqpActor = new HttpManagementActor(_rootLogger, IP, PORT);
+ super.setUp();
+ setAmqpActor(new HttpManagementActor(getRootLogger(), IP, PORT));
}
public void testSubjectPrincipalNameAppearance()
@@ -48,13 +48,13 @@ public class HttpManagementActorTest extends BaseActorTestCase
{
public String run()
{
- return sendTestLogMessage(_amqpActor);
+ return sendTestLogMessage(getAmqpActor());
}
});
assertNotNull("Test log message is not created!", message);
- List<Object> logs = _rawLogger.getLogMessages();
+ List<Object> logs = getRawLogger().getLogMessages();
assertEquals("Message log size not as expected.", 1, logs.size());
String logMessage = logs.get(0).toString();
@@ -74,7 +74,7 @@ public class HttpManagementActorTest extends BaseActorTestCase
private void assertLogMessageWithoutPrincipal()
{
- String message = _amqpActor.getLogMessage();
+ String message = getAmqpActor().getLogMessage();
assertEquals("Unexpected log message", "[mng:" + AbstractManagementActor.UNKNOWN_PRINCIPAL + SUFFIX, message);
}
@@ -85,7 +85,7 @@ public class HttpManagementActorTest extends BaseActorTestCase
{
public String run()
{
- return _amqpActor.getLogMessage();
+ return getAmqpActor().getLogMessage();
}
});
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/actors/ManagementActorTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/actors/ManagementActorTest.java
index 20cc321aab..a0bfa592db 100644
--- a/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/actors/ManagementActorTest.java
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/actors/ManagementActorTest.java
@@ -35,10 +35,10 @@ public class ManagementActorTest extends BaseActorTestCase
private String _threadName;
@Override
- public void createBroker() throws Exception
+ public void setUp() throws Exception
{
- super.createBroker();
- _amqpActor = new ManagementActor(_rootLogger);
+ super.setUp();
+ setAmqpActor(new ManagementActor(getRootLogger()));
// Set the thread name to be the same as a RMI JMX Connection would use
_threadName = Thread.currentThread().getName();
@@ -57,14 +57,14 @@ public class ManagementActorTest extends BaseActorTestCase
*
* The test sends a message then verifies that it entered the logs.
*
- * The log message should be fully repalaced (no '{n}' values) and should
+ * The log message should be fully replaced (no '{n}' values) and should
* not contain any channel identification.
*/
public void testConnection()
{
- final String message = sendTestLogMessage(_amqpActor);
+ final String message = sendTestLogMessage(getAmqpActor());
- List<Object> logs = _rawLogger.getLogMessages();
+ List<Object> logs = getRawLogger().getLogMessages();
assertEquals("Message log size not as expected.", 1, logs.size());
@@ -101,14 +101,14 @@ public class ManagementActorTest extends BaseActorTestCase
{
public String run()
{
- return sendTestLogMessage(_amqpActor);
+ return sendTestLogMessage(getAmqpActor());
}
});
// Verify that the log message was created
assertNotNull("Test log message is not created!", message);
- List<Object> logs = _rawLogger.getLogMessages();
+ List<Object> logs = getRawLogger().getLogMessages();
// Verify that at least one log message was added to log
assertEquals("Message log size not as expected.", 1, logs.size());
@@ -130,8 +130,8 @@ public class ManagementActorTest extends BaseActorTestCase
public void testGetLogMessageWithoutSubjectButWithActorPrincipal()
{
String principalName = "my_principal";
- _amqpActor = new ManagementActor(_rootLogger, principalName);
- String message = _amqpActor.getLogMessage();
+ setAmqpActor(new ManagementActor(getRootLogger(), principalName));
+ String message = getAmqpActor().getLogMessage();
assertEquals("Unexpected log message", "[mng:" + principalName + "(" + IP + ")] ", message);
}
@@ -149,7 +149,7 @@ public class ManagementActorTest extends BaseActorTestCase
assertLogMessageInRMIThreadWithPrincipal("RMI TCP Connection(1)-" + IP, "my_principal");
Thread.currentThread().setName("RMI TCP Connection(2)-" + IP );
- String message = _amqpActor.getLogMessage();
+ String message = getAmqpActor().getLogMessage();
assertEquals("Unexpected log message", "[mng:N/A(" + IP + ")] ", message);
assertLogMessageWithoutPrincipal("TEST");
@@ -158,14 +158,14 @@ public class ManagementActorTest extends BaseActorTestCase
private void assertLogMessageInRMIThreadWithoutPrincipal(String threadName)
{
Thread.currentThread().setName(threadName );
- String message = _amqpActor.getLogMessage();
+ String message = getAmqpActor().getLogMessage();
assertEquals("Unexpected log message", "[mng:N/A(" + IP + ")] ", message);
}
private void assertLogMessageWithoutPrincipal(String threadName)
{
Thread.currentThread().setName(threadName );
- String message = _amqpActor.getLogMessage();
+ String message = getAmqpActor().getLogMessage();
assertEquals("Unexpected log message", "[" + threadName +"] ", message);
}
@@ -177,7 +177,7 @@ public class ManagementActorTest extends BaseActorTestCase
{
public String run()
{
- return _amqpActor.getLogMessage();
+ return getAmqpActor().getLogMessage();
}
});
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/actors/QueueActorTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/actors/QueueActorTest.java
index 409f7c84b7..2dc44c58ce 100644
--- a/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/actors/QueueActorTest.java
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/actors/QueueActorTest.java
@@ -22,14 +22,16 @@ package org.apache.qpid.server.logging.actors;
import java.util.List;
+import org.apache.qpid.server.util.BrokerTestHelper;
+
public class QueueActorTest extends BaseConnectionActorTestCase
{
@Override
- public void createBroker() throws Exception
+ public void setUp() throws Exception
{
- super.createBroker();
- _amqpActor = new QueueActor(getQueue(), _rootLogger);
+ super.setUp();
+ setAmqpActor(new QueueActor(BrokerTestHelper.createQueue(getName(), getSession().getVirtualHost()), getRootLogger()));
}
/**
@@ -42,9 +44,9 @@ public class QueueActorTest extends BaseConnectionActorTestCase
*/
public void testQueueActor()
{
- final String message = sendTestLogMessage(_amqpActor);
+ final String message = sendTestLogMessage(getAmqpActor());
- List<Object> logs = _rawLogger.getLogMessages();
+ List<Object> logs = getRawLogger().getLogMessages();
assertEquals("Message log size not as expected.", 1, logs.size());
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/actors/SubscriptionActorTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/actors/SubscriptionActorTest.java
index 8eaa165853..58fca488c4 100644
--- a/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/actors/SubscriptionActorTest.java
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/actors/SubscriptionActorTest.java
@@ -21,6 +21,7 @@
package org.apache.qpid.server.logging.actors;
import org.apache.qpid.server.subscription.MockSubscription;
+import org.apache.qpid.server.util.BrokerTestHelper;
import java.util.List;
@@ -37,15 +38,15 @@ public class SubscriptionActorTest extends BaseConnectionActorTestCase
{
@Override
- public void createBroker() throws Exception
+ public void setUp() throws Exception
{
- super.createBroker();
+ super.setUp();
MockSubscription mockSubscription = new MockSubscription();
- mockSubscription.setQueue(getQueue(), false);
+ mockSubscription.setQueue(BrokerTestHelper.createQueue(getName(), getSession().getVirtualHost()), false);
- _amqpActor = new SubscriptionActor(_rootLogger, mockSubscription);
+ setAmqpActor(new SubscriptionActor(getRootLogger(), mockSubscription));
}
/**
@@ -58,9 +59,9 @@ public class SubscriptionActorTest extends BaseConnectionActorTestCase
*/
public void testSubscription()
{
- final String message = sendTestLogMessage(_amqpActor);
+ final String message = sendTestLogMessage(getAmqpActor());
- List<Object> logs = _rawLogger.getLogMessages();
+ List<Object> logs = getRawLogger().getLogMessages();
assertEquals("Message log size not as expected.", 1, logs.size());
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/messages/AbstractTestMessages.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/messages/AbstractTestMessages.java
index 24e7225d82..229d75c69f 100644
--- a/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/messages/AbstractTestMessages.java
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/messages/AbstractTestMessages.java
@@ -29,11 +29,12 @@ import org.apache.qpid.server.logging.LogSubject;
import org.apache.qpid.server.logging.UnitTestMessageLogger;
import org.apache.qpid.server.logging.actors.TestLogActor;
import org.apache.qpid.server.logging.subjects.TestBlankSubject;
-import org.apache.qpid.server.util.InternalBrokerBaseCase;
+import org.apache.qpid.server.util.BrokerTestHelper;
+import org.apache.qpid.test.utils.QpidTestCase;
import java.util.List;
-public abstract class AbstractTestMessages extends InternalBrokerBaseCase
+public abstract class AbstractTestMessages extends QpidTestCase
{
protected Configuration _config = new PropertiesConfiguration();
protected LogMessage _logMessage = null;
@@ -49,6 +50,14 @@ public abstract class AbstractTestMessages extends InternalBrokerBaseCase
_logger = new UnitTestMessageLogger();
_actor = new TestLogActor(_logger);
+ BrokerTestHelper.setUp();
+ }
+
+ @Override
+ public void tearDown() throws Exception
+ {
+ BrokerTestHelper.tearDown();
+ super.tearDown();
}
protected List<Object> performLog()
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/messages/ExchangeMessagesTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/messages/ExchangeMessagesTest.java
index 4364376000..1cb4da55c3 100644
--- a/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/messages/ExchangeMessagesTest.java
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/messages/ExchangeMessagesTest.java
@@ -21,7 +21,7 @@
package org.apache.qpid.server.logging.messages;
import org.apache.qpid.server.exchange.Exchange;
-import org.apache.qpid.server.registry.ApplicationRegistry;
+import org.apache.qpid.server.util.BrokerTestHelper;
import java.util.List;
@@ -30,12 +30,9 @@ import java.util.List;
*/
public class ExchangeMessagesTest extends AbstractTestMessages
{
- public void testExchangeCreated_Transient()
+ public void testExchangeCreated_Transient() throws Exception
{
- // Get the Default Exchange on the Test Vhost for testing
- Exchange exchange = ApplicationRegistry.getInstance().
- getVirtualHostRegistry().getVirtualHost("test").
- getExchangeRegistry().getDefaultExchange();
+ Exchange exchange = BrokerTestHelper.createExchange("test");
String type = exchange.getTypeShortString().toString();
String name = exchange.getNameShortString().toString();
@@ -48,12 +45,9 @@ public class ExchangeMessagesTest extends AbstractTestMessages
validateLogMessage(log, "EXH-1001", expected);
}
- public void testExchangeCreated_Persistent()
+ public void testExchangeCreated_Persistent() throws Exception
{
- // Get the Default Exchange on the Test Vhost for testing
- Exchange exchange = ApplicationRegistry.getInstance().
- getVirtualHostRegistry().getVirtualHost("test").
- getExchangeRegistry().getDefaultExchange();
+ Exchange exchange = BrokerTestHelper.createExchange("test");
String type = exchange.getTypeShortString().toString();
String name = exchange.getNameShortString().toString();
@@ -76,12 +70,9 @@ public class ExchangeMessagesTest extends AbstractTestMessages
validateLogMessage(log, "EXH-1002", expected);
}
- public void testExchangeDiscardedMessage()
+ public void testExchangeDiscardedMessage() throws Exception
{
- // Get the Default Exchange on the Test Vhost for testing
- final Exchange exchange = ApplicationRegistry.getInstance().
- getVirtualHostRegistry().getVirtualHost("test").
- getExchangeRegistry().getDefaultExchange();
+ Exchange exchange = BrokerTestHelper.createExchange("test");
final String name = exchange.getNameShortString().toString();
final String routingKey = "routingKey";
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/AbstractTestLogSubject.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/AbstractTestLogSubject.java
index c2558d2d1b..193e8a490d 100644
--- a/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/AbstractTestLogSubject.java
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/AbstractTestLogSubject.java
@@ -20,21 +20,19 @@
*/
package org.apache.qpid.server.logging.subjects;
-import org.apache.commons.configuration.Configuration;
-import org.apache.commons.configuration.ConfigurationException;
-import org.apache.commons.configuration.PropertiesConfiguration;
import org.apache.qpid.framing.AMQShortString;
-import org.apache.qpid.server.configuration.ServerConfiguration;
import org.apache.qpid.server.exchange.Exchange;
import org.apache.qpid.server.logging.LogActor;
import org.apache.qpid.server.logging.LogMessage;
import org.apache.qpid.server.logging.LogSubject;
import org.apache.qpid.server.logging.UnitTestMessageLogger;
+import org.apache.qpid.server.logging.actors.CurrentActor;
import org.apache.qpid.server.logging.actors.TestLogActor;
import org.apache.qpid.server.queue.AMQQueue;
-import org.apache.qpid.server.util.InternalBrokerBaseCase;
+import org.apache.qpid.server.util.BrokerTestHelper;
import org.apache.qpid.server.virtualhost.VirtualHost;
+import org.apache.qpid.test.utils.QpidTestCase;
import java.util.List;
@@ -49,29 +47,39 @@ import java.util.List;
* The resulting log file is then validated.
*
*/
-public abstract class AbstractTestLogSubject extends InternalBrokerBaseCase
+public abstract class AbstractTestLogSubject extends QpidTestCase
{
- protected Configuration _config = new PropertiesConfiguration();
protected LogSubject _subject = null;
@Override
public void setUp() throws Exception
{
super.setUp();
-
- _config.setProperty(ServerConfiguration.STATUS_UPDATES, "ON");
+ BrokerTestHelper.setUp();
}
+ @Override
+ public void tearDown() throws Exception
+ {
+ BrokerTestHelper.tearDown();
+ try
+ {
+ CurrentActor.removeAll();
+ }
+ finally
+ {
+ super.tearDown();
+ }
+ }
- protected List<Object> performLog() throws ConfigurationException
+ protected List<Object> performLog(boolean statusUpdatesEnabled)
{
if (_subject == null)
{
throw new NullPointerException("LogSubject has not been set");
}
- ServerConfiguration serverConfig = new ServerConfiguration(_config);
- UnitTestMessageLogger logger = new UnitTestMessageLogger(serverConfig);
+ UnitTestMessageLogger logger = new UnitTestMessageLogger(statusUpdatesEnabled);
LogActor actor = new TestLogActor(logger);
@@ -247,11 +255,10 @@ public abstract class AbstractTestLogSubject extends InternalBrokerBaseCase
/**
* Test that when Logging occurs a single log statement is provided
*
- * @throws ConfigurationException
*/
- public void testEnabled() throws ConfigurationException
+ public void testEnabled()
{
- List<Object> logs = performLog();
+ List<Object> logs = performLog(true);
assertEquals("Log has incorrect message count", 1, logs.size());
@@ -267,15 +274,11 @@ public abstract class AbstractTestLogSubject extends InternalBrokerBaseCase
protected abstract void validateLogStatement(String message);
/**
- * Ensure that when status-updates are off this does not perform logging
- *
- * @throws ConfigurationException
+ * Ensure that when status updates are off this does not perform logging
*/
- public void testDisabled() throws ConfigurationException
+ public void testDisabled()
{
- _config.setProperty(ServerConfiguration.STATUS_UPDATES, "OFF");
-
- List<Object> logs = performLog();
+ List<Object> logs = performLog(false);
assertEquals("Log has incorrect message count", 0, logs.size());
}
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/BindingLogSubjectTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/BindingLogSubjectTest.java
index e80c4c4679..dd8d28e836 100644
--- a/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/BindingLogSubjectTest.java
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/BindingLogSubjectTest.java
@@ -24,7 +24,7 @@ import org.apache.qpid.framing.AMQShortString;
import org.apache.qpid.server.exchange.Exchange;
import org.apache.qpid.server.queue.AMQQueue;
import org.apache.qpid.server.queue.MockAMQQueue;
-import org.apache.qpid.server.registry.ApplicationRegistry;
+import org.apache.qpid.server.util.BrokerTestHelper;
import org.apache.qpid.server.virtualhost.VirtualHost;
/**
@@ -38,13 +38,12 @@ public class BindingLogSubjectTest extends AbstractTestLogSubject
private Exchange _exchange;
private VirtualHost _testVhost;
+ @Override
public void setUp() throws Exception
{
super.setUp();
- _testVhost = ApplicationRegistry.getInstance().getVirtualHostRegistry().
- getVirtualHost("test");
- // Configure items for subjectCreation
+ _testVhost = BrokerTestHelper.createVirtualHost("test");
_routingKey = new AMQShortString("RoutingKey");
_exchange = _testVhost.getExchangeRegistry().getDefaultExchange();
_queue = new MockAMQQueue("BindingLogSubjectTest");
@@ -53,6 +52,16 @@ public class BindingLogSubjectTest extends AbstractTestLogSubject
_subject = new BindingLogSubject(String.valueOf(_routingKey), _exchange, _queue);
}
+ @Override
+ public void tearDown() throws Exception
+ {
+ if (_testVhost != null)
+ {
+ _testVhost.close();
+ }
+ super.tearDown();
+ }
+
/**
* Validate that the logged Subject message is as expected:
* MESSAGE [Blank][vh(/test)/ex(direct/<<default>>)/qu(BindingLogSubjectTest)/rk(RoutingKey)] <Log Message>
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/ChannelLogSubjectTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/ChannelLogSubjectTest.java
index 6bc5effa05..d75e033739 100644
--- a/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/ChannelLogSubjectTest.java
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/ChannelLogSubjectTest.java
@@ -34,6 +34,7 @@ public class ChannelLogSubjectTest extends ConnectionLogSubjectTest
{
super.setUp();
+
AMQChannel channel = new AMQChannel(getSession(), _channelID, getSession().getVirtualHost().getMessageStore());
_subject = new ChannelLogSubject(channel);
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/ConnectionLogSubjectTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/ConnectionLogSubjectTest.java
index c246fff2a8..7dc4c443ba 100644
--- a/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/ConnectionLogSubjectTest.java
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/ConnectionLogSubjectTest.java
@@ -20,17 +20,34 @@
*/
package org.apache.qpid.server.logging.subjects;
+import org.apache.qpid.server.protocol.InternalTestProtocolSession;
+import org.apache.qpid.server.util.BrokerTestHelper;
+
/**
* Validate ConnectionLogSubjects are logged as expected
*/
public class ConnectionLogSubjectTest extends AbstractTestLogSubject
{
+ private InternalTestProtocolSession _session;
+
+ @Override
public void setUp() throws Exception
{
super.setUp();
- _subject = new ConnectionLogSubject(getSession());
+ _session = BrokerTestHelper.createSession("test");
+ _subject = new ConnectionLogSubject(_session);
+ }
+
+ @Override
+ public void tearDown() throws Exception
+ {
+ if (_session != null)
+ {
+ _session.getVirtualHost().close();
+ }
+ super.tearDown();
}
/**
@@ -40,7 +57,12 @@ public class ConnectionLogSubjectTest extends AbstractTestLogSubject
*/
protected void validateLogStatement(String message)
{
- verifyConnection(getSession().getSessionID(), "InternalTestProtocolSession", "127.0.0.1:1", "test", message);
+ verifyConnection(_session.getSessionID(), "InternalTestProtocolSession", "127.0.0.1:1", "test", message);
+ }
+
+ public InternalTestProtocolSession getSession()
+ {
+ return _session;
}
}
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/ExchangeLogSubjectTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/ExchangeLogSubjectTest.java
index cc06b05bf6..8d1b89bf3c 100644
--- a/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/ExchangeLogSubjectTest.java
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/ExchangeLogSubjectTest.java
@@ -21,7 +21,7 @@
package org.apache.qpid.server.logging.subjects;
import org.apache.qpid.server.exchange.Exchange;
-import org.apache.qpid.server.registry.ApplicationRegistry;
+import org.apache.qpid.server.util.BrokerTestHelper;
import org.apache.qpid.server.virtualhost.VirtualHost;
@@ -33,17 +33,27 @@ public class ExchangeLogSubjectTest extends AbstractTestLogSubject
private Exchange _exchange;
private VirtualHost _testVhost;
+ @Override
public void setUp() throws Exception
{
super.setUp();
- _testVhost = ApplicationRegistry.getInstance().getVirtualHostRegistry().
- getVirtualHost("test");
+ _testVhost = BrokerTestHelper.createVirtualHost("test");
_exchange = _testVhost.getExchangeRegistry().getDefaultExchange();
_subject = new ExchangeLogSubject(_exchange,_testVhost);
}
+ @Override
+ public void tearDown() throws Exception
+ {
+ if (_testVhost != null)
+ {
+ _testVhost.close();
+ }
+ super.tearDown();
+ }
+
/**
* Validate that the logged Subject message is as expected:
* MESSAGE [Blank][vh(/test)/ex(direct/<<default>>)] <Log Message>
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/MessageStoreLogSubjectTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/MessageStoreLogSubjectTest.java
index c62b24c3b9..65fd249d03 100644
--- a/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/MessageStoreLogSubjectTest.java
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/MessageStoreLogSubjectTest.java
@@ -20,7 +20,7 @@
*/
package org.apache.qpid.server.logging.subjects;
-import org.apache.qpid.server.registry.ApplicationRegistry;
+import org.apache.qpid.server.util.BrokerTestHelper;
import org.apache.qpid.server.virtualhost.VirtualHost;
/**
@@ -30,16 +30,26 @@ public class MessageStoreLogSubjectTest extends AbstractTestLogSubject
{
private VirtualHost _testVhost;
+ @Override
public void setUp() throws Exception
{
super.setUp();
- _testVhost = ApplicationRegistry.getInstance().getVirtualHostRegistry().
- getVirtualHost("test");
+ _testVhost = BrokerTestHelper.createVirtualHost("test");
_subject = new MessageStoreLogSubject(_testVhost, _testVhost.getMessageStore().getClass().getSimpleName());
}
+ @Override
+ public void tearDown() throws Exception
+ {
+ if (_testVhost != null)
+ {
+ _testVhost.close();
+ }
+ super.tearDown();
+ }
+
/**
* Validate that the logged Subject message is as expected:
* MESSAGE [Blank][vh(/test)/ms(MemoryMessageStore)] <Log Message>
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/QueueLogSubjectTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/QueueLogSubjectTest.java
index 1f432be57a..e2765f338b 100644
--- a/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/QueueLogSubjectTest.java
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/QueueLogSubjectTest.java
@@ -22,7 +22,7 @@ package org.apache.qpid.server.logging.subjects;
import org.apache.qpid.server.queue.AMQQueue;
import org.apache.qpid.server.queue.MockAMQQueue;
-import org.apache.qpid.server.registry.ApplicationRegistry;
+import org.apache.qpid.server.util.BrokerTestHelper;
import org.apache.qpid.server.virtualhost.VirtualHost;
/**
@@ -39,8 +39,7 @@ public class QueueLogSubjectTest extends AbstractTestLogSubject
{
super.setUp();
- _testVhost = ApplicationRegistry.getInstance().getVirtualHostRegistry().
- getVirtualHost("test");
+ _testVhost = BrokerTestHelper.createVirtualHost("test");
_queue = new MockAMQQueue("QueueLogSubjectTest");
((MockAMQQueue) _queue).setVirtualHost(_testVhost);
@@ -48,6 +47,16 @@ public class QueueLogSubjectTest extends AbstractTestLogSubject
_subject = new QueueLogSubject(_queue);
}
+ @Override
+ public void tearDown() throws Exception
+ {
+ if (_testVhost != null)
+ {
+ _testVhost.close();
+ }
+ super.tearDown();
+ }
+
/**
* Validate that the logged Subject message is as expected:
* MESSAGE [Blank][vh(/test)/qu(QueueLogSubjectTest)] <Log Message>
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/SubscriptionLogSubjectTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/SubscriptionLogSubjectTest.java
index 0c356e1838..153d01f355 100644
--- a/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/SubscriptionLogSubjectTest.java
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/SubscriptionLogSubjectTest.java
@@ -23,12 +23,13 @@ package org.apache.qpid.server.logging.subjects;
import org.apache.qpid.framing.AMQShortString;
import org.apache.qpid.server.AMQChannel;
import org.apache.qpid.server.flow.LimitlessCreditManager;
+import org.apache.qpid.server.protocol.InternalTestProtocolSession;
import org.apache.qpid.server.queue.AMQQueue;
import org.apache.qpid.server.queue.MockAMQQueue;
-import org.apache.qpid.server.registry.ApplicationRegistry;
import org.apache.qpid.server.subscription.Subscription;
import org.apache.qpid.server.subscription.SubscriptionFactory;
import org.apache.qpid.server.subscription.SubscriptionFactoryImpl;
+import org.apache.qpid.server.util.BrokerTestHelper;
import org.apache.qpid.server.virtualhost.VirtualHost;
/**
@@ -42,23 +43,24 @@ public class SubscriptionLogSubjectTest extends AbstractTestLogSubject
private int _channelID = 1;
private Subscription _subscription;
+ @Override
public void setUp() throws Exception
{
super.setUp();
- _testVhost = ApplicationRegistry.getInstance().getVirtualHostRegistry().
- getVirtualHost("test");
+ InternalTestProtocolSession session = BrokerTestHelper.createSession();
+ _testVhost = session.getVirtualHost();
_queue = new MockAMQQueue("SubscriptionLogSubjectTest");
((MockAMQQueue) _queue).setVirtualHost(_testVhost);
- AMQChannel channel = new AMQChannel(getSession(), _channelID, getSession().getVirtualHost().getMessageStore());
+ AMQChannel channel = new AMQChannel(session, _channelID, _testVhost.getMessageStore());
- getSession().addChannel(channel);
+ session.addChannel(channel);
SubscriptionFactory factory = new SubscriptionFactoryImpl();
- _subscription = factory.createSubscription(_channelID, getSession(), new AMQShortString("cTag"),
+ _subscription = factory.createSubscription(_channelID, session, new AMQShortString("cTag"),
false, null, false,
new LimitlessCreditManager());
@@ -67,6 +69,16 @@ public class SubscriptionLogSubjectTest extends AbstractTestLogSubject
_subject = new SubscriptionLogSubject(_subscription);
}
+ @Override
+ public void tearDown() throws Exception
+ {
+ if (_testVhost != null)
+ {
+ _testVhost.close();
+ }
+ super.tearDown();
+ }
+
/**
* Validate that the logged Subject message is as expected:
* MESSAGE [Blank][sub:0(vh(/test)/qu(SubscriptionLogSubjectTest))] <Log Message>
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/model/BrokerShutdownTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/model/BrokerShutdownTest.java
new file mode 100644
index 0000000000..6ed9740c6d
--- /dev/null
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/model/BrokerShutdownTest.java
@@ -0,0 +1,216 @@
+/*
+ *
+ * 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.qpid.server.model;
+
+import static org.mockito.Mockito.mock;
+
+import org.apache.qpid.server.configuration.ConfigurationEntry;
+import org.apache.qpid.server.configuration.ConfigurationEntryStore;
+import org.apache.qpid.server.configuration.ConfiguredObjectRecoverer;
+import org.apache.qpid.server.configuration.RecovererProvider;
+import org.apache.qpid.server.configuration.startup.DefaultRecovererProvider;
+import org.apache.qpid.server.logging.LogRecorder;
+import org.apache.qpid.server.logging.RootMessageLogger;
+import org.apache.qpid.server.model.AuthenticationProvider;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.ConfiguredObject;
+import org.apache.qpid.server.model.State;
+import org.apache.qpid.server.configuration.updater.TaskExecutor;
+import org.apache.qpid.server.plugin.AuthenticationManagerFactory;
+import org.apache.qpid.server.security.auth.manager.PlainPasswordFileAuthenticationManagerFactory;
+import org.apache.qpid.server.stats.StatisticsGatherer;
+import org.apache.qpid.server.virtualhost.VirtualHostRegistry;
+import org.apache.qpid.test.utils.QpidTestCase;
+import org.apache.qpid.test.utils.TestFileUtils;
+
+import java.io.File;
+import java.security.Provider;
+import java.security.Security;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+/**
+ * QPID-1390 : Test to validate that the AuthenticationManger can successfully unregister any new SASL providers when
+ * the broker is stopped.
+ */
+public class BrokerShutdownTest extends QpidTestCase
+{
+ private Provider[] _defaultProviders;
+ private Broker _broker;
+ private TaskExecutor _taskExecutor;
+
+ @Override
+ public void setUp() throws Exception
+ {
+ // Get default providers
+ _defaultProviders = Security.getProviders();
+
+ super.setUp();
+
+ _taskExecutor = new TaskExecutor();
+ _taskExecutor.start();
+
+ // Startup the new broker and register the new providers
+ _broker = startBroker();
+ }
+
+ @Override
+ public void tearDown() throws Exception
+ {
+ try
+ {
+ super.tearDown();
+ }
+ finally
+ {
+ if (_taskExecutor != null)
+ {
+ _taskExecutor.stopImmediately();
+ }
+ }
+
+ }
+
+ private Broker startBroker() throws Exception
+ {
+ // test store with only broker and authentication provider entries
+ ConfigurationEntryStore store = new ConfigurationEntryStore()
+ {
+ private UUID _brokerId = UUID.randomUUID();
+ private UUID _authenticationProviderId = UUID.randomUUID();
+
+ @Override
+ public ConfigurationEntry getRootEntry()
+ {
+ return new ConfigurationEntry(_brokerId, Broker.class.getSimpleName(), Collections.<String, Object> emptyMap(),
+ Collections.singleton(_authenticationProviderId), this);
+ }
+
+ @Override
+ public ConfigurationEntry getEntry(UUID id)
+ {
+ if (_authenticationProviderId.equals(id))
+ {
+ File file = TestFileUtils.createTempFile(BrokerShutdownTest.this, ".db.users");
+ Map<String, Object> attributes = new HashMap<String, Object>();
+ attributes.put(AuthenticationManagerFactory.ATTRIBUTE_TYPE, PlainPasswordFileAuthenticationManagerFactory.PROVIDER_TYPE);
+ attributes.put(PlainPasswordFileAuthenticationManagerFactory.ATTRIBUTE_PATH, file.getAbsolutePath());
+ return new ConfigurationEntry(_authenticationProviderId, AuthenticationProvider.class.getSimpleName(), attributes,
+ Collections.<UUID> emptySet(), this);
+ }
+ return null;
+ }
+
+ @Override
+ public void save(ConfigurationEntry... entries)
+ {
+ }
+
+ @Override
+ public UUID[] remove(UUID... entryIds)
+ {
+ return null;
+ }
+
+ @Override
+ public void open(String storeLocation)
+ {
+ }
+
+ };
+
+ // mocking the required object
+ StatisticsGatherer statisticsGatherer = mock(StatisticsGatherer.class);
+ VirtualHostRegistry virtualHostRegistry = mock(VirtualHostRegistry.class);
+ LogRecorder logRecorder = mock(LogRecorder.class);
+ RootMessageLogger rootMessageLogger = mock(RootMessageLogger.class);
+
+ // recover the broker from the store
+ RecovererProvider provider = new DefaultRecovererProvider(statisticsGatherer, virtualHostRegistry, logRecorder, rootMessageLogger, _taskExecutor);
+ ConfiguredObjectRecoverer<? extends ConfiguredObject> brokerRecoverer = provider.getRecoverer(Broker.class.getSimpleName());
+
+ Broker broker = (Broker) brokerRecoverer.create(provider, store.getRootEntry());
+
+ // start broker
+ broker.setDesiredState(State.INITIALISING, State.ACTIVE);
+ return broker;
+ }
+
+ private void stopBroker()
+ {
+ _broker.setDesiredState(State.ACTIVE, State.STOPPED);
+ }
+
+ /**
+ * QPID-1399 : Ensure that the Authentication manager unregisters any SASL providers created during
+ * broker start-up.
+ *
+ */
+ public void testAuthenticationMangerCleansUp() throws Exception
+ {
+
+ // Get the providers after initialisation
+ Provider[] providersAfterInitialisation = Security.getProviders();
+
+ // Find the additions
+ List<Provider> additions = new LinkedList<Provider>();
+ for (Provider afterInit : providersAfterInitialisation)
+ {
+ boolean found = false;
+ for (Provider defaultProvider : _defaultProviders)
+ {
+ if (defaultProvider == afterInit)
+ {
+ found = true;
+ break;
+ }
+ }
+
+ // Record added registies
+ if (!found)
+ {
+ additions.add(afterInit);
+ }
+ }
+
+ assertFalse("No new SASL mechanisms added by initialisation.", additions.isEmpty());
+
+ // Close the registry which will perform the close the
+ // AuthenticationManager
+ stopBroker();
+
+ // Validate that the SASL plugins have been removed.
+ Provider[] providersAfterClose = Security.getProviders();
+
+ assertTrue("No providers unregistered", providersAfterInitialisation.length > providersAfterClose.length);
+
+ // Ensure that the additions are not still present after close().
+ for (Provider afterClose : providersAfterClose)
+ {
+ assertFalse("Added provider not unregistered", additions.contains(afterClose));
+ }
+ }
+
+}
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/model/adapter/AuthenticationProviderFactoryTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/model/adapter/AuthenticationProviderFactoryTest.java
new file mode 100644
index 0000000000..585fecae83
--- /dev/null
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/model/adapter/AuthenticationProviderFactoryTest.java
@@ -0,0 +1,85 @@
+/*
+ *
+ * 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.qpid.server.model.adapter;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+
+import junit.framework.TestCase;
+
+import org.apache.qpid.server.configuration.ConfigurationEntry;
+import org.apache.qpid.server.model.AuthenticationProvider;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.PasswordCredentialManagingAuthenticationProvider;
+import org.apache.qpid.server.plugin.AuthenticationManagerFactory;
+import org.apache.qpid.server.plugin.QpidServiceLoader;
+import org.apache.qpid.server.security.auth.manager.AuthenticationManager;
+import org.apache.qpid.server.security.auth.manager.PrincipalDatabaseAuthenticationManager;
+
+public class AuthenticationProviderFactoryTest extends TestCase
+{
+
+ public void testCreatePasswordCredentialManagingAuthenticationProvider()
+ {
+ AuthenticationProvider provider = testForFactory(mock(PrincipalDatabaseAuthenticationManager.class));
+ assertTrue("The created provider should match the factory's AuthenticationManager type",
+ provider instanceof PasswordCredentialManagingAuthenticationProvider);
+ }
+
+ public void testCreateNonPasswordCredentialManagingAuthenticationProvider()
+ {
+ AuthenticationProvider provider = testForFactory(mock(AuthenticationManager.class));
+ assertFalse("The created provider should match the factory's AuthenticationManager type",
+ provider instanceof PasswordCredentialManagingAuthenticationProvider);
+ }
+
+ @SuppressWarnings("unchecked")
+ private AuthenticationProvider testForFactory(AuthenticationManager authenticationManager)
+ {
+ UUID id = UUID.randomUUID();
+ Map<String, Object> attributes = new HashMap<String, Object>();
+
+ QpidServiceLoader<AuthenticationManagerFactory> authManagerFactoryServiceLoader = mock(QpidServiceLoader.class);
+ AuthenticationManagerFactory authenticationManagerFactory = mock(AuthenticationManagerFactory.class);
+ ConfigurationEntry configurationEntry = mock(ConfigurationEntry.class);
+
+ when(configurationEntry.getId()).thenReturn(id);
+ Broker broker = mock(Broker.class);
+
+ when(authManagerFactoryServiceLoader.atLeastOneInstanceOf(AuthenticationManagerFactory.class)).thenReturn(
+ Collections.singleton(authenticationManagerFactory));
+ when(authenticationManagerFactory.createInstance(attributes)).thenReturn(authenticationManager);
+
+ AuthenticationProviderFactory providerFactory = new AuthenticationProviderFactory(authManagerFactoryServiceLoader);
+ AuthenticationProvider provider = providerFactory.create(id, broker, attributes, null);
+
+ assertNotNull("Provider is not created", provider);
+ assertEquals("Unexpected ID", id, provider.getId());
+
+ return provider;
+ }
+
+}
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/model/adapter/PortFactoryTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/model/adapter/PortFactoryTest.java
new file mode 100644
index 0000000000..14c5c265c9
--- /dev/null
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/model/adapter/PortFactoryTest.java
@@ -0,0 +1,212 @@
+/*
+ *
+ * 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.qpid.server.model.adapter;
+
+import static org.mockito.Mockito.mock;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.EnumSet;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+
+import org.apache.qpid.server.configuration.BrokerProperties;
+import org.apache.qpid.server.configuration.IllegalConfigurationException;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.Port;
+import org.apache.qpid.server.model.Protocol;
+import org.apache.qpid.server.model.Transport;
+import org.apache.qpid.test.utils.QpidTestCase;
+
+public class PortFactoryTest extends QpidTestCase
+{
+ private UUID _portId = UUID.randomUUID();
+ private int _portNumber = 123;
+ private Set<String> _tcpStringSet = Collections.singleton(Transport.SSL.name());
+ private Set<Transport> _tcpTransportSet = Collections.singleton(Transport.SSL);
+
+ private Map<String, Object> _attributes = new HashMap<String, Object>();
+
+ private Broker _broker = mock(Broker.class);
+ private PortFactory _portFactory;
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ setTestSystemProperty(BrokerProperties.PROPERTY_BROKER_DEFAULT_AMQP_PROTOCOL_EXCLUDES, null);
+ setTestSystemProperty(BrokerProperties.PROPERTY_BROKER_DEFAULT_AMQP_PROTOCOL_INCLUDES, null);
+ _portFactory = new PortFactory();
+
+ _attributes.put(Port.PORT, _portNumber);
+ _attributes.put(Port.TRANSPORTS, _tcpStringSet);
+
+ _attributes.put(Port.TCP_NO_DELAY, "true");
+ _attributes.put(Port.RECEIVE_BUFFER_SIZE, "1");
+ _attributes.put(Port.SEND_BUFFER_SIZE, "2");
+ _attributes.put(Port.NEED_CLIENT_AUTH, "true");
+ _attributes.put(Port.WANT_CLIENT_AUTH, "true");
+ _attributes.put(Port.BINDING_ADDRESS, "127.0.0.1");
+ }
+
+ public void testDefaultProtocols()
+ {
+ Collection<Protocol> protocols = _portFactory.getDefaultProtocols();
+ EnumSet<Protocol> expected = EnumSet.of(Protocol.AMQP_0_8, Protocol.AMQP_0_9, Protocol.AMQP_0_9_1, Protocol.AMQP_0_10,
+ Protocol.AMQP_1_0);
+ assertEquals("Unexpected protocols", new HashSet<Protocol>(expected), new HashSet<Protocol>(protocols));
+ }
+
+ public void testDefaultProtocolsWhenProtocolExcludeSystemPropertyIsSet()
+ {
+ setTestSystemProperty(BrokerProperties.PROPERTY_BROKER_DEFAULT_AMQP_PROTOCOL_EXCLUDES, Protocol.AMQP_1_0.name() + ","
+ + Protocol.AMQP_0_10.name());
+ _portFactory = new PortFactory();
+ Collection<Protocol> protocols = _portFactory.getDefaultProtocols();
+ EnumSet<Protocol> expected = EnumSet.of(Protocol.AMQP_0_8, Protocol.AMQP_0_9, Protocol.AMQP_0_9_1);
+ assertEquals("Unexpected protocols", new HashSet<Protocol>(expected), new HashSet<Protocol>(protocols));
+ }
+
+ public void testDefaultProtocolsWhenProtocolIncludeSystemPropertyIsSet()
+ {
+ setTestSystemProperty(BrokerProperties.PROPERTY_BROKER_DEFAULT_AMQP_PROTOCOL_EXCLUDES, Protocol.AMQP_1_0.name() + ","
+ + Protocol.AMQP_0_10.name() + "," + Protocol.AMQP_0_9_1.name());
+ setTestSystemProperty(BrokerProperties.PROPERTY_BROKER_DEFAULT_AMQP_PROTOCOL_INCLUDES, Protocol.AMQP_0_10.name() + ","
+ + Protocol.AMQP_0_9_1.name());
+ _portFactory = new PortFactory();
+ Collection<Protocol> protocols = _portFactory.getDefaultProtocols();
+ EnumSet<Protocol> expected = EnumSet.of(Protocol.AMQP_0_8, Protocol.AMQP_0_9, Protocol.AMQP_0_9_1, Protocol.AMQP_0_10);
+ assertEquals("Unexpected protocols", new HashSet<Protocol>(expected), new HashSet<Protocol>(protocols));
+ }
+
+ public void testCreatePortWithMinimumAttributes()
+ {
+ Map<String, Object> attributes = new HashMap<String, Object>();
+ attributes.put(Port.PORT, 1);
+ Port port = _portFactory.createPort(_portId, _broker, attributes);
+
+ assertNotNull(port);
+ assertTrue(port instanceof AmqpPortAdapter);
+ assertEquals("Unexpected port", 1, port.getPort());
+ assertEquals("Unexpected transports", Collections.singleton(PortFactory.DEFAULT_TRANSPORT), port.getTransports());
+ assertEquals("Unexpected protocols", _portFactory.getDefaultProtocols(), port.getProtocols());
+ assertEquals("Unexpected send buffer size", PortFactory.DEFAULT_AMQP_SEND_BUFFER_SIZE,
+ port.getAttribute(Port.SEND_BUFFER_SIZE));
+ assertEquals("Unexpected receive buffer size", PortFactory.DEFAULT_AMQP_RECEIVE_BUFFER_SIZE,
+ port.getAttribute(Port.RECEIVE_BUFFER_SIZE));
+ assertEquals("Unexpected need client auth", PortFactory.DEFAULT_AMQP_NEED_CLIENT_AUTH,
+ port.getAttribute(Port.NEED_CLIENT_AUTH));
+ assertEquals("Unexpected want client auth", PortFactory.DEFAULT_AMQP_WANT_CLIENT_AUTH,
+ port.getAttribute(Port.WANT_CLIENT_AUTH));
+ assertEquals("Unexpected tcp no delay", PortFactory.DEFAULT_AMQP_TCP_NO_DELAY, port.getAttribute(Port.TCP_NO_DELAY));
+ assertEquals("Unexpected binding", PortFactory.DEFAULT_AMQP_BINDING, port.getAttribute(Port.BINDING_ADDRESS));
+ }
+
+ public void testCreateAmqpPort()
+ {
+ Set<Protocol> amqp010ProtocolSet = Collections.singleton(Protocol.AMQP_0_10);
+ Set<String> amqp010StringSet = Collections.singleton(Protocol.AMQP_0_10.name());
+ _attributes.put(Port.PROTOCOLS, amqp010StringSet);
+
+ Port port = _portFactory.createPort(_portId, _broker, _attributes);
+
+ assertNotNull(port);
+ assertTrue(port instanceof AmqpPortAdapter);
+ assertEquals(_portId, port.getId());
+ assertEquals(_portNumber, port.getPort());
+ assertEquals(_tcpTransportSet, port.getTransports());
+ assertEquals(amqp010ProtocolSet, port.getProtocols());
+ assertEquals("Unexpected send buffer size", 2, port.getAttribute(Port.SEND_BUFFER_SIZE));
+ assertEquals("Unexpected receive buffer size", 1, port.getAttribute(Port.RECEIVE_BUFFER_SIZE));
+ assertEquals("Unexpected need client auth", true, port.getAttribute(Port.NEED_CLIENT_AUTH));
+ assertEquals("Unexpected want client auth", true, port.getAttribute(Port.WANT_CLIENT_AUTH));
+ assertEquals("Unexpected tcp no delay", true, port.getAttribute(Port.TCP_NO_DELAY));
+ assertEquals("Unexpected binding", "127.0.0.1", port.getAttribute(Port.BINDING_ADDRESS));
+ }
+
+ public void testCreateNonAmqpPort()
+ {
+ Set<Protocol> nonAmqpProtocolSet = Collections.singleton(Protocol.JMX_RMI);
+ Set<String> nonAmqpStringSet = Collections.singleton(Protocol.JMX_RMI.name());
+ _attributes = new HashMap<String, Object>();
+ _attributes.put(Port.PROTOCOLS, nonAmqpStringSet);
+ _attributes.put(Port.PORT, _portNumber);
+ _attributes.put(Port.TRANSPORTS, _tcpStringSet);
+
+ Port port = _portFactory.createPort(_portId, _broker, _attributes);
+
+ assertNotNull(port);
+ assertFalse("Port should be a PortAdapter, not its AMQP-specific subclass", port instanceof AmqpPortAdapter);
+ assertEquals(_portId, port.getId());
+ assertEquals(_portNumber, port.getPort());
+ assertEquals(_tcpTransportSet, port.getTransports());
+ assertEquals(nonAmqpProtocolSet, port.getProtocols());
+ assertNull("Unexpected send buffer size", port.getAttribute(Port.SEND_BUFFER_SIZE));
+ assertNull("Unexpected receive buffer size", port.getAttribute(Port.RECEIVE_BUFFER_SIZE));
+ assertNull("Unexpected need client auth", port.getAttribute(Port.NEED_CLIENT_AUTH));
+ assertNull("Unexpected want client auth", port.getAttribute(Port.WANT_CLIENT_AUTH));
+ assertNull("Unexpected tcp no delay", port.getAttribute(Port.TCP_NO_DELAY));
+ assertNull("Unexpected binding", port.getAttribute(Port.BINDING_ADDRESS));
+ }
+
+ public void testCreateNonAmqpPortWithPartiallySetAttributes()
+ {
+ Set<Protocol> nonAmqpProtocolSet = Collections.singleton(Protocol.JMX_RMI);
+ Set<String> nonAmqpStringSet = Collections.singleton(Protocol.JMX_RMI.name());
+ _attributes = new HashMap<String, Object>();
+ _attributes.put(Port.PROTOCOLS, nonAmqpStringSet);
+ _attributes.put(Port.PORT, _portNumber);
+
+ Port port = _portFactory.createPort(_portId, _broker, _attributes);
+
+ assertNotNull(port);
+ assertFalse("Port should be a PortAdapter, not its AMQP-specific subclass", port instanceof AmqpPortAdapter);
+ assertEquals(_portId, port.getId());
+ assertEquals(_portNumber, port.getPort());
+ assertEquals(Collections.singleton(PortFactory.DEFAULT_TRANSPORT), port.getTransports());
+ assertEquals(nonAmqpProtocolSet, port.getProtocols());
+ assertNull("Unexpected send buffer size", port.getAttribute(Port.SEND_BUFFER_SIZE));
+ assertNull("Unexpected receive buffer size", port.getAttribute(Port.RECEIVE_BUFFER_SIZE));
+ assertNull("Unexpected need client auth", port.getAttribute(Port.NEED_CLIENT_AUTH));
+ assertNull("Unexpected want client auth", port.getAttribute(Port.WANT_CLIENT_AUTH));
+ assertNull("Unexpected tcp no delay", port.getAttribute(Port.TCP_NO_DELAY));
+ assertNull("Unexpected binding", port.getAttribute(Port.BINDING_ADDRESS));
+ }
+
+ public void testCreateMixedAmqpAndNonAmqpThrowsException()
+ {
+ Set<String> mixedProtocolSet = new HashSet<String>(Arrays.asList(Protocol.AMQP_0_10.name(), Protocol.JMX_RMI.name()));
+ _attributes.put(Port.PROTOCOLS, mixedProtocolSet);
+
+ try
+ {
+ _portFactory.createPort(_portId, _broker, _attributes);
+ fail("Exception not thrown");
+ }
+ catch (IllegalConfigurationException e)
+ {
+ // pass
+ }
+ }
+}
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/model/configuration/ConfigurationEntryTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/model/configuration/ConfigurationEntryTest.java
new file mode 100644
index 0000000000..dd48d7b56d
--- /dev/null
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/model/configuration/ConfigurationEntryTest.java
@@ -0,0 +1,129 @@
+/*
+ *
+ * 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.qpid.server.model.configuration;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+
+import junit.framework.TestCase;
+
+import org.apache.qpid.server.configuration.ConfigurationEntry;
+import org.apache.qpid.server.configuration.ConfigurationEntryStore;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.Port;
+import org.apache.qpid.server.model.VirtualHost;
+
+public class ConfigurationEntryTest extends TestCase
+{
+ public void testGetChildren()
+ {
+ ConfigurationEntryStore store = mock(ConfigurationEntryStore.class);
+
+ ConfigurationEntry virtualHostEntry1 = new ConfigurationEntry(UUID.randomUUID(), VirtualHost.class.getSimpleName(),
+ Collections.<String, Object> emptyMap(), Collections.<UUID> emptySet(), store);
+ ConfigurationEntry virtualHostEntry2 = new ConfigurationEntry(UUID.randomUUID(), VirtualHost.class.getSimpleName(),
+ Collections.<String, Object> emptyMap(), Collections.<UUID> emptySet(), store);
+ ConfigurationEntry portEntry = new ConfigurationEntry(UUID.randomUUID(), Port.class.getSimpleName(),
+ Collections.<String, Object> emptyMap(), Collections.<UUID> emptySet(), store);
+
+ when(store.getEntry(virtualHostEntry1.getId())).thenReturn(virtualHostEntry1);
+ when(store.getEntry(virtualHostEntry2.getId())).thenReturn(virtualHostEntry2);
+ when(store.getEntry(portEntry.getId())).thenReturn(portEntry);
+
+ Set<UUID> childrenIds = new HashSet<UUID>();
+ childrenIds.add(virtualHostEntry1.getId());
+ childrenIds.add(virtualHostEntry2.getId());
+ childrenIds.add(portEntry.getId());
+ ConfigurationEntry parentEntry = new ConfigurationEntry(UUID.randomUUID(), Broker.class.getSimpleName(),
+ Collections.<String, Object> emptyMap(), childrenIds, store);
+
+ Map<String, Collection<ConfigurationEntry>> children = parentEntry.getChildren();
+ assertNotNull("Null is returned for children", children);
+ assertEquals("Unexpected size", 2, children.size());
+ Collection<ConfigurationEntry> virtualHosts = children.get(VirtualHost.class.getSimpleName());
+ Collection<ConfigurationEntry> ports = children.get(Port.class.getSimpleName());
+ assertEquals("Unexpected virtual hosts",
+ new HashSet<ConfigurationEntry>(Arrays.asList(virtualHostEntry1, virtualHostEntry2)),
+ new HashSet<ConfigurationEntry>(virtualHosts));
+ assertEquals("Unexpected ports", new HashSet<ConfigurationEntry>(Arrays.asList(portEntry)),
+ new HashSet<ConfigurationEntry>(ports));
+ }
+
+ public void testHashCode()
+ {
+ ConfigurationEntryStore store = mock(ConfigurationEntryStore.class);
+
+ UUID id = UUID.randomUUID();
+ ConfigurationEntry entry1 = new ConfigurationEntry(id, VirtualHost.class.getSimpleName(),
+ Collections.<String, Object> emptyMap(), Collections.singleton(UUID.randomUUID()), store);
+ ConfigurationEntry entry2 = new ConfigurationEntry(id, VirtualHost.class.getSimpleName(),
+ Collections.<String, Object> emptyMap(), Collections.singleton(UUID.randomUUID()), store);
+ ConfigurationEntry entryWithDifferentId = new ConfigurationEntry(UUID.randomUUID(),
+ VirtualHost.class.getSimpleName(), Collections.<String, Object> emptyMap(), Collections.singleton(UUID.randomUUID()), store);
+
+ assertTrue(entry1.hashCode() == entry2.hashCode());
+ assertFalse(entry1.hashCode() == entryWithDifferentId.hashCode());
+ }
+
+ public void testEqualsObject()
+ {
+ ConfigurationEntryStore store = mock(ConfigurationEntryStore.class);
+
+ UUID id = UUID.randomUUID();
+ Map<String, Object> attributes1 = new HashMap<String, Object>();
+ attributes1.put(VirtualHost.NAME, "name1");
+ Set<UUID> childrenIds = Collections.singleton(UUID.randomUUID());
+ ConfigurationEntry entry1 = new ConfigurationEntry(id, VirtualHost.class.getSimpleName(), attributes1,
+ childrenIds, store);
+
+ Map<String, Object> attributes2 = new HashMap<String, Object>();
+ attributes2.put(VirtualHost.NAME, "name2");
+
+ ConfigurationEntry entry2 = new ConfigurationEntry(id, VirtualHost.class.getSimpleName(), attributes1,
+ childrenIds, store);
+ ConfigurationEntry entryWithDifferentId = new ConfigurationEntry(UUID.randomUUID(),
+ VirtualHost.class.getSimpleName(), attributes1, childrenIds, store);
+
+ assertTrue(entry1.equals(entry2));
+ assertFalse("Entries should be diferrent because of diferrent IDs", entry1.equals(entryWithDifferentId));
+
+ ConfigurationEntry entryWithDifferentChildId = new ConfigurationEntry(id,
+ VirtualHost.class.getSimpleName(), attributes1, Collections.singleton(UUID.randomUUID()), store);
+ assertFalse("Entries should be diferrent because of diferrent children", entry1.equals(entryWithDifferentChildId));
+
+ ConfigurationEntry entryWithDifferentName = new ConfigurationEntry(id,
+ VirtualHost.class.getSimpleName(), attributes2, childrenIds, store);
+ assertFalse("Entries should be diferrent because of diferrent attributes", entry1.equals(entryWithDifferentName));
+
+ ConfigurationEntry entryWithDifferentType = new ConfigurationEntry(id,
+ Broker.class.getSimpleName(), attributes1, childrenIds, store);
+ assertFalse("Entries should be diferrent because of diferrent types", entry1.equals(entryWithDifferentType));
+ }
+}
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/protocol/InternalTestProtocolSession.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/protocol/InternalTestProtocolSession.java
index 0016e31236..3216f8886a 100644
--- a/qpid/java/broker/src/test/java/org/apache/qpid/server/protocol/InternalTestProtocolSession.java
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/protocol/InternalTestProtocolSession.java
@@ -28,9 +28,9 @@ import org.apache.qpid.protocol.AMQConstant;
import org.apache.qpid.server.AMQChannel;
import org.apache.qpid.server.message.AMQMessage;
import org.apache.qpid.server.message.MessageContentSource;
+import org.apache.qpid.server.model.Broker;
import org.apache.qpid.server.output.ProtocolOutputConverter;
import org.apache.qpid.server.queue.QueueEntry;
-import org.apache.qpid.server.registry.ApplicationRegistry;
import org.apache.qpid.server.security.auth.AuthenticatedPrincipal;
import org.apache.qpid.server.security.auth.UsernamePrincipal;
import org.apache.qpid.server.subscription.ClientDeliveryMethod;
@@ -58,9 +58,9 @@ public class InternalTestProtocolSession extends AMQProtocolEngine implements Pr
private AtomicInteger _deliveryCount = new AtomicInteger(0);
private static final AtomicLong ID_GENERATOR = new AtomicLong(0);
- public InternalTestProtocolSession(VirtualHost virtualHost) throws AMQException
+ public InternalTestProtocolSession(VirtualHost virtualHost, Broker broker) throws AMQException
{
- super(ApplicationRegistry.getInstance().getVirtualHostRegistry(), new TestNetworkConnection(), ID_GENERATOR.getAndIncrement());
+ super(broker, new TestNetworkConnection(), ID_GENERATOR.getAndIncrement());
_channelDelivers = new HashMap<Integer, Map<AMQShortString, LinkedList<DeliveryPair>>>();
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/protocol/MaxChannelsTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/protocol/MaxChannelsTest.java
index e8ee2c4d0b..99dd42e179 100644
--- a/qpid/java/broker/src/test/java/org/apache/qpid/server/protocol/MaxChannelsTest.java
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/protocol/MaxChannelsTest.java
@@ -23,20 +23,24 @@ package org.apache.qpid.server.protocol;
import org.apache.qpid.AMQException;
import org.apache.qpid.protocol.AMQConstant;
import org.apache.qpid.server.AMQChannel;
-import org.apache.qpid.server.registry.ApplicationRegistry;
-import org.apache.qpid.server.util.InternalBrokerBaseCase;
-import org.apache.qpid.server.virtualhost.VirtualHost;
+import org.apache.qpid.server.util.BrokerTestHelper;
+import org.apache.qpid.test.utils.QpidTestCase;
/** Test class to test MBean operations for AMQMinaProtocolSession. */
-public class MaxChannelsTest extends InternalBrokerBaseCase
+public class MaxChannelsTest extends QpidTestCase
{
- private AMQProtocolEngine _session;
+ private AMQProtocolEngine _session;
- public void testChannels() throws Exception
+ @Override
+ public void setUp() throws Exception
{
- VirtualHost vhost = ApplicationRegistry.getInstance().getVirtualHostRegistry().getVirtualHost("test");
- _session = new InternalTestProtocolSession(vhost);
+ super.setUp();
+ BrokerTestHelper.setUp();
+ _session = BrokerTestHelper.createSession();
+ }
+ public void testChannels() throws Exception
+ {
// check the channel count is correct
int channelCount = _session.getChannels().size();
assertEquals("Initial channel count wrong", 0, channelCount);
@@ -45,13 +49,15 @@ public class MaxChannelsTest extends InternalBrokerBaseCase
_session.setMaximumNumberOfChannels(maxChannels);
assertEquals("Number of channels not correctly set.", new Long(maxChannels), _session.getMaximumNumberOfChannels());
+ for (long currentChannel = 0L; currentChannel < maxChannels; currentChannel++)
+ {
+ _session.addChannel(new AMQChannel(_session, (int) currentChannel, null));
+ }
try
{
- for (long currentChannel = 0L; currentChannel < maxChannels; currentChannel++)
- {
- _session.addChannel(new AMQChannel(_session, (int) currentChannel, null));
- }
+ _session.addChannel(new AMQChannel(_session, (int) maxChannels, null));
+ fail("Cannot create more channels then maximum");
}
catch (AMQException e)
{
@@ -63,14 +69,14 @@ public class MaxChannelsTest extends InternalBrokerBaseCase
@Override
public void tearDown() throws Exception
{
- try {
- _session.closeSession();
- } catch (AMQException e) {
- // Yikes
- fail(e.getMessage());
- }
+ try
+ {
+ _session.getVirtualHost().close();
+ _session.closeSession();
+ }
finally
{
+ BrokerTestHelper.tearDown();
super.tearDown();
}
}
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/protocol/MultiVersionProtocolEngineFactoryTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/protocol/MultiVersionProtocolEngineFactoryTest.java
index e951dd494b..02b8c74feb 100644
--- a/qpid/java/broker/src/test/java/org/apache/qpid/server/protocol/MultiVersionProtocolEngineFactoryTest.java
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/protocol/MultiVersionProtocolEngineFactoryTest.java
@@ -20,61 +20,52 @@
*/
package org.apache.qpid.server.protocol;
-import java.util.UUID;
-import java.util.concurrent.ScheduledFuture;
-import org.apache.commons.configuration.XMLConfiguration;
+import static org.mockito.Mockito.when;
+
+import java.nio.ByteBuffer;
+import java.util.EnumSet;
+import java.util.Set;
import org.apache.qpid.protocol.ServerProtocolEngine;
-import org.apache.qpid.server.binding.BindingFactory;
-import org.apache.qpid.server.configuration.ServerConfiguration;
-import org.apache.qpid.server.configuration.VirtualHostConfiguration;
-import org.apache.qpid.server.connection.IConnectionRegistry;
-import org.apache.qpid.server.exchange.ExchangeFactory;
-import org.apache.qpid.server.exchange.ExchangeRegistry;
-import org.apache.qpid.server.protocol.v1_0.LinkRegistry;
-import org.apache.qpid.server.queue.QueueRegistry;
-import org.apache.qpid.server.registry.ApplicationRegistry;
-import org.apache.qpid.server.registry.IApplicationRegistry;
-import org.apache.qpid.server.security.*;
-import org.apache.qpid.server.stats.StatisticsCounter;
-import org.apache.qpid.server.store.MessageStore;
-import org.apache.qpid.server.txn.DtxRegistry;
-import org.apache.qpid.server.util.TestApplicationRegistry;
-import org.apache.qpid.server.virtualhost.HouseKeepingTask;
-import org.apache.qpid.server.virtualhost.State;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.util.BrokerTestHelper;
import org.apache.qpid.server.virtualhost.VirtualHost;
-import org.apache.qpid.server.virtualhost.VirtualHostImpl;
import org.apache.qpid.server.virtualhost.VirtualHostRegistry;
import org.apache.qpid.test.utils.QpidTestCase;
import org.apache.qpid.transport.TestNetworkConnection;
-import java.nio.ByteBuffer;
-import java.util.EnumSet;
-import java.util.Set;
-
public class MultiVersionProtocolEngineFactoryTest extends QpidTestCase
{
+ private VirtualHost _virtualHost;
+ private Broker _broker;
+ @Override
protected void setUp() throws Exception
{
super.setUp();
+ BrokerTestHelper.setUp();
+ _broker = BrokerTestHelper.createBrokerMock();
+ VirtualHostRegistry virtualHostRegistry = _broker.getVirtualHostRegistry();
+ when(_broker.getAttribute(Broker.DEFAULT_VIRTUAL_HOST)).thenReturn("default");
- //the factory needs a registry instance
- ApplicationRegistry.initialise(new TestApplicationRegistry(new ServerConfiguration(new XMLConfiguration())));
// AMQP 1-0 connection needs default vhost to be present
- VirtualHostRegistry virtualHostRegistry = ApplicationRegistry.getInstance().getVirtualHostRegistry();
- VirtualHostImpl vhostImpl = new VirtualHostImpl(ApplicationRegistry.getInstance(), new VirtualHostConfiguration("default",new XMLConfiguration()));
- virtualHostRegistry.registerVirtualHost(vhostImpl);
- virtualHostRegistry.setDefaultVirtualHostName("default");
-
+ _virtualHost = BrokerTestHelper.createVirtualHost("default", virtualHostRegistry);
}
- protected void tearDown()
+ @Override
+ protected void tearDown() throws Exception
{
- //the factory opens a registry instance
- ApplicationRegistry.remove();
+ try
+ {
+ _virtualHost.close();
+ }
+ finally
+ {
+ BrokerTestHelper.tearDown();
+ super.tearDown();
+ }
}
-
+
private static final byte[] AMQP_0_8_HEADER =
new byte[] { (byte) 'A',
(byte) 'M',
@@ -133,6 +124,7 @@ public class MultiVersionProtocolEngineFactoryTest extends QpidTestCase
(byte) 0
};
+
private byte[] getAmqpHeader(final AmqpProtocolVersion version)
{
switch(version)
@@ -162,7 +154,7 @@ public class MultiVersionProtocolEngineFactoryTest extends QpidTestCase
Set<AmqpProtocolVersion> versions = EnumSet.allOf(AmqpProtocolVersion.class);
MultiVersionProtocolEngineFactory factory =
- new MultiVersionProtocolEngineFactory(versions, null);
+ new MultiVersionProtocolEngineFactory(_broker, versions, null);
//create a dummy to retrieve the 'current' ID number
long previousId = factory.newProtocolEngine().getConnectionId();
@@ -200,7 +192,7 @@ public class MultiVersionProtocolEngineFactoryTest extends QpidTestCase
try
{
- new MultiVersionProtocolEngineFactory(versions, AmqpProtocolVersion.v0_9);
+ new MultiVersionProtocolEngineFactory(_broker, versions, AmqpProtocolVersion.v0_9);
fail("should not have been allowed to create the factory");
}
catch(IllegalArgumentException iae)
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/AMQPriorityQueueTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/AMQPriorityQueueTest.java
index c3d58f3bdc..81ad57c040 100644
--- a/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/AMQPriorityQueueTest.java
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/AMQPriorityQueueTest.java
@@ -36,8 +36,9 @@ public class AMQPriorityQueueTest extends SimpleAMQQueueTest
@Override
public void setUp() throws Exception
{
- _arguments = new FieldTable();
- _arguments.put(new AMQShortString(AMQQueueFactory.X_QPID_PRIORITIES), 3);
+ FieldTable arguments = new FieldTable();
+ arguments.put(new AMQShortString(AMQQueueFactory.X_QPID_PRIORITIES), 3);
+ setArguments(arguments);
super.setUp();
}
@@ -45,25 +46,26 @@ public class AMQPriorityQueueTest extends SimpleAMQQueueTest
{
// Enqueue messages in order
- _queue.enqueue(createMessage(1L, (byte) 10));
- _queue.enqueue(createMessage(2L, (byte) 4));
- _queue.enqueue(createMessage(3L, (byte) 0));
+ SimpleAMQQueue queue = getQueue();
+ queue.enqueue(createMessage(1L, (byte) 10));
+ queue.enqueue(createMessage(2L, (byte) 4));
+ queue.enqueue(createMessage(3L, (byte) 0));
// Enqueue messages in reverse order
- _queue.enqueue(createMessage(4L, (byte) 0));
- _queue.enqueue(createMessage(5L, (byte) 4));
- _queue.enqueue(createMessage(6L, (byte) 10));
+ queue.enqueue(createMessage(4L, (byte) 0));
+ queue.enqueue(createMessage(5L, (byte) 4));
+ queue.enqueue(createMessage(6L, (byte) 10));
// Enqueue messages out of order
- _queue.enqueue(createMessage(7L, (byte) 4));
- _queue.enqueue(createMessage(8L, (byte) 10));
- _queue.enqueue(createMessage(9L, (byte) 0));
+ queue.enqueue(createMessage(7L, (byte) 4));
+ queue.enqueue(createMessage(8L, (byte) 10));
+ queue.enqueue(createMessage(9L, (byte) 0));
// Register subscriber
- _queue.registerSubscription(_subscription, false);
+ queue.registerSubscription(getSubscription(), false);
Thread.sleep(150);
- ArrayList<QueueEntry> msgs = _subscription.getMessages();
+ ArrayList<QueueEntry> msgs = getSubscription().getMessages();
try
{
assertEquals(1L, msgs.get(0).getMessage().getMessageNumber());
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/AMQQueueFactoryTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/AMQQueueFactoryTest.java
index 186be4dff7..0f82345271 100644
--- a/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/AMQQueueFactoryTest.java
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/AMQQueueFactoryTest.java
@@ -20,23 +20,23 @@
*/
package org.apache.qpid.server.queue;
+import static org.mockito.Mockito.when;
+
import org.apache.commons.configuration.XMLConfiguration;
import org.apache.qpid.AMQException;
import org.apache.qpid.exchange.ExchangeDefaults;
import org.apache.qpid.framing.AMQShortString;
import org.apache.qpid.framing.FieldTable;
-import org.apache.qpid.server.configuration.ServerConfiguration;
+import org.apache.qpid.server.configuration.BrokerProperties;
+import org.apache.qpid.server.configuration.VirtualHostConfiguration;
import org.apache.qpid.server.exchange.DefaultExchangeFactory;
import org.apache.qpid.server.exchange.Exchange;
import org.apache.qpid.server.exchange.ExchangeRegistry;
-import org.apache.qpid.server.logging.SystemOutMessageLogger;
-import org.apache.qpid.server.logging.actors.CurrentActor;
-import org.apache.qpid.server.logging.actors.TestLogActor;
+import org.apache.qpid.server.model.Broker;
import org.apache.qpid.server.model.UUIDGenerator;
-import org.apache.qpid.server.registry.ApplicationRegistry;
import org.apache.qpid.server.store.TestableMemoryMessageStore;
-import org.apache.qpid.server.util.TestApplicationRegistry;
+import org.apache.qpid.server.util.BrokerTestHelper;
import org.apache.qpid.server.virtualhost.VirtualHost;
import org.apache.qpid.test.utils.QpidTestCase;
@@ -50,19 +50,19 @@ public class AMQQueueFactoryTest extends QpidTestCase
{
super.setUp();
- CurrentActor.set(new TestLogActor(new SystemOutMessageLogger()));
-
+ BrokerTestHelper.setUp();
XMLConfiguration configXml = new XMLConfiguration();
- configXml.addProperty("virtualhosts.virtualhost(-1).name", getName());
- configXml.addProperty("virtualhosts.virtualhost(-1)."+getName()+".store.class", TestableMemoryMessageStore.class.getName());
+ configXml.addProperty("store.class", TestableMemoryMessageStore.class.getName());
- ServerConfiguration configuration = new ServerConfiguration(configXml);
- ApplicationRegistry registry = new TestApplicationRegistry(configuration);
- ApplicationRegistry.initialise(registry);
- registry.getVirtualHostRegistry().setDefaultVirtualHostName(getName());
+ Broker broker = BrokerTestHelper.createBrokerMock();
+ if (getName().equals("testDeadLetterQueueDoesNotInheritDLQorMDCSettings"))
+ {
+ when(broker.getAttribute(Broker.MAXIMUM_DELIVERY_ATTEMPTS)).thenReturn(5);
+ when(broker.getAttribute(Broker.DEAD_LETTER_QUEUE_ENABLED)).thenReturn(true);
+ }
- _virtualHost = registry.getVirtualHostRegistry().getVirtualHost(getName());
+ _virtualHost = BrokerTestHelper.createVirtualHost(new VirtualHostConfiguration(getName(), configXml, broker));
_queueRegistry = _virtualHost.getQueueRegistry();
@@ -73,11 +73,12 @@ public class AMQQueueFactoryTest extends QpidTestCase
{
try
{
- super.tearDown();
+ _virtualHost.close();
}
finally
{
- ApplicationRegistry.remove();
+ BrokerTestHelper.tearDown();
+ super.tearDown();
}
}
@@ -172,11 +173,8 @@ public class AMQQueueFactoryTest extends QpidTestCase
* are not applied to the DLQ itself.
* @throws AMQException
*/
- public void testDeadLetterQueueDoesNotInheritDLQorMDCSettings() throws AMQException
+ public void testDeadLetterQueueDoesNotInheritDLQorMDCSettings() throws Exception
{
- ApplicationRegistry.getInstance().getConfiguration().getConfig().addProperty("deadLetterQueues","true");
- ApplicationRegistry.getInstance().getConfiguration().getConfig().addProperty("maximumDeliveryCount","5");
-
String queueName = "testDeadLetterQueueEnabled";
AMQShortString dlExchangeName = new AMQShortString(queueName + DefaultExchangeFactory.DEFAULT_DLE_NAME_SUFFIX);
AMQShortString dlQueueName = new AMQShortString(queueName + AMQQueueFactory.DEFAULT_DLQ_NAME_SUFFIX);
@@ -336,11 +334,8 @@ public class AMQQueueFactoryTest extends QpidTestCase
try
{
// change DLQ name to make its length bigger than exchange name
- ApplicationRegistry.getInstance().getConfiguration().getConfig()
- .addProperty("deadLetterExchangeSuffix", "_DLE");
- ApplicationRegistry.getInstance().getConfiguration().getConfig()
- .addProperty("deadLetterQueueSuffix", "_DLQUEUE");
-
+ setTestSystemProperty(BrokerProperties.PROPERTY_DEAD_LETTER_EXCHANGE_SUFFIX, "_DLE");
+ setTestSystemProperty(BrokerProperties.PROPERTY_DEAD_LETTER_QUEUE_SUFFIX, "_DLQUEUE");
FieldTable fieldTable = new FieldTable();
fieldTable.setBoolean(AMQQueueFactory.X_QPID_DLQ_ENABLED, true);
AMQQueueFactory.createAMQQueueImpl(UUIDGenerator.generateRandomUUID(), queueName, false, "owner",
@@ -353,13 +348,6 @@ public class AMQQueueFactoryTest extends QpidTestCase
assertTrue("Unexpected exception message!", e.getMessage().contains("DLQ queue name")
&& e.getMessage().contains("length exceeds limit of 255"));
}
- finally
- {
- ApplicationRegistry.getInstance().getConfiguration().getConfig()
- .addProperty("deadLetterExchangeSuffix", DefaultExchangeFactory.DEFAULT_DLE_NAME_SUFFIX);
- ApplicationRegistry.getInstance().getConfiguration().getConfig()
- .addProperty("deadLetterQueueSuffix", AMQQueueFactory.DEFAULT_DLQ_NAME_SUFFIX);
- }
}
/**
@@ -372,11 +360,8 @@ public class AMQQueueFactoryTest extends QpidTestCase
try
{
// change DLQ name to make its length bigger than exchange name
- ApplicationRegistry.getInstance().getConfiguration().getConfig()
- .addProperty("deadLetterExchangeSuffix", "_DLEXCHANGE");
- ApplicationRegistry.getInstance().getConfiguration().getConfig()
- .addProperty("deadLetterQueueSuffix", "_DLQ");
-
+ setTestSystemProperty(BrokerProperties.PROPERTY_DEAD_LETTER_EXCHANGE_SUFFIX, "_DLEXCHANGE");
+ setTestSystemProperty(BrokerProperties.PROPERTY_DEAD_LETTER_QUEUE_SUFFIX, "_DLQ");
FieldTable fieldTable = new FieldTable();
fieldTable.setBoolean(AMQQueueFactory.X_QPID_DLQ_ENABLED, true);
AMQQueueFactory.createAMQQueueImpl(UUIDGenerator.generateRandomUUID(), queueName, false, "owner",
@@ -389,13 +374,6 @@ public class AMQQueueFactoryTest extends QpidTestCase
assertTrue("Unexpected exception message!", e.getMessage().contains("DL exchange name")
&& e.getMessage().contains("length exceeds limit of 255"));
}
- finally
- {
- ApplicationRegistry.getInstance().getConfiguration().getConfig()
- .addProperty("deadLetterExchangeSuffix", DefaultExchangeFactory.DEFAULT_DLE_NAME_SUFFIX);
- ApplicationRegistry.getInstance().getConfiguration().getConfig()
- .addProperty("deadLetterQueueSuffix", AMQQueueFactory.DEFAULT_DLQ_NAME_SUFFIX);
- }
}
private String generateStringWithLength(char ch, int length)
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/AckTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/AckTest.java
index 190d5c777b..cbbf183232 100644
--- a/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/AckTest.java
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/AckTest.java
@@ -32,18 +32,16 @@ import org.apache.qpid.server.flow.LimitlessCreditManager;
import org.apache.qpid.server.flow.Pre0_10CreditManager;
import org.apache.qpid.server.message.AMQMessage;
import org.apache.qpid.server.message.MessageMetaData;
-import org.apache.qpid.server.model.UUIDGenerator;
import org.apache.qpid.server.protocol.AMQProtocolSession;
-import org.apache.qpid.server.protocol.InternalTestProtocolSession;
-import org.apache.qpid.server.registry.ApplicationRegistry;
import org.apache.qpid.server.store.StoredMessage;
import org.apache.qpid.server.store.TestableMemoryMessageStore;
import org.apache.qpid.server.subscription.Subscription;
import org.apache.qpid.server.subscription.SubscriptionFactoryImpl;
import org.apache.qpid.server.txn.AutoCommitTransaction;
import org.apache.qpid.server.txn.ServerTransaction;
-import org.apache.qpid.server.util.InternalBrokerBaseCase;
+import org.apache.qpid.server.util.BrokerTestHelper;
import org.apache.qpid.server.virtualhost.VirtualHost;
+import org.apache.qpid.test.utils.QpidTestCase;
import java.util.ArrayList;
import java.util.Set;
@@ -51,7 +49,7 @@ import java.util.Set;
/**
* Tests that acknowledgements are handled correctly.
*/
-public class AckTest extends InternalBrokerBaseCase
+public class AckTest extends QpidTestCase
{
private Subscription _subscription;
@@ -70,15 +68,19 @@ public class AckTest extends InternalBrokerBaseCase
public void setUp() throws Exception
{
super.setUp();
- _virtualHost = ApplicationRegistry.getInstance().getVirtualHostRegistry().getVirtualHost("test");
- _messageStore = new TestableMemoryMessageStore();
- _protocolSession = new InternalTestProtocolSession(_virtualHost);
- _channel = new AMQChannel(_protocolSession,5, _messageStore /*dont need exchange registry*/);
-
- _protocolSession.addChannel(_channel);
+ BrokerTestHelper.setUp();
+ _channel = BrokerTestHelper.createChannel(5);
+ _protocolSession = _channel.getProtocolSession();
+ _virtualHost = _protocolSession.getVirtualHost();
+ _queue = BrokerTestHelper.createQueue(getTestName(), _virtualHost);
+ _messageStore = (TestableMemoryMessageStore)_virtualHost.getMessageStore();
+ }
- _queue = AMQQueueFactory.createAMQQueueImpl(UUIDGenerator.generateRandomUUID(), "myQ", false, "guest", true, false,
- _virtualHost, null);
+ @Override
+ protected void tearDown() throws Exception
+ {
+ BrokerTestHelper.tearDown();
+ super.tearDown();
}
private void publishMessages(int count) throws AMQException
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/SimpleAMQQueueTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/SimpleAMQQueueTest.java
index ea07c14f8a..ece42f7de3 100644
--- a/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/SimpleAMQQueueTest.java
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/SimpleAMQQueueTest.java
@@ -28,8 +28,6 @@ import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Matchers.contains;
import static org.mockito.Matchers.eq;
-import org.apache.commons.configuration.PropertiesConfiguration;
-
import org.apache.qpid.AMQException;
import org.apache.qpid.AMQInternalException;
import org.apache.qpid.AMQSecurityException;
@@ -39,7 +37,6 @@ import org.apache.qpid.framing.BasicContentHeaderProperties;
import org.apache.qpid.framing.ContentHeaderBody;
import org.apache.qpid.framing.FieldTable;
import org.apache.qpid.framing.abstraction.MessagePublishInfo;
-import org.apache.qpid.server.configuration.VirtualHostConfiguration;
import org.apache.qpid.server.exchange.DirectExchange;
import org.apache.qpid.server.message.AMQMessage;
import org.apache.qpid.server.message.MessageMetaData;
@@ -47,16 +44,15 @@ import org.apache.qpid.server.message.ServerMessage;
import org.apache.qpid.server.model.UUIDGenerator;
import org.apache.qpid.server.queue.BaseQueue.PostEnqueueAction;
import org.apache.qpid.server.queue.SimpleAMQQueue.QueueEntryFilter;
-import org.apache.qpid.server.registry.ApplicationRegistry;
import org.apache.qpid.server.store.StoredMessage;
import org.apache.qpid.server.store.TestableMemoryMessageStore;
import org.apache.qpid.server.subscription.MockSubscription;
import org.apache.qpid.server.subscription.Subscription;
import org.apache.qpid.server.txn.AutoCommitTransaction;
import org.apache.qpid.server.txn.ServerTransaction;
-import org.apache.qpid.server.util.InternalBrokerBaseCase;
+import org.apache.qpid.server.util.BrokerTestHelper;
import org.apache.qpid.server.virtualhost.VirtualHost;
-import org.apache.qpid.server.virtualhost.VirtualHostImpl;
+import org.apache.qpid.test.utils.QpidTestCase;
import java.util.ArrayList;
import java.util.Collections;
@@ -64,17 +60,17 @@ import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
-public class SimpleAMQQueueTest extends InternalBrokerBaseCase
+public class SimpleAMQQueueTest extends QpidTestCase
{
- protected SimpleAMQQueue _queue;
- protected VirtualHost _virtualHost;
- protected AMQShortString _qname = new AMQShortString("qname");
- protected AMQShortString _owner = new AMQShortString("owner");
- protected AMQShortString _routingKey = new AMQShortString("routing key");
- protected DirectExchange _exchange;
- protected MockSubscription _subscription = new MockSubscription();
- protected FieldTable _arguments = null;
+ private SimpleAMQQueue _queue;
+ private VirtualHost _virtualHost;
+ private AMQShortString _qname = new AMQShortString("qname");
+ private AMQShortString _owner = new AMQShortString("owner");
+ private AMQShortString _routingKey = new AMQShortString("routing key");
+ private DirectExchange _exchange;
+ private MockSubscription _subscription = new MockSubscription();
+ private FieldTable _arguments = null;
private MessagePublishInfo info = new MessagePublishInfo()
{
@@ -108,25 +104,29 @@ public class SimpleAMQQueueTest extends InternalBrokerBaseCase
public void setUp() throws Exception
{
super.setUp();
- //Create Application Registry for test
- ApplicationRegistry applicationRegistry = (ApplicationRegistry)ApplicationRegistry.getInstance();
+ BrokerTestHelper.setUp();
- PropertiesConfiguration env = new PropertiesConfiguration();
- final VirtualHostConfiguration vhostConfig = new VirtualHostConfiguration(getClass().getName(), env);
- vhostConfig.setMessageStoreClass(TestableMemoryMessageStore.class.getName());
- _virtualHost = new VirtualHostImpl(ApplicationRegistry.getInstance(), vhostConfig);
- applicationRegistry.getVirtualHostRegistry().registerVirtualHost(_virtualHost);
+ _virtualHost = BrokerTestHelper.createVirtualHost(getClass().getName());
- _queue = (SimpleAMQQueue) AMQQueueFactory.createAMQQueueImpl(UUIDGenerator.generateRandomUUID(), _qname.asString(), false, _owner.asString(), false, false, _virtualHost, FieldTable.convertToMap(_arguments));
+ _queue = (SimpleAMQQueue) AMQQueueFactory.createAMQQueueImpl(UUIDGenerator.generateRandomUUID(), _qname.asString(), false, _owner.asString(),
+ false, false, _virtualHost, FieldTable.convertToMap(_arguments));
- _exchange = (DirectExchange)_virtualHost.getExchangeRegistry().getExchange(ExchangeDefaults.DIRECT_EXCHANGE_NAME);
+ _exchange = (DirectExchange) _virtualHost.getExchangeRegistry().getExchange(ExchangeDefaults.DIRECT_EXCHANGE_NAME);
}
@Override
public void tearDown() throws Exception
{
- _queue.stop();
- super.tearDown();
+ try
+ {
+ _queue.stop();
+ _virtualHost.close();
+ }
+ finally
+ {
+ BrokerTestHelper.tearDown();
+ super.tearDown();
+ }
}
public void testCreateQueue() throws AMQException
@@ -1269,6 +1269,26 @@ public class SimpleAMQQueueTest extends InternalBrokerBaseCase
}
}
+ public SimpleAMQQueue getQueue()
+ {
+ return _queue;
+ }
+
+ public MockSubscription getSubscription()
+ {
+ return _subscription;
+ }
+
+ public FieldTable getArguments()
+ {
+ return _arguments;
+ }
+
+ public void setArguments(FieldTable arguments)
+ {
+ _arguments = arguments;
+ }
+
public class TestMessage extends AMQMessage
{
private final long _tag;
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/SimpleAMQQueueThreadPoolTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/SimpleAMQQueueThreadPoolTest.java
index 6b82cd361a..4abb7233dc 100644
--- a/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/SimpleAMQQueueThreadPoolTest.java
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/SimpleAMQQueueThreadPoolTest.java
@@ -20,20 +20,33 @@
*/
package org.apache.qpid.server.queue;
-import org.apache.qpid.AMQException;
import org.apache.qpid.pool.ReferenceCountingExecutorService;
import org.apache.qpid.server.model.UUIDGenerator;
-import org.apache.qpid.server.registry.ApplicationRegistry;
-import org.apache.qpid.server.util.InternalBrokerBaseCase;
+import org.apache.qpid.server.util.BrokerTestHelper;
import org.apache.qpid.server.virtualhost.VirtualHost;
+import org.apache.qpid.test.utils.QpidTestCase;
-public class SimpleAMQQueueThreadPoolTest extends InternalBrokerBaseCase
+public class SimpleAMQQueueThreadPoolTest extends QpidTestCase
{
- public void test() throws AMQException
+ @Override
+ public void setUp() throws Exception
+ {
+ super.setUp();
+ BrokerTestHelper.setUp();
+ }
+
+ @Override
+ public void tearDown() throws Exception
+ {
+ BrokerTestHelper.tearDown();
+ super.tearDown();
+ }
+
+ public void test() throws Exception
{
int initialCount = ReferenceCountingExecutorService.getInstance().getReferenceCount();
- VirtualHost test = ApplicationRegistry.getInstance().getVirtualHostRegistry().getVirtualHost("test");
+ VirtualHost test = BrokerTestHelper.createVirtualHost("test");
try
{
@@ -50,7 +63,7 @@ public class SimpleAMQQueueThreadPoolTest extends InternalBrokerBaseCase
}
finally
{
- ApplicationRegistry.remove();
+ test.close();
}
}
}
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/registry/ApplicationRegistryShutdownTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/registry/ApplicationRegistryShutdownTest.java
deleted file mode 100644
index 9af950d385..0000000000
--- a/qpid/java/broker/src/test/java/org/apache/qpid/server/registry/ApplicationRegistryShutdownTest.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- *
- * 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.qpid.server.registry;
-
-import org.apache.qpid.server.util.InternalBrokerBaseCase;
-
-import java.security.Provider;
-import java.security.Security;
-import java.util.LinkedList;
-import java.util.List;
-
-/**
- * QPID-1390 : Test to validate that the AuthenticationManger can successfully unregister any new SASL providers when
- * The ApplicationRegistry is closed.
- *
- * This should be expanded as QPID-1399 is implemented.
- */
-public class ApplicationRegistryShutdownTest extends InternalBrokerBaseCase
-{
-
- private Provider[] _defaultProviders;
- @Override
- public void setUp() throws Exception
- {
- // Get default providers
- _defaultProviders = Security.getProviders();
-
- //Startup the new broker and register the new providers
- super.setUp();
- }
-
-
- /**
- * QPID-1399 : Ensure that the Authentication manager unregisters any SASL providers created during
- * ApplicationRegistry initialisation.
- *
- */
- public void testAuthenticationMangerCleansUp() throws Exception
- {
-
- // Get the providers after initialisation
- Provider[] providersAfterInitialisation = Security.getProviders();
-
- // Find the additions
- List additions = new LinkedList();
- for (Provider afterInit : providersAfterInitialisation)
- {
- boolean found = false;
- for (Provider defaultProvider : _defaultProviders)
- {
- if (defaultProvider == afterInit)
- {
- found=true;
- break;
- }
- }
-
- // Record added registies
- if (!found)
- {
- additions.add(afterInit);
- }
- }
-
- assertFalse("No new SASL mechanisms added by initialisation.", additions.isEmpty());
-
- //Close the registry which will perform the close the AuthenticationManager
- stopBroker();
-
- //Validate that the SASL plugFins have been removed.
- Provider[] providersAfterClose = Security.getProviders();
-
- assertTrue("No providers unregistered", providersAfterInitialisation.length > providersAfterClose.length);
-
- //Ensure that the additions are not still present after close().
- for (Provider afterClose : providersAfterClose)
- {
- assertFalse("Added provider not unregistered", additions.contains(afterClose));
- }
- }
-
-
-
-
-
-}
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/AuthenticationManagerRegistryTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/AuthenticationManagerRegistryTest.java
deleted file mode 100644
index aeab1e4343..0000000000
--- a/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/AuthenticationManagerRegistryTest.java
+++ /dev/null
@@ -1,355 +0,0 @@
-/*
- * 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.qpid.server.security.auth.manager;
-
-import static org.mockito.Mockito.doThrow;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import java.net.InetSocketAddress;
-import java.net.SocketAddress;
-import java.security.Principal;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-
-import javax.security.sasl.SaslException;
-import javax.security.sasl.SaslServer;
-
-import junit.framework.TestCase;
-
-import org.apache.commons.configuration.Configuration;
-import org.apache.commons.configuration.ConfigurationException;
-import org.apache.qpid.server.configuration.ServerConfiguration;
-import org.apache.qpid.server.plugin.AuthenticationManagerFactory;
-import org.apache.qpid.server.plugin.QpidServiceLoader;
-import org.apache.qpid.server.security.SubjectCreator;
-import org.apache.qpid.server.security.auth.AuthenticationResult;
-import org.apache.qpid.server.security.group.GroupPrincipalAccessor;
-
-public class AuthenticationManagerRegistryTest extends TestCase
-{
- @SuppressWarnings("unchecked")
- private QpidServiceLoader<AuthenticationManagerFactory> _authManagerServiceLoader = mock(QpidServiceLoader.class);
-
- private ServerConfiguration _serverConfiguration = mock(ServerConfiguration.class);
- private Configuration _serverCommonsConfig = mock(Configuration.class);
- private Configuration _securityCommonsConfig = mock(Configuration.class);
-
- private GroupPrincipalAccessor _groupPrincipalAccessor = mock(GroupPrincipalAccessor.class);
-
- private TestAuthenticationManager1 _testAuthManager1 = new TestAuthenticationManager1();
- private TestAuthenticationManager2 _testAuthManager2 = new TestAuthenticationManager2();
-
- private AuthenticationManagerFactory _testAuthManager1Factory = newMockFactoryProducing(_testAuthManager1);
- private AuthenticationManagerFactory _testAuthManager2Factory = newMockFactoryProducing(_testAuthManager2);
-
- @Override
- protected void setUp() throws Exception
- {
- super.setUp();
- when(_serverConfiguration.getConfig()).thenReturn(_serverCommonsConfig);
- when(_serverCommonsConfig.subset("security")).thenReturn(_securityCommonsConfig);
- }
-
- public void testNoAuthenticationManagerFactoryPluginsFound() throws Exception
- {
- String noServicesMessage = "mock exception - no services found";
- when(_authManagerServiceLoader.atLeastOneInstanceOf(AuthenticationManagerFactory.class)).thenThrow(new RuntimeException(noServicesMessage));
- try
- {
- new AuthenticationManagerRegistry(_serverConfiguration, _groupPrincipalAccessor, _authManagerServiceLoader);
- fail("Exception not thrown");
- }
- catch (RuntimeException ce)
- {
- // PASS
- assertEquals(noServicesMessage, ce.getMessage());
- }
- }
-
- public void testSameAuthenticationManagerSpecifiedTwice() throws Exception
- {
- List<AuthenticationManagerFactory> duplicateFactories = Arrays.asList(_testAuthManager1Factory, _testAuthManager1Factory);
-
- when(_authManagerServiceLoader.atLeastOneInstanceOf(AuthenticationManagerFactory.class)).thenReturn(duplicateFactories);
-
- try
- {
- new AuthenticationManagerRegistry(_serverConfiguration, _groupPrincipalAccessor, _authManagerServiceLoader);
- fail("Exception not thrown");
- }
- catch (RuntimeException e)
- {
- assertTrue(e.getMessage().contains("Cannot configure more than one authentication manager with name"));
- assertTrue(e.getMessage().contains(TestAuthenticationManager1.class.getSimpleName()));
- }
- }
-
- public void testMultipleAuthenticationManagersSpecifiedButNoDefaultSpecified() throws Exception
- {
- List<AuthenticationManagerFactory> factoryList = Arrays.asList(_testAuthManager1Factory, _testAuthManager2Factory);
-
- when(_authManagerServiceLoader.atLeastOneInstanceOf(AuthenticationManagerFactory.class)).thenReturn(factoryList);
- when(_serverConfiguration.getDefaultAuthenticationManager()).thenReturn(null);
-
- try
- {
- new AuthenticationManagerRegistry(_serverConfiguration, _groupPrincipalAccessor, _authManagerServiceLoader);
- fail("Exception not thrown");
- }
- catch (ConfigurationException ce)
- {
- // PASS
- assertEquals("If more than one authentication manager is configured a default MUST be specified.",
- ce.getMessage());
- }
- }
-
- public void testDefaultAuthenticationManagerNotKnown() throws Exception
- {
- String myDefaultAuthManagerSimpleClassName = "UnknownAuthenticationManager";
-
- List<AuthenticationManagerFactory> factoryList = Arrays.asList(_testAuthManager1Factory, _testAuthManager2Factory);
-
- when(_authManagerServiceLoader.atLeastOneInstanceOf(AuthenticationManagerFactory.class)).thenReturn(factoryList);
- when(_serverConfiguration.getDefaultAuthenticationManager()).thenReturn(myDefaultAuthManagerSimpleClassName);
-
- try
- {
- new AuthenticationManagerRegistry(_serverConfiguration, _groupPrincipalAccessor, _authManagerServiceLoader);
- fail("Exception not thrown");
- }
- catch (ConfigurationException ce)
- {
- // PASS
- assertTrue("Unexpected message " + ce.getMessage(),
- ce.getMessage().startsWith("No authentication managers configured of type " + myDefaultAuthManagerSimpleClassName + " which is specified as the default"));
- }
- }
-
- public void testPortMappedToUnknownAuthenticationManager() throws Exception
- {
- String myDefaultAuthManagerSimpleClassName = "UnknownAuthenticationManager";
- int portNumber = 1234;
-
- List<AuthenticationManagerFactory> factoryList = Arrays.asList(_testAuthManager1Factory);
-
- when(_authManagerServiceLoader.atLeastOneInstanceOf(AuthenticationManagerFactory.class)).thenReturn(factoryList);
- when(_serverConfiguration.getPortAuthenticationMappings()).thenReturn(Collections.singletonMap(portNumber, myDefaultAuthManagerSimpleClassName));
-
- try
- {
- new AuthenticationManagerRegistry(_serverConfiguration, _groupPrincipalAccessor, _authManagerServiceLoader);
- fail("Exception not thrown");
- }
- catch (ConfigurationException ce)
- {
- // PASS
- assertEquals("Unknown authentication manager class " + myDefaultAuthManagerSimpleClassName + " configured for port " + portNumber, ce.getMessage());
- }
- }
-
- public void testGetAuthenticationManagerForInetSocketAddress() throws Exception
- {
- List<AuthenticationManagerFactory> factoryList = Arrays.asList(_testAuthManager1Factory);
-
- when(_authManagerServiceLoader.atLeastOneInstanceOf(AuthenticationManagerFactory.class)).thenReturn(factoryList);
-
- AuthenticationManagerRegistry registry = new AuthenticationManagerRegistry(_serverConfiguration, _groupPrincipalAccessor, _authManagerServiceLoader);
-
- SubjectCreator subjectCreator = registry.getSubjectCreator(new InetSocketAddress(1234));
- assertSubjectCreatorUsingExpectedAuthManager(_testAuthManager1, subjectCreator);
- }
-
- public void testGetAuthenticationManagerForNonInetSocketAddress() throws Exception
- {
- List<AuthenticationManagerFactory> factoryList = Arrays.asList(_testAuthManager1Factory);
-
- when(_authManagerServiceLoader.atLeastOneInstanceOf(AuthenticationManagerFactory.class)).thenReturn(factoryList);
-
- AuthenticationManagerRegistry registry = new AuthenticationManagerRegistry(_serverConfiguration, _groupPrincipalAccessor, _authManagerServiceLoader);
-
- SubjectCreator subjectCreator = registry.getSubjectCreator(mock(SocketAddress.class));
- assertSubjectCreatorUsingExpectedAuthManager(_testAuthManager1, subjectCreator);
- }
-
- public void testGetAuthenticationManagerWithMultipleAuthenticationManager() throws Exception
- {
- List<AuthenticationManagerFactory> factoryList = Arrays.asList(_testAuthManager1Factory, _testAuthManager2Factory);
-
- AuthenticationManager defaultAuthManger = _testAuthManager1;
- AuthenticationManager unmappedAuthManager = _testAuthManager2;
-
- String defaultAuthMangerName = defaultAuthManger.getClass().getSimpleName();
- String mappedAuthManagerName = unmappedAuthManager.getClass().getSimpleName();
-
- int unmappedPortNumber = 1234;
- int mappedPortNumber = 1235;
-
- when(_authManagerServiceLoader.atLeastOneInstanceOf(AuthenticationManagerFactory.class)).thenReturn(factoryList);
- when(_serverConfiguration.getDefaultAuthenticationManager()).thenReturn(defaultAuthMangerName);
- when(_serverConfiguration.getPortAuthenticationMappings()).thenReturn(Collections.singletonMap(mappedPortNumber, mappedAuthManagerName));
-
- AuthenticationManagerRegistry registry = new AuthenticationManagerRegistry(_serverConfiguration, _groupPrincipalAccessor, _authManagerServiceLoader);
-
- SubjectCreator subjectCreatorForDefaultAuthManager = registry.getSubjectCreator(new InetSocketAddress(unmappedPortNumber));
- assertSubjectCreatorUsingExpectedAuthManager(defaultAuthManger, subjectCreatorForDefaultAuthManager);
-
- SubjectCreator subjectCreatorForUnmappedAuthManager = registry.getSubjectCreator(new InetSocketAddress(mappedPortNumber));
- assertSubjectCreatorUsingExpectedAuthManager(unmappedAuthManager, subjectCreatorForUnmappedAuthManager);
- }
-
- public void testAuthenticationManagersAreClosed() throws Exception
- {
- AuthenticationManager defaultAuthManager = mock(MockAuthenticationManager1.class);
- AuthenticationManagerFactory defaultAuthManagerFactory = newMockFactoryProducing(defaultAuthManager);
-
- AuthenticationManager authManager2 = mock(MockAuthenticationManager2.class);
- AuthenticationManagerFactory authManagerFactory2 = newMockFactoryProducing(authManager2);
-
- List<AuthenticationManagerFactory> factoryList = Arrays.asList(defaultAuthManagerFactory, authManagerFactory2);
-
- String defaultAuthMangerName = defaultAuthManager.getClass().getSimpleName();
- when(_serverConfiguration.getDefaultAuthenticationManager()).thenReturn(defaultAuthMangerName);
- when(_authManagerServiceLoader.atLeastOneInstanceOf(AuthenticationManagerFactory.class)).thenReturn(factoryList);
-
- AuthenticationManagerRegistry registry = new AuthenticationManagerRegistry(_serverConfiguration, _groupPrincipalAccessor, _authManagerServiceLoader);
-
- registry.close();
-
- verify(defaultAuthManager).close();
- verify(authManager2).close();
- }
-
- public void testAlreadyInitialisedAuthManagersAreClosedWhenAnotherAuthManagerInitFails() throws Exception
- {
- AuthenticationManager authManger1 = mock(MockAuthenticationManager1.class);
- AuthenticationManagerFactory authManager1Factory = newMockFactoryProducing(authManger1);
-
- AuthenticationManager authManager2 = mock(MockAuthenticationManager2.class);
- AuthenticationManagerFactory authManagerFactory2 = newMockFactoryProducing(authManager2);
-
- List<AuthenticationManagerFactory> factoryList = Arrays.asList(authManager1Factory, authManagerFactory2);
- when(_authManagerServiceLoader.atLeastOneInstanceOf(AuthenticationManagerFactory.class)).thenReturn(factoryList);
-
- doThrow(new RuntimeException("mock auth manager 2 init exception")).when(authManager2).initialise();
-
- try
- {
- new AuthenticationManagerRegistry(_serverConfiguration, _groupPrincipalAccessor, _authManagerServiceLoader);
- fail("Exception not thrown");
- }
- catch (RuntimeException e)
- {
- // PASS
- }
-
- verify(authManger1).close();
- }
-
-
- private AuthenticationManagerFactory newMockFactoryProducing(AuthenticationManager myAuthManager)
- {
- AuthenticationManagerFactory myAuthManagerFactory = mock(AuthenticationManagerFactory.class);
- when(myAuthManagerFactory.createInstance(_securityCommonsConfig)).thenReturn(myAuthManager);
- return myAuthManagerFactory;
- }
-
- private void assertSubjectCreatorUsingExpectedAuthManager(AuthenticationManager expectedAuthenticationManager, SubjectCreator subjectCreator)
- {
- assertEquals(
- "The subject creator should be using " + expectedAuthenticationManager + " so its mechanisms should match",
- expectedAuthenticationManager.getMechanisms(),
- subjectCreator.getMechanisms());
- }
-
- /** @see MockAuthenticationManager2 */
- private interface MockAuthenticationManager1 extends AuthenticationManager
- {
- }
-
- /**
- * I only exist so that mock implementations of me have a different class to {@link MockAuthenticationManager1},
- * as mandated by {@link AuthenticationManagerRegistry}
- */
- private interface MockAuthenticationManager2 extends AuthenticationManager
- {
- }
-
- /**
- * We use a stub rather than a mock because {@link AuthenticationManagerRegistry} relies on {@link AuthenticationManager} class names,
- * which are hard to predict for mocks.
- */
- private abstract class TestAuthenticationManager implements AuthenticationManager
- {
- @Override
- public void close()
- {
- // no-op
- }
-
- @Override
- public void initialise()
- {
- // no-op
- }
-
- @Override
- public SaslServer createSaslServer(String mechanism, String localFQDN, Principal externalPrincipal) throws SaslException
- {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public AuthenticationResult authenticate(SaslServer server, byte[] response)
- {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public AuthenticationResult authenticate(String username, String password)
- {
- throw new UnsupportedOperationException();
- }
- }
-
- private class TestAuthenticationManager1 extends TestAuthenticationManager
- {
- @Override
- public String getMechanisms()
- {
- return "MECHANISMS1";
- }
- }
-
- private class TestAuthenticationManager2 extends TestAuthenticationManager
- {
- /**
- * Needs to different from {@link TestAuthenticationManager1#getMechanisms()} to aid our test assertions.
- */
- @Override
- public String getMechanisms()
- {
- return "MECHANISMS2";
- }
- }
-}
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/Base64MD5PasswordFileAuthenticationManagerFactoryTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/Base64MD5PasswordFileAuthenticationManagerFactoryTest.java
new file mode 100644
index 0000000000..04e09e073f
--- /dev/null
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/Base64MD5PasswordFileAuthenticationManagerFactoryTest.java
@@ -0,0 +1,111 @@
+/*
+ * 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.qpid.server.security.auth.manager;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.util.HashMap;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+import org.apache.qpid.server.plugin.AuthenticationManagerFactory;
+import org.apache.qpid.server.security.auth.database.Base64MD5PasswordFilePrincipalDatabase;
+
+public class Base64MD5PasswordFileAuthenticationManagerFactoryTest extends TestCase
+{
+ AuthenticationManagerFactory _factory = new Base64MD5PasswordFileAuthenticationManagerFactory();
+ private Map<String, Object> _configuration = new HashMap<String, Object>();
+ private File _emptyPasswordFile;
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ _emptyPasswordFile = File.createTempFile(getName(), "passwd");
+ _emptyPasswordFile.deleteOnExit();
+ }
+
+ public void testBase64MD5InstanceCreated() throws Exception
+ {
+ _configuration.put(AbstractPrincipalDatabaseAuthManagerFactory.ATTRIBUTE_TYPE, Base64MD5PasswordFileAuthenticationManagerFactory.PROVIDER_TYPE);
+ _configuration.put(AbstractPrincipalDatabaseAuthManagerFactory.ATTRIBUTE_PATH, _emptyPasswordFile.getAbsolutePath());
+
+ AuthenticationManager manager = _factory.createInstance(_configuration);
+ assertNotNull(manager);
+ assertTrue(manager instanceof PrincipalDatabaseAuthenticationManager);
+ assertTrue(((PrincipalDatabaseAuthenticationManager)manager).getPrincipalDatabase() instanceof Base64MD5PasswordFilePrincipalDatabase);
+ }
+
+ public void testPasswordFileNotFound() throws Exception
+ {
+ //delete the file
+ _emptyPasswordFile.delete();
+
+ _configuration.put(AbstractPrincipalDatabaseAuthManagerFactory.ATTRIBUTE_TYPE, Base64MD5PasswordFileAuthenticationManagerFactory.PROVIDER_TYPE);
+ _configuration.put(AbstractPrincipalDatabaseAuthManagerFactory.ATTRIBUTE_PATH, _emptyPasswordFile.getAbsolutePath());
+
+ try
+ {
+ _factory.createInstance(_configuration);
+ }
+ catch (RuntimeException re)
+ {
+ assertTrue(re.getCause() instanceof FileNotFoundException);
+ }
+ }
+
+ public void testReturnsNullWhenNoConfig() throws Exception
+ {
+ AuthenticationManager manager = _factory.createInstance(_configuration);
+ assertNull(manager);
+ }
+
+ public void testReturnsNullWhenConfigForOtherAuthManagerType() throws Exception
+ {
+ _configuration.put(AbstractPrincipalDatabaseAuthManagerFactory.ATTRIBUTE_TYPE, "other-auth-manager");
+ AuthenticationManager manager = _factory.createInstance(_configuration);
+ assertNull(manager);
+ }
+
+ public void testReturnsNullWhenConfigForPlainPDImplementationNoPasswordFileValueSpecified() throws Exception
+ {
+ _configuration.put(AbstractPrincipalDatabaseAuthManagerFactory.ATTRIBUTE_TYPE, Base64MD5PasswordFileAuthenticationManagerFactory.PROVIDER_TYPE);
+
+ AuthenticationManager manager = _factory.createInstance(_configuration);
+ assertNull(manager);
+ }
+
+ @Override
+ protected void tearDown() throws Exception
+ {
+ try
+ {
+ if (_emptyPasswordFile == null && _emptyPasswordFile.exists())
+ {
+ _emptyPasswordFile.delete();
+ }
+ }
+ finally
+ {
+ super.tearDown();
+ }
+ }
+} \ No newline at end of file
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/PlainPasswordFileAuthenticationManagerFactoryTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/PlainPasswordFileAuthenticationManagerFactoryTest.java
new file mode 100644
index 0000000000..d428f8b211
--- /dev/null
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/PlainPasswordFileAuthenticationManagerFactoryTest.java
@@ -0,0 +1,111 @@
+/*
+ * 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.qpid.server.security.auth.manager;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.util.HashMap;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+import org.apache.qpid.server.plugin.AuthenticationManagerFactory;
+import org.apache.qpid.server.security.auth.database.PlainPasswordFilePrincipalDatabase;
+
+public class PlainPasswordFileAuthenticationManagerFactoryTest extends TestCase
+{
+ AuthenticationManagerFactory _factory = new PlainPasswordFileAuthenticationManagerFactory();
+ private Map<String, Object> _configuration = new HashMap<String, Object>();
+ private File _emptyPasswordFile;
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ _emptyPasswordFile = File.createTempFile(getName(), "passwd");
+ _emptyPasswordFile.deleteOnExit();
+ }
+
+ public void testPlainInstanceCreated() throws Exception
+ {
+ _configuration.put(AbstractPrincipalDatabaseAuthManagerFactory.ATTRIBUTE_TYPE, PlainPasswordFileAuthenticationManagerFactory.PROVIDER_TYPE);
+ _configuration.put(AbstractPrincipalDatabaseAuthManagerFactory.ATTRIBUTE_PATH, _emptyPasswordFile.getAbsolutePath());
+
+ AuthenticationManager manager = _factory.createInstance(_configuration);
+ assertNotNull(manager);
+ assertTrue(manager instanceof PrincipalDatabaseAuthenticationManager);
+ assertTrue(((PrincipalDatabaseAuthenticationManager)manager).getPrincipalDatabase() instanceof PlainPasswordFilePrincipalDatabase);
+ }
+
+ public void testPasswordFileNotFound() throws Exception
+ {
+ //delete the file
+ _emptyPasswordFile.delete();
+
+ _configuration.put(AbstractPrincipalDatabaseAuthManagerFactory.ATTRIBUTE_TYPE, PlainPasswordFileAuthenticationManagerFactory.PROVIDER_TYPE);
+ _configuration.put(AbstractPrincipalDatabaseAuthManagerFactory.ATTRIBUTE_PATH, _emptyPasswordFile.getAbsolutePath());
+
+ try
+ {
+ _factory.createInstance(_configuration);
+ }
+ catch (RuntimeException re)
+ {
+ assertTrue(re.getCause() instanceof FileNotFoundException);
+ }
+ }
+
+ public void testReturnsNullWhenNoConfig() throws Exception
+ {
+ AuthenticationManager manager = _factory.createInstance(_configuration);
+ assertNull(manager);
+ }
+
+ public void testReturnsNullWhenConfigForOtherAuthManagerType() throws Exception
+ {
+ _configuration.put(AbstractPrincipalDatabaseAuthManagerFactory.ATTRIBUTE_TYPE, "other-auth-manager");
+ AuthenticationManager manager = _factory.createInstance(_configuration);
+ assertNull(manager);
+ }
+
+ public void testReturnsNullWhenConfigForPlainPDImplementationNoPasswordFileValueSpecified() throws Exception
+ {
+ _configuration.put(AbstractPrincipalDatabaseAuthManagerFactory.ATTRIBUTE_TYPE, PlainPasswordFileAuthenticationManagerFactory.PROVIDER_TYPE);
+
+ AuthenticationManager manager = _factory.createInstance(_configuration);
+ assertNull(manager);
+ }
+
+ @Override
+ protected void tearDown() throws Exception
+ {
+ try
+ {
+ if (_emptyPasswordFile == null && _emptyPasswordFile.exists())
+ {
+ _emptyPasswordFile.delete();
+ }
+ }
+ finally
+ {
+ super.tearDown();
+ }
+ }
+}
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthManagerFactoryTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthManagerFactoryTest.java
deleted file mode 100644
index d76ea2674c..0000000000
--- a/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthManagerFactoryTest.java
+++ /dev/null
@@ -1,139 +0,0 @@
-/*
- * 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.qpid.server.security.auth.manager;
-
-import java.io.File;
-import java.io.FileNotFoundException;
-
-import org.apache.commons.configuration.Configuration;
-import org.apache.commons.configuration.XMLConfiguration;
-import org.apache.qpid.server.security.auth.database.Base64MD5PasswordFilePrincipalDatabase;
-import org.apache.qpid.server.security.auth.database.PlainPasswordFilePrincipalDatabase;
-
-import junit.framework.TestCase;
-
-public class PrincipalDatabaseAuthManagerFactoryTest extends TestCase
-{
- PrincipalDatabaseAuthManagerFactory _factory = new PrincipalDatabaseAuthManagerFactory();
- private Configuration _configuration = new XMLConfiguration();
- private File _emptyPasswordFile;
-
- @Override
- protected void setUp() throws Exception
- {
- super.setUp();
- _emptyPasswordFile = File.createTempFile(getName(), "passwd");
- _emptyPasswordFile.deleteOnExit();
- }
-
- public void testPlainInstanceCreated() throws Exception
- {
- _configuration.setProperty("pd-auth-manager.principal-database.class", PlainPasswordFilePrincipalDatabase.class.getName());
- _configuration.setProperty("pd-auth-manager.principal-database.attributes.attribute.name", "passwordFile");
- _configuration.setProperty("pd-auth-manager.principal-database.attributes.attribute.value", _emptyPasswordFile.getAbsolutePath());
-
- AuthenticationManager manager = _factory.createInstance(_configuration);
- assertNotNull(manager);
- assertTrue(manager instanceof PrincipalDatabaseAuthenticationManager);
- assertTrue(((PrincipalDatabaseAuthenticationManager)manager).getPrincipalDatabase() instanceof PlainPasswordFilePrincipalDatabase);
- }
-
- public void testBase64MD5nstanceCreated() throws Exception
- {
- _configuration.setProperty("pd-auth-manager.principal-database.class", Base64MD5PasswordFilePrincipalDatabase.class.getName());
- _configuration.setProperty("pd-auth-manager.principal-database.attributes.attribute.name", "passwordFile");
- _configuration.setProperty("pd-auth-manager.principal-database.attributes.attribute.value", _emptyPasswordFile.getAbsolutePath());
-
- AuthenticationManager manager = _factory.createInstance(_configuration);
- assertNotNull(manager);
- assertTrue(manager instanceof PrincipalDatabaseAuthenticationManager);
- assertTrue(((PrincipalDatabaseAuthenticationManager)manager).getPrincipalDatabase() instanceof Base64MD5PasswordFilePrincipalDatabase);
- }
-
- public void testPasswordFileNotFound() throws Exception
- {
- _emptyPasswordFile.delete();
-
- _configuration.setProperty("pd-auth-manager.principal-database.class", PlainPasswordFilePrincipalDatabase.class.getName());
- _configuration.setProperty("pd-auth-manager.principal-database.attributes.attribute.name", "passwordFile");
- _configuration.setProperty("pd-auth-manager.principal-database.attributes.attribute.value", _emptyPasswordFile.getAbsolutePath());
-
- try
- {
- _factory.createInstance(_configuration);
- }
- catch (RuntimeException re)
- {
- assertTrue(re.getCause() instanceof FileNotFoundException);
- }
- }
-
- public void testReturnsNullWhenNoConfig() throws Exception
- {
- AuthenticationManager manager = _factory.createInstance(_configuration);
- assertNull(manager);
- }
-
- public void testReturnsNullWhenConfigForOtherPDImplementation() throws Exception
- {
- _configuration.setProperty("pd-auth-manager.principal-database.class", "mypdimpl");
-
- AuthenticationManager manager = _factory.createInstance(_configuration);
- assertNull(manager);
- }
-
- public void testReturnsNullWhenConfigForPlainPDImplementationNoPasswordFileValueSpecified() throws Exception
- {
- _configuration.setProperty("pd-auth-manager.principal-database.class", PlainPasswordFilePrincipalDatabase.class.getName());
- _configuration.setProperty("pd-auth-manager.principal-database.attributes.attribute.name", "passwordFile");
- // no pd-auth-manager.attributes.attribute.value
-
- AuthenticationManager manager = _factory.createInstance(_configuration);
- assertNull(manager);
- }
-
- public void testReturnsNullWhenConfigForPlainPDImplementationWrongArgumentName() throws Exception
- {
- _configuration.setProperty("pd-auth-manager.principal-database.class", PlainPasswordFilePrincipalDatabase.class.getName());
- _configuration.setProperty("pd-auth-manager.principal-database.attributes.attribute.name", "wrong");
- _configuration.setProperty("pd-auth-manager.principal-database.attributes.attribute.value", "/does/not/matter");
-
- AuthenticationManager manager = _factory.createInstance(_configuration);
- assertNull(manager);
- }
-
-
-
- @Override
- protected void tearDown() throws Exception
- {
- try
- {
- if (_emptyPasswordFile == null && _emptyPasswordFile.exists())
- {
- _emptyPasswordFile.delete();
- }
- }
- finally
- {
- super.tearDown();
- }
- }
-}
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/SimpleLDAPAuthenticationManagerFactoryTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/SimpleLDAPAuthenticationManagerFactoryTest.java
index aab5f80836..1424bee611 100644
--- a/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/SimpleLDAPAuthenticationManagerFactoryTest.java
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/SimpleLDAPAuthenticationManagerFactoryTest.java
@@ -19,20 +19,22 @@
*/
package org.apache.qpid.server.security.auth.manager;
-import org.apache.commons.configuration.Configuration;
-import org.apache.commons.configuration.XMLConfiguration;
+import java.util.HashMap;
+import java.util.Map;
+
import junit.framework.TestCase;
public class SimpleLDAPAuthenticationManagerFactoryTest extends TestCase
{
private SimpleLDAPAuthenticationManagerFactory _factory = new SimpleLDAPAuthenticationManagerFactory();
- private Configuration _configuration = new XMLConfiguration();
+ private Map<String, Object> _configuration = new HashMap<String, Object>();
public void testInstanceCreated() throws Exception
{
- _configuration.setProperty("simple-ldap-auth-manager.provider-url", "ldaps://example.com:636/");
- _configuration.setProperty("simple-ldap-auth-manager.search-context", "dc=example");
+ _configuration.put(SimpleLDAPAuthenticationManagerFactory.ATTRIBUTE_TYPE, SimpleLDAPAuthenticationManagerFactory.PROVIDER_TYPE);
+ _configuration.put("providerUrl", "ldaps://example.com:636/");
+ _configuration.put("searchContext", "dc=example");
AuthenticationManager manager = _factory.createInstance(_configuration);
assertNotNull(manager);
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/rmi/RMIPasswordAuthenticatorTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/rmi/RMIPasswordAuthenticatorTest.java
index 89580dc392..52b525dd80 100644
--- a/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/rmi/RMIPasswordAuthenticatorTest.java
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/rmi/RMIPasswordAuthenticatorTest.java
@@ -21,17 +21,20 @@
package org.apache.qpid.server.security.auth.rmi;
import static org.mockito.Matchers.anyString;
+import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.net.InetSocketAddress;
+import java.net.SocketAddress;
import java.security.Principal;
+import java.util.regex.Pattern;
import javax.security.auth.Subject;
import junit.framework.TestCase;
-import org.apache.qpid.server.registry.ApplicationRegistry;
+import org.apache.qpid.server.model.Broker;
import org.apache.qpid.server.security.SubjectCreator;
import org.apache.qpid.server.security.auth.AuthenticationResult;
import org.apache.qpid.server.security.auth.AuthenticationResult.AuthenticationStatus;
@@ -47,9 +50,8 @@ public class RMIPasswordAuthenticatorTest extends TestCase
private static final String USERNAME = "guest";
private static final String PASSWORD = "password";
- private final ApplicationRegistry _applicationRegistry = mock(ApplicationRegistry.class);
+ private final Broker _broker = mock(Broker.class);
private final SecurityManager _securityManager = mock(SecurityManager.class);
- private final InetSocketAddress _jmxSocketAddress = new InetSocketAddress(8999);
private final Subject _loginSubject = new Subject();
private final String[] _credentials = new String[] {USERNAME, PASSWORD};
@@ -60,9 +62,8 @@ public class RMIPasswordAuthenticatorTest extends TestCase
protected void setUp() throws Exception
{
- _rmipa = new RMIPasswordAuthenticator(_applicationRegistry, _jmxSocketAddress);
-
- when(_applicationRegistry.getSecurityManager()).thenReturn(_securityManager);
+ when(_broker.getSecurityManager()).thenReturn(_securityManager);
+ _rmipa = new RMIPasswordAuthenticator(_broker, new InetSocketAddress(8999));
}
/**
@@ -70,7 +71,7 @@ public class RMIPasswordAuthenticatorTest extends TestCase
*/
public void testAuthenticationSuccess()
{
- when(_applicationRegistry.getSubjectCreator(_jmxSocketAddress)).thenReturn(_usernamePasswordOkaySuvjectCreator);
+ when(_broker.getSubjectCreator(any(SocketAddress.class))).thenReturn(_usernamePasswordOkaySuvjectCreator);
when(_securityManager.accessManagement()).thenReturn(true);
Subject newSubject = _rmipa.authenticate(_credentials);
@@ -82,7 +83,7 @@ public class RMIPasswordAuthenticatorTest extends TestCase
*/
public void testUsernameOrPasswordInvalid()
{
- when(_applicationRegistry.getSubjectCreator(_jmxSocketAddress)).thenReturn(_badPasswordSubjectCreator);
+ when(_broker.getSubjectCreator(any(SocketAddress.class))).thenReturn(_badPasswordSubjectCreator);
try
{
@@ -98,7 +99,7 @@ public class RMIPasswordAuthenticatorTest extends TestCase
public void testAuthorisationFailure()
{
- when(_applicationRegistry.getSubjectCreator(_jmxSocketAddress)).thenReturn(_usernamePasswordOkaySuvjectCreator);
+ when(_broker.getSubjectCreator(any(SocketAddress.class))).thenReturn(_usernamePasswordOkaySuvjectCreator);
when(_securityManager.accessManagement()).thenReturn(false);
try
@@ -117,7 +118,7 @@ public class RMIPasswordAuthenticatorTest extends TestCase
{
final Exception mockAuthException = new Exception("Mock Auth system failure");
SubjectCreator subjectCreator = createMockSubjectCreator(false, mockAuthException);
- when(_applicationRegistry.getSubjectCreator(_jmxSocketAddress)).thenReturn(subjectCreator);
+ when(_broker.getSubjectCreator(any(SocketAddress.class))).thenReturn(subjectCreator);
try
{
@@ -135,7 +136,7 @@ public class RMIPasswordAuthenticatorTest extends TestCase
*/
public void testNullSubjectCreator() throws Exception
{
- when(_applicationRegistry.getSubjectCreator(_jmxSocketAddress)).thenReturn(null);
+ when(_broker.getSubjectCreator(any(SocketAddress.class))).thenReturn(null);
try
{
@@ -144,8 +145,7 @@ public class RMIPasswordAuthenticatorTest extends TestCase
}
catch (SecurityException se)
{
- assertEquals("Unexpected exception message",
- "Can't get subject creator for 0.0.0.0/0.0.0.0:8999", se.getMessage());
+ assertTrue("Unexpected exception message", Pattern.matches("Can't get subject creator for .*:8999", se.getMessage()));
}
}
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/security/group/FileGroupManagerFactoryTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/group/FileGroupManagerFactoryTest.java
index 5b04df2fc5..934c0082ea 100644
--- a/qpid/java/broker/src/test/java/org/apache/qpid/server/security/group/FileGroupManagerFactoryTest.java
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/group/FileGroupManagerFactoryTest.java
@@ -18,23 +18,25 @@
*/
package org.apache.qpid.server.security.group;
-import org.apache.commons.configuration.Configuration;
-import org.apache.commons.configuration.XMLConfiguration;
-import org.apache.qpid.test.utils.TestFileUtils;
+import java.util.HashMap;
+import java.util.Map;
import junit.framework.TestCase;
+import org.apache.qpid.server.model.GroupProvider;
+import org.apache.qpid.test.utils.TestFileUtils;
+
public class FileGroupManagerFactoryTest extends TestCase
{
private FileGroupManagerFactory _factory = new FileGroupManagerFactory();
- private Configuration _configuration = new XMLConfiguration();
+ private Map<String, Object> _configuration = new HashMap<String, Object>();
private String _emptyButValidGroupFile = TestFileUtils.createTempFile(this).getAbsolutePath();
public void testInstanceCreated() throws Exception
{
- _configuration.setProperty("file-group-manager.attributes.attribute.name", "groupFile");
- _configuration.setProperty("file-group-manager.attributes.attribute.value", _emptyButValidGroupFile);
+ _configuration.put(GroupProvider.TYPE, FileGroupManagerFactory.FILE_GROUP_MANAGER_TYPE);
+ _configuration.put(FileGroupManagerFactory.FILE, _emptyButValidGroupFile);
GroupManager manager = _factory.createInstance(_configuration);
assertNotNull(manager);
@@ -49,32 +51,17 @@ public class FileGroupManagerFactoryTest extends TestCase
public void testReturnsNullWhenConfigNotForThisPlugin() throws Exception
{
- _configuration.setProperty("other-group-manager", "config");
+ _configuration.put(GroupProvider.TYPE, "other-group-manager");
GroupManager manager = _factory.createInstance(_configuration);
assertNull(manager);
}
- public void testRejectsConfigThatHasUnexpectedAttributeName() throws Exception
- {
- _configuration.setProperty("file-group-manager.attributes.attribute.name", "unexpected");
- _configuration.setProperty("file-group-manager.attributes.attribute.value", _emptyButValidGroupFile);
-
- try
- {
- _factory.createInstance(_configuration);
- fail("Exception not thrown");
- }
- catch (RuntimeException re)
- {
- // PASS
- }
- }
public void testRejectsConfigThatIsMissingAttributeValue() throws Exception
{
- _configuration.setProperty("file-group-manager.attributes.attribute.name", "groupFile");
- _configuration.setProperty("file-group-manager.attributes.attribute.value", null);
+ _configuration.put(GroupProvider.TYPE, FileGroupManagerFactory.FILE_GROUP_MANAGER_TYPE);
+ _configuration.put(FileGroupManagerFactory.FILE, null);
try
{
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/security/group/FileGroupManagerTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/group/FileGroupManagerTest.java
index e926d72607..b83d25b206 100644
--- a/qpid/java/broker/src/test/java/org/apache/qpid/server/security/group/FileGroupManagerTest.java
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/group/FileGroupManagerTest.java
@@ -26,7 +26,7 @@ import java.security.Principal;
import java.util.Properties;
import java.util.Set;
-import org.apache.commons.configuration.ConfigurationException;
+import org.apache.qpid.server.configuration.IllegalConfigurationException;
import org.apache.qpid.server.security.auth.UsernamePrincipal;
import org.apache.qpid.test.utils.QpidTestCase;
@@ -69,7 +69,7 @@ public class FileGroupManagerTest extends QpidTestCase
_manager = new FileGroupManager(filePath);
fail("expected exception was not thrown");
}
- catch(ConfigurationException ce)
+ catch(IllegalConfigurationException ce)
{
assertNotNull(ce.getCause());
assertTrue(ce.getCause() instanceof FileNotFoundException);
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/security/group/GroupPrincipalAccessorTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/group/GroupPrincipalAccessorTest.java
index 6f9b73845d..e58a1a01f8 100644
--- a/qpid/java/broker/src/test/java/org/apache/qpid/server/security/group/GroupPrincipalAccessorTest.java
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/security/group/GroupPrincipalAccessorTest.java
@@ -29,15 +29,14 @@ import java.util.Set;
import junit.framework.TestCase;
-import org.apache.qpid.server.security.group.GroupManager;
-import org.apache.qpid.server.security.group.GroupPrincipalAccessor;
+import org.apache.qpid.server.model.GroupProvider;
public class GroupPrincipalAccessorTest extends TestCase
{
private static final String USERNAME = "username";
- private GroupManager _groupManager1 = mock(GroupManager.class);
- private GroupManager _groupManager2 = mock(GroupManager.class);
+ private GroupProvider _groupManager1 = mock(GroupProvider.class);
+ private GroupProvider _groupManager2 = mock(GroupProvider.class);
private Principal _group1 = mock(Principal.class);
private Principal _group2 = mock(Principal.class);
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/store/MessageStoreCreatorTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/store/MessageStoreCreatorTest.java
new file mode 100644
index 0000000000..e74937dd1c
--- /dev/null
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/store/MessageStoreCreatorTest.java
@@ -0,0 +1,39 @@
+/*
+ *
+ * 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.qpid.server.store;
+
+import org.apache.qpid.server.store.derby.DerbyMessageStore;
+import org.apache.qpid.test.utils.QpidTestCase;
+
+public class MessageStoreCreatorTest extends QpidTestCase
+{
+ private static final String[] STORE_TYPES = {MemoryMessageStore.TYPE, DerbyMessageStore.TYPE};
+
+ public void testMessageStoreCreator()
+ {
+ MessageStoreCreator messageStoreCreator = new MessageStoreCreator();
+ for (String type : STORE_TYPES)
+ {
+ MessageStore store = messageStoreCreator.createMessageStore(type);
+ assertNotNull("Store of type " + type + " is not created", store);
+ }
+ }
+}
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/store/MessageStoreTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/store/MessageStoreTest.java
index 8b7807e999..ffd777243b 100644
--- a/qpid/java/broker/src/test/java/org/apache/qpid/server/store/MessageStoreTest.java
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/store/MessageStoreTest.java
@@ -20,6 +20,7 @@
*/
package org.apache.qpid.server.store;
+
import org.apache.commons.configuration.PropertiesConfiguration;
import org.apache.qpid.AMQException;
@@ -38,6 +39,7 @@ import org.apache.qpid.server.exchange.ExchangeRegistry;
import org.apache.qpid.server.exchange.TopicExchange;
import org.apache.qpid.server.message.AMQMessage;
import org.apache.qpid.server.message.MessageMetaData;
+import org.apache.qpid.server.model.Broker;
import org.apache.qpid.server.model.UUIDGenerator;
import org.apache.qpid.server.plugin.ExchangeType;
import org.apache.qpid.server.queue.AMQPriorityQueue;
@@ -48,11 +50,11 @@ import org.apache.qpid.server.queue.ConflationQueue;
import org.apache.qpid.server.queue.IncomingMessage;
import org.apache.qpid.server.queue.QueueRegistry;
import org.apache.qpid.server.queue.SimpleAMQQueue;
-import org.apache.qpid.server.registry.ApplicationRegistry;
import org.apache.qpid.server.txn.AutoCommitTransaction;
import org.apache.qpid.server.txn.ServerTransaction;
-import org.apache.qpid.server.util.InternalBrokerBaseCase;
+import org.apache.qpid.server.util.BrokerTestHelper;
import org.apache.qpid.server.virtualhost.VirtualHost;
+import org.apache.qpid.test.utils.QpidTestCase;
import org.apache.qpid.util.FileUtils;
import java.io.File;
@@ -66,7 +68,7 @@ import java.util.Map;
* For persistent stores, it validates that Exchanges, Queues, Bindings and
* Messages are persisted and recovered correctly.
*/
-public class MessageStoreTest extends InternalBrokerBaseCase
+public class MessageStoreTest extends QpidTestCase
{
public static final int DEFAULT_PRIORTY_LEVEL = 5;
public static final String SELECTOR_VALUE = "Test = 'MST'";
@@ -93,13 +95,15 @@ public class MessageStoreTest extends InternalBrokerBaseCase
private AMQShortString queueOwner = new AMQShortString("MST");
- protected PropertiesConfiguration _config;
+ private PropertiesConfiguration _config;
+
+ private VirtualHost _virtualHost;
+ private Broker _broker;
public void setUp() throws Exception
{
- getConfigXml().addProperty("management.enabled", "false");
-
super.setUp();
+ BrokerTestHelper.setUp();
String storePath = System.getProperty("QPID_WORK") + File.separator + getName();
@@ -109,9 +113,38 @@ public class MessageStoreTest extends InternalBrokerBaseCase
cleanup(new File(storePath));
+ _broker = BrokerTestHelper.createBrokerMock();
+
reloadVirtualHost();
}
+ @Override
+ public void tearDown() throws Exception
+ {
+ try
+ {
+ if (_virtualHost != null)
+ {
+ _virtualHost.close();
+ }
+ }
+ finally
+ {
+ BrokerTestHelper.tearDown();
+ super.tearDown();
+ }
+ }
+
+ public VirtualHost getVirtualHost()
+ {
+ return _virtualHost;
+ }
+
+ public PropertiesConfiguration getConfig()
+ {
+ return _config;
+ }
+
protected void reloadVirtualHost()
{
VirtualHost original = getVirtualHost();
@@ -121,8 +154,6 @@ public class MessageStoreTest extends InternalBrokerBaseCase
try
{
getVirtualHost().close();
- getVirtualHost().getApplicationRegistry().
- getVirtualHostRegistry().unregisterVirtualHost(getVirtualHost());
}
catch (Exception e)
{
@@ -133,7 +164,7 @@ public class MessageStoreTest extends InternalBrokerBaseCase
try
{
- setVirtualHost(ApplicationRegistry.getInstance().createVirtualHost(new VirtualHostConfiguration(getClass().getName(), _config)));
+ _virtualHost = BrokerTestHelper.createVirtualHost(new VirtualHostConfiguration(getClass().getName(), _config, _broker));
}
catch (Exception e)
{
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/subscription/QueueBrowserUsesNoAckTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/subscription/QueueBrowserUsesNoAckTest.java
index 3272bd5447..d35a90e3c8 100644
--- a/qpid/java/broker/src/test/java/org/apache/qpid/server/subscription/QueueBrowserUsesNoAckTest.java
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/subscription/QueueBrowserUsesNoAckTest.java
@@ -21,14 +21,75 @@
package org.apache.qpid.server.subscription;
import org.apache.qpid.AMQException;
+import org.apache.qpid.common.AMQPFilterTypes;
+import org.apache.qpid.exchange.ExchangeDefaults;
import org.apache.qpid.framing.AMQShortString;
+import org.apache.qpid.framing.FieldTable;
+import org.apache.qpid.server.AMQChannel;
+import org.apache.qpid.server.exchange.Exchange;
import org.apache.qpid.server.protocol.InternalTestProtocolSession;
-import org.apache.qpid.server.util.InternalBrokerBaseCase;
+import org.apache.qpid.server.queue.AMQQueue;
+import org.apache.qpid.server.queue.SimpleAMQQueue;
+import org.apache.qpid.server.store.MessageStore;
+import org.apache.qpid.server.store.TestableMemoryMessageStore;
+import org.apache.qpid.server.util.BrokerTestHelper;
+import org.apache.qpid.server.virtualhost.VirtualHost;
+import org.apache.qpid.test.utils.QpidTestCase;
import java.util.List;
-public class QueueBrowserUsesNoAckTest extends InternalBrokerBaseCase
+public class QueueBrowserUsesNoAckTest extends QpidTestCase
{
+ private AMQChannel _channel;
+ private SimpleAMQQueue _queue;
+ private MessageStore _messageStore;
+ private String _queueName;
+
+ @Override
+ public void setUp() throws Exception
+ {
+ super.setUp();
+ BrokerTestHelper.setUp();
+ _channel = BrokerTestHelper.createChannel();
+ VirtualHost virtualHost = _channel.getVirtualHost();
+ _queueName = getTestName();
+ _queue = BrokerTestHelper.createQueue(_queueName, virtualHost);
+ _messageStore = virtualHost.getMessageStore();
+ Exchange defaultExchange = virtualHost.getExchangeRegistry().getDefaultExchange();
+ virtualHost.getBindingFactory().addBinding(_queueName, _queue, defaultExchange, null);
+ }
+
+ @Override
+ public void tearDown() throws Exception
+ {
+ try
+ {
+ if (_channel != null)
+ {
+ _channel.getVirtualHost().close();
+ }
+ }
+ finally
+ {
+ BrokerTestHelper.tearDown();
+ super.tearDown();
+ }
+ }
+
+ private AMQChannel getChannel()
+ {
+ return _channel;
+ }
+
+ private InternalTestProtocolSession getSession()
+ {
+ return (InternalTestProtocolSession)_channel.getProtocolSession();
+ }
+
+ private SimpleAMQQueue getQueue()
+ {
+ return _queue;
+ }
public void testQueueBrowserUsesNoAck() throws AMQException
{
@@ -39,7 +100,7 @@ public class QueueBrowserUsesNoAckTest extends InternalBrokerBaseCase
checkStoreContents(0);
//Send required messsages to the queue
- publishMessages(getSession(), getChannel(), sendMessageCount);
+ BrokerTestHelper.publishMessages(getChannel(), sendMessageCount, _queueName, ExchangeDefaults.DEFAULT_EXCHANGE_NAME.asString());
//Ensure they are stored
checkStoreContents(sendMessageCount);
@@ -74,4 +135,16 @@ public class QueueBrowserUsesNoAckTest extends InternalBrokerBaseCase
.equals(Subscription.State.SUSPENDED));
}
+ private void checkStoreContents(int messageCount)
+ {
+ assertEquals("Message header count incorrect in the MetaDataMap", messageCount, ((TestableMemoryMessageStore) _messageStore).getMessageCount());
+ }
+
+ private AMQShortString browse(AMQChannel channel, AMQQueue queue) throws AMQException
+ {
+ FieldTable filters = new FieldTable();
+ filters.put(AMQPFilterTypes.NO_CONSUME.getValue(), true);
+
+ return channel.subscribeToQueue(null, queue, true, filters, false, true);
+ }
}
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/subscription/SubscriptionFactoryImplTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/subscription/SubscriptionFactoryImplTest.java
index e7b0725edf..89d434e95d 100644
--- a/qpid/java/broker/src/test/java/org/apache/qpid/server/subscription/SubscriptionFactoryImplTest.java
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/subscription/SubscriptionFactoryImplTest.java
@@ -23,20 +23,55 @@ package org.apache.qpid.server.subscription;
import org.apache.qpid.common.AMQPFilterTypes;
import org.apache.qpid.framing.AMQShortString;
import org.apache.qpid.framing.FieldTable;
+import org.apache.qpid.server.AMQChannel;
import org.apache.qpid.server.flow.WindowCreditManager;
+import org.apache.qpid.server.logging.UnitTestMessageLogger;
+import org.apache.qpid.server.logging.actors.GenericActor;
+import org.apache.qpid.server.protocol.AMQProtocolSession;
import org.apache.qpid.server.protocol.ProtocolEngine_0_10;
import org.apache.qpid.server.transport.ServerConnection;
import org.apache.qpid.server.transport.ServerSession;
import org.apache.qpid.server.transport.ServerSessionDelegate;
-import org.apache.qpid.server.util.InternalBrokerBaseCase;
+import org.apache.qpid.server.util.BrokerTestHelper;
+import org.apache.qpid.test.utils.QpidTestCase;
import org.apache.qpid.transport.Binary;
import org.apache.qpid.transport.MessageAcceptMode;
import org.apache.qpid.transport.MessageAcquireMode;
import org.apache.qpid.transport.MessageFlowMode;
import org.apache.qpid.transport.TestNetworkConnection;
-public class SubscriptionFactoryImplTest extends InternalBrokerBaseCase
+public class SubscriptionFactoryImplTest extends QpidTestCase
{
+ private AMQChannel _channel;
+ private AMQProtocolSession _session;
+
+ @Override
+ public void setUp() throws Exception
+ {
+ super.setUp();
+ BrokerTestHelper.setUp();
+ _channel = BrokerTestHelper.createChannel();
+ _session = _channel.getProtocolSession();
+ GenericActor.setDefaultMessageLogger(new UnitTestMessageLogger(false));
+ }
+
+ @Override
+ public void tearDown() throws Exception
+ {
+ try
+ {
+ if (_channel != null)
+ {
+ _channel.getVirtualHost().close();
+ }
+ }
+ finally
+ {
+ BrokerTestHelper.tearDown();
+ super.tearDown();
+ }
+ }
+
/**
* Tests that while creating Subscriptions of various types, the
* ID numbers assigned are allocated from a common sequence
@@ -46,31 +81,31 @@ public class SubscriptionFactoryImplTest extends InternalBrokerBaseCase
{
//create a No-Ack subscription, get the first Subscription ID
long previousId = 0;
- Subscription noAckSub = SubscriptionFactoryImpl.INSTANCE.createSubscription(1, getSession(), new AMQShortString("1"), false, null, false, getChannel().getCreditManager());
+ Subscription noAckSub = SubscriptionFactoryImpl.INSTANCE.createSubscription(1, _session, new AMQShortString("1"), false, null, false, _channel.getCreditManager());
previousId = noAckSub.getSubscriptionID();
//create an ack subscription, verify the next Subscription ID is used
- Subscription ackSub = SubscriptionFactoryImpl.INSTANCE.createSubscription(1, getSession(), new AMQShortString("1"), true, null, false, getChannel().getCreditManager());
+ Subscription ackSub = SubscriptionFactoryImpl.INSTANCE.createSubscription(1, _session, new AMQShortString("1"), true, null, false, _channel.getCreditManager());
assertEquals("Unexpected Subscription ID allocated", previousId + 1, ackSub.getSubscriptionID());
previousId = ackSub.getSubscriptionID();
//create a browser subscription
FieldTable filters = new FieldTable();
filters.put(AMQPFilterTypes.NO_CONSUME.getValue(), true);
- Subscription browerSub = SubscriptionFactoryImpl.INSTANCE.createSubscription(1, getSession(), new AMQShortString("1"), true, null, false, getChannel().getCreditManager());
+ Subscription browerSub = SubscriptionFactoryImpl.INSTANCE.createSubscription(1, _session, new AMQShortString("1"), true, null, false, _channel.getCreditManager());
assertEquals("Unexpected Subscription ID allocated", previousId + 1, browerSub.getSubscriptionID());
previousId = browerSub.getSubscriptionID();
//create an BasicGet NoAck subscription
- Subscription getNoAckSub = SubscriptionFactoryImpl.INSTANCE.createBasicGetNoAckSubscription(getChannel(), getSession(), new AMQShortString("1"), null, false,
- getChannel().getCreditManager(),getChannel().getClientDeliveryMethod(), getChannel().getRecordDeliveryMethod());
+ Subscription getNoAckSub = SubscriptionFactoryImpl.INSTANCE.createBasicGetNoAckSubscription(_channel, _session, new AMQShortString("1"), null, false,
+ _channel.getCreditManager(),_channel.getClientDeliveryMethod(), _channel.getRecordDeliveryMethod());
assertEquals("Unexpected Subscription ID allocated", previousId + 1, getNoAckSub.getSubscriptionID());
previousId = getNoAckSub.getSubscriptionID();
//create a 0-10 subscription
ServerConnection conn = new ServerConnection(1);
- ProtocolEngine_0_10 engine = new ProtocolEngine_0_10(conn, new TestNetworkConnection(), getRegistry());
- conn.setVirtualHost(getVirtualHost());
+ ProtocolEngine_0_10 engine = new ProtocolEngine_0_10(conn, new TestNetworkConnection());
+ conn.setVirtualHost(_session.getVirtualHost());
ServerSessionDelegate sesDel = new ServerSessionDelegate();
Binary name = new Binary(new byte[]{new Byte("1")});
ServerSession session = new ServerSession(conn, sesDel, name, 0);
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/transport/ServerSessionTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/transport/ServerSessionTest.java
index ac3c0d5722..3389773ff8 100644
--- a/qpid/java/broker/src/test/java/org/apache/qpid/server/transport/ServerSessionTest.java
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/transport/ServerSessionTest.java
@@ -18,12 +18,14 @@
*/
package org.apache.qpid.server.transport;
-import org.apache.qpid.server.registry.ApplicationRegistry;
-import org.apache.qpid.server.util.InternalBrokerBaseCase;
+import org.apache.qpid.server.logging.actors.CurrentActor;
+import org.apache.qpid.server.logging.actors.GenericActor;
+import org.apache.qpid.server.util.BrokerTestHelper;
import org.apache.qpid.server.virtualhost.VirtualHost;
+import org.apache.qpid.test.utils.QpidTestCase;
import org.apache.qpid.transport.Binary;
-public class ServerSessionTest extends InternalBrokerBaseCase
+public class ServerSessionTest extends QpidTestCase
{
private VirtualHost _virtualHost;
@@ -32,7 +34,26 @@ public class ServerSessionTest extends InternalBrokerBaseCase
public void setUp() throws Exception
{
super.setUp();
- _virtualHost = ApplicationRegistry.getInstance().getVirtualHostRegistry().getVirtualHosts().iterator().next();
+ BrokerTestHelper.setUp();
+ _virtualHost = BrokerTestHelper.createVirtualHost(getName());
+ GenericActor.setDefaultMessageLogger(CurrentActor.get().getRootMessageLogger());
+ }
+
+ @Override
+ public void tearDown() throws Exception
+ {
+ try
+ {
+ if (_virtualHost != null)
+ {
+ _virtualHost.close();
+ }
+ }
+ finally
+ {
+ BrokerTestHelper.tearDown();
+ super.tearDown();
+ }
}
public void testCompareTo() throws Exception
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/util/BrokerTestHelper.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/util/BrokerTestHelper.java
new file mode 100644
index 0000000000..3be8927224
--- /dev/null
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/util/BrokerTestHelper.java
@@ -0,0 +1,209 @@
+/*
+ *
+ * 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.qpid.server.util;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.net.SocketAddress;
+import java.util.Collections;
+import java.util.UUID;
+
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.PropertiesConfiguration;
+import org.apache.qpid.AMQException;
+import org.apache.qpid.framing.AMQShortString;
+import org.apache.qpid.framing.BasicContentHeaderProperties;
+import org.apache.qpid.framing.ContentHeaderBody;
+import org.apache.qpid.framing.abstraction.MessagePublishInfo;
+import org.apache.qpid.server.AMQChannel;
+import org.apache.qpid.server.configuration.VirtualHostConfiguration;
+import org.apache.qpid.server.configuration.store.JsonConfigurationEntryStore;
+import org.apache.qpid.server.exchange.DefaultExchangeFactory;
+import org.apache.qpid.server.exchange.Exchange;
+import org.apache.qpid.server.logging.RootMessageLogger;
+import org.apache.qpid.server.logging.SystemOutMessageLogger;
+import org.apache.qpid.server.logging.actors.CurrentActor;
+import org.apache.qpid.server.logging.actors.GenericActor;
+import org.apache.qpid.server.logging.actors.TestLogActor;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.UUIDGenerator;
+import org.apache.qpid.server.protocol.AMQProtocolSession;
+import org.apache.qpid.server.protocol.InternalTestProtocolSession;
+import org.apache.qpid.server.queue.AMQQueueFactory;
+import org.apache.qpid.server.queue.SimpleAMQQueue;
+import org.apache.qpid.server.security.SecurityManager;
+import org.apache.qpid.server.security.SubjectCreator;
+import org.apache.qpid.server.stats.StatisticsGatherer;
+import org.apache.qpid.server.store.TestableMemoryMessageStore;
+import org.apache.qpid.server.virtualhost.VirtualHost;
+import org.apache.qpid.server.virtualhost.VirtualHostImpl;
+import org.apache.qpid.server.virtualhost.VirtualHostRegistry;
+
+public class BrokerTestHelper
+{
+
+ protected static final String BROKER_STORE_CLASS_NAME_KEY = "brokerstore.class.name";
+ protected static final String JSON_BROKER_STORE_CLASS_NAME = JsonConfigurationEntryStore.class.getName();
+
+ public static Broker createBrokerMock()
+ {
+ SubjectCreator subjectCreator = mock(SubjectCreator.class);
+ when(subjectCreator.getMechanisms()).thenReturn("");
+ Broker broker = mock(Broker.class);
+ when(broker.getAttribute(Broker.SESSION_COUNT_LIMIT)).thenReturn(1);
+ when(broker.getAttribute(Broker.HOUSEKEEPING_CHECK_PERIOD)).thenReturn(10000l);
+ when(broker.getId()).thenReturn(UUID.randomUUID());
+ when(broker.getSubjectCreator(any(SocketAddress.class))).thenReturn(subjectCreator);
+ RootMessageLogger rootMessageLogger = CurrentActor.get().getRootMessageLogger();
+ when(broker.getRootMessageLogger()).thenReturn(rootMessageLogger);
+ when(broker.getVirtualHostRegistry()).thenReturn(new VirtualHostRegistry());
+ when(broker.getSecurityManager()).thenReturn(new SecurityManager(null));
+ GenericActor.setDefaultMessageLogger(rootMessageLogger);
+ return broker;
+ }
+
+ public static void setUp()
+ {
+ CurrentActor.set(new TestLogActor(new SystemOutMessageLogger()));
+ }
+
+ public static void tearDown()
+ {
+ CurrentActor.remove();
+ }
+
+ public static VirtualHost createVirtualHost(VirtualHostConfiguration virtualHostConfiguration, VirtualHostRegistry virtualHostRegistry)
+ throws Exception
+ {
+ StatisticsGatherer statisticsGatherer = mock(StatisticsGatherer.class);
+ VirtualHost host = new VirtualHostImpl(virtualHostRegistry, statisticsGatherer, new SecurityManager(null), virtualHostConfiguration);
+ virtualHostRegistry.registerVirtualHost(host);
+ return host;
+ }
+
+ public static VirtualHost createVirtualHost(VirtualHostConfiguration virtualHostConfiguration) throws Exception
+ {
+ return new VirtualHostImpl(null, mock(StatisticsGatherer.class), new SecurityManager(null), virtualHostConfiguration);
+ }
+
+ public static VirtualHost createVirtualHost(String name, VirtualHostRegistry virtualHostRegistry) throws Exception
+ {
+ VirtualHostConfiguration vhostConfig = createVirtualHostConfiguration(name);
+ return createVirtualHost(vhostConfig, virtualHostRegistry);
+ }
+
+ public static VirtualHost createVirtualHost(String name) throws Exception
+ {
+ VirtualHostConfiguration configuration = createVirtualHostConfiguration(name);
+ return createVirtualHost(configuration);
+ }
+
+ private static VirtualHostConfiguration createVirtualHostConfiguration(String name) throws ConfigurationException
+ {
+ VirtualHostConfiguration vhostConfig = new VirtualHostConfiguration(name, new PropertiesConfiguration(), createBrokerMock());
+ vhostConfig.setMessageStoreClass(TestableMemoryMessageStore.class.getName());
+ return vhostConfig;
+ }
+
+ public static AMQChannel createChannel(int channelId, AMQProtocolSession session) throws AMQException
+ {
+ AMQChannel channel = new AMQChannel(session, channelId, session.getVirtualHost().getMessageStore());
+ session.addChannel(channel);
+ return channel;
+ }
+
+ public static AMQChannel createChannel(int channelId) throws Exception
+ {
+ InternalTestProtocolSession session = createSession();
+ return createChannel(channelId, session);
+ }
+
+ public static AMQChannel createChannel() throws Exception
+ {
+ return createChannel(1);
+ }
+
+ public static InternalTestProtocolSession createSession() throws Exception
+ {
+ return createSession("test");
+ }
+
+ public static InternalTestProtocolSession createSession(String hostName) throws Exception
+ {
+ VirtualHost virtualHost = createVirtualHost(hostName);
+ return new InternalTestProtocolSession(virtualHost, createBrokerMock());
+ }
+
+ public static Exchange createExchange(String hostName) throws Exception
+ {
+ SecurityManager securityManager = new SecurityManager(null);
+ VirtualHost virtualHost = mock(VirtualHost.class);
+ when(virtualHost.getName()).thenReturn(hostName);
+ when(virtualHost.getSecurityManager()).thenReturn(securityManager);
+ DefaultExchangeFactory factory = new DefaultExchangeFactory(virtualHost);
+ return factory.createExchange("amp.direct", "direct", false, false);
+ }
+
+ public static void publishMessages(AMQChannel channel, int numberOfMessages, String queueName, String exchangeName) throws AMQException
+ {
+ AMQShortString rouningKey = new AMQShortString(queueName);
+ AMQShortString exchangeNameAsShortString = new AMQShortString(exchangeName);
+ MessagePublishInfo info = mock(MessagePublishInfo.class);
+ when(info.getExchange()).thenReturn(exchangeNameAsShortString);
+ when(info.getRoutingKey()).thenReturn(rouningKey);
+
+ Exchange exchange = channel.getVirtualHost().getExchangeRegistry().getExchange(exchangeName);
+ for (int count = 0; count < numberOfMessages; count++)
+ {
+ channel.setPublishFrame(info, exchange);
+
+ // Set the body size
+ ContentHeaderBody _headerBody = new ContentHeaderBody();
+ _headerBody.setBodySize(0);
+
+ // Set Minimum properties
+ BasicContentHeaderProperties properties = new BasicContentHeaderProperties();
+
+ properties.setExpiration(0L);
+ properties.setTimestamp(System.currentTimeMillis());
+
+ // Make Message Persistent
+ properties.setDeliveryMode((byte) 2);
+
+ _headerBody.setProperties(properties);
+
+ channel.publishContentHeader(_headerBody);
+ }
+ channel.sync();
+ }
+
+ public static SimpleAMQQueue createQueue(String queueName, VirtualHost virtualHost) throws AMQException
+ {
+ SimpleAMQQueue queue = (SimpleAMQQueue) AMQQueueFactory.createAMQQueueImpl(UUIDGenerator.generateRandomUUID(), queueName, false, null,
+ false, false, virtualHost, Collections.<String, Object>emptyMap());
+ virtualHost.getQueueRegistry().registerQueue(queue);
+ return queue;
+ }
+
+
+}
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/util/InternalBrokerBaseCase.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/util/InternalBrokerBaseCase.java
deleted file mode 100644
index d7a9078412..0000000000
--- a/qpid/java/broker/src/test/java/org/apache/qpid/server/util/InternalBrokerBaseCase.java
+++ /dev/null
@@ -1,372 +0,0 @@
-/*
- *
- * 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.qpid.server.util;
-
-import org.apache.commons.configuration.ConfigurationException;
-import org.apache.commons.configuration.XMLConfiguration;
-
-import org.apache.qpid.AMQException;
-import org.apache.qpid.common.AMQPFilterTypes;
-import org.apache.qpid.exchange.ExchangeDefaults;
-import org.apache.qpid.framing.AMQShortString;
-import org.apache.qpid.framing.BasicContentHeaderProperties;
-import org.apache.qpid.framing.ContentHeaderBody;
-import org.apache.qpid.framing.FieldTable;
-import org.apache.qpid.framing.abstraction.MessagePublishInfo;
-import org.apache.qpid.server.AMQChannel;
-import org.apache.qpid.server.configuration.ServerConfiguration;
-import org.apache.qpid.server.exchange.Exchange;
-import org.apache.qpid.server.logging.SystemOutMessageLogger;
-import org.apache.qpid.server.logging.actors.CurrentActor;
-import org.apache.qpid.server.logging.actors.TestLogActor;
-import org.apache.qpid.server.model.UUIDGenerator;
-import org.apache.qpid.server.protocol.InternalTestProtocolSession;
-import org.apache.qpid.server.queue.AMQQueue;
-import org.apache.qpid.server.queue.AMQQueueFactory;
-import org.apache.qpid.server.registry.ApplicationRegistry;
-import org.apache.qpid.server.registry.IApplicationRegistry;
-import org.apache.qpid.server.store.MessageStore;
-import org.apache.qpid.server.store.TestableMemoryMessageStore;
-import org.apache.qpid.server.virtualhost.VirtualHost;
-import org.apache.qpid.test.utils.QpidTestCase;
-
-
-public class InternalBrokerBaseCase extends QpidTestCase
-{
- private IApplicationRegistry _registry;
- private MessageStore _messageStore;
- private AMQChannel _channel;
- private InternalTestProtocolSession _session;
- private VirtualHost _virtualHost;
- private AMQQueue _queue;
- private AMQShortString QUEUE_NAME;
- private ServerConfiguration _configuration;
- private XMLConfiguration _configXml = new XMLConfiguration();
- private boolean _started = false;
-
- public void setUp() throws Exception
- {
- super.setUp();
-
- _configXml.addProperty("virtualhosts.virtualhost.name", "test");
- _configXml.addProperty("virtualhosts.virtualhost.test.store.class", TestableMemoryMessageStore.class.getName());
-
- _configXml.addProperty("virtualhosts.virtualhost(-1).name", getName());
- _configXml.addProperty("virtualhosts.virtualhost(-1)."+getName()+".store.class", TestableMemoryMessageStore.class.getName());
-
- createBroker();
- }
-
- protected void createBroker() throws Exception
- {
- _started = true;
- CurrentActor.set(new TestLogActor(new SystemOutMessageLogger()));
-
- _configuration = new ServerConfiguration(_configXml);
-
- configure();
-
- _registry = createApplicationRegistry();
- ApplicationRegistry.initialise(_registry);
- _registry.getVirtualHostRegistry().setDefaultVirtualHostName(getName());
- _virtualHost = _registry.getVirtualHostRegistry().getVirtualHost(getName());
-
- QUEUE_NAME = new AMQShortString("test");
- // Create a queue on the test Vhost.. this will aid in diagnosing duff tests
- // as the ExpiredMessage Task will log with the test Name.
- _queue = AMQQueueFactory.createAMQQueueImpl(UUIDGenerator.generateRandomUUID(), QUEUE_NAME.asString(), false, "testowner",
- false, false, _virtualHost, null);
-
- Exchange defaultExchange = _virtualHost.getExchangeRegistry().getDefaultExchange();
- _virtualHost.getBindingFactory().addBinding(QUEUE_NAME.toString(), _queue, defaultExchange, null);
-
- _virtualHost = _registry.getVirtualHostRegistry().getVirtualHost("test");
- _messageStore = _virtualHost.getMessageStore();
-
- _queue = AMQQueueFactory.createAMQQueueImpl(UUIDGenerator.generateRandomUUID(), getName(), false, "testowner",
- false, false, _virtualHost, null);
-
- _virtualHost.getQueueRegistry().registerQueue(_queue);
-
- defaultExchange = _virtualHost.getExchangeRegistry().getDefaultExchange();
-
- _virtualHost.getBindingFactory().addBinding(getName(), _queue, defaultExchange, null);
-
- _session = new InternalTestProtocolSession(_virtualHost);
- CurrentActor.set(_session.getLogActor());
-
- _channel = new AMQChannel(_session, 1, _messageStore);
-
- _session.addChannel(_channel);
- }
-
- protected IApplicationRegistry createApplicationRegistry() throws ConfigurationException
- {
- return new TestApplicationRegistry(_configuration);
- }
-
- protected void configure()
- {
- // Allow other tests to override configuration
- }
-
- protected void stopBroker()
- {
- try
- {
- //Remove the ProtocolSession Actor added during createBroker
- CurrentActor.remove();
- }
- finally
- {
- ApplicationRegistry.remove();
- _started = false;
- }
- }
-
-
- public void tearDown() throws Exception
- {
- try
- {
- if (_started)
- {
- stopBroker();
- }
- }
- finally
- {
- super.tearDown();
- // Purge Any erroneously added actors
- CurrentActor.removeAll();
- }
- }
-
- protected void checkStoreContents(int messageCount)
- {
- assertEquals("Message header count incorrect in the MetaDataMap", messageCount, ((TestableMemoryMessageStore) _messageStore).getMessageCount());
-
- //The above publish message is sufficiently small not to fit in the header so no Body is required.
- //assertEquals("Message body count incorrect in the ContentBodyMap", messageCount, ((TestableMemoryMessageStore) _messageStore).getContentBodyMap().size());
- }
-
- protected AMQShortString subscribe(InternalTestProtocolSession session, AMQChannel channel, AMQQueue queue)
- {
- try
- {
- return channel.subscribeToQueue(null, queue, true, null, false, true);
- }
- catch (AMQException e)
- {
- e.printStackTrace();
- fail(e.getMessage());
- }
-
- //Keep the compiler happy
- return null;
- }
-
- protected AMQShortString browse(AMQChannel channel, AMQQueue queue)
- {
- try
- {
- FieldTable filters = new FieldTable();
- filters.put(AMQPFilterTypes.NO_CONSUME.getValue(), true);
-
- return channel.subscribeToQueue(null, queue, true, filters, false, true);
- }
- catch (AMQException e)
- {
- e.printStackTrace();
- fail(e.getMessage());
- }
-
- //Keep the compiler happy
- return null;
- }
-
- public void publishMessages(InternalTestProtocolSession session, AMQChannel channel, int messages) throws AMQException
- {
- MessagePublishInfo info = new MessagePublishInfo()
- {
- public AMQShortString getExchange()
- {
- return ExchangeDefaults.DEFAULT_EXCHANGE_NAME;
- }
-
- public void setExchange(AMQShortString exchange)
- {
-
- }
-
- public boolean isImmediate()
- {
- return false;
- }
-
- public boolean isMandatory()
- {
- return false;
- }
-
- public AMQShortString getRoutingKey()
- {
- return new AMQShortString(getName());
- }
- };
-
- for (int count = 0; count < messages; count++)
- {
- channel.setPublishFrame(info, _virtualHost.getExchangeRegistry().getExchange(info.getExchange()));
-
- //Set the body size
- ContentHeaderBody _headerBody = new ContentHeaderBody();
- _headerBody.setBodySize(0);
-
- //Set Minimum properties
- BasicContentHeaderProperties properties = new BasicContentHeaderProperties();
-
- properties.setExpiration(0L);
- properties.setTimestamp(System.currentTimeMillis());
-
- //Make Message Persistent
- properties.setDeliveryMode((byte) 2);
-
- _headerBody.setProperties(properties);
-
- channel.publishContentHeader(_headerBody);
- }
- channel.sync();
- }
-
- public void acknowledge(AMQChannel channel, long deliveryTag)
- {
- try
- {
- channel.acknowledgeMessage(deliveryTag, false);
- }
- catch (AMQException e)
- {
- e.printStackTrace();
- fail(e.getMessage());
- }
- }
-
- public IApplicationRegistry getRegistry()
- {
- return _registry;
- }
-
- public void setRegistry(IApplicationRegistry registry)
- {
- _registry = registry;
- }
-
- public MessageStore getMessageStore()
- {
- return _messageStore;
- }
-
- public void setMessageStore(MessageStore messageStore)
- {
- _messageStore = messageStore;
- }
-
- public AMQChannel getChannel()
- {
- return _channel;
- }
-
- public void setChannel(AMQChannel channel)
- {
- _channel = channel;
- }
-
- public InternalTestProtocolSession getSession()
- {
- return _session;
- }
-
- public void setSession(InternalTestProtocolSession session)
- {
- _session = session;
- }
-
- public VirtualHost getVirtualHost()
- {
- return _virtualHost;
- }
-
- public void setVirtualHost(VirtualHost virtualHost)
- {
- _virtualHost = virtualHost;
- }
-
- public AMQQueue getQueue()
- {
- return _queue;
- }
-
- public void setQueue(AMQQueue queue)
- {
- _queue = queue;
- }
-
- public AMQShortString getQUEUE_NAME()
- {
- return QUEUE_NAME;
- }
-
- public void setQUEUE_NAME(AMQShortString QUEUE_NAME)
- {
- this.QUEUE_NAME = QUEUE_NAME;
- }
-
- public ServerConfiguration getConfiguration()
- {
- return _configuration;
- }
-
- public void setConfiguration(ServerConfiguration configuration)
- {
- _configuration = configuration;
- }
-
- public XMLConfiguration getConfigXml()
- {
- return _configXml;
- }
-
- public void setConfigXml(XMLConfiguration configXml)
- {
- _configXml = configXml;
- }
-
- public boolean isStarted()
- {
- return _started;
- }
-
- public void setStarted(boolean started)
- {
- _started = started;
- }
-}
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/util/TestApplicationRegistry.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/util/TestApplicationRegistry.java
deleted file mode 100644
index fd3791a8e1..0000000000
--- a/qpid/java/broker/src/test/java/org/apache/qpid/server/util/TestApplicationRegistry.java
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- *
- * 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.qpid.server.util;
-
-import java.net.SocketAddress;
-import java.util.Collections;
-import java.util.Map;
-import org.apache.commons.configuration.ConfigurationException;
-
-import org.apache.qpid.server.configuration.ServerConfiguration;
-import org.apache.qpid.server.logging.NullRootMessageLogger;
-import org.apache.qpid.server.logging.actors.BrokerActor;
-import org.apache.qpid.server.logging.actors.CurrentActor;
-import org.apache.qpid.server.logging.actors.GenericActor;
-import org.apache.qpid.server.logging.log4j.LoggingManagementFacade;
-import org.apache.qpid.server.registry.ApplicationRegistry;
-import org.apache.qpid.server.security.SubjectCreator;
-import org.apache.qpid.server.security.auth.database.PropertiesPrincipalDatabase;
-import org.apache.qpid.server.security.auth.manager.AuthenticationManager;
-import org.apache.qpid.server.security.auth.manager.IAuthenticationManagerRegistry;
-import org.apache.qpid.server.security.auth.manager.PrincipalDatabaseAuthenticationManager;
-import org.apache.qpid.server.security.group.GroupPrincipalAccessor;
-import org.apache.qpid.test.utils.QpidTestCase;
-
-import java.util.Properties;
-
-public class TestApplicationRegistry extends ApplicationRegistry
-{
-
- public TestApplicationRegistry(ServerConfiguration config) throws ConfigurationException
- {
- super(config);
- }
-
- @Override
- public void initialise() throws Exception
- {
- CurrentActor.setDefault(new BrokerActor(new NullRootMessageLogger()));
- GenericActor.setDefaultMessageLogger(new NullRootMessageLogger());
- LoggingManagementFacade.configure(QpidTestCase.LOG4J_CONFIG_FILE_PATH);
-
- super.initialise();
- }
-
- @Override
- protected IAuthenticationManagerRegistry createAuthenticationManagerRegistry(
- ServerConfiguration configuration, final GroupPrincipalAccessor groupPrincipalAccessor)
- throws ConfigurationException
- {
- final Properties users = new Properties();
- users.put("guest","guest");
- users.put("admin","admin");
-
- final PropertiesPrincipalDatabase ppd = new PropertiesPrincipalDatabase(users);
-
- final AuthenticationManager pdam = new PrincipalDatabaseAuthenticationManager(ppd);
- pdam.initialise();
-
- return new IAuthenticationManagerRegistry()
- {
- @Override
- public void close()
- {
- pdam.close();
- }
-
- @Override
- public SubjectCreator getSubjectCreator(SocketAddress address)
- {
- return new SubjectCreator(pdam, groupPrincipalAccessor);
- }
-
- @Override
- public Map<String, AuthenticationManager> getAvailableAuthenticationManagers()
- {
- return Collections.singletonMap(pdam.getClass().getName(), pdam);
- }
-
- @Override
- public void addRegistryChangeListener(RegistryChangeListener listener)
- {
- }
- };
- }
-}
-
-
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/virtualhost/MockVirtualHost.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/virtualhost/MockVirtualHost.java
index 5e02fda40b..1d99d99820 100644
--- a/qpid/java/broker/src/test/java/org/apache/qpid/server/virtualhost/MockVirtualHost.java
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/virtualhost/MockVirtualHost.java
@@ -28,14 +28,12 @@ import org.apache.qpid.server.exchange.ExchangeFactory;
import org.apache.qpid.server.exchange.ExchangeRegistry;
import org.apache.qpid.server.protocol.v1_0.LinkRegistry;
import org.apache.qpid.server.queue.QueueRegistry;
-import org.apache.qpid.server.registry.IApplicationRegistry;
import org.apache.qpid.server.security.SecurityManager;
import org.apache.qpid.server.security.auth.manager.AuthenticationManager;
import org.apache.qpid.server.stats.StatisticsCounter;
import org.apache.qpid.server.store.MessageStore;
import org.apache.qpid.server.txn.DtxRegistry;
-import java.util.Map;
import java.util.UUID;
public class MockVirtualHost implements VirtualHost
@@ -52,7 +50,8 @@ public class MockVirtualHost implements VirtualHost
}
- public IApplicationRegistry getApplicationRegistry()
+ @Override
+ public VirtualHostRegistry getVirtualHostRegistry()
{
return null;
}
@@ -67,11 +66,6 @@ public class MockVirtualHost implements VirtualHost
return null;
}
- public UUID getBrokerId()
- {
- return null;
- }
-
public DtxRegistry getDtxRegistry()
{
return null;
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/virtualhost/VirtualHostImplTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/virtualhost/VirtualHostImplTest.java
index b8ba76e43d..559a7f8aaf 100644
--- a/qpid/java/broker/src/test/java/org/apache/qpid/server/virtualhost/VirtualHostImplTest.java
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/virtualhost/VirtualHostImplTest.java
@@ -20,15 +20,21 @@
*/
package org.apache.qpid.server.virtualhost;
+import static org.mockito.Mockito.mock;
+
+import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.ConfigurationException;
-import org.apache.commons.configuration.XMLConfiguration;
+import org.apache.commons.configuration.PropertiesConfiguration;
+
+import org.apache.qpid.server.configuration.VirtualHostConfiguration;
-import org.apache.qpid.server.configuration.ServerConfiguration;
import org.apache.qpid.server.exchange.Exchange;
+import org.apache.qpid.server.model.Broker;
import org.apache.qpid.server.queue.AMQQueue;
-import org.apache.qpid.server.registry.ApplicationRegistry;
+import org.apache.qpid.server.security.SecurityManager;
+import org.apache.qpid.server.stats.StatisticsGatherer;
import org.apache.qpid.server.store.MemoryMessageStore;
-import org.apache.qpid.server.util.TestApplicationRegistry;
+import org.apache.qpid.server.util.BrokerTestHelper;
import org.apache.qpid.test.utils.QpidTestCase;
import java.io.BufferedWriter;
@@ -38,15 +44,31 @@ import java.io.IOException;
public class VirtualHostImplTest extends QpidTestCase
{
- private ServerConfiguration _configuration;
- private ApplicationRegistry _registry;
+ private VirtualHostRegistry _virtualHostRegistry;
+
+ @Override
+ public void setUp() throws Exception
+ {
+ super.setUp();
+ BrokerTestHelper.setUp();
+ }
@Override
public void tearDown() throws Exception
{
- super.tearDown();
+ try
+ {
+ if (_virtualHostRegistry != null)
+ {
+ _virtualHostRegistry.close();
+ }
+ }
+ finally
+ {
+ BrokerTestHelper.tearDown();
+ super.tearDown();
+ }
- ApplicationRegistry.remove();
}
/**
@@ -74,17 +96,23 @@ public class VirtualHostImplTest extends QpidTestCase
*/
public void testSpecifyingCustomBindingForDefaultExchangeThrowsException() throws Exception
{
- File config = writeConfigFile(getName(), getName(), null, false, new String[]{"custom-binding"});
+ final String queueName = getName();
+ final String customBinding = "custom-binding";
+ File config = writeConfigFile(queueName, queueName, null, false, new String[]{customBinding});
try
{
- createVirtualHost(getName(), config);
+ createVirtualHost(queueName, config);
fail("virtualhost creation should have failed due to illegal configuration");
}
catch (RuntimeException e)
{
+ assertNotNull(e.getCause());
+
assertEquals(ConfigurationException.class, e.getCause().getClass());
- //expected
+
+ Throwable configException = e.getCause();
+ assertEquals("Illegal attempt to bind queue '" + queueName + "' to the default exchange with a key other than the queue name: " + customBinding, configException.getMessage());
}
}
@@ -96,6 +124,14 @@ public class VirtualHostImplTest extends QpidTestCase
assertEquals(State.ACTIVE, vhost.getState());
}
+ public void testVirtualHostHavingStoreSetAsTypeBecomesActive() throws Exception
+ {
+ String virtualHostName = getName();
+ VirtualHost host = createVirtualHostUsingStoreType(virtualHostName);
+ assertNotNull(host);
+ assertEquals(State.ACTIVE, host.getState());
+ }
+
public void testVirtualHostBecomesStoppedOnClose() throws Exception
{
File config = writeConfigFile(getName(), getName(), getName() +".direct", false, new String[0]);
@@ -107,22 +143,39 @@ public class VirtualHostImplTest extends QpidTestCase
assertEquals(0, vhost.getHouseKeepingActiveCount());
}
+ public void testVirtualHostHavingStoreSetAsTypeBecomesStoppedOnClose() throws Exception
+ {
+ String virtualHostName = getName();
+ VirtualHost host = createVirtualHostUsingStoreType(virtualHostName);
+ assertNotNull(host);
+ assertEquals(State.ACTIVE, host.getState());
+ host.close();
+ assertEquals(State.STOPPED, host.getState());
+ assertEquals(0, host.getHouseKeepingActiveCount());
+ }
+
/**
* Tests that specifying an unknown exchange to bind the queue to results in failure to create the vhost
*/
public void testSpecifyingUnknownExchangeThrowsException() throws Exception
{
- File config = writeConfigFile(getName(), getName(), "made-up-exchange", true, new String[0]);
+ final String queueName = getName();
+ final String exchangeName = "made-up-exchange";
+ File config = writeConfigFile(queueName, queueName, exchangeName, true, new String[0]);
try
{
- createVirtualHost(getName(), config);
+ createVirtualHost(queueName, config);
fail("virtualhost creation should have failed due to illegal configuration");
}
catch (RuntimeException e)
{
+ assertNotNull(e.getCause());
+
assertEquals(ConfigurationException.class, e.getCause().getClass());
- //expected
+
+ Throwable configException = e.getCause();
+ assertEquals("Attempt to bind queue '" + queueName + "' to unknown exchange:" + exchangeName, configException.getMessage());
}
}
@@ -154,12 +207,14 @@ public class VirtualHostImplTest extends QpidTestCase
private VirtualHost createVirtualHost(String vhostName, File config) throws Exception
{
- _configuration = new ServerConfiguration(new XMLConfiguration(config));
+ Broker broker = BrokerTestHelper.createBrokerMock();
+ _virtualHostRegistry = broker.getVirtualHostRegistry();
- _registry = new TestApplicationRegistry(_configuration);
- ApplicationRegistry.initialise(_registry);
+ VirtualHostConfiguration configuration = new VirtualHostConfiguration(vhostName, config, broker);
+ VirtualHost host = new VirtualHostImpl(_virtualHostRegistry, mock(StatisticsGatherer.class), new SecurityManager(null), configuration);
+ _virtualHostRegistry.registerVirtualHost(host);
- return _registry.getVirtualHostRegistry().getVirtualHost(vhostName);
+ return host;
}
/**
@@ -184,7 +239,6 @@ public class VirtualHostImplTest extends QpidTestCase
BufferedWriter writer = new BufferedWriter(fstream);
//extra outer tag to please Commons Configuration
- writer.write("<configuration>");
writer.write("<virtualhosts>");
writer.write(" <default>" + vhostName + "</default>");
@@ -222,8 +276,6 @@ public class VirtualHostImplTest extends QpidTestCase
writer.write(" </virtualhost>");
writer.write("</virtualhosts>");
- writer.write("</configuration>");
-
writer.flush();
writer.close();
}
@@ -234,4 +286,17 @@ public class VirtualHostImplTest extends QpidTestCase
return tmpFile;
}
+
+ private VirtualHost createVirtualHostUsingStoreType(String virtualHostName) throws ConfigurationException, Exception
+ {
+ Broker broker = BrokerTestHelper.createBrokerMock();
+ _virtualHostRegistry = broker.getVirtualHostRegistry();
+
+ Configuration config = new PropertiesConfiguration();
+ config.setProperty("store.type", MemoryMessageStore.TYPE);
+ VirtualHostConfiguration configuration = new VirtualHostConfiguration(virtualHostName, config, broker);
+ VirtualHost host = new VirtualHostImpl(_virtualHostRegistry, mock(StatisticsGatherer.class), new SecurityManager(null), configuration);
+ _virtualHostRegistry.registerVirtualHost(host);
+ return host;
+ }
}
diff --git a/qpid/java/broker/src/velocity/templates/org/apache/qpid/server/logging/messages/LogMessages.vm b/qpid/java/broker/src/velocity/templates/org/apache/qpid/server/logging/messages/LogMessages.vm
index 02bf155c44..cddfcfb581 100644
--- a/qpid/java/broker/src/velocity/templates/org/apache/qpid/server/logging/messages/LogMessages.vm
+++ b/qpid/java/broker/src/velocity/templates/org/apache/qpid/server/logging/messages/LogMessages.vm
@@ -23,8 +23,8 @@ package ${package};
import static org.apache.qpid.server.logging.AbstractRootMessageLogger.DEFAULT_LOG_HIERARCHY_PREFIX;
import org.apache.log4j.Logger;
+import org.apache.qpid.server.configuration.BrokerProperties;
import org.apache.qpid.server.logging.LogMessage;
-import org.apache.qpid.server.registry.ApplicationRegistry;
import java.text.MessageFormat;
import java.util.Locale;
@@ -44,7 +44,7 @@ import java.util.ResourceBundle;
public class ${type.name}Messages
{
private static ResourceBundle _messages;
- private static Locale _currentLocale;
+ private static Locale _currentLocale = BrokerProperties.getLocale();
public static final String ${type.name.toUpperCase()}_LOG_HIERARCHY = DEFAULT_LOG_HIERARCHY_PREFIX + "${type.name.toLowerCase()}";
#foreach( $message in ${type.list} )
@@ -58,24 +58,9 @@ public class ${type.name}Messages
Logger.getLogger(${message.methodName.toUpperCase()}_LOG_HIERARCHY);
#end
- reload();
- }
-
- public static void reload()
- {
- if (ApplicationRegistry.isConfigured())
- {
- _currentLocale = ApplicationRegistry.getInstance().getConfiguration().getLocale();
- }
- else
- {
- _currentLocale = Locale.getDefault();
- }
-
_messages = ResourceBundle.getBundle("${resource}", _currentLocale);
}
-
##
## The list stored under key 'list' in the 'type' HashMap contains all the
## log messages that this class should contain. So for each entry in the list
diff --git a/qpid/java/common/src/main/java/org/apache/qpid/transport/NetworkTransportConfiguration.java b/qpid/java/common/src/main/java/org/apache/qpid/transport/NetworkTransportConfiguration.java
index 20d6f98fa6..12f8d801dc 100644
--- a/qpid/java/common/src/main/java/org/apache/qpid/transport/NetworkTransportConfiguration.java
+++ b/qpid/java/common/src/main/java/org/apache/qpid/transport/NetworkTransportConfiguration.java
@@ -38,14 +38,6 @@ public interface NetworkTransportConfiguration
// The amount of memory in bytes to allocate to the outgoing buffer
Integer getSendBufferSize();
- Integer getPort();
-
- String getHost();
-
- String getTransport();
-
- Integer getConnectorProcessors();
-
InetSocketAddress getAddress();
boolean needClientAuth();
diff --git a/qpid/java/common/src/main/java/org/apache/qpid/transport/network/io/IoNetworkTransport.java b/qpid/java/common/src/main/java/org/apache/qpid/transport/network/io/IoNetworkTransport.java
index 3f1cd3519b..c8027e143e 100644
--- a/qpid/java/common/src/main/java/org/apache/qpid/transport/network/io/IoNetworkTransport.java
+++ b/qpid/java/common/src/main/java/org/apache/qpid/transport/network/io/IoNetworkTransport.java
@@ -258,14 +258,14 @@ public class IoNetworkTransport implements OutgoingNetworkTransport, IncomingNet
}
catch(RuntimeException e)
{
- LOGGER.error("Error in Acceptor thread on port " + _config.getPort(), e);
+ LOGGER.error("Error in Acceptor thread on address " + _config.getAddress(), e);
closeSocketIfNecessary(socket);
}
catch(IOException e)
{
if(!_closed)
{
- LOGGER.error("Error in Acceptor thread on port " + _config.getPort(), e);
+ LOGGER.error("Error in Acceptor thread on address " + _config.getAddress(), e);
closeSocketIfNecessary(socket);
try
{
@@ -285,7 +285,7 @@ public class IoNetworkTransport implements OutgoingNetworkTransport, IncomingNet
{
if(LOGGER.isDebugEnabled())
{
- LOGGER.debug("Acceptor exiting, no new connections will be accepted on port " + _config.getPort());
+ LOGGER.debug("Acceptor exiting, no new connections will be accepted on address " + _config.getAddress());
}
}
}
diff --git a/qpid/java/common/src/test/java/org/apache/qpid/test/utils/QpidTestCase.java b/qpid/java/common/src/test/java/org/apache/qpid/test/utils/QpidTestCase.java
index c16e42eb7c..08f7387b75 100644
--- a/qpid/java/common/src/test/java/org/apache/qpid/test/utils/QpidTestCase.java
+++ b/qpid/java/common/src/test/java/org/apache/qpid/test/utils/QpidTestCase.java
@@ -116,12 +116,7 @@ public class QpidTestCase extends TestCase
public QpidTestCase()
{
- this("QpidTestCase");
- }
-
- public QpidTestCase(String name)
- {
- super(name);
+ super();
}
public void run(TestResult testResult)
diff --git a/qpid/java/common/src/test/java/org/apache/qpid/test/utils/TestFileUtils.java b/qpid/java/common/src/test/java/org/apache/qpid/test/utils/TestFileUtils.java
index d77049c780..14dec8efad 100644
--- a/qpid/java/common/src/test/java/org/apache/qpid/test/utils/TestFileUtils.java
+++ b/qpid/java/common/src/test/java/org/apache/qpid/test/utils/TestFileUtils.java
@@ -24,6 +24,8 @@ import java.io.File;
import java.io.IOException;
import java.io.InputStream;
+import java.io.FileOutputStream;
+
import junit.framework.TestCase;
import org.apache.qpid.util.FileUtils;
@@ -110,4 +112,42 @@ public class TestFileUtils
dst.deleteOnExit();
return dst;
}
+
+ /**
+ * Creates a temporary file for given test with given suffix in file name.
+ * The given content is stored in the file using UTF-8 encoding.
+ */
+ public static File createTempFile(TestCase testcase, String suffix, String content)
+ {
+ File file = createTempFile(testcase, suffix);
+ if (content != null)
+ {
+ FileOutputStream fos = null;
+ try
+ {
+ fos = new FileOutputStream(file);
+ fos.write(content.getBytes("UTF-8"));
+ fos.flush();
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Cannot add the content into temp file " + file.getAbsolutePath(), e);
+ }
+ finally
+ {
+ if (fos != null)
+ {
+ try
+ {
+ fos.close();
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException("Cannot close output stream into temp file " + file.getAbsolutePath(), e);
+ }
+ }
+ }
+ }
+ return file;
+ }
}
diff --git a/qpid/java/module.xml b/qpid/java/module.xml
index 00c6d73959..9146403d04 100644
--- a/qpid/java/module.xml
+++ b/qpid/java/module.xml
@@ -48,15 +48,17 @@
<property name="module.api" location="${build.api}/${module}/"/>
<property name="module.test.api" location="${build.test.api}/${module}"/>
<property name="module.test.classes" location="${module.build}/test/classes"/>
- <property name="module.test.resources" location="${module.build}/test/resources"/>
+ <property name="module.test.resources" location="src/test/resources"/>
<property name="module.results" location="${build.results}/${module}"/>
<property name="module.failed" location="${module.results}/FAILED"/>
<property name="module.src" location="src/main/java"/>
<property name="module.test.src" location="src/test/java"/>
<property name="module.bin" location="bin"/>
<property name="module.etc" location="etc"/>
+
+ <property name="module.src.resources" location="src/main/resources"/>
+ <property name="module.src.resources.metainf" location="${module.src.resources}/META-INF"/>
<property name="module.resources.dir" location="resources/"/>
- <property name="module.src.resources.metainf" location="src/main/resources/META-INF"/>
<property name="module.metainf" location="${module.build}/META-INF"/>
<property name="module.namever" value="${project.name}-${module.name}-${project.version}"/>
@@ -86,6 +88,8 @@
<available property="module.test.src.exists" file="${module.test.src}"/>
<available property="module.etc.exists" file="${module.etc}"/>
<available property="module.bin.exists" file="${module.bin}"/>
+ <available property="module.src.resources.exists" file="${module.src.resources}"/>
+ <available property="module.test.src.resources.exists" file="${module.test.resources}"/>
<available property="module.src.resources.metainf.exists" file="${module.src.resources.metainf}"/>
<available property="module.resources.dir.exists" file="${module.resources.dir}"/>
@@ -197,7 +201,6 @@
<path refid="module.runtime.class.path"/>
<pathelement path="${module.test.depends.jars.path}"/>
<path refid="module.test.libs"/>
- <pathelement path="${module.test.resources}"/>
</path>
<!-- used to run the tests -->
@@ -206,7 +209,6 @@
<path refid="module.runtime.class.path"/>
<pathelement path="${module.test.depends.jars.path}"/>
<path refid="module.test.libs"/>
- <pathelement path="${module.test.resources}"/>
</path>
<property name="javac.deprecation" value="off"/>
@@ -331,6 +333,13 @@
<target name="precompile-tests" if="module.test.src.exists"/>
+ <target name="copy-test-resources" if="module.test.src.resources.exists">
+ <echo message="Copying test resources from ${module.test.resources} to ${module.test.classes}..."/>
+ <copy todir="${module.test.classes}" failonerror="true">
+ <fileset dir="${module.test.resources}"/>
+ </copy>
+ </target>
+
<target name="compile-tests" depends="compile,precompile-tests" if="module.test.src.exists"
description="compilte unit tests">
<javac target="${java.target}" source="${java.source}"
@@ -391,6 +400,7 @@
<propertyref prefix="profile"/>
<propertyref prefix="javax.net.ssl"/>
<propertyref prefix="broker"/>
+ <propertyref prefix="qpid"/>
<propertyref name="amqj.logging.level"/>
<propertyref name="amqj.server.logging.level"/>
@@ -404,11 +414,8 @@
<propertyref name="java.naming.factory.initial"/>
<propertyref name="java.naming.provider.url"/>
<propertyref name="messagestore.class.name" />
- <propertyref name="qpid.amqp.version"/>
<propertyref name="max_prefetch"/>
- <propertyref name="qpid.dest_syntax"/>
- <propertyref name="test.output"/>
<propertyref name="QPID_HOME"/>
<propertyref name="QPID_WORK"/>
<propertyref name="example.plugin.target"/>
@@ -498,13 +505,13 @@
<target name="build" depends="jar,jar-tests,jar-sources,libs,copy-bin,copy-etc,postbuild,copy-broker-plugin-jars" description="compile and copy resources into build tree"/>
- <target name="jar.manifest" depends="compile,copy-files-to-module-metainf" if="module.manifest">
+ <target name="jar.manifest" depends="compile,copy-resources,copy-files-to-module-metainf" if="module.manifest">
<jar destfile="${module.jar}" basedir="${module.classes}" manifest="${module.manifest}">
<metainf dir="${module.metainf}" />
</jar>
</target>
- <target name="jar.nomanifest" depends="compile,copy-files-to-module-metainf" unless="module.manifest">
+ <target name="jar.nomanifest" depends="compile,copy-resources,copy-files-to-module-metainf" unless="module.manifest">
<jar destfile="${module.jar}" basedir="${module.classes}">
<metainf dir="${module.metainf}" />
</jar>
@@ -522,6 +529,13 @@
</copy>
</target>
+ <target name="copy-resources" if="module.src.resources.exists">
+ <echo message="Copying resources from ${module.src.resources} to ${module.classes}..."/>
+ <copy todir="${module.classes}" failonerror="true">
+ <fileset dir="${module.src.resources}" excludes="META-INF/**"/>
+ </copy>
+ </target>
+
<target name="copy-module-resources-metainf" if="module.resources.dir.exists">
<copy todir="${module.metainf}" failonerror="false" overwrite="true">
<fileset dir="${module.resources.dir}"/>
@@ -536,7 +550,7 @@
<target name="jar" depends="jar.manifest,jar.nomanifest" description="create jar"/>
- <target name="jar-tests" depends="compile-tests" description="create unit test jar">
+ <target name="jar-tests" depends="compile-tests, copy-test-resources" description="create unit test jar">
<jar destfile="${module.test.jar}" basedir="${module.test.classes}"/>
</target>
diff --git a/qpid/java/systests/etc/config-systests-bdb-settings.xml b/qpid/java/systests/etc/config-systests-bdb-settings.xml
deleted file mode 100644
index 4fa69d0abc..0000000000
--- a/qpid/java/systests/etc/config-systests-bdb-settings.xml
+++ /dev/null
@@ -1,26 +0,0 @@
-<?xml version="1.0" encoding="ISO-8859-1"?>
-<!--
- -
- - 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.
- -
- -->
-<broker>
- <virtualhosts>${QPID_HOME}/etc/virtualhosts-systests-bdb.xml</virtualhosts>
-</broker>
-
-
diff --git a/qpid/java/systests/etc/config-systests-bdb.xml b/qpid/java/systests/etc/config-systests-bdb.xml
deleted file mode 100644
index 6b17b564a8..0000000000
--- a/qpid/java/systests/etc/config-systests-bdb.xml
+++ /dev/null
@@ -1,29 +0,0 @@
-<?xml version="1.0" encoding="ISO-8859-1"?>
-<!--
- -
- - 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.
- -
- -->
-<configuration>
- <system/>
- <override>
- <xml fileName="${QPID_HOME}/${test.config}" optional="true"/>
- <xml fileName="${QPID_HOME}/etc/config-systests-bdb-settings.xml"/>
- <xml fileName="${QPID_HOME}/etc/config-systests-settings.xml"/>
- </override>
-</configuration>
diff --git a/qpid/java/systests/etc/config-systests-derby-mem-settings.xml b/qpid/java/systests/etc/config-systests-derby-mem-settings.xml
deleted file mode 100644
index 69369d9ac9..0000000000
--- a/qpid/java/systests/etc/config-systests-derby-mem-settings.xml
+++ /dev/null
@@ -1,26 +0,0 @@
-<?xml version="1.0" encoding="ISO-8859-1"?>
-<!--
- -
- - 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.
- -
- -->
-<broker>
- <virtualhosts>${QPID_HOME}/etc/virtualhosts-systests-derby-mem.xml</virtualhosts>
-</broker>
-
-
diff --git a/qpid/java/systests/etc/config-systests-derby-mem.xml b/qpid/java/systests/etc/config-systests-derby-mem.xml
deleted file mode 100644
index 8e40df986e..0000000000
--- a/qpid/java/systests/etc/config-systests-derby-mem.xml
+++ /dev/null
@@ -1,29 +0,0 @@
-<?xml version="1.0" encoding="ISO-8859-1"?>
-<!--
- -
- - 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.
- -
- -->
-<configuration>
- <system/>
- <override>
- <xml fileName="${QPID_HOME}/${test.config}" optional="true"/>
- <xml fileName="${QPID_HOME}/etc/config-systests-derby-mem-settings.xml"/>
- <xml fileName="${QPID_HOME}/etc/config-systests-settings.xml"/>
- </override>
-</configuration>
diff --git a/qpid/java/systests/etc/config-systests-derby-settings.xml b/qpid/java/systests/etc/config-systests-derby-settings.xml
deleted file mode 100644
index 3ed3a9e33b..0000000000
--- a/qpid/java/systests/etc/config-systests-derby-settings.xml
+++ /dev/null
@@ -1,26 +0,0 @@
-<?xml version="1.0" encoding="ISO-8859-1"?>
-<!--
- -
- - 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.
- -
- -->
-<broker>
- <virtualhosts>${QPID_HOME}/etc/virtualhosts-systests-derby.xml</virtualhosts>
-</broker>
-
-
diff --git a/qpid/java/systests/etc/config-systests-derby.xml b/qpid/java/systests/etc/config-systests-derby.xml
deleted file mode 100644
index 21a7a8cabe..0000000000
--- a/qpid/java/systests/etc/config-systests-derby.xml
+++ /dev/null
@@ -1,29 +0,0 @@
-<?xml version="1.0" encoding="ISO-8859-1"?>
-<!--
- -
- - 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.
- -
- -->
-<configuration>
- <system/>
- <override>
- <xml fileName="${QPID_HOME}/${test.config}" optional="true"/>
- <xml fileName="${QPID_HOME}/etc/config-systests-derby-settings.xml"/>
- <xml fileName="${QPID_HOME}/etc/config-systests-settings.xml"/>
- </override>
-</configuration>
diff --git a/qpid/java/systests/etc/config-systests-settings.xml b/qpid/java/systests/etc/config-systests-settings.xml
deleted file mode 100644
index b5a97d44a3..0000000000
--- a/qpid/java/systests/etc/config-systests-settings.xml
+++ /dev/null
@@ -1,102 +0,0 @@
-<?xml version="1.0" encoding="ISO-8859-1"?>
-<!--
- -
- - 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.
- -
- -->
-<broker>
- <prefix>${QPID_HOME}</prefix>
- <work>${QPID_WORK}</work>
- <conf>${prefix}/etc</conf>
-
- <connector>
- <!-- To enable SSL edit the keystorePath and keystorePassword
- and set enabled to true.
- To disable Non-SSL port set sslOnly to true -->
- <ssl>
- <port>15671</port>
- <enabled>false</enabled>
- <sslOnly>false</sslOnly>
- <keyStorePath>${QPID_HOME}/../test-profiles/test_resources/ssl/java_broker_keystore.jks</keyStorePath>
- <keyStorePassword>password</keyStorePassword>
- </ssl>
- <port>5672</port>
- <socketReceiveBuffer>262144</socketReceiveBuffer>
- <socketSendBuffer>262144</socketSendBuffer>
- </connector>
- <management>
- <enabled>false</enabled>
- <jmxport>
- <registryServer>8999</registryServer>
- <!--
- If unspecified, connectorServer defaults to 100 + registryServer port.
- <connectorServer>9099</connectionServer>
- -->
- </jmxport>
- <ssl>
- <enabled>false</enabled>
- <keyStorePath>${QPID_HOME}/../test-profiles/test_resources/ssl/java_broker_keystore.jks</keyStorePath>
- <keyStorePassword>password</keyStorePassword>
- </ssl>
- <http>
- <enabled>false</enabled>
- </http>
- </management>
- <advanced>
- <framesize>65535</framesize>
- <locale>en_US</locale>
- </advanced>
-
- <security>
- <pd-auth-manager>
- <principal-database>
- <class>org.apache.qpid.server.security.auth.database.PlainPasswordFilePrincipalDatabase</class>
- <attributes>
- <attribute>
- <name>passwordFile</name>
- <value>${conf}/passwd</value>
- </attribute>
- </attributes>
- </principal-database>
- </pd-auth-manager>
-
- <file-group-manager>
- <attributes>
- <attribute>
- <name>groupFile</name>
- <value>${conf}/groups-systests</value>
- </attribute>
- </attributes>
- </file-group-manager>
-
- <msg-auth>false</msg-auth>
- </security>
-
- <virtualhosts>${QPID_HOME}/etc/virtualhosts-systests.xml</virtualhosts>
-
- <heartbeat>
- <delay>0</delay>
- <timeoutFactor>2.0</timeoutFactor>
- </heartbeat>
- <queue>
- <auto_register>true</auto_register>
- </queue>
-
- <status-updates>ON</status-updates>
-
-</broker>
diff --git a/qpid/java/systests/etc/config-systests.json b/qpid/java/systests/etc/config-systests.json
new file mode 100644
index 0000000000..a5b85a2050
--- /dev/null
+++ b/qpid/java/systests/etc/config-systests.json
@@ -0,0 +1,64 @@
+/*
+ *
+ * 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.
+ *
+ */
+{
+ "name": "QpidBroker",
+ "defaultAuthenticationProvider" : "plain",
+ "defaultVirtualHost" : "test",
+ "keyStorePath": "${QPID_HOME}/../test-profiles/test_resources/ssl/java_broker_keystore.jks",
+ "keyStorePassword": "password",
+ "trustStorePath": "${QPID_HOME}/../test-profiles/test_resources/ssl/java_client_truststore.jks",
+ "trustStorePassword": "password",
+ "authenticationproviders" : [ {
+ "name" : "plain",
+ "authenticationProviderType" : "PlainPasswordFileAuthenticationProvider",
+ "path" : "${QPID_HOME}/etc/passwd"
+ } ],
+ "ports" : [ {
+ "name" : "amqp",
+ "port" : "${test.port}"
+ }, {
+ "name" : "http",
+ "port" : "${test.hport}",
+ "protocols" : [ "HTTP" ]
+ }, {
+ "name" : "rmi",
+ "port" : "${test.mport}",
+ "protocols" : [ "RMI" ]
+ }, {
+ "name" : "jmx",
+ "port" : "${test.cport}",
+ "protocols" : [ "JMX_RMI" ]
+ }],
+ "virtualhosts" : [ {
+ "name" : "test",
+ "configPath" : "${broker.virtualhosts-config}"
+ } ]
+ /*
+,
+ "plugins" : [ {
+ "pluginType" : "MANAGEMENT-HTTP",
+ "name" : "httpManagement"
+ }, {
+ "pluginType" : "MANAGEMENT-JMX",
+ "name" : "jmxManagement"
+ } ]
+ */
+} \ No newline at end of file
diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/client/failover/MultipleBrokersFailoverTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/client/failover/MultipleBrokersFailoverTest.java
index 0e55557806..a0fd093bfe 100644
--- a/qpid/java/systests/src/main/java/org/apache/qpid/client/failover/MultipleBrokersFailoverTest.java
+++ b/qpid/java/systests/src/main/java/org/apache/qpid/client/failover/MultipleBrokersFailoverTest.java
@@ -20,7 +20,6 @@
*/
package org.apache.qpid.client.failover;
-import java.net.InetSocketAddress;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
@@ -33,16 +32,12 @@ import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage;
-import org.apache.commons.configuration.XMLConfiguration;
import org.apache.log4j.Logger;
-import org.apache.qpid.client.AMQBrokerDetails;
import org.apache.qpid.client.AMQConnection;
import org.apache.qpid.client.AMQConnectionURL;
import org.apache.qpid.jms.ConnectionListener;
-import org.apache.qpid.server.store.MessageStoreConstants;
import org.apache.qpid.test.utils.QpidBrokerTestCase;
import org.apache.qpid.test.utils.TestUtils;
-import org.apache.qpid.transport.network.NetworkConnection;
import org.apache.qpid.util.FileUtils;
public class MultipleBrokersFailoverTest extends QpidBrokerTestCase implements ConnectionListener
@@ -90,10 +85,7 @@ public class MultipleBrokersFailoverTest extends QpidBrokerTestCase implements C
}
_brokerPorts[i] = port;
- XMLConfiguration testConfiguration = new XMLConfiguration();
- testConfiguration.addProperty("management.enabled", "false");
-
- XMLConfiguration testVirtualhosts = new XMLConfiguration();
+ createBrokerConfiguration(port);
String host = null;
if (i == 1 || i == _brokerPorts.length - 1)
{
@@ -103,13 +95,9 @@ public class MultipleBrokersFailoverTest extends QpidBrokerTestCase implements C
{
host = NON_FAILOVER_VIRTUAL_HOST;
}
- testVirtualhosts.addProperty("virtualhost.name", host);
- testVirtualhosts.addProperty("virtualhost." + host + ".store.class", getTestProfileMessageStoreClassName());
- testVirtualhosts.addProperty(
- "virtualhost." + host + ".store." + MessageStoreConstants.ENVIRONMENT_PATH_PROPERTY, "${QPID_WORK}/"
- + host);
+ createTestVirtualHost(port, host);
- startBroker(port, testConfiguration, testVirtualhosts);
+ startBroker(port);
revertSystemProperties();
}
@@ -121,6 +109,11 @@ public class MultipleBrokersFailoverTest extends QpidBrokerTestCase implements C
_failoverStarted = new CountDownLatch(1);
}
+ public void startBroker() throws Exception
+ {
+ // noop, prevent the broker startup in super.setUp()
+ }
+
private String generateUrlString(int numBrokers)
{
String baseString = "amqp://guest:guest@test/" + FAILOVER_VIRTUAL_HOST
@@ -163,10 +156,6 @@ public class MultipleBrokersFailoverTest extends QpidBrokerTestCase implements C
}
}
- public void startBroker() throws Exception
- {
- // noop, stop starting broker in super.tearDown()
- }
public void testFailoverOnBrokerKill() throws Exception
{
diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/client/ssl/SSLTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/client/ssl/SSLTest.java
index 4fafcb3504..884e89fb65 100644
--- a/qpid/java/systests/src/main/java/org/apache/qpid/client/ssl/SSLTest.java
+++ b/qpid/java/systests/src/main/java/org/apache/qpid/client/ssl/SSLTest.java
@@ -29,13 +29,19 @@ import org.apache.commons.configuration.ConfigurationException;
import org.apache.qpid.client.AMQConnectionURL;
import org.apache.qpid.client.AMQTestConnection_0_10;
import org.apache.qpid.jms.ConnectionURL;
+import org.apache.qpid.server.model.Port;
+import org.apache.qpid.server.model.Transport;
import org.apache.qpid.test.utils.QpidBrokerTestCase;
+import org.apache.qpid.test.utils.TestBrokerConfiguration;
import javax.jms.Connection;
import javax.jms.JMSException;
import javax.jms.Session;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
public class SSLTest extends QpidBrokerTestCase
{
@@ -353,17 +359,13 @@ public class SSLTest extends QpidBrokerTestCase
{
if(isJavaBroker())
{
- setConfigurationProperty("connector.ssl.enabled", String.valueOf(sslEnabled));
- setConfigurationProperty("connector.ssl.sslOnly", String.valueOf(sslOnly));
- setConfigurationProperty("connector.ssl.needClientAuth", String.valueOf(needClientAuth));
- setConfigurationProperty("connector.ssl.wantClientAuth", String.valueOf(wantClientAuth));
-
- if(needClientAuth || wantClientAuth)
- {
- //TODO: make a broker trust store?
- setConfigurationProperty("connector.ssl.trustStorePath", TRUSTSTORE);
- setConfigurationProperty("connector.ssl.trustStorePassword", TRUSTSTORE_PASSWORD);
- }
+ Map<String, Object> sslPortAttributes = new HashMap<String, Object>();
+ sslPortAttributes.put(Port.TRANSPORTS, Collections.singleton(Transport.SSL));
+ sslPortAttributes.put(Port.PORT, DEFAULT_SSL_PORT);
+ sslPortAttributes.put(Port.NEED_CLIENT_AUTH, needClientAuth);
+ sslPortAttributes.put(Port.WANT_CLIENT_AUTH, wantClientAuth);
+ sslPortAttributes.put(Port.NAME, TestBrokerConfiguration.ENTRY_NAME_SSL_PORT);
+ getBrokerConfiguration().addPortConfiguration(sslPortAttributes);
}
}
diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/server/SupportedProtocolVersionsTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/server/SupportedProtocolVersionsTest.java
index e8d72c13bd..23a00431d1 100644
--- a/qpid/java/systests/src/main/java/org/apache/qpid/server/SupportedProtocolVersionsTest.java
+++ b/qpid/java/systests/src/main/java/org/apache/qpid/server/SupportedProtocolVersionsTest.java
@@ -23,13 +23,17 @@ package org.apache.qpid.server;
import org.apache.qpid.client.AMQConnection;
import org.apache.qpid.configuration.ClientProperties;
import org.apache.qpid.framing.ProtocolVersion;
-import org.apache.qpid.server.configuration.ServerConfiguration;
+import org.apache.qpid.server.configuration.BrokerProperties;
+import org.apache.qpid.server.model.Protocol;
+import org.apache.qpid.server.model.adapter.PortFactoryTest;
import org.apache.qpid.test.utils.QpidBrokerTestCase;
/**
* Tests to validate it is possible to disable support for particular protocol
* versions entirely, rather than selectively excluding them on particular ports,
* and it is possible to configure the reply to an unsupported protocol initiation.
+ *<p>
+ * Protocol exclusion/inclusion are unit tested as part of {@link PortFactoryTest}
*/
public class SupportedProtocolVersionsTest extends QpidBrokerTestCase
{
@@ -41,8 +45,8 @@ public class SupportedProtocolVersionsTest extends QpidBrokerTestCase
private void clearProtocolSupportManipulations()
{
//Remove the QBTC provided protocol manipulations, giving only the protocols which default to enabled
- setTestSystemProperty(QpidBrokerTestCase.BROKER_PROTOCOL_EXCLUDES, null);
- setTestSystemProperty(QpidBrokerTestCase.BROKER_PROTOCOL_INCLUDES, null);
+ setSystemProperty(BrokerProperties.PROPERTY_BROKER_DEFAULT_AMQP_PROTOCOL_EXCLUDES, null);
+ setSystemProperty(BrokerProperties.PROPERTY_BROKER_DEFAULT_AMQP_PROTOCOL_INCLUDES, null);
}
/**
@@ -87,8 +91,8 @@ public class SupportedProtocolVersionsTest extends QpidBrokerTestCase
clearProtocolSupportManipulations();
//disable 0-10 and 1-0 support
- setConfigurationProperty(ServerConfiguration.CONNECTOR_AMQP010ENABLED, "false");
- setConfigurationProperty(ServerConfiguration.CONNECTOR_AMQP10ENABLED, "false");
+ setSystemProperty(BrokerProperties.PROPERTY_BROKER_DEFAULT_AMQP_PROTOCOL_EXCLUDES,
+ Protocol.AMQP_1_0 + "," + Protocol.AMQP_0_10);
super.setUp();
@@ -100,52 +104,14 @@ public class SupportedProtocolVersionsTest extends QpidBrokerTestCase
connection.close();
}
- public void testDisabling091and010and10() throws Exception
- {
- clearProtocolSupportManipulations();
-
- //disable 0-91 and 0-10 and 1-0 support
- setConfigurationProperty(ServerConfiguration.CONNECTOR_AMQP10ENABLED, "false");
- setConfigurationProperty(ServerConfiguration.CONNECTOR_AMQP010ENABLED, "false");
- setConfigurationProperty(ServerConfiguration.CONNECTOR_AMQP091ENABLED, "false");
-
- super.setUp();
-
- //Verify initially requesting a 0-10 connection now negotiates a 0-9
- //connection as the broker should reply with its highest supported protocol
- setTestClientSystemProperty(ClientProperties.AMQP_VERSION, "0-10");
- AMQConnection connection = (AMQConnection) getConnection();
- assertEquals("Unexpected protocol version in use", ProtocolVersion.v0_9, connection.getProtocolVersion());
- connection.close();
- }
-
- public void testDisabling09and091and010and10() throws Exception
- {
- clearProtocolSupportManipulations();
-
- //disable 0-9, 0-91, 0-10 and 1-0 support
- setConfigurationProperty(ServerConfiguration.CONNECTOR_AMQP09ENABLED, "false");
- setConfigurationProperty(ServerConfiguration.CONNECTOR_AMQP091ENABLED, "false");
- setConfigurationProperty(ServerConfiguration.CONNECTOR_AMQP010ENABLED, "false");
- setConfigurationProperty(ServerConfiguration.CONNECTOR_AMQP10ENABLED, "false");
-
- super.setUp();
-
- //Verify initially requesting a 0-10 connection now negotiates a 0-8
- //connection as the broker should reply with its highest supported protocol
- setTestClientSystemProperty(ClientProperties.AMQP_VERSION, "0-10");
- AMQConnection connection = (AMQConnection) getConnection();
- assertEquals("Unexpected protocol version in use", ProtocolVersion.v8_0, connection.getProtocolVersion());
- connection.close();
- }
-
public void testConfiguringReplyingToUnsupported010ProtocolInitiationWith09insteadOf091() throws Exception
{
clearProtocolSupportManipulations();
//disable 0-10 support, and set the default unsupported protocol initiation reply to 0-9
- setConfigurationProperty(ServerConfiguration.CONNECTOR_AMQP010ENABLED, "false");
- setConfigurationProperty(ServerConfiguration.CONNECTOR_AMQP_SUPPORTED_REPLY, "v0_9");
+ setSystemProperty(BrokerProperties.PROPERTY_BROKER_DEFAULT_AMQP_PROTOCOL_EXCLUDES,
+ Protocol.AMQP_1_0 + "," + Protocol.AMQP_0_10);
+ setSystemProperty(BrokerProperties.PROPERTY_DEFAULT_SUPPORTED_PROTOCOL_REPLY, "v0_9");
super.setUp();
@@ -164,71 +130,5 @@ public class SupportedProtocolVersionsTest extends QpidBrokerTestCase
connection.close();
}
- public void testProtocolInclusionThroughQBTCSystemPropertiesOverridesProtocolExclusion() throws Exception
- {
- testProtocolInclusionOverridesProtocolExclusion(false);
- }
-
- public void testProtocolInclusionThroughConfigOverridesProtocolExclusion() throws Exception
- {
- testProtocolInclusionOverridesProtocolExclusion(true);
- }
-
- private void testProtocolInclusionOverridesProtocolExclusion(boolean useConfig) throws Exception
- {
- clearProtocolSupportManipulations();
-
- //selectively exclude 0-10 and 1-0 on the test port
- setTestSystemProperty(QpidBrokerTestCase.BROKER_PROTOCOL_EXCLUDES,"--exclude-0-10 @PORT --exclude-1-0 @PORT");
-
- super.setUp();
-
- //Verify initially requesting a 0-10 connection negotiates a 0-9-1 connection
- setTestClientSystemProperty(ClientProperties.AMQP_VERSION, "0-10");
- AMQConnection connection = (AMQConnection) getConnection();
- assertEquals("Unexpected protocol version in use", ProtocolVersion.v0_91, connection.getProtocolVersion());
- connection.close();
-
- stopBroker();
-
- if(useConfig)
- {
- //selectively include 0-10 support again on the test port through config
- setConfigurationProperty(ServerConfiguration.CONNECTOR_INCLUDE_010, String.valueOf(getPort()));
- }
- else
- {
- //selectively include 0-10 support again on the test port through QBTC sys props
- setTestSystemProperty(QpidBrokerTestCase.BROKER_PROTOCOL_INCLUDES,"--include-0-10 @PORT");
- }
-
- startBroker();
-
- //Verify requesting a 0-10 connection now returns one
- setTestClientSystemProperty(ClientProperties.AMQP_VERSION, "0-10");
- connection = (AMQConnection) getConnection();
- assertEquals("Unexpected protocol version in use", ProtocolVersion.v0_10, connection.getProtocolVersion());
- connection.close();
- }
-
- public void testProtocolInclusionOverridesProtocolDisabling() throws Exception
- {
- clearProtocolSupportManipulations();
-
- //disable 0-10 and 1-0
- setConfigurationProperty(ServerConfiguration.CONNECTOR_AMQP010ENABLED, "false");
- setConfigurationProperty(ServerConfiguration.CONNECTOR_AMQP10ENABLED, "false");
-
- //selectively include 0-10 support again on the test port
- setConfigurationProperty(ServerConfiguration.CONNECTOR_INCLUDE_010, String.valueOf(getPort()));
-
- super.setUp();
-
- //Verify initially requesting a 0-10 connection still works
- setTestClientSystemProperty(ClientProperties.AMQP_VERSION, "0-10");
- AMQConnection connection = (AMQConnection) getConnection();
- assertEquals("Unexpected protocol version in use", ProtocolVersion.v0_10, connection.getProtocolVersion());
- connection.close();
- }
} \ No newline at end of file
diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/server/configuration/ServerConfigurationFileTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/server/configuration/ServerConfigurationFileTest.java
deleted file mode 100644
index 6f54a56e93..0000000000
--- a/qpid/java/systests/src/main/java/org/apache/qpid/server/configuration/ServerConfigurationFileTest.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- *
- * 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.qpid.server.configuration;
-
-import org.apache.commons.configuration.ConfigurationException;
-
-import org.apache.qpid.test.utils.QpidBrokerTestCase;
-
-/**
- * This system test ensures that when loading our default system-test
- * configuration file the configuration is correctly loaded.
- *
- * All configuration values should be set in the systest config file so that
- * the ability to load them can be validated.
- */
-public class ServerConfigurationFileTest extends QpidBrokerTestCase
-{
- private ServerConfiguration _serverConfig;
-
- public void setUp() throws ConfigurationException
- {
- if (!_configFile.exists())
- {
- fail("Unable to test without config file:" + _configFile);
- }
-
- saveTestConfiguration();
- saveTestVirtualhosts();
-
- _serverConfig = new ServerConfiguration(_configFile);
- }
-
- /**
- * This helper method ensures that when we attempt to read a value that is
- * set in the configuration file we do actualy read a value and not
- * simply get a defaulted value from the ServerConfiguration.get*() methods.
- *
- * @param property the propert to test
- */
- private void validatePropertyDefinedInFile(String property)
- {
- //Verify that we are not just picking up the the default value from the getBoolean
- assertNotNull("The value set in the configuration file is not being read for property:" + property,
- _serverConfig.getConfig().getProperty(property));
- }
-
- public void testStatusUpdates() throws ConfigurationException
- {
- validatePropertyDefinedInFile(ServerConfiguration.STATUS_UPDATES);
- }
-
- public void testLocale() throws ConfigurationException
- {
- validatePropertyDefinedInFile(ServerConfiguration.ADVANCED_LOCALE);
- }
-
-}
diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/AbstractTestLogging.java b/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/AbstractTestLogging.java
index b666b1f424..84017b6850 100644
--- a/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/AbstractTestLogging.java
+++ b/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/AbstractTestLogging.java
@@ -20,12 +20,7 @@
*/
package org.apache.qpid.server.logging;
-import org.apache.commons.configuration.ConfigurationException;
-
-import org.apache.qpid.server.configuration.ServerConfiguration;
import org.apache.qpid.server.logging.subjects.AbstractTestLogSubject;
-import org.apache.qpid.server.registry.ApplicationRegistry;
-import org.apache.qpid.server.util.InternalBrokerBaseCase;
import org.apache.qpid.test.utils.QpidBrokerTestCase;
import org.apache.qpid.util.LogMonitor;
@@ -47,8 +42,6 @@ public class AbstractTestLogging extends QpidBrokerTestCase
public static final String TEST_LOG_PREFIX = "MESSAGE";
protected LogMonitor _monitor;
- private InternalBrokerBaseCase _configLoader;
-
@Override
public void setUp() throws Exception
{
@@ -58,32 +51,6 @@ public class AbstractTestLogging extends QpidBrokerTestCase
_monitor = new LogMonitor(_outputFile);
}
- protected ServerConfiguration getServerConfig() throws ConfigurationException
- {
- ServerConfiguration _serverConfiguration;
- if (isExternalBroker())
- {
- _serverConfiguration = new ServerConfiguration(_configFile)
- {
- @Override
- public void initialise() throws ConfigurationException
- {
- //Overriding initialise to only setup the vhosts and not
- //perform the ConfigurationPlugin setup, removing need for
- //an ApplicationRegistry to be loaded.
- setupVirtualHosts(getConfig());
- }
- };
- _serverConfiguration.initialise();
- }
- else
- {
- _serverConfiguration = ApplicationRegistry.getInstance().getConfiguration();
- }
-
- return _serverConfiguration;
- }
-
protected void setLogMessagePrefix()
{
//set the message prefix to facilitate scraping from the munged test output.
@@ -94,10 +61,6 @@ public class AbstractTestLogging extends QpidBrokerTestCase
public void tearDown() throws Exception
{
_monitor.close();
- if (isExternalBroker() && _configLoader != null)
- {
- _configLoader.tearDown();
- }
super.tearDown();
}
@@ -159,7 +122,7 @@ public class AbstractTestLogging extends QpidBrokerTestCase
}
protected String fromMessage(String log)
- {
+ {;
int startSubject = log.indexOf("]") + 1;
int start = log.indexOf("]", startSubject) + 1;
diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/AlertingTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/AlertingTest.java
index 7c676ad01d..68ec101245 100644
--- a/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/AlertingTest.java
+++ b/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/AlertingTest.java
@@ -42,8 +42,8 @@ public class AlertingTest extends AbstractTestLogging
{
_numMessages = 50;
- setConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".housekeeping.checkPeriod", String.valueOf(ALERT_LOG_WAIT_PERIOD));
- setConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".queues.maximumMessageCount", String.valueOf(_numMessages));
+ setVirtualHostConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".housekeeping.checkPeriod", String.valueOf(ALERT_LOG_WAIT_PERIOD));
+ setVirtualHostConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".queues.maximumMessageCount", String.valueOf(_numMessages));
// Then we do the normal setup stuff like starting the broker, getting a connection etc.
super.setUp();
@@ -141,7 +141,7 @@ public class AlertingTest extends AbstractTestLogging
_monitor.markDiscardPoint();
// Change max message count to 5, start broker and make sure that that's triggered at the right time
- setConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".queues.maximumMessageCount", "5");
+ setVirtualHostConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".queues.maximumMessageCount", "5");
startBroker();
diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/BrokerLoggingTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/BrokerLoggingTest.java
index 24c0aed611..c5f5e06ae1 100644
--- a/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/BrokerLoggingTest.java
+++ b/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/BrokerLoggingTest.java
@@ -23,12 +23,20 @@ package org.apache.qpid.server.logging;
import junit.framework.AssertionFailedError;
import org.apache.qpid.server.BrokerOptions;
+import org.apache.qpid.server.model.Port;
+import org.apache.qpid.server.model.Transport;
+import org.apache.qpid.test.utils.TestBrokerConfiguration;
import org.apache.qpid.transport.ConnectionException;
import org.apache.qpid.util.LogMonitor;
import java.io.IOException;
import java.net.Socket;
+import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
/**
* Broker Test Suite
@@ -47,6 +55,8 @@ import java.util.List;
*/
public class BrokerLoggingTest extends AbstractTestLogging
{
+ private static final String BROKER_MESSAGE_LOG_REG_EXP = ".*\\[\\w*\\] (BRK\\-\\d*) .*";
+ private static final Pattern BROKER_MESSAGE_LOG_PATTERN = Pattern.compile(BROKER_MESSAGE_LOG_REG_EXP);
private static final String BRK_LOG_PREFIX = "BRK-";
public void setUp() throws Exception
@@ -95,7 +105,7 @@ public class BrokerLoggingTest extends AbstractTestLogging
_monitor = new LogMonitor(_outputFile);
- String configFilePath = _configFile.toString();
+ String configFilePath = getConfigPath();
// Ensure we wait for TESTID to be logged
waitAndFindMatches(TESTID);
@@ -118,8 +128,9 @@ public class BrokerLoggingTest extends AbstractTestLogging
1, results.size());
//3
- assertTrue("Config file details not correctly logged",
- log.endsWith(configFilePath));
+ assertTrue("Config file details not correctly logged, got "
+ + log + " but expected it to end with " + configFilePath,
+ log.endsWith(configFilePath));
}
catch (AssertionFailedError afe)
{
@@ -130,6 +141,11 @@ public class BrokerLoggingTest extends AbstractTestLogging
}
}
+ private String getConfigPath()
+ {
+ return getPathRelativeToWorkingDirectory(getTestConfigFile(DEFAULT_PORT));
+ }
+
/**
* Description:
* On startup the broker must report correctly report the log4j file in use. This is important as it can help diagnose why logging messages are not being reported.
@@ -242,6 +258,8 @@ public class BrokerLoggingTest extends AbstractTestLogging
// This logging startup code only occurs when you run a Java broker
if (isJavaBroker() && isExternalBroker())
{
+ String customLog4j = getBrokerCommandLog4JFile().getAbsolutePath();
+
String TESTID = "BRK-1007";
startBroker();
@@ -290,10 +308,9 @@ public class BrokerLoggingTest extends AbstractTestLogging
//3
String messageString = getMessageString(log);
- String customLog4j = getBrokerCommandLog4JFile().getAbsolutePath();
- assertTrue("Log4j file details not correctly logged. Message '" + messageString
- + "' should contain '" + customLog4j + "'",
- messageString.contains(customLog4j));
+ assertTrue("Log4j file details not correctly logged. Message '"
+ + messageString + "' should contain '" +customLog4j + "'",
+ messageString.endsWith(customLog4j));
validation = true;
}
@@ -441,10 +458,13 @@ public class BrokerLoggingTest extends AbstractTestLogging
{
String log = getLog(rawLog);
+ // using custom method to get id as getMessageId() fails to correctly identify id
+ // because of using brackets for protocols
+ String id = getBrokerLogId(log);
// Ensure we do not have a BRK-1002 message
- if (!getMessageID(log).equals(TESTID))
+ if (!id.equals(TESTID))
{
- if (getMessageID(log).equals("BRK-1001"))
+ if (id.equals("BRK-1001"))
{
foundBRK1001 = true;
}
@@ -454,7 +474,7 @@ public class BrokerLoggingTest extends AbstractTestLogging
assertTrue("BRK-1001 not logged before this message", foundBRK1001);
//1
- validateMessageID(TESTID, log);
+ assertEquals("Incorrect message", TESTID, id);
//2
//There will be 2 copies of the startup message (one via SystemOut, and one via Log4J)
@@ -464,7 +484,7 @@ public class BrokerLoggingTest extends AbstractTestLogging
//3
String message = getMessageString(log);
assertTrue("Expected Listen log not correct" + message,
- message.endsWith("Listening on TCP port " + getPort()));
+ message.endsWith("Listening on [TCP] port " + getPort()));
validation = true;
}
@@ -480,6 +500,16 @@ public class BrokerLoggingTest extends AbstractTestLogging
}
}
+ private String getBrokerLogId(String log)
+ {
+ Matcher m = BROKER_MESSAGE_LOG_PATTERN.matcher(log);
+ if (m.matches())
+ {
+ return m.group(1);
+ }
+ return getMessageID(log);
+ }
+
/**
* Description:
* On startup the broker may listen on a number of ports and protocols. Each of these must be reported as they are made available.
@@ -497,8 +527,8 @@ public class BrokerLoggingTest extends AbstractTestLogging
* 1. The BRK ID is correct
* 2. This occurs after the BRK-1001 startup message
* 3. With SSL enabled in the configuration two BRK-1002 will be printed (order is not specified)
- * 1. One showing values TCP / 5672
- * 2. One showing values TCP/SSL / 5672
+ * 1. One showing values [TCP] 5672
+ * 2. One showing values [SSL] 5671
*
* @throws Exception caused by broker startup
*/
@@ -511,12 +541,11 @@ public class BrokerLoggingTest extends AbstractTestLogging
String TESTID = "BRK-1002";
// Enable SSL on the connection
- setConfigurationProperty("connector.ssl.enabled", "true");
- setConfigurationProperty("connector.ssl.sslOnly", "false");
- setConfigurationProperty("connector.ssl.keyStorePath", getConfigurationStringProperty("management.ssl.keyStorePath"));
- setConfigurationProperty("connector.ssl.keyStorePassword", getConfigurationStringProperty("management.ssl.keyStorePassword"));
-
- Integer sslPort = Integer.parseInt(getConfigurationStringProperty("connector.ssl.port"));
+ Map<String, Object> sslPortAttributes = new HashMap<String, Object>();
+ sslPortAttributes.put(Port.TRANSPORTS, Collections.singleton(Transport.SSL));
+ sslPortAttributes.put(Port.PORT, DEFAULT_SSL_PORT);
+ sslPortAttributes.put(Port.NAME, TestBrokerConfiguration.ENTRY_NAME_SSL_PORT);
+ getBrokerConfiguration().addPortConfiguration(sslPortAttributes);
startBroker();
@@ -544,10 +573,11 @@ public class BrokerLoggingTest extends AbstractTestLogging
{
String log = getLog(rawLog);
+ String id = getBrokerLogId(log);
// Ensure we do not have a BRK-1002 message
- if (!getMessageID(log).equals(TESTID))
+ if (!id.equals(TESTID))
{
- if (getMessageID(log).equals("BRK-1001"))
+ if (id.equals("BRK-1001"))
{
foundBRK1001 = true;
}
@@ -557,7 +587,7 @@ public class BrokerLoggingTest extends AbstractTestLogging
assertTrue("BRK-1001 not logged before this message", foundBRK1001);
//1
- validateMessageID(TESTID, log);
+ assertEquals("Incorrect message", TESTID, id);
//2
//There will be 4 copies of the startup message (two via SystemOut, and two via Log4J)
@@ -569,16 +599,16 @@ public class BrokerLoggingTest extends AbstractTestLogging
//Check the first
String message = getMessageString(getLog(listenMessages .get(0)));
assertTrue("Expected Listen log not correct" + message,
- message.endsWith("Listening on TCP port " + getPort()));
+ message.endsWith("Listening on [TCP] port " + getPort()));
// Check the third, ssl listen.
message = getMessageString(getLog(listenMessages .get(2)));
assertTrue("Expected Listen log not correct" + message,
- message.endsWith("Listening on TCP/SSL port " + sslPort));
+ message.endsWith("Listening on [SSL] port " + DEFAULT_SSL_PORT));
//4 Test ports open
testSocketOpen(getPort());
- testSocketOpen(sslPort);
+ testSocketOpen(DEFAULT_SSL_PORT);
validation = true;
}
@@ -802,11 +832,11 @@ public class BrokerLoggingTest extends AbstractTestLogging
String TESTID = "BRK-1003";
// Enable SSL on the connection
- setConfigurationProperty("connector.ssl.enabled", "true");
- setConfigurationProperty("connector.ssl.keyStorePath", getConfigurationStringProperty("management.ssl.keyStorePath"));
- setConfigurationProperty("connector.ssl.keyStorePassword", getConfigurationStringProperty("management.ssl.keyStorePassword"));
-
- Integer sslPort = Integer.parseInt(getConfigurationStringProperty("connector.ssl.port"));
+ Map<String, Object> sslPortAttributes = new HashMap<String, Object>();
+ sslPortAttributes.put(Port.TRANSPORTS, Collections.singleton(Transport.SSL));
+ sslPortAttributes.put(Port.PORT, DEFAULT_SSL_PORT);
+ sslPortAttributes.put(Port.NAME, TestBrokerConfiguration.ENTRY_NAME_SSL_PORT);
+ getBrokerConfiguration().addPortConfiguration(sslPortAttributes);
startBroker();
@@ -847,13 +877,13 @@ public class BrokerLoggingTest extends AbstractTestLogging
// Check second, ssl, listen.
message = getMessageString(getLog(listenMessages.get(1)));
assertTrue("Expected shutdown log not correct" + message,
- message.endsWith("TCP/SSL port " + sslPort));
+ message.endsWith("TCP/SSL port " + DEFAULT_SSL_PORT));
//4
//Test Port closed
checkSocketClosed(getPort());
//Test SSL Port closed
- checkSocketClosed(sslPort);
+ checkSocketClosed(DEFAULT_SSL_PORT);
}
catch (AssertionFailedError afe)
{
@@ -998,4 +1028,5 @@ public class BrokerLoggingTest extends AbstractTestLogging
+ ". Due to:" + e.getMessage());
}
}
+
}
diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/VirtualHostLoggingTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/VirtualHostLoggingTest.java
index 5f96215269..1ea105ae1a 100644
--- a/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/VirtualHostLoggingTest.java
+++ b/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/VirtualHostLoggingTest.java
@@ -23,7 +23,6 @@ package org.apache.qpid.server.logging;
import junit.framework.AssertionFailedError;
-import org.apache.qpid.server.configuration.ServerConfiguration;
import java.util.Arrays;
import java.util.List;
@@ -68,7 +67,7 @@ public class VirtualHostLoggingTest extends AbstractTestLogging
try
{
- List<String> vhosts = Arrays.asList(getServerConfig().getVirtualHosts());
+ List<String> vhosts = Arrays.asList("test");
assertEquals("Each vhost did not create a store.", vhosts.size(), results.size());
@@ -110,23 +109,17 @@ public class VirtualHostLoggingTest extends AbstractTestLogging
// Wait for the correct VHT message to arrive.
waitForMessage(VHT_PREFIX + "1002");
-
+
// Validate each vhost logs a closure
List<String> results = findMatches(VHT_PREFIX + "1002");
-
+
try
{
- // Load VirtualHost list from file.
- ServerConfiguration configuration = new ServerConfiguration(_configFile);
- configuration.initialise();
- List<String> vhosts = Arrays.asList(configuration.getVirtualHosts());
-
- assertEquals("Each vhost did not close their store.", vhosts.size(), results.size());
+ assertEquals("Each vhost did not close their store.", 1, results.size());
}
catch (AssertionFailedError afe)
{
dumpLogs(results, _monitor);
-
throw afe;
}
}
diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/server/persistent/NoLocalAfterRecoveryTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/server/persistent/NoLocalAfterRecoveryTest.java
index bcad59a1fa..82b421a531 100644
--- a/qpid/java/systests/src/main/java/org/apache/qpid/server/persistent/NoLocalAfterRecoveryTest.java
+++ b/qpid/java/systests/src/main/java/org/apache/qpid/server/persistent/NoLocalAfterRecoveryTest.java
@@ -39,7 +39,7 @@ import org.apache.qpid.test.utils.QpidBrokerTestCase;
*/
public class NoLocalAfterRecoveryTest extends QpidBrokerTestCase
{
- protected final String MY_TOPIC_SUBSCRIPTION_NAME = this.getName();
+ protected final String MY_TOPIC_SUBSCRIPTION_NAME = getTestQueueName();
protected static final int SEND_COUNT = 10;
public void testNoLocalNotQueued() throws Exception
diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/server/queue/MultipleTransactedBatchProducerTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/server/queue/MultipleTransactedBatchProducerTest.java
index 8536651ffb..cbf4e032db 100644
--- a/qpid/java/systests/src/main/java/org/apache/qpid/server/queue/MultipleTransactedBatchProducerTest.java
+++ b/qpid/java/systests/src/main/java/org/apache/qpid/server/queue/MultipleTransactedBatchProducerTest.java
@@ -30,6 +30,7 @@ import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.MessageListener;
import javax.jms.Session;
+
import java.util.Random;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
@@ -54,7 +55,9 @@ public class MultipleTransactedBatchProducerTest extends QpidBrokerTestCase
//debug level logging often makes this test pass artificially, turn the level down to info.
setSystemProperty("amqj.server.logging.level", "INFO");
_receivedLatch = new CountDownLatch(MESSAGE_COUNT * NUM_PRODUCERS);
- setConfigurationProperty("management.enabled", "true");
+
+ getBrokerConfiguration().addJmxManagementConfiguration();
+
super.setUp();
_queueName = getTestQueueName();
_failMsg = null;
diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/server/security/acl/AbstractACLTestCase.java b/qpid/java/systests/src/main/java/org/apache/qpid/server/security/acl/AbstractACLTestCase.java
index 7b50749f5f..814936f342 100644
--- a/qpid/java/systests/src/main/java/org/apache/qpid/server/security/acl/AbstractACLTestCase.java
+++ b/qpid/java/systests/src/main/java/org/apache/qpid/server/security/acl/AbstractACLTestCase.java
@@ -26,6 +26,7 @@ import org.apache.qpid.client.AMQConnection;
import org.apache.qpid.client.AMQConnectionURL;
import org.apache.qpid.jms.ConnectionListener;
import org.apache.qpid.protocol.AMQConstant;
+import org.apache.qpid.server.model.Broker;
import org.apache.qpid.test.utils.QpidBrokerTestCase;
import org.apache.qpid.url.URLSyntaxException;
@@ -58,25 +59,11 @@ public abstract class AbstractACLTestCase extends QpidBrokerTestCase implements
{
/** Used to synchronise {@link #tearDown()} when exceptions are thrown */
protected CountDownLatch _exceptionReceived;
-
- /** Override this to return the name of the configuration XML file. */
- public String getConfig()
- {
- return "config-systests.xml";
- }
- /**
- * This setup method checks {@link #getConfig()} and {@link #getHostList()} to initialise the broker with specific
- * ACL configurations and then runs an optional per-test setup method, which is simply a method with the same name
- * as the test, but starting with {@code setUp} rather than {@code test}.
- *
- * @see org.apache.qpid.test.utils.QpidBrokerTestCase#setUp()
- */
@Override
public void setUp() throws Exception
{
- // Initialise ACLs.
- _configFile = new File("build" + File.separator + "etc" + File.separator + getConfig());
+ getBrokerConfiguration().setBrokerAttribute(Broker.GROUP_FILE, System.getProperty(QPID_HOME) + "/etc/groups-systests");
// run test specific setup
String testSetup = StringUtils.replace(getName(), "test", "setUp");
@@ -123,11 +110,11 @@ public abstract class AbstractACLTestCase extends QpidBrokerTestCase implements
if (vhost == null)
{
- testcase.setConfigurationProperty("security.acl", aclFile.getAbsolutePath());
+ testcase.getBrokerConfiguration().setBrokerAttribute(Broker.ACL_FILE, aclFile.getAbsolutePath());
}
else
{
- testcase.setConfigurationProperty("virtualhosts.virtualhost." + vhost + ".security.acl", aclFile.getAbsolutePath());
+ testcase.setVirtualHostConfigurationProperty("virtualhosts.virtualhost." + vhost + ".security.acl", aclFile.getAbsolutePath());
}
PrintWriter out = new PrintWriter(new FileWriter(aclFile));
diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/server/security/acl/ExternalACLJMXTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/server/security/acl/ExternalACLJMXTest.java
index 52229316be..1830040007 100644
--- a/qpid/java/systests/src/main/java/org/apache/qpid/server/security/acl/ExternalACLJMXTest.java
+++ b/qpid/java/systests/src/main/java/org/apache/qpid/server/security/acl/ExternalACLJMXTest.java
@@ -43,8 +43,8 @@ public class ExternalACLJMXTest extends AbstractACLTestCase
@Override
public void setUp() throws Exception
{
- createTestVirtualHost(TEST_VHOST);
- createTestVirtualHost(TEST2_VHOST);
+ createTestVirtualHost(0, TEST_VHOST);
+ createTestVirtualHost(0, TEST2_VHOST);
_jmx = new JMXTestUtils(this);
_jmx.setUp();
diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/server/security/auth/manager/ExternalAuthenticationTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/server/security/auth/manager/ExternalAuthenticationTest.java
index 295aac9f97..c7a43a292b 100644
--- a/qpid/java/systests/src/main/java/org/apache/qpid/server/security/auth/manager/ExternalAuthenticationTest.java
+++ b/qpid/java/systests/src/main/java/org/apache/qpid/server/security/auth/manager/ExternalAuthenticationTest.java
@@ -20,21 +20,30 @@
*/
package org.apache.qpid.server.security.auth.manager;
+import static org.apache.qpid.test.utils.TestSSLConstants.KEYSTORE;
+import static org.apache.qpid.test.utils.TestSSLConstants.KEYSTORE_PASSWORD;
+import static org.apache.qpid.test.utils.TestSSLConstants.TRUSTSTORE;
+import static org.apache.qpid.test.utils.TestSSLConstants.TRUSTSTORE_PASSWORD;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
import javax.jms.Connection;
import javax.jms.JMSException;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.qpid.client.AMQConnectionURL;
+import org.apache.qpid.server.model.AuthenticationProvider;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.Port;
+import org.apache.qpid.server.model.Transport;
+import org.apache.qpid.server.plugin.AuthenticationManagerFactory;
import org.apache.qpid.test.utils.QpidBrokerTestCase;
+import org.apache.qpid.test.utils.TestBrokerConfiguration;
public class ExternalAuthenticationTest extends QpidBrokerTestCase
{
- private static final String EXTERNAL_AUTH_MANAGER = ExternalAuthenticationManager.class.getSimpleName();
- private static final String KEYSTORE = "test-profiles/test_resources/ssl/java_client_keystore.jks";
- private static final String KEYSTORE_PASSWORD = "password";
- private static final String TRUSTSTORE = "test-profiles/test_resources/ssl/java_client_truststore.jks";
- private static final String TRUSTSTORE_PASSWORD = "password";
-
@Override
protected void setUp() throws Exception
{
@@ -48,9 +57,7 @@ public class ExternalAuthenticationTest extends QpidBrokerTestCase
public void testExternalAuthenticationManagerOnSSLPort() throws Exception
{
setCommonBrokerSSLProperties(true);
- setConfigurationProperty("security.port-mappings.port-mapping.port", String.valueOf(QpidBrokerTestCase.DEFAULT_SSL_PORT));
- setConfigurationProperty("security.port-mappings.port-mapping.auth-manager", EXTERNAL_AUTH_MANAGER);
- setConfigurationProperty("security.default-auth-manager", PrincipalDatabaseAuthenticationManager.class.getSimpleName());
+ getBrokerConfiguration().setObjectAttribute(TestBrokerConfiguration.ENTRY_NAME_SSL_PORT, Port.AUTHENTICATION_MANAGER, TestBrokerConfiguration.ENTRY_NAME_EXTERNAL_PROVIDER);
super.setUp();
setClientKeystoreProperties();
@@ -83,7 +90,7 @@ public class ExternalAuthenticationTest extends QpidBrokerTestCase
public void testExternalAuthenticationManagerAsDefault() throws Exception
{
setCommonBrokerSSLProperties(true);
- setConfigurationProperty("security.default-auth-manager", EXTERNAL_AUTH_MANAGER);
+ getBrokerConfiguration().setBrokerAttribute(Broker.DEFAULT_AUTHENTICATION_PROVIDER, TestBrokerConfiguration.ENTRY_NAME_EXTERNAL_PROVIDER);
super.setUp();
setClientKeystoreProperties();
@@ -116,7 +123,7 @@ public class ExternalAuthenticationTest extends QpidBrokerTestCase
public void testExternalAuthenticationManagerWithoutClientKeyStore() throws Exception
{
setCommonBrokerSSLProperties(false);
- setConfigurationProperty("security.default-auth-manager", EXTERNAL_AUTH_MANAGER);
+ getBrokerConfiguration().setBrokerAttribute(Broker.DEFAULT_AUTHENTICATION_PROVIDER, TestBrokerConfiguration.ENTRY_NAME_EXTERNAL_PROVIDER);
super.setUp();
setClientTrustoreProperties();
@@ -148,12 +155,18 @@ public class ExternalAuthenticationTest extends QpidBrokerTestCase
private void setCommonBrokerSSLProperties(boolean needClientAuth) throws ConfigurationException
{
- setConfigurationProperty("connector.ssl.enabled", "true");
- setConfigurationProperty("connector.ssl.sslOnly", "false");
- setConfigurationProperty("connector.ssl.trustStorePath", TRUSTSTORE);
- setConfigurationProperty("connector.ssl.trustStorePassword", TRUSTSTORE_PASSWORD);
- setConfigurationProperty("connector.ssl.needClientAuth", String.valueOf(needClientAuth));
- setConfigurationProperty("security.external-auth-manager", "");
+ TestBrokerConfiguration config = getBrokerConfiguration();
+ Map<String, Object> sslPortAttributes = new HashMap<String, Object>();
+ sslPortAttributes.put(Port.TRANSPORTS, Collections.singleton(Transport.SSL));
+ sslPortAttributes.put(Port.PORT, DEFAULT_SSL_PORT);
+ sslPortAttributes.put(Port.NEED_CLIENT_AUTH, String.valueOf(needClientAuth));
+ sslPortAttributes.put(Port.NAME, TestBrokerConfiguration.ENTRY_NAME_SSL_PORT);
+ config.addPortConfiguration(sslPortAttributes);
+
+ Map<String, Object> externalAuthProviderAttributes = new HashMap<String, Object>();
+ externalAuthProviderAttributes.put(AuthenticationManagerFactory.ATTRIBUTE_TYPE, ExternalAuthenticationManagerFactory.PROVIDER_TYPE);
+ externalAuthProviderAttributes.put(AuthenticationProvider.NAME, TestBrokerConfiguration.ENTRY_NAME_EXTERNAL_PROVIDER);
+ config.addAuthenticationProviderConfiguration(externalAuthProviderAttributes);
}
private void setClientKeystoreProperties()
diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/server/security/auth/manager/MultipleAuthenticationManagersTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/server/security/auth/manager/MultipleAuthenticationManagersTest.java
index 34b62e0b92..f41f1159ab 100644
--- a/qpid/java/systests/src/main/java/org/apache/qpid/server/security/auth/manager/MultipleAuthenticationManagersTest.java
+++ b/qpid/java/systests/src/main/java/org/apache/qpid/server/security/auth/manager/MultipleAuthenticationManagersTest.java
@@ -25,23 +25,39 @@ import static org.apache.qpid.test.utils.TestSSLConstants.KEYSTORE_PASSWORD;
import static org.apache.qpid.test.utils.TestSSLConstants.TRUSTSTORE;
import static org.apache.qpid.test.utils.TestSSLConstants.TRUSTSTORE_PASSWORD;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
import javax.jms.Connection;
import javax.jms.JMSException;
import org.apache.qpid.AMQException;
import org.apache.qpid.client.AMQConnection;
+import org.apache.qpid.server.model.AuthenticationProvider;
+import org.apache.qpid.server.model.Port;
+import org.apache.qpid.server.model.Transport;
+import org.apache.qpid.server.plugin.AuthenticationManagerFactory;
import org.apache.qpid.test.utils.QpidBrokerTestCase;
+import org.apache.qpid.test.utils.TestBrokerConfiguration;
public class MultipleAuthenticationManagersTest extends QpidBrokerTestCase
{
@Override
protected void setUp() throws Exception
{
- setConfigurationProperty("connector.ssl.enabled", "true");
- setConfigurationProperty("connector.ssl.sslOnly", "false");
- setConfigurationProperty("security.anonymous-auth-manager", "");
- setConfigurationProperty("security.default-auth-manager", "PrincipalDatabaseAuthenticationManager");
- setConfigurationProperty("security.port-mappings.port-mapping.port", String.valueOf(QpidBrokerTestCase.DEFAULT_SSL_PORT));
- setConfigurationProperty("security.port-mappings.port-mapping.auth-manager", "AnonymousAuthenticationManager");
+ TestBrokerConfiguration config = getBrokerConfiguration();
+
+ Map<String, Object> externalAuthProviderAttributes = new HashMap<String, Object>();
+ externalAuthProviderAttributes.put(AuthenticationManagerFactory.ATTRIBUTE_TYPE, AnonymousAuthenticationManagerFactory.PROVIDER_TYPE);
+ externalAuthProviderAttributes.put(AuthenticationProvider.NAME, TestBrokerConfiguration.ENTRY_NAME_ANONYMOUS_PROVIDER);
+ config.addAuthenticationProviderConfiguration(externalAuthProviderAttributes);
+
+ Map<String, Object> sslPortAttributes = new HashMap<String, Object>();
+ sslPortAttributes.put(Port.TRANSPORTS, Collections.singleton(Transport.SSL));
+ sslPortAttributes.put(Port.PORT, DEFAULT_SSL_PORT);
+ sslPortAttributes.put(Port.NAME, TestBrokerConfiguration.ENTRY_NAME_SSL_PORT);
+ sslPortAttributes.put(Port.AUTHENTICATION_MANAGER, TestBrokerConfiguration.ENTRY_NAME_ANONYMOUS_PROVIDER);
+ config.addPortConfiguration(sslPortAttributes);
// set the ssl system properties
setSystemProperty("javax.net.ssl.keyStore", KEYSTORE);
diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/server/stats/StatisticsReportingTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/server/stats/StatisticsReportingTest.java
index 1e61ff9382..6d53896371 100644
--- a/qpid/java/systests/src/main/java/org/apache/qpid/server/stats/StatisticsReportingTest.java
+++ b/qpid/java/systests/src/main/java/org/apache/qpid/server/stats/StatisticsReportingTest.java
@@ -27,10 +27,13 @@ import org.apache.qpid.client.AMQQueue;
import org.apache.qpid.client.AMQSession;
import org.apache.qpid.exchange.ExchangeDefaults;
import org.apache.qpid.framing.AMQShortString;
+import org.apache.qpid.server.model.Broker;
import org.apache.qpid.test.utils.QpidBrokerTestCase;
+import org.apache.qpid.test.utils.TestBrokerConfiguration;
import org.apache.qpid.util.LogMonitor;
import java.util.List;
+import java.util.Map;
import javax.jms.Connection;
import javax.jms.Destination;
@@ -48,6 +51,7 @@ public class StatisticsReportingTest extends QpidBrokerTestCase
private static final String VHOST_NAME1 = "vhost1";
private static final String VHOST_NAME2 = "vhost2";
private static final String VHOST_NAME3 = "vhost3";
+ private static long STATISTICS_REPORTING_PERIOD_IN_SECONDS = 10l;
protected LogMonitor _monitor;
protected static final String USER = "admin";
@@ -56,23 +60,24 @@ public class StatisticsReportingTest extends QpidBrokerTestCase
protected String _queueName = "statistics";
protected Destination _queue;
protected String _brokerUrl;
+ private long _startTestTime;
@Override
public void setUp() throws Exception
{
- createTestVirtualHost(VHOST_NAME1);
- createTestVirtualHost(VHOST_NAME2);
- createTestVirtualHost(VHOST_NAME3);
-
- setConfigurationProperty("statistics.generation.broker", "true");
- setConfigurationProperty("statistics.generation.virtualhosts", "true");
+ createTestVirtualHost(0, VHOST_NAME1);
+ createTestVirtualHost(0, VHOST_NAME2);
+ createTestVirtualHost(0, VHOST_NAME3);
if (getName().equals("testEnabledStatisticsReporting"))
{
- setConfigurationProperty("statistics.reporting.period", "10");
+ TestBrokerConfiguration config = getBrokerConfiguration();
+ config.removeObjectConfiguration(TestBrokerConfiguration.ENTRY_NAME_VIRTUAL_HOST);
+ config.setBrokerAttribute(Broker.STATISTICS_REPORTING_PERIOD, STATISTICS_REPORTING_PERIOD_IN_SECONDS);
}
_monitor = new LogMonitor(_outputFile);
+ _startTestTime = System.currentTimeMillis();
super.setUp();
@@ -105,17 +110,26 @@ public class StatisticsReportingTest extends QpidBrokerTestCase
sendUsing(_conToVhost2, 20, 100);
sendUsing(_conToVhost3, 15, 100);
- Thread.sleep(10 * 1000); // 15s
+ Thread.sleep(STATISTICS_REPORTING_PERIOD_IN_SECONDS * 1000);
- List<String> brokerStatsData = _monitor.findMatches("BRK-1008");
- List<String> brokerStatsMessages = _monitor.findMatches("BRK-1009");
- List<String> vhostStatsData = _monitor.findMatches("VHT-1003");
- List<String> vhostStatsMessages = _monitor.findMatches("VHT-1004");
+ Map<String, List<String>> brokerStatsData = _monitor.findMatches("BRK-1008", "BRK-1009", "VHT-1003", "VHT-1004");
+ long endTestTime = System.currentTimeMillis();
+
+ int maxNumberOfReports = (int)((endTestTime - _startTestTime)/STATISTICS_REPORTING_PERIOD_IN_SECONDS);
+
+ int brk1008LinesNumber = brokerStatsData.get("BRK-1008").size();
+ int brk1009LinesNumber = brokerStatsData.get("BRK-1009").size();
+ int vht1003LinesNumber = brokerStatsData.get("VHT-1003").size();
+ int vht1004LinesNumber = brokerStatsData.get("VHT-1004").size();
- assertEquals("Incorrect number of broker data stats log messages", 2, brokerStatsData.size());
- assertEquals("Incorrect number of broker message stats log messages", 2, brokerStatsMessages.size());
- assertEquals("Incorrect number of virtualhost data stats log messages", 6, vhostStatsData.size());
- assertEquals("Incorrect number of virtualhost message stats log messages", 6, vhostStatsMessages.size());
+ assertTrue("Incorrect number of broker data stats log messages:" + brk1008LinesNumber, 2 <= brk1008LinesNumber
+ && brk1008LinesNumber <= maxNumberOfReports * 2);
+ assertTrue("Incorrect number of broker message stats log messages:" + brk1009LinesNumber, 2 <= brk1009LinesNumber
+ && brk1009LinesNumber <= maxNumberOfReports * 2);
+ assertTrue("Incorrect number of virtualhost data stats log messages:" + vht1003LinesNumber, 6 <= vht1003LinesNumber
+ && vht1003LinesNumber <= maxNumberOfReports * 6);
+ assertTrue("Incorrect number of virtualhost message stats log messages: " + vht1004LinesNumber, 6 <= vht1004LinesNumber
+ && vht1004LinesNumber <= maxNumberOfReports * 6);
}
/**
@@ -142,7 +156,7 @@ public class StatisticsReportingTest extends QpidBrokerTestCase
private void sendUsing(Connection con, int number, int size) throws Exception
{
- Session session = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ Session session = con.createSession(true, Session.SESSION_TRANSACTED);
createQueue(session);
MessageProducer producer = session.createProducer(_queue);
String content = new String(new byte[size]);
@@ -151,6 +165,8 @@ public class StatisticsReportingTest extends QpidBrokerTestCase
{
producer.send(msg);
}
+ session.commit();
+ session.close();
}
private void createQueue(Session session) throws AMQException, JMSException
diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/server/store/StoreOverfullTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/server/store/StoreOverfullTest.java
index 9fb1db3a4f..61ca6d9c28 100644
--- a/qpid/java/systests/src/main/java/org/apache/qpid/server/store/StoreOverfullTest.java
+++ b/qpid/java/systests/src/main/java/org/apache/qpid/server/store/StoreOverfullTest.java
@@ -60,9 +60,9 @@ public class StoreOverfullTest extends QpidBrokerTestCase
public void setUp() throws Exception
{
- setConfigurationProperty("virtualhosts.virtualhost.test.store.class", QuotaMessageStore.class.getName());
- setConfigurationProperty("virtualhosts.virtualhost.test.store.overfull-size", String.valueOf(OVERFULL_SIZE));
- setConfigurationProperty("virtualhosts.virtualhost.test.store.underfull-size", String.valueOf(UNDERFULL_SIZE));
+ setVirtualHostConfigurationProperty("virtualhosts.virtualhost.test.store.class", QuotaMessageStore.class.getName());
+ setVirtualHostConfigurationProperty("virtualhosts.virtualhost.test.store.overfull-size", String.valueOf(OVERFULL_SIZE));
+ setVirtualHostConfigurationProperty("virtualhosts.virtualhost.test.store.underfull-size", String.valueOf(UNDERFULL_SIZE));
super.setUp();
diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/systest/management/jmx/BrokerManagementTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/systest/management/jmx/BrokerManagementTest.java
index 7473a4d3e7..954208e78e 100644
--- a/qpid/java/systests/src/main/java/org/apache/qpid/systest/management/jmx/BrokerManagementTest.java
+++ b/qpid/java/systests/src/main/java/org/apache/qpid/systest/management/jmx/BrokerManagementTest.java
@@ -107,6 +107,8 @@ public class BrokerManagementTest extends QpidBrokerTestCase
{
String defaultExchangeName = ExchangeDefaults.DEFAULT_EXCHANGE_NAME.asString();
+ ManagedExchange defaultExchange = _jmxUtils.getManagedExchange(defaultExchangeName);
+ assertNotNull("Exchange should exist", defaultExchange);
try
{
_managedBroker.unregisterExchange(defaultExchangeName);
@@ -117,7 +119,7 @@ public class BrokerManagementTest extends QpidBrokerTestCase
// PASS
assertEquals("'<<default>>' is a reserved exchange and can't be deleted", e.getMessage());
}
- final ManagedExchange defaultExchange = _jmxUtils.getManagedExchange(defaultExchangeName);
+ defaultExchange = _jmxUtils.getManagedExchange(defaultExchangeName);
assertNotNull("Exchange should exist", defaultExchange);
}
diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/systest/management/jmx/ManagementLoggingTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/systest/management/jmx/ManagementLoggingTest.java
index 9fe043b23d..950b002b87 100644
--- a/qpid/java/systests/src/main/java/org/apache/qpid/systest/management/jmx/ManagementLoggingTest.java
+++ b/qpid/java/systests/src/main/java/org/apache/qpid/systest/management/jmx/ManagementLoggingTest.java
@@ -21,12 +21,16 @@
package org.apache.qpid.systest.management.jmx;
-import org.apache.qpid.server.configuration.ServerConfiguration;
+import org.apache.qpid.server.configuration.BrokerProperties;
import org.apache.qpid.server.logging.AbstractTestLogging;
+import org.apache.qpid.server.model.Port;
+import org.apache.qpid.server.model.Transport;
import org.apache.qpid.test.utils.JMXTestUtils;
+import org.apache.qpid.test.utils.TestBrokerConfiguration;
+import org.apache.qpid.test.utils.TestSSLConstants;
import org.apache.qpid.util.LogMonitor;
-import java.io.File;
+import java.util.Collections;
import java.util.List;
/**
@@ -202,7 +206,7 @@ public class ManagementLoggingTest extends AbstractTestLogging
// We expect the RMI Registry port (the defined 'management port') to be
// 100 lower than the JMX RMIConnector Server Port (the actual JMX server)
- int jmxPort = mPort + ServerConfiguration.JMXPORT_CONNECTORSERVER_OFFSET;
+ int jmxPort = mPort + JMXPORT_CONNECTORSERVER_OFFSET;
assertTrue("JMX RMIConnectorServer port not as expected(" + jmxPort + ").:" + getMessageString(log),
getMessageString(log).endsWith(String.valueOf(jmxPort)));
}
@@ -245,7 +249,7 @@ public class ManagementLoggingTest extends AbstractTestLogging
// Validate the keystore path is as expected
assertTrue("SSL Keystore entry expected.:" + getMessageString(log),
- getMessageString(log).endsWith(new File(getConfigurationStringProperty("management.ssl.keyStorePath")).getName()));
+ getMessageString(log).endsWith(TestSSLConstants.BROKER_KEYSTORE));
}
}
@@ -266,6 +270,7 @@ public class ManagementLoggingTest extends AbstractTestLogging
{
if (isJavaBroker())
{
+ setSystemProperty(BrokerProperties.PROPERTY_USE_CUSTOM_RMI_SOCKET_FACTORY, "false");
startBrokerAndCreateMonitor(true, false);
final JMXTestUtils jmxUtils = new JMXTestUtils(this);
@@ -301,13 +306,20 @@ public class ManagementLoggingTest extends AbstractTestLogging
private void startBrokerAndCreateMonitor(boolean managementEnabled, boolean useManagementSSL) throws Exception
{
- //Ensure management is on
- setConfigurationProperty("management.enabled", String.valueOf(managementEnabled));
+ TestBrokerConfiguration config = getBrokerConfiguration();
+
+ if (managementEnabled)
+ {
+ config.addJmxManagementConfiguration();
+ }
if(useManagementSSL)
{
// This test requires we have an ssl connection
- setConfigurationProperty("management.ssl.enabled", "true");
+ config.setObjectAttribute(TestBrokerConfiguration.ENTRY_NAME_JMX_PORT, Port.TRANSPORTS, Collections.singleton(Transport.SSL));
+
+ setSystemProperty("javax.net.ssl.keyStore", "test-profiles/test_resources/ssl/java_broker_keystore.jks");
+ setSystemProperty("javax.net.ssl.keyStorePassword", "password");
}
startBroker();
diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/systest/management/jmx/StatisticsTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/systest/management/jmx/StatisticsTest.java
index 49207e2d7a..72fbd65acc 100644
--- a/qpid/java/systests/src/main/java/org/apache/qpid/systest/management/jmx/StatisticsTest.java
+++ b/qpid/java/systests/src/main/java/org/apache/qpid/systest/management/jmx/StatisticsTest.java
@@ -53,8 +53,8 @@ public class StatisticsTest extends QpidBrokerTestCase
@Override
public void setUp() throws Exception
{
- createTestVirtualHost(TEST_VIRTUALHOST1);
- createTestVirtualHost(TEST_VIRTUALHOST2);
+ createTestVirtualHost(0, TEST_VIRTUALHOST1);
+ createTestVirtualHost(0, TEST_VIRTUALHOST2);
_jmxUtils = new JMXTestUtils(this, TEST_USER, TEST_PASSWORD);
_jmxUtils.setUp();
diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/systest/management/jmx/UserManagementTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/systest/management/jmx/UserManagementTest.java
index 62b1b554a9..7eff1c89ee 100644
--- a/qpid/java/systests/src/main/java/org/apache/qpid/systest/management/jmx/UserManagementTest.java
+++ b/qpid/java/systests/src/main/java/org/apache/qpid/systest/management/jmx/UserManagementTest.java
@@ -23,15 +23,23 @@ import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
import javax.jms.Connection;
import javax.jms.JMSException;
import org.apache.qpid.management.common.mbeans.UserManagement;
-import org.apache.qpid.server.security.auth.database.PlainPasswordFilePrincipalDatabase;
-import org.apache.qpid.server.security.auth.database.PrincipalDatabase;
+import org.apache.qpid.server.model.Port;
+import org.apache.qpid.server.model.Protocol;
+import org.apache.qpid.server.model.Transport;
+import org.apache.qpid.server.plugin.AuthenticationManagerFactory;
+import org.apache.qpid.server.security.auth.manager.AbstractPrincipalDatabaseAuthManagerFactory;
+import org.apache.qpid.server.security.auth.manager.PlainPasswordFileAuthenticationManagerFactory;
import org.apache.qpid.test.utils.JMXTestUtils;
import org.apache.qpid.test.utils.QpidBrokerTestCase;
+import org.apache.qpid.test.utils.TestBrokerConfiguration;
import org.apache.qpid.tools.security.Passwd;
/**
@@ -53,9 +61,10 @@ public class UserManagementTest extends QpidBrokerTestCase
_passwd = createPasswordEncodingUtility();
_passwordFile = createTemporaryPasswordFileWithJmxAdminUser();
- setConfigurationProperty("security.pd-auth-manager.principal-database.class", getPrincipalDatabaseImplClass().getName());
- setConfigurationProperty("security.pd-auth-manager.principal-database.attributes.attribute.name", "passwordFile");
- setConfigurationProperty("security.pd-auth-manager.principal-database.attributes.attribute.value", _passwordFile.getAbsolutePath());
+ Map<String, Object> newAttributes = new HashMap<String, Object>();
+ newAttributes.put(AuthenticationManagerFactory.ATTRIBUTE_TYPE, getAuthenticationManagerType());
+ newAttributes.put(AbstractPrincipalDatabaseAuthManagerFactory.ATTRIBUTE_PATH, _passwordFile.getAbsolutePath());
+ getBrokerConfiguration().setObjectAttributes(TestBrokerConfiguration.ENTRY_NAME_AUTHENTICATION_PROVIDER, newAttributes);
_jmxUtils = new JMXTestUtils(this);
_jmxUtils.setUp();
@@ -163,9 +172,9 @@ public class UserManagementTest extends QpidBrokerTestCase
};
}
- protected Class<? extends PrincipalDatabase> getPrincipalDatabaseImplClass()
+ protected String getAuthenticationManagerType()
{
- return PlainPasswordFilePrincipalDatabase.class;
+ return PlainPasswordFileAuthenticationManagerFactory.PROVIDER_TYPE;
}
private File createTemporaryPasswordFileWithJmxAdminUser() throws Exception
diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/systest/management/jmx/UserManagementWithBase64MD5PasswordsTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/systest/management/jmx/UserManagementWithBase64MD5PasswordsTest.java
index 84a66232ce..1423bc557e 100644
--- a/qpid/java/systests/src/main/java/org/apache/qpid/systest/management/jmx/UserManagementWithBase64MD5PasswordsTest.java
+++ b/qpid/java/systests/src/main/java/org/apache/qpid/systest/management/jmx/UserManagementWithBase64MD5PasswordsTest.java
@@ -18,8 +18,7 @@
*/
package org.apache.qpid.systest.management.jmx;
-import org.apache.qpid.server.security.auth.database.Base64MD5PasswordFilePrincipalDatabase;
-import org.apache.qpid.server.security.auth.database.PrincipalDatabase;
+import org.apache.qpid.server.security.auth.manager.Base64MD5PasswordFileAuthenticationManagerFactory;
import org.apache.qpid.tools.security.Passwd;
public class UserManagementWithBase64MD5PasswordsTest extends UserManagementTest
@@ -31,9 +30,8 @@ public class UserManagementWithBase64MD5PasswordsTest extends UserManagementTest
}
@Override
- protected Class<? extends PrincipalDatabase> getPrincipalDatabaseImplClass()
+ protected String getAuthenticationManagerType()
{
- return Base64MD5PasswordFilePrincipalDatabase.class;
+ return Base64MD5PasswordFileAuthenticationManagerFactory.PROVIDER_TYPE;
}
-
}
diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/Asserts.java b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/Asserts.java
index 2991ba7890..16253139ce 100644
--- a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/Asserts.java
+++ b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/Asserts.java
@@ -37,6 +37,7 @@ import org.apache.qpid.server.model.Connection;
import org.apache.qpid.server.model.Exchange;
import org.apache.qpid.server.model.LifetimePolicy;
import org.apache.qpid.server.model.Port;
+import org.apache.qpid.server.model.Protocol;
import org.apache.qpid.server.model.Queue;
import org.apache.qpid.server.model.State;
import org.apache.qpid.server.model.VirtualHost;
@@ -49,7 +50,7 @@ public class Asserts
{
assertNotNull("Virtualhost " + virtualHostName + " data are not found", virtualHost);
assertAttributesPresent(virtualHost, VirtualHost.AVAILABLE_ATTRIBUTES, VirtualHost.TIME_TO_LIVE,
- VirtualHost.CREATED, VirtualHost.UPDATED, VirtualHost.SUPPORTED_QUEUE_TYPES, VirtualHost.STORE_CONFIGURATION);
+ VirtualHost.CREATED, VirtualHost.UPDATED, VirtualHost.SUPPORTED_QUEUE_TYPES, VirtualHost.STORE_PATH, VirtualHost.CONFIG_PATH);
assertEquals("Unexpected value of attribute " + VirtualHost.NAME, virtualHostName, virtualHost.get(VirtualHost.NAME));
assertNotNull("Unexpected value of attribute " + VirtualHost.ID, virtualHost.get(VirtualHost.ID));
@@ -180,7 +181,6 @@ public class Asserts
public static void assertPortAttributes(Map<String, Object> port)
{
- assertAttributesPresent(port, Port.AVAILABLE_ATTRIBUTES, Port.CREATED, Port.UPDATED);
assertNotNull("Unexpected value of attribute " + Port.ID, port.get(Port.ID));
assertEquals("Unexpected value of attribute " + Port.DURABLE, Boolean.FALSE, port.get(Port.DURABLE));
@@ -188,9 +188,30 @@ public class Asserts
port.get(Broker.LIFETIME_POLICY));
assertEquals("Unexpected value of attribute " + Port.STATE, State.ACTIVE.name(), port.get(Port.STATE));
assertEquals("Unexpected value of attribute " + Port.TIME_TO_LIVE, 0, port.get(Port.TIME_TO_LIVE));
- assertNotNull("Unexpected value of attribute " + Port.BINDING_ADDRESS, port.get(Port.BINDING_ADDRESS));
- assertNotNull("Unexpected value of attribute " + Port.PROTOCOLS, port.get(Port.PROTOCOLS));
- assertNotNull("Unexpected value of attribute " + Port.NAME, port.get(Port.NAME));
+
+ @SuppressWarnings("unchecked")
+ Collection<String> protocols = (Collection<String>) port.get(Port.PROTOCOLS);
+ assertNotNull("Unexpected value of attribute " + Port.PROTOCOLS, protocols);
+ boolean isAMQPPort = false;
+ for (String protocolName : protocols)
+ {
+ if (Protocol.valueOf(protocolName).isAMQP())
+ {
+ isAMQPPort = true;
+ break;
+ }
+ }
+ if (isAMQPPort)
+ {
+ assertAttributesPresent(port, Port.AVAILABLE_ATTRIBUTES, Port.CREATED, Port.UPDATED, Port.AUTHENTICATION_MANAGER);
+ assertNotNull("Unexpected value of attribute " + Port.BINDING_ADDRESS, port.get(Port.BINDING_ADDRESS));
+ }
+ else
+ {
+ assertAttributesPresent(port, Port.AVAILABLE_ATTRIBUTES, Port.CREATED, Port.UPDATED, Port.AUTHENTICATION_MANAGER,
+ Port.BINDING_ADDRESS, Port.TCP_NO_DELAY, Port.SEND_BUFFER_SIZE, Port.RECEIVE_BUFFER_SIZE,
+ Port.NEED_CLIENT_AUTH, Port.WANT_CLIENT_AUTH);
+ }
@SuppressWarnings("unchecked")
Collection<String> transports = (Collection<String>) port.get(Port.TRANSPORTS);
diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/BasicAuthRestTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/BasicAuthRestTest.java
index 74b773c1fa..0574b6cc24 100644
--- a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/BasicAuthRestTest.java
+++ b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/BasicAuthRestTest.java
@@ -25,10 +25,14 @@ import static org.apache.qpid.test.utils.TestSSLConstants.TRUSTSTORE_PASSWORD;
import java.io.IOException;
import java.net.HttpURLConnection;
+import java.util.Collections;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.configuration.ConfigurationException;
+import org.apache.qpid.server.model.Port;
+import org.apache.qpid.server.model.Protocol;
+import org.apache.qpid.test.utils.TestBrokerConfiguration;
public class BasicAuthRestTest extends QpidRestTestCase
{
@@ -51,11 +55,11 @@ public class BasicAuthRestTest extends QpidRestTestCase
private void configure(boolean useSsl) throws ConfigurationException, IOException
{
getRestTestHelper().setUseSsl(useSsl);
- setConfigurationProperty("management.http.enabled", String.valueOf(!useSsl));
- setConfigurationProperty("management.http.port", Integer.toString(getRestTestHelper().getHttpPort()));
- setConfigurationProperty("management.https.enabled", String.valueOf(useSsl));
- setConfigurationProperty("management.https.port", Integer.toString(getRestTestHelper().getHttpPort()));
- setConfigurationProperty("management.enabled", "false"); //JMX
+ if (useSsl)
+ {
+ getBrokerConfiguration().setObjectAttribute(TestBrokerConfiguration.ENTRY_NAME_HTTP_PORT, Port.PROTOCOLS, Collections.singleton(Protocol.HTTPS));
+ }
+ super.customizeConfiguration();
}
private void verifyGetBrokerAttempt(int responseCode) throws IOException
@@ -91,7 +95,8 @@ public class BasicAuthRestTest extends QpidRestTestCase
public void testEnablingForHttp() throws Exception
{
configure(false);
- setConfigurationProperty("management.http.basic-auth", "true");
+
+ getBrokerConfiguration().setObjectAttribute(TestBrokerConfiguration.ENTRY_NAME_HTTP_MANAGEMENT, "httpBasicAuthenticationEnabled", true);
super.setUp();
// Try the attempt with authentication, it should succeed because
@@ -103,7 +108,7 @@ public class BasicAuthRestTest extends QpidRestTestCase
public void testDisablingForHttps() throws Exception
{
configure(true);
- setConfigurationProperty("management.https.basic-auth", "false");
+ getBrokerConfiguration().setObjectAttribute(TestBrokerConfiguration.ENTRY_NAME_HTTP_MANAGEMENT, "httpsBasicAuthenticationEnabled", false);
super.setUp();
setSystemProperty("javax.net.ssl.trustStore", TRUSTSTORE);
setSystemProperty("javax.net.ssl.trustStorePassword", TRUSTSTORE_PASSWORD);
diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/BindingRestTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/BindingRestTest.java
index 7daac0eb46..372db8f560 100644
--- a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/BindingRestTest.java
+++ b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/BindingRestTest.java
@@ -34,7 +34,8 @@ public class BindingRestTest extends QpidRestTestCase
{
List<Map<String, Object>> bindings = getRestTestHelper().getJsonAsList("/rest/binding");
assertNotNull("Bindings cannot be null", bindings);
- assertTrue("Unexpected number of bindings", bindings.size() >= EXPECTED_VIRTUALHOSTS.length * EXPECTED_QUEUES.length);
+ assertTrue("Unexpected number of bindings: " + bindings.size(),
+ bindings.size() >= EXPECTED_VIRTUALHOSTS.length * EXPECTED_QUEUES.length);
for (Map<String, Object> binding : bindings)
{
Asserts.assertBinding((String) binding.get(Binding.NAME), (String) binding.get(Binding.EXCHANGE), binding);
diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/BrokerRestHttpsTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/BrokerRestHttpsTest.java
index c25f160ec8..13e0c1e819 100644
--- a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/BrokerRestHttpsTest.java
+++ b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/BrokerRestHttpsTest.java
@@ -24,10 +24,16 @@ import static org.apache.qpid.test.utils.TestSSLConstants.TRUSTSTORE;
import static org.apache.qpid.test.utils.TestSSLConstants.TRUSTSTORE_PASSWORD;
import java.io.IOException;
+import java.util.Collections;
+import java.util.HashMap;
import java.util.Map;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.Port;
+import org.apache.qpid.server.model.Protocol;
+import org.apache.qpid.server.model.Transport;
+import org.apache.qpid.test.utils.TestBrokerConfiguration;
public class BrokerRestHttpsTest extends QpidRestTestCase
{
@@ -43,11 +49,12 @@ public class BrokerRestHttpsTest extends QpidRestTestCase
@Override
protected void customizeConfiguration() throws ConfigurationException, IOException
{
+ super.customizeConfiguration();
getRestTestHelper().setUseSsl(true);
- setConfigurationProperty("management.enabled", "true");
- setConfigurationProperty("management.http.enabled", "false");
- setConfigurationProperty("management.https.enabled", "true");
- setConfigurationProperty("management.https.port", Integer.toString(getRestTestHelper().getHttpPort()));
+ Map<String, Object> newAttributes = new HashMap<String, Object>();
+ newAttributes.put(Port.PROTOCOLS, Collections.singleton(Protocol.HTTPS));
+ newAttributes.put(Port.TRANSPORTS, Collections.singleton(Transport.SSL));
+ getBrokerConfiguration().setObjectAttributes(TestBrokerConfiguration.ENTRY_NAME_HTTP_PORT,newAttributes);
}
public void testGetWithHttps() throws Exception
@@ -55,6 +62,8 @@ public class BrokerRestHttpsTest extends QpidRestTestCase
Map<String, Object> brokerDetails = getRestTestHelper().getJsonAsSingletonList("/rest/broker");
Asserts.assertAttributesPresent(brokerDetails, Broker.AVAILABLE_ATTRIBUTES, Broker.BYTES_RETAINED,
- Broker.PROCESS_PID, Broker.SUPPORTED_STORE_TYPES, Broker.CREATED, Broker.TIME_TO_LIVE, Broker.UPDATED);
+ Broker.PROCESS_PID, Broker.SUPPORTED_STORE_TYPES, Broker.CREATED, Broker.TIME_TO_LIVE, Broker.UPDATED,
+ Broker.ACL_FILE, Broker.KEY_STORE_CERT_ALIAS, Broker.TRUST_STORE_PATH, Broker.TRUST_STORE_PASSWORD,
+ Broker.GROUP_FILE);
}
}
diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/BrokerRestTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/BrokerRestTest.java
index e5b4ffb297..d479d39287 100644
--- a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/BrokerRestTest.java
+++ b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/BrokerRestTest.java
@@ -32,6 +32,7 @@ import org.apache.qpid.server.model.LifetimePolicy;
import org.apache.qpid.server.model.Port;
import org.apache.qpid.server.model.State;
import org.apache.qpid.server.model.VirtualHost;
+import org.apache.qpid.test.utils.TestBrokerConfiguration;
public class BrokerRestTest extends QpidRestTestCase
{
@@ -61,18 +62,17 @@ public class BrokerRestTest extends QpidRestTestCase
@SuppressWarnings("unchecked")
List<Map<String, Object>> ports = (List<Map<String, Object>>) brokerDetails.get(BROKER_PORTS_ATTRIBUTE);
- assertEquals("Unexpected number of ports", 2, ports.size());
+ assertEquals("Unexpected number of ports", 4, ports.size());
for (Map<String, Object> port : ports)
{
Asserts.assertPortAttributes(port);
}
- String bindingAddress = (String)ports.get(0).get(Port.BINDING_ADDRESS);
-
- Map<String, Object> amqpPort = getRestTestHelper().find(Port.NAME, bindingAddress + ":" + getPort(), ports);
- Map<String, Object> httpPort = getRestTestHelper().find(Port.NAME, bindingAddress + ":" + getRestTestHelper().getHttpPort(), ports);
+ Map<String, Object> amqpPort = getRestTestHelper().find(Port.NAME, TestBrokerConfiguration.ENTRY_NAME_AMQP_PORT, ports);
+ Map<String, Object> httpPort = getRestTestHelper().find(Port.NAME, TestBrokerConfiguration.ENTRY_NAME_HTTP_PORT, ports);
+ assertEquals("Unexpected binding address", "*", amqpPort.get(Port.BINDING_ADDRESS));
assertNotNull("Cannot find AMQP port", amqpPort);
assertNotNull("Cannot find HTTP port", httpPort);
@@ -90,7 +90,9 @@ public class BrokerRestTest extends QpidRestTestCase
{
Asserts.assertAttributesPresent(brokerDetails, Broker.AVAILABLE_ATTRIBUTES,
Broker.BYTES_RETAINED, Broker.PROCESS_PID, Broker.SUPPORTED_STORE_TYPES,
- Broker.CREATED, Broker.TIME_TO_LIVE, Broker.UPDATED);
+ Broker.CREATED, Broker.TIME_TO_LIVE, Broker.UPDATED, Broker.ACL_FILE,
+ Broker.KEY_STORE_PATH, Broker.KEY_STORE_PASSWORD, Broker.KEY_STORE_CERT_ALIAS,
+ Broker.TRUST_STORE_PATH, Broker.TRUST_STORE_PASSWORD, Broker.GROUP_FILE);
assertEquals("Unexpected value of attribute " + Broker.BUILD_VERSION, QpidProperties.getBuildVersion(),
brokerDetails.get(Broker.BUILD_VERSION));
@@ -105,7 +107,7 @@ public class BrokerRestTest extends QpidRestTestCase
assertEquals("Unexpected value of attribute " + Broker.DURABLE, Boolean.TRUE, brokerDetails.get(Broker.DURABLE));
assertEquals("Unexpected value of attribute " + Broker.LIFETIME_POLICY, LifetimePolicy.PERMANENT.name(),
brokerDetails.get(Broker.LIFETIME_POLICY));
- assertEquals("Unexpected value of attribute " + Broker.NAME, "Broker", brokerDetails.get(Broker.NAME));
+ assertEquals("Unexpected value of attribute " + Broker.NAME, "QpidBroker", brokerDetails.get(Broker.NAME));
assertEquals("Unexpected value of attribute " + Broker.STATE, State.ACTIVE.name(), brokerDetails.get(Broker.STATE));
assertNotNull("Unexpected value of attribute " + Broker.ID, brokerDetails.get(Broker.ID));
diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/GroupProviderRestTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/GroupProviderRestTest.java
index 2852de6fb3..861bf8cb71 100644
--- a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/GroupProviderRestTest.java
+++ b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/GroupProviderRestTest.java
@@ -26,6 +26,7 @@ import java.util.List;
import java.util.Map;
import java.util.Properties;
+import org.apache.qpid.server.model.Broker;
import org.apache.qpid.server.model.Group;
import org.apache.qpid.server.model.GroupProvider;
import org.apache.qpid.server.model.LifetimePolicy;
@@ -42,8 +43,7 @@ public class GroupProviderRestTest extends QpidRestTestCase
{
_groupFile = createTemporaryGroupFile();
- setConfigurationProperty("security.file-group-manager.attributes.attribute.name", "groupFile");
- setConfigurationProperty("security.file-group-manager.attributes.attribute.value", _groupFile.getAbsolutePath());
+ getBrokerConfiguration().setBrokerAttribute(Broker.GROUP_FILE, _groupFile.getAbsolutePath());
super.setUp();
}
diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/GroupRestTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/GroupRestTest.java
index cbfd943f8f..d3f93cc0fe 100644
--- a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/GroupRestTest.java
+++ b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/GroupRestTest.java
@@ -26,6 +26,7 @@ import java.util.List;
import java.util.Map;
import java.util.Properties;
+import org.apache.qpid.server.model.Broker;
import org.apache.qpid.server.model.GroupMember;
public class GroupRestTest extends QpidRestTestCase
@@ -42,8 +43,7 @@ public class GroupRestTest extends QpidRestTestCase
{
_groupFile = createTemporaryGroupFile();
- setConfigurationProperty("security.file-group-manager.attributes.attribute.name", "groupFile");
- setConfigurationProperty("security.file-group-manager.attributes.attribute.value", _groupFile.getAbsolutePath());
+ getBrokerConfiguration().setBrokerAttribute(Broker.GROUP_FILE, _groupFile.getAbsolutePath());
super.setUp();
}
diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/PortRestTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/PortRestTest.java
index d5a8c31010..578565be05 100644
--- a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/PortRestTest.java
+++ b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/PortRestTest.java
@@ -25,6 +25,7 @@ import java.util.List;
import java.util.Map;
import org.apache.qpid.server.model.Port;
+import org.apache.qpid.test.utils.TestBrokerConfiguration;
public class PortRestTest extends QpidRestTestCase
{
@@ -32,22 +33,24 @@ public class PortRestTest extends QpidRestTestCase
{
List<Map<String, Object>> ports = getRestTestHelper().getJsonAsList("/rest/port/");
assertNotNull("Port data cannot be null", ports);
- assertEquals("Unexpected number of ports", 2, ports.size());
- int[] expectedPorts = { getPort(), getRestTestHelper().getHttpPort() };
- for (int port : expectedPorts)
- {
- String portName = "0.0.0.0:" + port;
- Map<String, Object> portData = getRestTestHelper().find(Port.NAME, portName, ports);
- assertNotNull("Port " + portName + " is not found", portData);
- Asserts.assertPortAttributes(portData);
- }
+ assertEquals("Unexpected number of ports", 4, ports.size());
+
+ String httpPortName = TestBrokerConfiguration.ENTRY_NAME_HTTP_PORT;
+ Map<String, Object> portData = getRestTestHelper().find(Port.NAME, httpPortName, ports);
+ assertNotNull("Http port " + httpPortName + " is not found", portData);
+ Asserts.assertPortAttributes(portData);
+
+ String amqpPortName = TestBrokerConfiguration.ENTRY_NAME_AMQP_PORT;
+ Map<String, Object> amqpPortData = getRestTestHelper().find(Port.NAME, amqpPortName, ports);
+ assertNotNull("Amqp port " + amqpPortName + " is not found", amqpPortData);
+ Asserts.assertPortAttributes(amqpPortData);
}
public void testGetPort() throws Exception
{
List<Map<String, Object>> ports = getRestTestHelper().getJsonAsList("/rest/port/");
assertNotNull("Ports data cannot be null", ports);
- assertEquals("Unexpected number of ports", 2, ports.size());
+ assertEquals("Unexpected number of ports", 4, ports.size());
for (Map<String, Object> portMap : ports)
{
String portName = (String) portMap.get(Port.NAME);
diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/QpidRestTestCase.java b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/QpidRestTestCase.java
index d63d17f6e5..671bdd7eb8 100644
--- a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/QpidRestTestCase.java
+++ b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/QpidRestTestCase.java
@@ -23,6 +23,8 @@ package org.apache.qpid.systest.rest;
import java.io.IOException;
import org.apache.commons.configuration.ConfigurationException;
+import org.apache.qpid.server.model.Port;
+import org.apache.qpid.test.utils.TestBrokerConfiguration;
import org.apache.qpid.test.utils.QpidBrokerTestCase;
public class QpidRestTestCase extends QpidBrokerTestCase
@@ -43,11 +45,11 @@ public class QpidRestTestCase extends QpidBrokerTestCase
// Set up virtualhost config with queues and bindings to the amq.direct
for (String virtualhost : EXPECTED_VIRTUALHOSTS)
{
- createTestVirtualHost(virtualhost);
+ createTestVirtualHost(0, virtualhost);
for (String queue : EXPECTED_QUEUES)
{
- setConfigurationProperty("virtualhosts.virtualhost." + virtualhost + ".queues.exchange", "amq.direct");
- setConfigurationProperty("virtualhosts.virtualhost." + virtualhost + ".queues.queue(-1).name", queue);
+ setVirtualHostConfigurationProperty("virtualhosts.virtualhost." + virtualhost + ".queues.exchange", "amq.direct");
+ setVirtualHostConfigurationProperty("virtualhosts.virtualhost." + virtualhost + ".queues.queue(-1).name", queue);
}
}
@@ -70,10 +72,9 @@ public class QpidRestTestCase extends QpidBrokerTestCase
protected void customizeConfiguration() throws ConfigurationException, IOException
{
- setConfigurationProperty("management.enabled", "false");
- setConfigurationProperty("management.http.enabled", "true");
- setConfigurationProperty("management.https.enabled", "false");
- setConfigurationProperty("management.http.port", Integer.toString(_restTestHelper.getHttpPort()));
+ TestBrokerConfiguration config = getBrokerConfiguration();
+ config.addHttpManagementConfiguration();
+ config.setObjectAttribute(TestBrokerConfiguration.ENTRY_NAME_HTTP_PORT, Port.PORT, _restTestHelper.getHttpPort());
}
public RestTestHelper getRestTestHelper()
diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/RestTestHelper.java b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/RestTestHelper.java
index 4de603ae6e..0db1f7e50d 100644
--- a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/RestTestHelper.java
+++ b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/RestTestHelper.java
@@ -51,8 +51,10 @@ import junit.framework.Assert;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.log4j.Logger;
+import org.apache.qpid.server.security.auth.manager.AbstractPrincipalDatabaseAuthManagerFactory;
import org.apache.qpid.ssl.SSLContextFactory;
import org.apache.qpid.test.utils.QpidBrokerTestCase;
+import org.apache.qpid.test.utils.TestBrokerConfiguration;
import org.codehaus.jackson.JsonGenerationException;
import org.codehaus.jackson.JsonParseException;
import org.codehaus.jackson.map.JsonMappingException;
@@ -292,6 +294,7 @@ public class RestTestHelper
public void assertNumberOfGroupMembers(Map<String, Object> data, int expectedNumberOfGroupMembers)
{
+ @SuppressWarnings("unchecked")
List<Map<String, Object>> groups = (List<Map<String, Object>>) data.get("groupmembers");
if (groups == null)
{
@@ -327,7 +330,8 @@ public class RestTestHelper
public void createOrUpdateUser(String username, String password, int responseCode) throws IOException
{
- HttpURLConnection connection = openManagementConnection("/rest/user/PrincipalDatabaseAuthenticationManager/" + username, "PUT");
+ HttpURLConnection connection = openManagementConnection("/rest/user/"
+ + TestBrokerConfiguration.ENTRY_NAME_AUTHENTICATION_PROVIDER + "/" + username, "PUT");
Map<String, Object> data = new HashMap<String, Object>();
data.put("password", password);
@@ -355,14 +359,16 @@ public class RestTestHelper
public void removeUserById(String id) throws IOException
{
- HttpURLConnection connection = openManagementConnection("/rest/user/PrincipalDatabaseAuthenticationManager?id=" + id, "DELETE");
+ HttpURLConnection connection = openManagementConnection("/rest/user/"
+ + TestBrokerConfiguration.ENTRY_NAME_AUTHENTICATION_PROVIDER + "?id=" + id, "DELETE");
Assert.assertEquals("Unexpected response code", HttpServletResponse.SC_OK, connection.getResponseCode());
connection.disconnect();
}
public void removeUser(String username, int responseCode) throws IOException
{
- HttpURLConnection connection = openManagementConnection("/rest/user/PrincipalDatabaseAuthenticationManager/" + username, "DELETE");
+ HttpURLConnection connection = openManagementConnection("/rest/user/"
+ + TestBrokerConfiguration.ENTRY_NAME_AUTHENTICATION_PROVIDER + "/" + username, "DELETE");
Assert.assertEquals("Unexpected response code", responseCode, connection.getResponseCode());
connection.disconnect();
}
@@ -374,6 +380,7 @@ public class RestTestHelper
public void assertNumberOfGroups(Map<String, Object> data, int expectedNumberOfGroups)
{
+ @SuppressWarnings("unchecked")
List<Map<String, Object>> groups = (List<Map<String, Object>>) data.get("groups");
if (groups == null)
{
@@ -400,8 +407,8 @@ public class RestTestHelper
{
_passwdFile = createTemporaryPasswdFile(users);
- testCase.setConfigurationProperty("security.pd-auth-manager.principal-database.attributes.attribute.name", "passwordFile");
- testCase.setConfigurationProperty("security.pd-auth-manager.principal-database.attributes.attribute.value", _passwdFile.getAbsolutePath());
+ testCase.getBrokerConfiguration().setObjectAttribute(TestBrokerConfiguration.ENTRY_NAME_AUTHENTICATION_PROVIDER,
+ AbstractPrincipalDatabaseAuthManagerFactory.ATTRIBUTE_PATH, _passwdFile.getAbsolutePath());
}
public void tearDown()
diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/SaslRestTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/SaslRestTest.java
index a775af5dcf..856fda9419 100644
--- a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/SaslRestTest.java
+++ b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/SaslRestTest.java
@@ -27,6 +27,7 @@ import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -35,6 +36,10 @@ import javax.crypto.spec.SecretKeySpec;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.configuration.ConfigurationException;
+import org.apache.qpid.server.plugin.AuthenticationManagerFactory;
+import org.apache.qpid.server.security.auth.manager.AbstractPrincipalDatabaseAuthManagerFactory;
+import org.apache.qpid.server.security.auth.manager.Base64MD5PasswordFileAuthenticationManagerFactory;
+import org.apache.qpid.test.utils.TestBrokerConfiguration;
import org.apache.qpid.tools.security.Passwd;
import org.codehaus.jackson.JsonParseException;
import org.codehaus.jackson.map.JsonMappingException;
@@ -422,9 +427,9 @@ public class SaslRestTest extends QpidRestTestCase
}
// configure broker to use Base64MD5PasswordFilePrincipalDatabase
- setConfigurationProperty("security.pd-auth-manager.principal-database.class",
- "org.apache.qpid.server.security.auth.database.Base64MD5PasswordFilePrincipalDatabase");
- setConfigurationProperty("security.pd-auth-manager.principal-database.attributes.attribute.value", passwordFile.getAbsolutePath());
- setConfigurationProperty("management.http.sasl-auth", "true");
+ Map<String, Object> newAttributes = new HashMap<String, Object>();
+ newAttributes.put(AbstractPrincipalDatabaseAuthManagerFactory.ATTRIBUTE_PATH, passwordFile.getAbsolutePath());
+ newAttributes.put(AuthenticationManagerFactory.ATTRIBUTE_TYPE, Base64MD5PasswordFileAuthenticationManagerFactory.PROVIDER_TYPE);
+ getBrokerConfiguration().setObjectAttributes(TestBrokerConfiguration.ENTRY_NAME_AUTHENTICATION_PROVIDER, newAttributes);
}
}
diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/StructureRestTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/StructureRestTest.java
index 30433fb40a..427934fac2 100644
--- a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/StructureRestTest.java
+++ b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/StructureRestTest.java
@@ -23,6 +23,9 @@ package org.apache.qpid.systest.rest;
import java.util.List;
import java.util.Map;
+import org.apache.qpid.server.model.Port;
+import org.apache.qpid.test.utils.TestBrokerConfiguration;
+
public class StructureRestTest extends QpidRestTestCase
{
@@ -30,7 +33,7 @@ public class StructureRestTest extends QpidRestTestCase
{
Map<String, Object> structure = getRestTestHelper().getJsonAsMap("/rest/structure");
assertNotNull("Structure data cannot be null", structure);
- assertNode(structure, "Broker");
+ assertNode(structure, "QpidBroker");
@SuppressWarnings("unchecked")
List<Map<String, Object>> virtualhosts = (List<Map<String, Object>>) structure.get("virtualhosts");
@@ -38,7 +41,7 @@ public class StructureRestTest extends QpidRestTestCase
@SuppressWarnings("unchecked")
List<Map<String, Object>> ports = (List<Map<String, Object>>) structure.get("ports");
- assertEquals("Unexpected number of ports", 2, ports.size());
+ assertEquals("Unexpected number of ports", 4, ports.size());
@SuppressWarnings("unchecked")
List<Map<String, Object>> providers = (List<Map<String, Object>>) structure.get("authenticationproviders");
@@ -89,22 +92,18 @@ public class StructureRestTest extends QpidRestTestCase
}
}
}
-
- @SuppressWarnings("unchecked")
- List<Map<String, Object>> aliases = (List<Map<String, Object>>) host.get("virtualhostaliases");
- assertNotNull("Host " + hostName + " aliaces are not found ", aliases);
- assertEquals("Unexpected aliaces size", 1, aliases.size());
- assertNode(aliases.get(0), hostName);
}
- int[] expectedPorts = { getPort(), getRestTestHelper().getHttpPort() };
- for (int port : expectedPorts)
- {
- String portName = "0.0.0.0:" + port;
- Map<String, Object> portData = getRestTestHelper().find("name", portName, ports);
- assertNotNull("Port " + portName + " is not found ", portData);
- assertNode(portData, portName);
- }
+
+ String httpPortName = TestBrokerConfiguration.ENTRY_NAME_HTTP_PORT;
+ Map<String, Object> portData = getRestTestHelper().find(Port.NAME, httpPortName, ports);
+ assertNotNull("Http Port " + httpPortName + " is not found", portData);
+ assertNode(portData, httpPortName);
+
+ String amqpPortName = TestBrokerConfiguration.ENTRY_NAME_AMQP_PORT;
+ Map<String, Object> amqpPortData = getRestTestHelper().find(Port.NAME, amqpPortName, ports);
+ assertNotNull("Amqp port " + amqpPortName + " is not found", amqpPortData);
+ assertNode(amqpPortData, amqpPortName);
}
private void assertNode(Map<String, Object> node, String name)
diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/UserRestTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/UserRestTest.java
index 159cd8e52d..017467a8be 100644
--- a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/UserRestTest.java
+++ b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/UserRestTest.java
@@ -24,6 +24,7 @@ import java.util.List;
import java.util.Map;
import org.apache.qpid.server.model.User;
+import org.apache.qpid.test.utils.TestBrokerConfiguration;
public class UserRestTest extends QpidRestTestCase
{
@@ -56,8 +57,8 @@ public class UserRestTest extends QpidRestTestCase
assertNotNull("Attribute " + User.ID, user.get(User.ID));
String userName = (String) user.get(User.NAME);
assertNotNull("Attribute " + User.NAME, userName);
- Map<String, Object> userDetails = getRestTestHelper().getJsonAsSingletonList("/rest/user/PrincipalDatabaseAuthenticationManager/"
- + userName);
+ Map<String, Object> userDetails = getRestTestHelper().getJsonAsSingletonList("/rest/user/"
+ + TestBrokerConfiguration.ENTRY_NAME_AUTHENTICATION_PROVIDER + "/" + userName);
assertUser(userDetails);
assertEquals("Unexpected user name", userName, userDetails.get(User.NAME));
}
@@ -68,8 +69,8 @@ public class UserRestTest extends QpidRestTestCase
String userName = getTestName();
getRestTestHelper().createOrUpdateUser(userName, "newPassword");
- Map<String, Object> userDetails = getRestTestHelper().getJsonAsSingletonList("/rest/user/PrincipalDatabaseAuthenticationManager/"
- + userName);
+ Map<String, Object> userDetails = getRestTestHelper().getJsonAsSingletonList("/rest/user/"
+ + TestBrokerConfiguration.ENTRY_NAME_AUTHENTICATION_PROVIDER + "/" + userName);
assertUser(userDetails);
assertEquals("Unexpected user name", userName, userDetails.get(User.NAME));
}
@@ -79,13 +80,14 @@ public class UserRestTest extends QpidRestTestCase
String userName = getTestName();
getRestTestHelper().createOrUpdateUser(userName, "newPassword");
- Map<String, Object> userDetails = getRestTestHelper().getJsonAsSingletonList("/rest/user/PrincipalDatabaseAuthenticationManager/"
- + userName);
+ Map<String, Object> userDetails = getRestTestHelper().getJsonAsSingletonList("/rest/user/"
+ + TestBrokerConfiguration.ENTRY_NAME_AUTHENTICATION_PROVIDER + "/" + userName);
String id = (String) userDetails.get(User.ID);
getRestTestHelper().removeUserById(id);
- List<Map<String, Object>> users = getRestTestHelper().getJsonAsList("/rest/user/PrincipalDatabaseAuthenticationManager/" + userName);
+ List<Map<String, Object>> users = getRestTestHelper().getJsonAsList("/rest/user/"
+ + TestBrokerConfiguration.ENTRY_NAME_AUTHENTICATION_PROVIDER + "/" + userName);
assertEquals("User should be deleted", 0, users.size());
}
diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/VirtualHostRestTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/VirtualHostRestTest.java
index 5b8c3fce33..fb2c941203 100644
--- a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/VirtualHostRestTest.java
+++ b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/VirtualHostRestTest.java
@@ -20,6 +20,7 @@
*/
package org.apache.qpid.systest.rest;
+import java.io.File;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.util.HashMap;
@@ -29,11 +30,15 @@ import java.util.Map;
import javax.jms.Session;
import javax.servlet.http.HttpServletResponse;
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.XMLConfiguration;
import org.apache.qpid.client.AMQConnection;
import org.apache.qpid.server.model.Exchange;
import org.apache.qpid.server.model.Queue;
import org.apache.qpid.server.model.VirtualHost;
import org.apache.qpid.server.queue.AMQQueueFactory;
+import org.apache.qpid.test.utils.TestFileUtils;
+import org.apache.qpid.util.FileUtils;
import org.codehaus.jackson.JsonGenerationException;
import org.codehaus.jackson.map.JsonMappingException;
@@ -98,6 +103,72 @@ public class VirtualHostRestTest extends QpidRestTestCase
Asserts.assertConnection(connections.get(0), _connection);
}
+ public void testPutCreateVirtualHostUsingStoreType() throws Exception
+ {
+ String hostName = getTestName();
+ String storeType = getTestProfileMessageStoreType();
+ String storeLocation = createHost(hostName, storeType, null);
+ try
+ {
+ // make sure that the host is saved in the broker store
+ restartBroker();
+ Map<String, Object> hostDetails = getRestTestHelper().getJsonAsSingletonList("/rest/virtualhost/" + hostName);
+ Asserts.assertVirtualHost(hostName, hostDetails);
+ assertEquals("Unexpected store type", storeType, hostDetails.get(VirtualHost.STORE_TYPE));
+
+ assertNewVirtualHost(hostDetails);
+ }
+ finally
+ {
+ if (storeLocation != null)
+ {
+ FileUtils.delete(new File(storeLocation), true);
+ }
+ }
+ }
+
+ public void testPutCreateVirtualHostUsingConfigPath() throws Exception
+ {
+ String hostName = getTestName();
+ File configFile = TestFileUtils.createTempFile(this, hostName + "-config.xml");
+ String configPath = configFile.getAbsolutePath();
+ String storeLocation = getStoreLocation(hostName);
+ createAndSaveVirtualHostConfiguration(hostName, configFile, storeLocation);
+ createHost(hostName, null, configPath);
+ try
+ {
+ // make sure that the host is saved in the broker store
+ restartBroker();
+ Map<String, Object> hostDetails = getRestTestHelper().getJsonAsSingletonList("/rest/virtualhost/" + hostName);
+ Asserts.assertVirtualHost(hostName, hostDetails);
+ assertEquals("Unexpected config path", configPath, hostDetails.get(VirtualHost.CONFIG_PATH));
+
+ assertNewVirtualHost(hostDetails);
+ }
+ finally
+ {
+ if (storeLocation != null)
+ {
+ FileUtils.delete(new File(storeLocation), true);
+ }
+ configFile.delete();
+ }
+ }
+
+ public void testDeleteHost() throws Exception
+ {
+ String hostToDelete = TEST3_VIRTUALHOST;
+ HttpURLConnection connection = getRestTestHelper().openManagementConnection("/rest/virtualhost/" + hostToDelete, "DELETE");
+ connection.connect();
+ assertEquals("Unexpected response code", 200, connection.getResponseCode());
+
+ // make sure that changes are saved in the broker store
+ restartBroker();
+
+ List<Map<String, Object>> hosts = getRestTestHelper().getJsonAsList("/rest/virtualhost/" + hostToDelete);
+ assertEquals("Host should be deleted", 0, hosts.size());
+ }
+
public void testPutCreateQueue() throws Exception
{
String queueName = getTestQueueName();
@@ -431,4 +502,75 @@ public class VirtualHostRestTest extends QpidRestTestCase
return responseCode;
}
+ private String createHost(String hostName, String storeType, String configPath) throws IOException, JsonGenerationException,
+ JsonMappingException
+ {
+ String storePath = getStoreLocation(hostName);
+ int responseCode = tryCreateVirtualHost(hostName, storeType, storePath, configPath);
+ assertEquals("Unexpected response code", 201, responseCode);
+ return storePath;
+ }
+
+ private String getStoreLocation(String hostName)
+ {
+ return new File(TMP_FOLDER, "store-" + hostName + "-" + System.currentTimeMillis()).getAbsolutePath();
+ }
+
+ private int tryCreateVirtualHost(String hostName, String storeType, String storePath, String configPath) throws IOException,
+ JsonGenerationException, JsonMappingException
+ {
+ HttpURLConnection connection = getRestTestHelper().openManagementConnection("/rest/virtualhost/" + hostName, "PUT");
+
+ Map<String, Object> hostData = new HashMap<String, Object>();
+ hostData.put(VirtualHost.NAME, hostName);
+ if (storeType == null)
+ {
+ hostData.put(VirtualHost.CONFIG_PATH, configPath);
+ }
+ else
+ {
+ hostData.put(VirtualHost.STORE_PATH, storePath);
+ hostData.put(VirtualHost.STORE_TYPE, storeType);
+ }
+
+ getRestTestHelper().writeJsonRequest(connection, hostData);
+ int responseCode = connection.getResponseCode();
+ connection.disconnect();
+ return responseCode;
+ }
+
+ private XMLConfiguration createAndSaveVirtualHostConfiguration(String hostName, File configFile, String storeLocation)
+ throws ConfigurationException
+ {
+ XMLConfiguration testConfiguration = new XMLConfiguration();
+ testConfiguration.setProperty("virtualhosts.virtualhost." + hostName + ".store.class",
+ getTestProfileMessageStoreClassName());
+ testConfiguration.setProperty("virtualhosts.virtualhost." + hostName + ".store.environment-path", storeLocation);
+ testConfiguration.save(configFile);
+ return testConfiguration;
+ }
+
+ private void assertNewVirtualHost(Map<String, Object> hostDetails)
+ {
+ @SuppressWarnings("unchecked")
+ Map<String, Object> statistics = (Map<String, Object>) hostDetails.get(Asserts.STATISTICS_ATTRIBUTE);
+ assertEquals("Unexpected number of exchanges in statistics", EXPECTED_EXCHANGES.length,
+ statistics.get(VirtualHost.EXCHANGE_COUNT));
+ assertEquals("Unexpected number of queues in statistics", 0, statistics.get(VirtualHost.QUEUE_COUNT));
+ assertEquals("Unexpected number of connections in statistics", 0, statistics.get(VirtualHost.CONNECTION_COUNT));
+
+ @SuppressWarnings("unchecked")
+ List<Map<String, Object>> exchanges = (List<Map<String, Object>>) hostDetails.get(VIRTUALHOST_EXCHANGES_ATTRIBUTE);
+ assertEquals("Unexpected number of exchanges", EXPECTED_EXCHANGES.length, exchanges.size());
+ RestTestHelper restTestHelper = getRestTestHelper();
+ Asserts.assertDurableExchange("amq.fanout", "fanout", restTestHelper.find(Exchange.NAME, "amq.fanout", exchanges));
+ Asserts.assertDurableExchange("amq.topic", "topic", restTestHelper.find(Exchange.NAME, "amq.topic", exchanges));
+ Asserts.assertDurableExchange("amq.direct", "direct", restTestHelper.find(Exchange.NAME, "amq.direct", exchanges));
+ Asserts.assertDurableExchange("amq.match", "headers", restTestHelper.find(Exchange.NAME, "amq.match", exchanges));
+ Asserts.assertDurableExchange("<<default>>", "direct", restTestHelper.find(Exchange.NAME, "<<default>>", exchanges));
+
+ assertNull("Unexpected queues", hostDetails.get(VIRTUALHOST_QUEUES_ATTRIBUTE));
+ assertNull("Unexpected connections", hostDetails.get(VIRTUALHOST_CONNECTIONS_ATTRIBUTE));
+ }
+
}
diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/acl/GroupRestACLTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/acl/GroupRestACLTest.java
index 7b8ad9141c..40ea723b1e 100644
--- a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/acl/GroupRestACLTest.java
+++ b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/acl/GroupRestACLTest.java
@@ -28,8 +28,11 @@ import java.util.Properties;
import javax.servlet.http.HttpServletResponse;
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.qpid.server.model.Broker;
import org.apache.qpid.server.security.acl.AbstractACLTestCase;
import org.apache.qpid.systest.rest.QpidRestTestCase;
+import org.apache.qpid.test.utils.TestBrokerConfiguration;
public class GroupRestACLTest extends QpidRestTestCase
{
@@ -49,15 +52,19 @@ public class GroupRestACLTest extends QpidRestTestCase
public void setUp() throws Exception
{
_groupFile = createTemporaryGroupFile();
-
- setConfigurationProperty("management.http.basic-auth", "true");
- setConfigurationProperty("security.file-group-manager.attributes.attribute.name", "groupFile");
- setConfigurationProperty("security.file-group-manager.attributes.attribute.value", _groupFile.getAbsolutePath());
+ getBrokerConfiguration().setBrokerAttribute(Broker.GROUP_FILE, _groupFile.getAbsolutePath());
//DONT call super.setUp(), the tests will start the broker after configuring it
}
@Override
+ protected void customizeConfiguration() throws ConfigurationException, IOException
+ {
+ super.customizeConfiguration();
+ getBrokerConfiguration().setObjectAttribute(TestBrokerConfiguration.ENTRY_NAME_HTTP_MANAGEMENT, "httpBasicAuthenticationEnabled", true);
+ }
+
+ @Override
public void tearDown() throws Exception
{
super.tearDown();
diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/acl/UserRestACLTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/acl/UserRestACLTest.java
index c02dc804db..12973113d8 100644
--- a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/acl/UserRestACLTest.java
+++ b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/acl/UserRestACLTest.java
@@ -28,8 +28,11 @@ import java.util.Properties;
import javax.servlet.http.HttpServletResponse;
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.qpid.server.model.Broker;
import org.apache.qpid.server.security.acl.AbstractACLTestCase;
import org.apache.qpid.systest.rest.QpidRestTestCase;
+import org.apache.qpid.test.utils.TestBrokerConfiguration;
import org.codehaus.jackson.JsonParseException;
import org.codehaus.jackson.map.JsonMappingException;
@@ -49,10 +52,7 @@ public class UserRestACLTest extends QpidRestTestCase
public void setUp() throws Exception
{
_groupFile = createTemporaryGroupFile();
-
- setConfigurationProperty("management.http.basic-auth", "true");
- setConfigurationProperty("security.file-group-manager.attributes.attribute.name", "groupFile");
- setConfigurationProperty("security.file-group-manager.attributes.attribute.value", _groupFile.getAbsolutePath());
+ getBrokerConfiguration().setBrokerAttribute(Broker.GROUP_FILE, _groupFile.getAbsolutePath());
getRestTestHelper().configureTemporaryPasswordFile(this, ALLOWED_USER, DENIED_USER, OTHER_USER);
@@ -60,6 +60,13 @@ public class UserRestACLTest extends QpidRestTestCase
}
@Override
+ protected void customizeConfiguration() throws ConfigurationException, IOException
+ {
+ super.customizeConfiguration();
+ getBrokerConfiguration().setObjectAttribute(TestBrokerConfiguration.ENTRY_NAME_HTTP_MANAGEMENT, "httpBasicAuthenticationEnabled", true);
+ }
+
+ @Override
public void tearDown() throws Exception
{
super.tearDown();
@@ -163,7 +170,8 @@ public class UserRestACLTest extends QpidRestTestCase
private void checkPassword(String username, String password, boolean passwordExpectedToBeCorrect) throws IOException
{
getRestTestHelper().setUsernameAndPassword(username, password);
- HttpURLConnection connection = getRestTestHelper().openManagementConnection("/rest/user/PrincipalDatabaseAuthenticationManager/", "GET");
+ HttpURLConnection connection = getRestTestHelper().openManagementConnection("/rest/user/"
+ + TestBrokerConfiguration.ENTRY_NAME_AUTHENTICATION_PROVIDER + "/", "GET");
boolean passwordIsCorrect = connection.getResponseCode() == HttpServletResponse.SC_OK;
@@ -174,14 +182,14 @@ public class UserRestACLTest extends QpidRestTestCase
private void assertUserDoesNotExist(String newUser) throws JsonParseException, JsonMappingException, IOException
{
- String path = "/rest/user/PrincipalDatabaseAuthenticationManager/" + newUser;
+ String path = "/rest/user/" + TestBrokerConfiguration.ENTRY_NAME_AUTHENTICATION_PROVIDER + "/" + newUser;
List<Map<String, Object>> userDetailsList = getRestTestHelper().getJsonAsList(path);
assertTrue(userDetailsList.isEmpty());
}
private void assertUserExists(String username) throws IOException
{
- String path = "/rest/user/PrincipalDatabaseAuthenticationManager/" + username;
+ String path = "/rest/user/" + TestBrokerConfiguration.ENTRY_NAME_AUTHENTICATION_PROVIDER + "/" + username;
Map<String, Object> userDetails = getRestTestHelper().getJsonAsSingletonList(path);
assertEquals(
diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/client/message/JMSDestinationTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/test/client/message/JMSDestinationTest.java
index 5b350d2d89..3cc15d5e9d 100644
--- a/qpid/java/systests/src/main/java/org/apache/qpid/test/client/message/JMSDestinationTest.java
+++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/client/message/JMSDestinationTest.java
@@ -63,8 +63,7 @@ public class JMSDestinationTest extends QpidBrokerTestCase
public void setUp() throws Exception
{
- //Ensure JMX management is enabled for MovedToQueue test
- setConfigurationProperty("management.enabled", "true");
+ getBrokerConfiguration().addJmxManagementConfiguration();
super.setUp();
diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/client/timeouts/SyncWaitDelayTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/test/client/timeouts/SyncWaitDelayTest.java
index ee81e7c372..9bf7dbd62a 100644
--- a/qpid/java/systests/src/main/java/org/apache/qpid/test/client/timeouts/SyncWaitDelayTest.java
+++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/client/timeouts/SyncWaitDelayTest.java
@@ -54,11 +54,9 @@ public class SyncWaitDelayTest extends QpidBrokerTestCase
public void setUp() throws Exception
{
- setConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST+".store.class", "org.apache.qpid.server.store.SlowMessageStore");
- setConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST+".store.delays.commitTran.post", String.valueOf(POST_COMMIT_DELAY));
- setConfigurationProperty("management.enabled", "false");
+ setVirtualHostConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST+".store.class", "org.apache.qpid.server.store.SlowMessageStore");
+ setVirtualHostConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST+".store.delays.commitTran.post", String.valueOf(POST_COMMIT_DELAY));
-
super.setUp();
//Set the syncWrite timeout to be just larger than the delay on the commitTran.
diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/client/MaxDeliveryCountTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/client/MaxDeliveryCountTest.java
index 8c407d3def..40db17f799 100644
--- a/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/client/MaxDeliveryCountTest.java
+++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/client/MaxDeliveryCountTest.java
@@ -74,14 +74,13 @@ public class MaxDeliveryCountTest extends QpidBrokerTestCase
public void setUp() throws Exception
{
//enable DLQ/maximumDeliveryCount support for all queues at the vhost level
- setConfigurationProperty("virtualhosts.virtualhost.test.queues.maximumDeliveryCount",
+ setVirtualHostConfigurationProperty("virtualhosts.virtualhost.test.queues.maximumDeliveryCount",
String.valueOf(MAX_DELIVERY_COUNT));
- setConfigurationProperty("virtualhosts.virtualhost.test.queues.deadLetterQueues",
+ setVirtualHostConfigurationProperty("virtualhosts.virtualhost.test.queues.deadLetterQueues",
String.valueOf(true));
//Ensure management is on
- setConfigurationProperty("management.enabled", "true");
- setConfigurationProperty("management.ssl.enabled", "false");
+ getBrokerConfiguration().addJmxManagementConfiguration();
// Set client-side flag to allow the server to determine if messages
// dead-lettered or requeued.
diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/topic/DurableSubscriptionTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/topic/DurableSubscriptionTest.java
index a07e531b98..a9ac028af6 100644
--- a/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/topic/DurableSubscriptionTest.java
+++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/topic/DurableSubscriptionTest.java
@@ -73,7 +73,7 @@ public class DurableSubscriptionTest extends QpidBrokerTestCase
public void setUp() throws Exception
{
- setConfigurationProperty("management.enabled", "true");
+ getBrokerConfiguration().addJmxManagementConfiguration();
_jmxConnected=false;
super.setUp();
}
diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/transacted/TransactionTimeoutDisabledTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/transacted/TransactionTimeoutDisabledTest.java
index fd8beffbe6..d93c7a2e71 100644
--- a/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/transacted/TransactionTimeoutDisabledTest.java
+++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/transacted/TransactionTimeoutDisabledTest.java
@@ -29,7 +29,7 @@ public class TransactionTimeoutDisabledTest extends TransactionTimeoutTestCase
protected void configure() throws Exception
{
// Setup housekeeping every second
- setConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".housekeeping.checkPeriod", "100");
+ setVirtualHostConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".housekeeping.checkPeriod", "100");
// No transaction timeout configuration.
}
diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/transacted/TransactionTimeoutTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/transacted/TransactionTimeoutTest.java
index 1e8760dc33..4dc26847da 100644
--- a/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/transacted/TransactionTimeoutTest.java
+++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/transacted/TransactionTimeoutTest.java
@@ -40,28 +40,28 @@ public class TransactionTimeoutTest extends TransactionTimeoutTestCase
protected void configure() throws Exception
{
// Setup housekeeping every 100ms
- setConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".housekeeping.checkPeriod", "100");
+ setVirtualHostConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".housekeeping.checkPeriod", "100");
if (getName().contains("ProducerIdle"))
{
- setConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".transactionTimeout.openWarn", "0");
- setConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".transactionTimeout.openClose", "0");
- setConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".transactionTimeout.idleWarn", "500");
- setConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".transactionTimeout.idleClose", "1500");
+ setVirtualHostConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".transactionTimeout.openWarn", "0");
+ setVirtualHostConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".transactionTimeout.openClose", "0");
+ setVirtualHostConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".transactionTimeout.idleWarn", "500");
+ setVirtualHostConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".transactionTimeout.idleClose", "1500");
}
else if (getName().contains("ProducerOpen"))
{
- setConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".transactionTimeout.openWarn", "1000");
- setConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".transactionTimeout.openClose", "2000");
- setConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".transactionTimeout.idleWarn", "0");
- setConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".transactionTimeout.idleClose", "0");
+ setVirtualHostConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".transactionTimeout.openWarn", "1000");
+ setVirtualHostConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".transactionTimeout.openClose", "2000");
+ setVirtualHostConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".transactionTimeout.idleWarn", "0");
+ setVirtualHostConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".transactionTimeout.idleClose", "0");
}
else
{
- setConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".transactionTimeout.openWarn", "1000");
- setConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".transactionTimeout.openClose", "2000");
- setConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".transactionTimeout.idleWarn", "500");
- setConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".transactionTimeout.idleClose", "1000");
+ setVirtualHostConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".transactionTimeout.openWarn", "1000");
+ setVirtualHostConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".transactionTimeout.openClose", "2000");
+ setVirtualHostConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".transactionTimeout.idleWarn", "500");
+ setVirtualHostConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".transactionTimeout.idleClose", "1000");
}
}
diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/BrokerCommandHelper.java b/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/BrokerCommandHelper.java
index 4d5718f014..81b53e3dac 100644
--- a/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/BrokerCommandHelper.java
+++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/BrokerCommandHelper.java
@@ -17,14 +17,7 @@
*/
package org.apache.qpid.test.utils;
-import org.apache.commons.lang.StringUtils;
-import org.apache.log4j.Logger;
-
import java.io.File;
-import java.util.Arrays;
-import java.util.ArrayList;
-import java.util.LinkedList;
-import java.util.List;
/**
* Generates the command to start a broker by substituting the tokens
@@ -35,73 +28,25 @@ import java.util.List;
*/
public class BrokerCommandHelper
{
- private static final Logger _logger = Logger.getLogger(BrokerCommandHelper.class);
-
- /** use a LinkedList so we can call remove(int) */
- private final LinkedList<String> _brokerCommandTemplateAsList;
+ private String _brokerCommandTemplate;
public BrokerCommandHelper(String brokerCommandTemplate)
{
- _brokerCommandTemplateAsList = new LinkedList(Arrays.asList(brokerCommandTemplate.split("\\s+")));
+ _brokerCommandTemplate = brokerCommandTemplate;
}
- public List<String> getBrokerCommand(
- int port, int sslPort, int managementPort,
- File configFile, File logConfigFile,
- String protocolIncludesList, String protocolExcludesList)
+ public String getBrokerCommand( int port, String storePath, String storeType, File logConfigFile)
{
- List<String> substitutedCommands = new ArrayList<String>();
-
- // Replace the tokens in two passes.
- // The first pass is for protocol include/exclude lists, each of which needs to be
- // split into separate entries in the final list.
- // The second pass is for the remaining options, which include file paths that
- // are quoted in case they contain whitespace.
-
- for (String commandPart : _brokerCommandTemplateAsList)
- {
- String substitutedCommandPart = commandPart
- .replace("@EXCLUDES", protocolExcludesList)
- .replace("@INCLUDES", protocolIncludesList);
-
- String[] splitCommandPart = StringUtils.split(substitutedCommandPart);
- substitutedCommands.addAll(Arrays.asList(splitCommandPart));
- }
-
- int i = 0;
- for (String commandPart : substitutedCommands)
- {
- String substitutedCommandPart = commandPart
+ return _brokerCommandTemplate
.replace("@PORT", "" + port)
- .replace("@SSL_PORT", "" + sslPort)
- .replace("@MPORT", "" + managementPort)
- .replace("@CONFIG_FILE", '"' + configFile.getPath() + '"')
+ .replace("@STORE_PATH", storePath)
+ .replace("@STORE_TYPE", storeType)
.replace("@LOG_CONFIG_FILE", '"' + logConfigFile.getAbsolutePath() + '"');
-
- substitutedCommands.set(i, substitutedCommandPart);
- i++;
- }
-
- return substitutedCommands;
- }
-
- private int getBrokerCommandLogOptionIndex()
- {
- String logOption = "-l";
-
- int logOptionIndex = _brokerCommandTemplateAsList.indexOf(logOption);
- if(logOptionIndex == -1)
- {
- throw new RuntimeException("Could not find option " + logOption + " in " + _brokerCommandTemplateAsList);
- }
- return logOptionIndex;
}
public void removeBrokerCommandLog4JFile()
{
- int logOptionIndex = getBrokerCommandLogOptionIndex();
- _brokerCommandTemplateAsList.remove(logOptionIndex); // removes the "-l" entry
- _brokerCommandTemplateAsList.remove(logOptionIndex); // removes log file name that followed the -l
- _logger.info("Removed broker command log4j config file");
+ int logArgumentPosition = _brokerCommandTemplate.indexOf("-l");
+ _brokerCommandTemplate = _brokerCommandTemplate.substring(0, logArgumentPosition - 1);
}
}
diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/BrokerCommandHelperTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/BrokerCommandHelperTest.java
index 332059dbc0..663e7d92b4 100644
--- a/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/BrokerCommandHelperTest.java
+++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/BrokerCommandHelperTest.java
@@ -19,61 +19,32 @@ package org.apache.qpid.test.utils;
import static org.mockito.Mockito.*;
-import org.apache.commons.lang.StringUtils;
-import org.apache.log4j.Logger;
-
import java.io.File;
-import java.util.Arrays;
-import java.util.List;
public class BrokerCommandHelperTest extends QpidTestCase
{
- private BrokerCommandHelper _brokerCommandHelper = new BrokerCommandHelper("qpid -p @PORT -s @SSL_PORT -m @MPORT @INCLUDES @EXCLUDES -c @CONFIG_FILE -l @LOG_CONFIG_FILE");
+ private BrokerCommandHelper _brokerCommandHelper = new BrokerCommandHelper("qpid -p @PORT -sp @STORE_PATH -st @STORE_TYPE -l @LOG_CONFIG_FILE");
private File logConfigFile = mock(File.class);
- private File configFile = mock(File.class);
@Override
public void setUp()
{
when(logConfigFile.getAbsolutePath()).thenReturn("logConfigFile");
- when(configFile.getPath()).thenReturn("configFile");
}
public void testGetBrokerCommand()
{
- List<String> brokerCommand = _brokerCommandHelper.getBrokerCommand(
- 1, 2, 3, configFile, logConfigFile, "includes", "excludes");
-
- assertEquals(Arrays.asList("qpid", "-p", "1", "-s", "2", "-m", "3",
- "includes", "excludes",
- "-c", "\"configFile\"", "-l", "\"logConfigFile\""),
- brokerCommand);
- }
-
- public void testGetBrokerCommandForMultipleProtocolIncludesAndExcludes()
- {
- List<String> brokerCommand = _brokerCommandHelper.getBrokerCommand(
- 1, 2, 3, configFile, logConfigFile, "includes1 includes2", "excludes1 excludes2");
-
- assertEquals("The space-separated protocol include/exclude lists should be converted into separate entries in the returned list so that ProcessBuilder treats them as separate arguments",
- Arrays.asList("qpid", "-p", "1", "-s", "2", "-m", "3",
- "includes1", "includes2", "excludes1", "excludes2",
- "-c", "\"configFile\"", "-l", "\"logConfigFile\""),
- brokerCommand);
+ String brokerCommand = _brokerCommandHelper.getBrokerCommand(1, "configFile", "json", logConfigFile);
+ assertEquals("Unexpected broker command", "qpid -p 1 -sp configFile -st json -l \"logConfigFile\"", brokerCommand);
}
public void testRemoveBrokerCommandLog4JFile()
{
_brokerCommandHelper.removeBrokerCommandLog4JFile();
-
- List<String> brokerCommand = _brokerCommandHelper.getBrokerCommand(
- 1, 2, 3, configFile, logConfigFile, "includes", "excludes");
+ String brokerCommand = _brokerCommandHelper.getBrokerCommand(1, "configFile", "json", logConfigFile);
assertEquals("The broker command list should not contain a log4j config option",
- Arrays.asList("qpid", "-p", "1", "-s", "2", "-m", "3",
- "includes", "excludes",
- "-c", "\"configFile\""),
- brokerCommand);
+ "qpid -p 1 -sp configFile -st json", brokerCommand );
}
}
diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/InternalBrokerHolder.java b/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/InternalBrokerHolder.java
index c5e8a08ec6..8bad73d0ea 100644
--- a/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/InternalBrokerHolder.java
+++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/InternalBrokerHolder.java
@@ -20,9 +20,6 @@
*/
package org.apache.qpid.test.utils;
-import java.lang.management.ManagementFactory;
-import java.lang.management.ThreadInfo;
-import java.lang.management.ThreadMXBean;
import java.util.Set;
import org.apache.log4j.Logger;
diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/JMXTestUtils.java b/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/JMXTestUtils.java
index 826d00d0df..6e6e3271f0 100644
--- a/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/JMXTestUtils.java
+++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/JMXTestUtils.java
@@ -31,6 +31,8 @@ import org.apache.qpid.management.common.mbeans.ManagedExchange;
import org.apache.qpid.management.common.mbeans.ManagedQueue;
import org.apache.qpid.management.common.mbeans.ServerInformation;
import org.apache.qpid.management.common.mbeans.UserManagement;
+import org.apache.qpid.server.model.Plugin;
+import org.apache.qpid.server.plugin.PluginFactory;
import javax.management.InstanceNotFoundException;
import javax.management.JMException;
@@ -45,7 +47,9 @@ import javax.management.ObjectName;
import javax.management.remote.JMXConnector;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import java.util.Set;
/**
@@ -77,7 +81,7 @@ public class JMXTestUtils
public void setUp() throws IOException, ConfigurationException, Exception
{
- _test.setConfigurationProperty("management.enabled", "true");
+ _test.getBrokerConfiguration().addJmxManagementConfiguration();
}
public void open() throws Exception
diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidBrokerTestCase.java b/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidBrokerTestCase.java
index fe116f175b..4259254123 100755
--- a/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidBrokerTestCase.java
+++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidBrokerTestCase.java
@@ -23,6 +23,7 @@ import java.io.PrintStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -60,11 +61,14 @@ import org.apache.qpid.jms.BrokerDetails;
import org.apache.qpid.jms.ConnectionURL;
import org.apache.qpid.server.Broker;
import org.apache.qpid.server.BrokerOptions;
-import org.apache.qpid.server.ProtocolExclusion;
-import org.apache.qpid.server.ProtocolInclusion;
-import org.apache.qpid.server.configuration.ServerConfiguration;
+import org.apache.qpid.server.configuration.BrokerProperties;
+import org.apache.qpid.server.model.Port;
+import org.apache.qpid.server.model.VirtualHost;
import org.apache.qpid.server.protocol.AmqpProtocolVersion;
+import org.apache.qpid.server.store.MemoryMessageStore;
import org.apache.qpid.server.store.MessageStoreConstants;
+import org.apache.qpid.server.store.MessageStoreCreator;
+import org.apache.qpid.server.store.MessageStoreFactory;
import org.apache.qpid.server.store.derby.DerbyMessageStore;
import org.apache.qpid.url.URLSyntaxException;
import org.apache.qpid.util.FileUtils;
@@ -85,9 +89,9 @@ public class QpidBrokerTestCase extends QpidTestCase
public static final String GUEST_PASSWORD = "guest";
protected final static String QpidHome = System.getProperty("QPID_HOME");
- protected File _configFile = new File(System.getProperty("broker.config"));
+ private final File _configFile = new File(System.getProperty("broker.config"));
private File _logConfigFile;
-
+ protected final String _brokerStoreType = System.getProperty("broker.config-store-type", "json");
protected static final Logger _logger = Logger.getLogger(QpidBrokerTestCase.class);
protected static final int LOGMONITOR_TIMEOUT = 5000;
@@ -95,7 +99,7 @@ public class QpidBrokerTestCase extends QpidTestCase
private Map<String, String> _propertiesSetForBroker = new HashMap<String, String>();
- private XMLConfiguration _testConfiguration = new XMLConfiguration();
+ private Map<Integer, TestBrokerConfiguration> _brokerConfigurations;
private XMLConfiguration _testVirtualhosts = new XMLConfiguration();
protected static final String INDEX = "index";
@@ -103,6 +107,8 @@ public class QpidBrokerTestCase extends QpidTestCase
private static final String DEFAULT_INITIAL_CONTEXT = "org.apache.qpid.jndi.PropertiesFileInitialContextFactory";
+ private static Map<String, String> supportedStoresClassToTypeMapping = new HashMap<String, String>();
+
static
{
String initialContext = System.getProperty(Context.INITIAL_CONTEXT_FACTORY);
@@ -111,16 +117,21 @@ public class QpidBrokerTestCase extends QpidTestCase
{
System.setProperty(Context.INITIAL_CONTEXT_FACTORY, DEFAULT_INITIAL_CONTEXT);
}
+
+ MessageStoreCreator messageStoreCreator = new MessageStoreCreator();
+ Collection<MessageStoreFactory> factories = messageStoreCreator.getFactories();
+ for (MessageStoreFactory messageStoreFactory : factories)
+ {
+ supportedStoresClassToTypeMapping.put(messageStoreFactory.createMessageStore().getClass().getName(), messageStoreFactory.getType());
+ }
}
// system properties
private static final String TEST_VIRTUALHOSTS = "test.virtualhosts";
- private static final String TEST_CONFIG = "test.config";
private static final String BROKER_LANGUAGE = "broker.language";
protected static final String BROKER_TYPE = "broker.type";
private static final String BROKER_COMMAND = "broker.command";
private static final String BROKER_CLEAN_BETWEEN_TESTS = "broker.clean.between.tests";
- private static final String BROKER_EXISTING_QPID_WORK = "broker.existing.qpid.work";
private static final String BROKER_VERSION = "broker.version";
protected static final String BROKER_READY = "broker.ready";
private static final String BROKER_STOPPED = "broker.stopped";
@@ -128,21 +139,25 @@ public class QpidBrokerTestCase extends QpidTestCase
private static final String BROKER_LOG_INTERLEAVE = "broker.log.interleave";
private static final String BROKER_LOG_PREFIX = "broker.log.prefix";
private static final String BROKER_PERSITENT = "broker.persistent";
- public static final String BROKER_PROTOCOL_EXCLUDES = "broker.protocol.excludes";
- public static final String BROKER_PROTOCOL_INCLUDES = "broker.protocol.includes";
public static final String PROFILE_USE_SSL = "profile.use_ssl";
+ public static final int DEFAULT_PORT_VALUE = 5672;
+ public static final int DEFAULT_SSL_PORT_VALUE = 5671;
+ public static final int DEFAULT_JMXPORT_REGISTRYSERVER = 8999;
+ public static final int JMXPORT_CONNECTORSERVER_OFFSET = 100;
+ public static final int DEFAULT_HTTP_MANAGEMENT_PORT = 8080;
+ public static final int DEFAULT_HTTPS_MANAGEMENT_PORT = 8443;
+
// values
protected static final String JAVA = "java";
protected static final String CPP = "cpp";
protected static final String QPID_HOME = "QPID_HOME";
- public static final int DEFAULT_VM_PORT = 1;
- public static final int DEFAULT_PORT = Integer.getInteger("test.port", ServerConfiguration.DEFAULT_PORT);
+ public static final int DEFAULT_PORT = Integer.getInteger("test.port", DEFAULT_PORT_VALUE);
public static final int FAILING_PORT = Integer.parseInt(System.getProperty("test.port.alt"));
- public static final int DEFAULT_MANAGEMENT_PORT = Integer.getInteger("test.mport", ServerConfiguration.DEFAULT_JMXPORT_REGISTRYSERVER);
- public static final int DEFAULT_SSL_PORT = Integer.getInteger("test.port.ssl", ServerConfiguration.DEFAULT_SSL_PORT);
+ public static final int DEFAULT_MANAGEMENT_PORT = Integer.getInteger("test.mport", DEFAULT_JMXPORT_REGISTRYSERVER);
+ public static final int DEFAULT_SSL_PORT = Integer.getInteger("test.port.ssl", DEFAULT_SSL_PORT_VALUE);
protected String _brokerLanguage = System.getProperty(BROKER_LANGUAGE, JAVA);
protected BrokerType _brokerType = BrokerType.valueOf(System.getProperty(BROKER_TYPE, "").toUpperCase());
@@ -189,16 +204,48 @@ public class QpidBrokerTestCase extends QpidTestCase
}
private MessageType _messageType = MessageType.TEXT;
- public QpidBrokerTestCase(String name)
+ public QpidBrokerTestCase()
{
- super(name);
+ super();
+ _brokerConfigurations = new HashMap<Integer, TestBrokerConfiguration>();
initialiseLogConfigFile();
}
- public QpidBrokerTestCase()
+ public TestBrokerConfiguration getBrokerConfiguration(int port)
{
- super();
- initialiseLogConfigFile();
+ int actualPort = getPort(port);
+
+ synchronized (_brokerConfigurations)
+ {
+ TestBrokerConfiguration configuration = _brokerConfigurations.get(actualPort);
+ if (configuration == null)
+ {
+ configuration = createBrokerConfiguration(actualPort);
+ }
+ return configuration;
+ }
+ }
+
+ public TestBrokerConfiguration getBrokerConfiguration()
+ {
+ return getBrokerConfiguration(DEFAULT_PORT);
+ }
+
+ public TestBrokerConfiguration createBrokerConfiguration(int port)
+ {
+ int actualPort = getPort(port);
+ TestBrokerConfiguration configuration = new TestBrokerConfiguration(System.getProperty(_brokerStoreType), _configFile.getAbsolutePath());
+ synchronized (_brokerConfigurations)
+ {
+ _brokerConfigurations.put(actualPort, configuration);
+ }
+ if (actualPort != DEFAULT_PORT)
+ {
+ configuration.setObjectAttribute(TestBrokerConfiguration.ENTRY_NAME_AMQP_PORT, Port.PORT, actualPort);
+ configuration.setObjectAttribute(TestBrokerConfiguration.ENTRY_NAME_RMI_PORT, Port.PORT, getManagementPort(actualPort));
+ configuration.setObjectAttribute(TestBrokerConfiguration.ENTRY_NAME_JMX_PORT, Port.PORT, getManagementPort(actualPort) + JMXPORT_CONNECTORSERVER_OFFSET);
+ }
+ return configuration;
}
private void initialiseLogConfigFile()
@@ -309,16 +356,6 @@ public class QpidBrokerTestCase extends QpidTestCase
fail("Unable to test without config file:" + _configFile);
}
- String existingQpidWorkPath = System.getProperty(BROKER_EXISTING_QPID_WORK);
- if(existingQpidWorkPath != null && !existingQpidWorkPath.equals(""))
- {
-
- String qpidWork = getQpidWork(_brokerType, getPort());
- File existing = new File(existingQpidWorkPath);
- cleanBrokerWork(qpidWork);
- FileUtils.copyRecursive(existing, new File(qpidWork));
- }
-
startBroker();
}
@@ -342,7 +379,7 @@ public class QpidBrokerTestCase extends QpidTestCase
{
Set<Integer> ports = new HashSet<Integer>();
int managementPort = getManagementPort(mainPort);
- int connectorServerPort = managementPort + ServerConfiguration.JMXPORT_CONNECTORSERVER_OFFSET;
+ int connectorServerPort = managementPort + JMXPORT_CONNECTORSERVER_OFFSET;
ports.add(mainPort);
ports.add(managementPort);
@@ -381,19 +418,11 @@ public class QpidBrokerTestCase extends QpidTestCase
public void startBroker(int port) throws Exception
{
- startBroker(port, _testConfiguration, _testVirtualhosts);
+ int actualPort = getPort(port);
+ TestBrokerConfiguration configuration = getBrokerConfiguration(actualPort);
+ startBroker(actualPort, configuration, _testVirtualhosts);
}
- private List<String> getBrokerCommand(int port)
- {
- final int sslPort = port-1;
- final String protocolExcludesList = getProtocolExcludesList(port, sslPort);
- final String protocolIncludesList = getProtocolIncludesList(port, sslPort);
- return _brokerCommandHelper.getBrokerCommand(
- port, sslPort, getManagementPort(port),
- _configFile, _logConfigFile,
- protocolIncludesList, protocolExcludesList);
- }
protected File getBrokerCommandLog4JFile()
{
@@ -406,11 +435,10 @@ public class QpidBrokerTestCase extends QpidTestCase
_logger.info("Modified log config file to: " + file);
}
- public void startBroker(int port, XMLConfiguration testConfiguration, XMLConfiguration virtualHosts) throws Exception
+ public void startBroker(int port, TestBrokerConfiguration testConfiguration, XMLConfiguration virtualHosts) throws Exception
{
port = getPort(port);
-
- // Save only virtual host configuration changes that have been made
+ String testConfig = saveTestConfiguration(port, testConfiguration);
String virtualHostsConfig = saveTestVirtualhosts(port, virtualHosts);
if(_brokers.get(port) != null)
@@ -422,19 +450,13 @@ public class QpidBrokerTestCase extends QpidTestCase
if (_brokerType.equals(BrokerType.INTERNAL) && !existingInternalBroker())
{
- testConfiguration.setProperty(ServerConfiguration.MGMT_CUSTOM_REGISTRY_SOCKET, String.valueOf(false));
- String testConfig = saveTestConfiguration(port, testConfiguration);
- setSystemProperty(TEST_CONFIG, testConfig);
+ _logger.info("Set test.virtualhosts property to: " + virtualHostsConfig);
setSystemProperty(TEST_VIRTUALHOSTS, virtualHostsConfig);
-
+ setSystemProperty(BrokerProperties.PROPERTY_USE_CUSTOM_RMI_SOCKET_FACTORY, "false");
BrokerOptions options = new BrokerOptions();
- options.setConfigFile(_configFile.getAbsolutePath());
- options.addPort(port);
- addExcludedPorts(port, DEFAULT_SSL_PORT, options);
- addIncludedPorts(port, DEFAULT_SSL_PORT, options);
-
- options.setJmxPortRegistryServer(getManagementPort(port));
+ options.setConfigurationStoreType(_brokerStoreType);
+ options.setConfigurationStoreLocation(testConfig);
//Set the log config file, relying on the log4j.configuration system property
//set on the JVM by the JUnit runner task in module.xml.
@@ -450,9 +472,10 @@ public class QpidBrokerTestCase extends QpidTestCase
{
// Add the port to QPID_WORK to ensure unique working dirs for multi broker tests
final String qpidWork = getQpidWork(_brokerType, port);
- List<String> cmd = getBrokerCommand(port);
- _logger.info("Starting external broker using command: " + StringUtils.join(cmd, " "));
- ProcessBuilder pb = new ProcessBuilder(cmd);
+
+ String cmd = _brokerCommandHelper.getBrokerCommand(port, testConfig, _brokerStoreType, _logConfigFile);
+ _logger.info("Starting spawn broker using command: " + cmd);
+ ProcessBuilder pb = new ProcessBuilder(cmd.split("\\s+"));
pb.redirectErrorStream(true);
Map<String, String> processEnv = pb.environment();
String qpidHome = System.getProperty(QPID_HOME);
@@ -482,7 +505,6 @@ public class QpidBrokerTestCase extends QpidTestCase
}
}
- String testConfig = saveTestConfiguration(port, testConfiguration);
String qpidOpts = "";
// a synchronized hack to avoid adding into QPID_OPTS the values
@@ -492,19 +514,11 @@ public class QpidBrokerTestCase extends QpidTestCase
// Add default test logging levels that are used by the log4j-test
// Use the convenience methods to push the current logging setting
// in to the external broker's QPID_OPTS string.
- if (System.getProperty("amqj.protocol.logging.level") != null)
- {
- setSystemProperty("amqj.protocol.logging.level");
- }
- if (System.getProperty("root.logging.level") != null)
- {
- setSystemProperty("root.logging.level");
- }
-
- setSystemProperty(TEST_CONFIG, testConfig);
+ setSystemProperty("amqj.protocol.logging.level");
+ setSystemProperty("root.logging.level");
+ setSystemProperty(BrokerProperties.PROPERTY_BROKER_DEFAULT_AMQP_PROTOCOL_EXCLUDES);
+ setSystemProperty(BrokerProperties.PROPERTY_BROKER_DEFAULT_AMQP_PROTOCOL_INCLUDES);
setSystemProperty(TEST_VIRTUALHOSTS, virtualHostsConfig);
- // set test.config and test.virtualhosts
- qpidOpts += " -D" + TEST_CONFIG + "=" + testConfig + " -D" + TEST_VIRTUALHOSTS + "=" + virtualHostsConfig;
// Add all the specified system properties to QPID_OPTS
if (!_propertiesSetForBroker.isEmpty())
@@ -534,9 +548,15 @@ public class QpidBrokerTestCase extends QpidTestCase
p.start();
+ SpawnedBrokerHolder holder = new SpawnedBrokerHolder(process, qpidWork, portsUsedByBroker);
if (!p.await(30, TimeUnit.SECONDS))
{
_logger.info("broker failed to become ready (" + p.getReady() + "):" + p.getStopLine());
+ String threadDump = holder.dumpThreads();
+ if (!threadDump.isEmpty())
+ {
+ _logger.info("the result of a try to capture thread dump:" + threadDump);
+ }
//Ensure broker has stopped
process.destroy();
cleanBrokerWork(qpidWork);
@@ -557,65 +577,7 @@ public class QpidBrokerTestCase extends QpidTestCase
// this is expect if the broker started successfully
}
- _brokers.put(port, new SpawnedBrokerHolder(process, qpidWork, portsUsedByBroker));
- }
- }
-
- private void addExcludedPorts(int port, int sslPort, BrokerOptions options)
- {
- final String protocolExcludesList = getProtocolExcludesList(port, sslPort);
-
- if (protocolExcludesList.equals(""))
- {
- return;
- }
- final String[] toks = protocolExcludesList.split("\\s");
-
- if(toks.length % 2 != 0)
- {
- throw new IllegalArgumentException("Must be an even number of tokens in '" + protocolExcludesList + "'");
- }
- for (int i = 0; i < toks.length; i=i+2)
- {
- String excludeArg = toks[i];
- final int excludedPort = Integer.parseInt(toks[i+1]);
- options.addExcludedPort(ProtocolExclusion.lookup(excludeArg), excludedPort);
-
- _logger.info("Adding protocol exclusion " + excludeArg + " " + excludedPort);
- }
- }
-
- protected String getProtocolExcludesList(int port, int sslPort)
- {
- return System.getProperty(BROKER_PROTOCOL_EXCLUDES,"").replace("@PORT", "" + port).replace("@SSL_PORT", "" + sslPort);
- }
-
- private String getProtocolIncludesList(int port, int sslPort)
- {
- return System.getProperty(BROKER_PROTOCOL_INCLUDES, "").replace("@PORT", "" + port).replace("@SSL_PORT", "" + sslPort);
- }
-
- private void addIncludedPorts(int port, int sslPort, BrokerOptions options)
- {
- final String protocolIncludesList = getProtocolIncludesList(port, sslPort);
-
- if (protocolIncludesList.equals(""))
- {
- return;
- }
- final String[] toks = protocolIncludesList.split("\\s");
-
- if(toks.length % 2 != 0)
- {
- throw new IllegalArgumentException("Must be an even number of tokens in '" + protocolIncludesList + "'");
- }
- for (int i = 0; i < toks.length; i=i+2)
- {
- String includeArg = toks[i];
- final int includedPort = Integer.parseInt(toks[i+1]);
- options.addIncludedPort(ProtocolInclusion.lookup(includeArg), includedPort);
-
- _logger.info("Adding protocol inclusion " + includeArg + " " + includedPort);
+ _brokers.put(port, holder);
}
}
@@ -649,7 +611,7 @@ public class QpidBrokerTestCase extends QpidTestCase
public String getTestConfigFile(int port)
{
- return _output + "/" + getTestQueueName() + "-" + port + "-config.xml";
+ return _output + "/" + getTestQueueName() + "-" + port + "-config";
}
public String getTestVirtualhostsFile(int port)
@@ -662,35 +624,26 @@ public class QpidBrokerTestCase extends QpidTestCase
return file.replace(System.getProperty(QPID_HOME,"QPID_HOME") + "/","");
}
- protected void saveTestConfiguration() throws ConfigurationException
+ protected String getPathRelativeToWorkingDirectory(String file)
{
- String relative = saveTestConfiguration(getPort(), _testConfiguration);
- setSystemProperty(TEST_CONFIG, relative);
+ File configLocation = new File(file);
+ File workingDirectory = new File(System.getProperty("user.dir"));
+ return configLocation.getAbsolutePath().replace(workingDirectory.getAbsolutePath(), "").substring(1);
}
- protected String saveTestConfiguration(int port, XMLConfiguration testConfiguration) throws ConfigurationException
+ protected String saveTestConfiguration(int port, TestBrokerConfiguration testConfiguration)
{
- // Specify the test config file
String testConfig = getTestConfigFile(port);
- String relative = relativeToQpidHome(testConfig);
-
- _logger.info("Saving test virtualhosts file at: " + testConfig);
-
- // Create the file if configuration does not exist
- if (testConfiguration.isEmpty())
+ String relative = getPathRelativeToWorkingDirectory(testConfig);
+ if (!testConfiguration.isSaved())
{
- testConfiguration.addProperty("__ignore", "true");
+ _logger.info("Saving test broker configuration at: " + testConfig);
+ testConfiguration.save(new File(testConfig));
+ testConfiguration.setSaved(true);
}
- testConfiguration.save(testConfig);
return relative;
}
- protected void saveTestVirtualhosts() throws ConfigurationException
- {
- String relative = saveTestVirtualhosts(getPort(), _testVirtualhosts);
- setSystemProperty(TEST_VIRTUALHOSTS, relative);
- }
-
protected String saveTestVirtualhosts(int port, XMLConfiguration virtualHostConfiguration) throws ConfigurationException
{
// Specify the test virtualhosts file
@@ -846,11 +799,12 @@ public class QpidBrokerTestCase extends QpidTestCase
/**
* Creates a new virtual host within the test virtualhost file.
- *
+ * @param brokerPort broker port
* @param virtualHostName virtual host name
+ *
* @throws ConfigurationException
*/
- protected void createTestVirtualHost(String virtualHostName) throws ConfigurationException
+ protected void createTestVirtualHost(int brokerPort, String virtualHostName) throws ConfigurationException
{
String storeClassName = getTestProfileMessageStoreClassName();
@@ -872,29 +826,13 @@ public class QpidBrokerTestCase extends QpidTestCase
{
_testVirtualhosts.setProperty("virtualhost." + virtualHostName + ".store." + MessageStoreConstants.ENVIRONMENT_PATH_PROPERTY, storeDir);
}
- }
- /**
- * Get a property value from the current configuration file.
- *
- * @param property the property to lookup
- *
- * @return the requested String Value
- *
- * @throws org.apache.commons.configuration.ConfigurationException
- *
- */
- protected String getConfigurationStringProperty(String property) throws ConfigurationException
- {
- // Call save Configuration to be sure we have saved the test specific
- // file. As the optional status
- saveTestConfiguration();
- saveTestVirtualhosts();
-
- ServerConfiguration configuration = new ServerConfiguration(_configFile);
- // Don't need to configuration.configure() here as we are just pulling
- // values directly by String.
- return configuration.getConfig().getString(property);
+ // add new virtual host configuration to the broker store
+ Map<String, Object> attributes = new HashMap<String, Object>();
+ attributes.put(VirtualHost.NAME, virtualHostName);
+ attributes.put(VirtualHost.CONFIG_PATH, System.getProperty("broker.virtualhosts-config"));
+ int port = getPort(brokerPort);
+ getBrokerConfiguration(port).addHostConfiguration(attributes);
}
/**
@@ -911,7 +849,7 @@ public class QpidBrokerTestCase extends QpidTestCase
*
* @throws ConfigurationException when loading the current config file
*/
- public void setConfigurationProperty(String property, String value) throws ConfigurationException
+ public void setVirtualHostConfigurationProperty(String property, String value) throws ConfigurationException
{
// Choose which file to write the property to based on prefix.
if (property.startsWith("virtualhosts"))
@@ -920,7 +858,7 @@ public class QpidBrokerTestCase extends QpidTestCase
}
else
{
- _testConfiguration.setProperty(property, value);
+ throw new ConfigurationException("Cannot set broker configuration as property");
}
}
@@ -938,11 +876,13 @@ public class QpidBrokerTestCase extends QpidTestCase
*/
protected void setBrokerOnlySystemProperty(String property, String value)
{
- if (!_propertiesSetForBroker.containsKey(property))
+ synchronized (_propertiesSetForBroker)
{
- _propertiesSetForBroker.put(property, value);
+ if (!_propertiesSetForBroker.containsKey(property))
+ {
+ _propertiesSetForBroker.put(property, value);
+ }
}
-
}
/**
@@ -955,7 +895,11 @@ public class QpidBrokerTestCase extends QpidTestCase
*/
protected void setSystemProperty(String property)
{
- setSystemProperty(property, System.getProperty(property));
+ String value = System.getProperty(property);
+ if (value != null)
+ {
+ setSystemProperty(property, value);
+ }
}
/**
@@ -974,9 +918,18 @@ public class QpidBrokerTestCase extends QpidTestCase
*/
protected void setSystemProperty(String property, String value)
{
- // Record the value for the external broker
- _propertiesSetForBroker.put(property, value);
-
+ synchronized(_propertiesSetForBroker)
+ {
+ // Record the value for the external broker
+ if (value == null)
+ {
+ _propertiesSetForBroker.remove(property);
+ }
+ else
+ {
+ _propertiesSetForBroker.put(property, value);
+ }
+ }
//Set the value for the test client vm aswell.
setTestClientSystemProperty(property, value);
}
@@ -1440,13 +1393,14 @@ public class QpidBrokerTestCase extends QpidTestCase
_testVirtualhosts = testVirtualhosts;
}
- public XMLConfiguration getTestConfiguration()
+ public String getTestProfileMessageStoreType()
{
- return _testConfiguration;
+ final String storeClass = getTestProfileMessageStoreClassName();
+ if (storeClass == null)
+ {
+ return MemoryMessageStore.TYPE;
+ }
+ return supportedStoresClassToTypeMapping.get(storeClass);
}
- public void setTestConfiguration(XMLConfiguration testConfiguration)
- {
- _testConfiguration = testConfiguration;
- }
}
diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/TestBrokerConfiguration.java b/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/TestBrokerConfiguration.java
new file mode 100644
index 0000000000..5f712f1127
--- /dev/null
+++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/TestBrokerConfiguration.java
@@ -0,0 +1,229 @@
+/*
+ *
+ * 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.qpid.test.utils;
+
+import java.io.File;
+import java.net.MalformedURLException;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+
+import org.apache.qpid.server.configuration.ConfigurationEntry;
+import org.apache.qpid.server.configuration.store.JsonConfigurationEntryStore;
+import org.apache.qpid.server.model.AuthenticationProvider;
+import org.apache.qpid.server.model.Plugin;
+import org.apache.qpid.server.model.Port;
+import org.apache.qpid.server.model.UUIDGenerator;
+import org.apache.qpid.server.model.VirtualHost;
+import org.apache.qpid.server.plugin.PluginFactory;
+
+public class TestBrokerConfiguration
+{
+ public static final String ENTRY_NAME_HTTP_PORT = "http";
+ public static final String ENTRY_NAME_AMQP_PORT = "amqp";
+ public static final String ENTRY_NAME_RMI_PORT = "rmi";
+ public static final String ENTRY_NAME_JMX_PORT = "jmx";
+ public static final String ENTRY_NAME_VIRTUAL_HOST = "test";
+ public static final String ENTRY_NAME_AUTHENTICATION_PROVIDER = "plain";
+ public static final String ENTRY_NAME_EXTERNAL_PROVIDER = "external";
+ public static final String ENTRY_NAME_SSL_PORT = "sslPort";
+ public static final String ENTRY_NAME_HTTP_MANAGEMENT = "MANAGEMENT-HTTP";
+ public static final String MANAGEMENT_HTTP_PLUGIN_TYPE = "MANAGEMENT-HTTP";
+ public static final String ENTRY_NAME_JMX_MANAGEMENT = "MANAGEMENT-JMX";
+ public static final String MANAGEMENT_JMX_PLUGIN_TYPE = "MANAGEMENT-JMX";
+ public static final String ENTRY_NAME_ANONYMOUS_PROVIDER = "anonymous";
+
+ private JsonConfigurationEntryStore _store;
+ private boolean _saved;
+
+ public TestBrokerConfiguration(String storeType, String intialStoreLocation)
+ {
+ // TODO: add support for DERBY store
+ _store = new JsonConfigurationEntryStore();
+
+ try
+ {
+ // load the initial store data into our store
+ _store.load(new File(intialStoreLocation).toURI().toURL());
+ }
+ catch (MalformedURLException e)
+ {
+ // ignore
+ }
+ }
+
+ public boolean setBrokerAttribute(String name, Object value)
+ {
+ return setObjectAttribute(_store.getRootEntry(), name, value);
+ }
+
+ public boolean setObjectAttribute(String objectName, String attributeName, Object value)
+ {
+ ConfigurationEntry entry = findObjectByName(objectName);
+ if (entry == null)
+ {
+ return false;
+ }
+ return setObjectAttribute(entry, attributeName, value);
+ }
+
+ public boolean setObjectAttributes(String objectName, Map<String, Object> attributes)
+ {
+ ConfigurationEntry entry = findObjectByName(objectName);
+ if (entry == null)
+ {
+ return false;
+ }
+ return setObjectAttributes(entry, attributes);
+ }
+
+ public boolean save(File configFile)
+ {
+ _store.saveTo(configFile);
+ return true;
+ }
+
+ public UUID[] removeObjectConfiguration(String name)
+ {
+ ConfigurationEntry entry = findObjectByName(name);
+ if (entry != null)
+ {
+ return _store.remove(entry.getId());
+ }
+ return null;
+ }
+
+ public UUID addObjectConfiguration(String name, String type, Map<String, Object> attributes)
+ {
+ UUID id = UUIDGenerator.generateBrokerChildUUID(type, name);
+ addObjectConfiguration(id, type, attributes);
+ return id;
+ }
+
+ public UUID addJmxManagementConfiguration()
+ {
+ Map<String, Object> attributes = new HashMap<String, Object>();
+ attributes.put(PluginFactory.PLUGIN_TYPE, MANAGEMENT_JMX_PLUGIN_TYPE);
+ attributes.put(Plugin.NAME, ENTRY_NAME_JMX_MANAGEMENT);
+ return addObjectConfiguration(ENTRY_NAME_JMX_MANAGEMENT, Plugin.class.getSimpleName(), attributes);
+ }
+
+ public UUID addHttpManagementConfiguration()
+ {
+ Map<String, Object> attributes = new HashMap<String, Object>();
+ attributes.put(PluginFactory.PLUGIN_TYPE, MANAGEMENT_HTTP_PLUGIN_TYPE);
+ attributes.put(Plugin.NAME, ENTRY_NAME_HTTP_MANAGEMENT);
+ return addObjectConfiguration(ENTRY_NAME_HTTP_MANAGEMENT, Plugin.class.getSimpleName(), attributes);
+ }
+
+ public UUID addPortConfiguration(Map<String, Object> attributes)
+ {
+ String name = (String) attributes.get(Port.NAME);
+ return addObjectConfiguration(name, Port.class.getSimpleName(), attributes);
+ }
+
+ public UUID addHostConfiguration(Map<String, Object> attributes)
+ {
+ String name = (String) attributes.get(VirtualHost.NAME);
+ return addObjectConfiguration(name, VirtualHost.class.getSimpleName(), attributes);
+ }
+
+ public UUID addAuthenticationProviderConfiguration(Map<String, Object> attributes)
+ {
+ String name = (String) attributes.get(AuthenticationProvider.NAME);
+ return addObjectConfiguration(name, AuthenticationProvider.class.getSimpleName(), attributes);
+ }
+
+ private boolean setObjectAttributes(ConfigurationEntry entry, Map<String, Object> attributes)
+ {
+ Map<String, Object> newAttributes = new HashMap<String, Object>(entry.getAttributes());
+ newAttributes.putAll(attributes);
+ ConfigurationEntry newEntry = new ConfigurationEntry(entry.getId(), entry.getType(), newAttributes,
+ entry.getChildrenIds(), _store);
+ _store.save(newEntry);
+ return true;
+ }
+
+ private ConfigurationEntry findObjectByName(String objectName)
+ {
+ ConfigurationEntry root = _store.getRootEntry();
+ return findObjectByName(root, objectName);
+ }
+
+ private ConfigurationEntry findObjectByName(ConfigurationEntry entry, String objectName)
+ {
+ Map<String, Object> attributes = entry.getAttributes();
+ if (attributes != null)
+ {
+ String name = (String) attributes.get("name");
+ if (objectName.equals(name))
+ {
+ return entry;
+ }
+ }
+ Set<UUID> childrenIds = entry.getChildrenIds();
+ for (UUID uuid : childrenIds)
+ {
+ ConfigurationEntry child = _store.getEntry(uuid);
+ ConfigurationEntry result = findObjectByName(child, objectName);
+ if (result != null)
+ {
+ return result;
+ }
+ }
+ return null;
+ }
+
+ private void addObjectConfiguration(UUID id, String type, Map<String, Object> attributes)
+ {
+ ConfigurationEntry entry = new ConfigurationEntry(id, type, attributes, Collections.<UUID> emptySet(), _store);
+ ConfigurationEntry root = _store.getRootEntry();
+ Set<UUID> childrenIds = new HashSet<UUID>(root.getChildrenIds());
+ childrenIds.add(id);
+ ConfigurationEntry newRoot = new ConfigurationEntry(root.getId(), root.getType(), root.getAttributes(), childrenIds,
+ _store);
+ _store.save(newRoot, entry);
+ }
+
+ private boolean setObjectAttribute(ConfigurationEntry entry, String attributeName, Object value)
+ {
+ Map<String, Object> attributes = new HashMap<String, Object>(entry.getAttributes());
+ attributes.put(attributeName, value);
+ ConfigurationEntry newEntry = new ConfigurationEntry(entry.getId(), entry.getType(), attributes, entry.getChildrenIds(),
+ _store);
+ _store.save(newEntry);
+ return true;
+ }
+
+ public boolean isSaved()
+ {
+ return _saved;
+ }
+
+ public void setSaved(boolean saved)
+ {
+ _saved = saved;
+ }
+
+}
diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/TestSSLConstants.java b/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/TestSSLConstants.java
index 19c9b9fb17..9d5be775dc 100644
--- a/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/TestSSLConstants.java
+++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/TestSSLConstants.java
@@ -24,4 +24,7 @@ public interface TestSSLConstants
String KEYSTORE_PASSWORD = "password";
String TRUSTSTORE = "test-profiles/test_resources/ssl/java_client_truststore.jks";
String TRUSTSTORE_PASSWORD = "password";
+
+ String BROKER_KEYSTORE = "test-profiles/test_resources/ssl/java_broker_keystore.jks";
+ String BROKER_KEYSTORE_PASSWORD = "password";
}
diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/util/LogMonitor.java b/qpid/java/systests/src/main/java/org/apache/qpid/util/LogMonitor.java
index d6b8a8400c..d77731d09f 100644
--- a/qpid/java/systests/src/main/java/org/apache/qpid/util/LogMonitor.java
+++ b/qpid/java/systests/src/main/java/org/apache/qpid/util/LogMonitor.java
@@ -30,8 +30,10 @@ import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.LineNumberReader;
+import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
+import java.util.Map;
/**
* Utility to simplify the monitoring of Log4j file output
@@ -160,6 +162,39 @@ public class LogMonitor
return results;
}
+ public Map<String, List<String>> findMatches(String... pattern) throws IOException
+ {
+
+ Map<String, List<String>> results= new HashMap<String, List<String>>();
+ for (String p : pattern)
+ {
+ results.put(p, new LinkedList<String>());
+ }
+ LineNumberReader reader = new LineNumberReader(new FileReader(_logfile));
+ try
+ {
+ while (reader.ready())
+ {
+ String line = reader.readLine();
+ if (reader.getLineNumber() > _linesToSkip)
+ {
+ for (String p : pattern)
+ {
+ if (line.contains(p))
+ {
+ results.get(p).add(line);
+ }
+ }
+ }
+ }
+ }
+ finally
+ {
+ reader.close();
+ }
+
+ return results;
+ }
/**
* Checks the log file for a given message to appear. If the caller
* has previously called {@link #markDiscardPoint()}, lines up until the discard
diff --git a/qpid/java/test-profiles/java-bdb-spawn.0-10.testprofile b/qpid/java/test-profiles/java-bdb-spawn.0-10.testprofile
index 35991645d8..78ab05a179 100644
--- a/qpid/java/test-profiles/java-bdb-spawn.0-10.testprofile
+++ b/qpid/java/test-profiles/java-bdb-spawn.0-10.testprofile
@@ -19,11 +19,11 @@
broker.language=java
broker.type=spawned
-broker.command=build/bin/qpid-server -p @PORT -m @MPORT @EXCLUDES @INCLUDES -c @CONFIG_FILE -l @LOG_CONFIG_FILE
+broker.command=build/bin/qpid-server -sp @STORE_PATH -st @STORE_TYPE -l @LOG_CONFIG_FILE
broker.ready=BRK-1004
broker.stopped=Exception
-broker.protocol.excludes=--exclude-1-0 @PORT --exclude-1-0 @SSL_PORT
-broker.config=build/etc/config-systests-bdb.xml
+qpid.broker_default_amqp_protocol_excludes=AMQP_1_0
+broker.virtualhosts-config=${QPID_HOME}/etc/virtualhosts-systests-bdb.xml
messagestore.class.name=org.apache.qpid.server.store.berkeleydb.BDBMessageStore
profile.excludes=JavaExcludes JavaPersistentExcludes Java010Excludes JavaBDBExcludes
broker.clean.between.tests=true
diff --git a/qpid/java/test-profiles/java-bdb-spawn.0-8.testprofile b/qpid/java/test-profiles/java-bdb-spawn.0-8.testprofile
index a4b74748e6..7f6efcbc3d 100644
--- a/qpid/java/test-profiles/java-bdb-spawn.0-8.testprofile
+++ b/qpid/java/test-profiles/java-bdb-spawn.0-8.testprofile
@@ -19,15 +19,15 @@
broker.language=java
broker.type=spawned
-broker.command=build/bin/qpid-server -p @PORT -m @MPORT @EXCLUDES @INCLUDES -c @CONFIG_FILE -l @LOG_CONFIG_FILE
+broker.command=build/bin/qpid-server -sp @STORE_PATH -st @STORE_TYPE -l @LOG_CONFIG_FILE
broker.ready=BRK-1004
broker.stopped=Exception
-broker.config=build/etc/config-systests-bdb.xml
+qpid.broker_default_amqp_protocol_excludes=AMQP_1_0,AMQP_0_10,AMQP_0_9_1,AMQP_0_9
+broker.virtualhosts-config=${QPID_HOME}/etc/virtualhosts-systests-bdb.xml
messagestore.class.name=org.apache.qpid.server.store.berkeleydb.BDBMessageStore
profile.excludes=JavaExcludes JavaPersistentExcludes XAExcludes JavaPre010Excludes JavaBDBExcludes
broker.clean.between.tests=true
broker.persistent=true
-broker.protocol.excludes=--exclude-0-10 @PORT --exclude-0-10 @SSL_PORT --exclude-1-0 @PORT --exclude-1-0 @SSL_PORT --exclude-0-9-1 @PORT --exclude-0-9-1 @SSL_PORT --exclude-0-9 @PORT --exclude-0-9 @SSL_PORT
broker.version=v0_8
#
# Do not enable. Allow client to attempt 0-10 and negotiate downwards
diff --git a/qpid/java/test-profiles/java-bdb-spawn.0-9-1.testprofile b/qpid/java/test-profiles/java-bdb-spawn.0-9-1.testprofile
index 9cd70a4ea7..28668b94f7 100644
--- a/qpid/java/test-profiles/java-bdb-spawn.0-9-1.testprofile
+++ b/qpid/java/test-profiles/java-bdb-spawn.0-9-1.testprofile
@@ -19,15 +19,15 @@
broker.language=java
broker.type=spawned
-broker.command=build/bin/qpid-server -p @PORT -m @MPORT @EXCLUDES @INCLUDES -c @CONFIG_FILE -l @LOG_CONFIG_FILE
+broker.command=build/bin/qpid-server -sp @STORE_PATH -st @STORE_TYPE -l @LOG_CONFIG_FILE
broker.ready=BRK-1004
broker.stopped=Exception
-broker.config=build/etc/config-systests-bdb.xml
+qpid.broker_default_amqp_protocol_excludes=AMQP_1_0,AMQP_0_10
+broker.virtualhosts-config=${QPID_HOME}/etc/virtualhosts-systests-bdb.xml
messagestore.class.name=org.apache.qpid.server.store.berkeleydb.BDBMessageStore
profile.excludes=JavaExcludes JavaPersistentExcludes XAExcludes JavaPre010Excludes JavaBDBExcludes
broker.clean.between.tests=true
broker.persistent=true
-broker.protocol.excludes=--exclude-0-10 @PORT --exclude-0-10 @SSL_PORT --exclude-1-0 @PORT --exclude-1-0 @SSL_PORT
broker.version=v0_9_1
#
# Do not enable. Allow client to attempt 0-10 and negotiate downwards
diff --git a/qpid/java/test-profiles/java-bdb-spawn.0-9.testprofile b/qpid/java/test-profiles/java-bdb-spawn.0-9.testprofile
index 5c0ad2baf3..aa8e6830d4 100644
--- a/qpid/java/test-profiles/java-bdb-spawn.0-9.testprofile
+++ b/qpid/java/test-profiles/java-bdb-spawn.0-9.testprofile
@@ -19,15 +19,15 @@
broker.language=java
broker.type=spawned
-broker.command=build/bin/qpid-server -p @PORT -m @MPORT @EXCLUDES @INCLUDES -c @CONFIG_FILE -l @LOG_CONFIG_FILE
+broker.command=build/bin/qpid-server -sp @STORE_PATH -st @STORE_TYPE -l @LOG_CONFIG_FILE
broker.ready=BRK-1004
broker.stopped=Exception
-broker.config=build/etc/config-systests-bdb.xml
+qpid.broker_default_amqp_protocol_excludes=AMQP_1_0,AMQP_0_10,AMQP_0_9_1
+broker.virtualhosts-config=${QPID_HOME}/etc/virtualhosts-systests-bdb.xml
messagestore.class.name=org.apache.qpid.server.store.berkeleydb.BDBMessageStore
profile.excludes=JavaExcludes JavaPersistentExcludes XAExcludes JavaPre010Excludes JavaBDBExcludes
broker.clean.between.tests=true
broker.persistent=true
-broker.protocol.excludes=--exclude-0-10 @PORT --exclude-0-10 @SSL_PORT --exclude-1-0 @PORT --exclude-1-0 @SSL_PORT --exclude-0-9-1 @PORT --exclude-0-9-1 @SSL_PORT
broker.version=v0_9
#
# Do not enable. Allow client to attempt 0-10 and negotiate downwards
diff --git a/qpid/java/test-profiles/java-bdb.0-10.testprofile b/qpid/java/test-profiles/java-bdb.0-10.testprofile
index 892188aa24..8c4b145e0b 100644
--- a/qpid/java/test-profiles/java-bdb.0-10.testprofile
+++ b/qpid/java/test-profiles/java-bdb.0-10.testprofile
@@ -20,11 +20,11 @@
broker.language=java
broker.type=internal
#broker.command only used for the second broker during failover tests in this profile
-broker.command=build/bin/qpid-server -p @PORT -m @MPORT @EXCLUDES @INCLUDES -c @CONFIG_FILE -l @LOG_CONFIG_FILE
+broker.command=build/bin/qpid-server -sp @STORE_PATH -st @STORE_TYPE -l @LOG_CONFIG_FILE
broker.ready=BRK-1004
broker.stopped=Exception
-broker.protocol.excludes=--exclude-1-0 @PORT --exclude-1-0 @SSL_PORT
-broker.config=build/etc/config-systests-bdb.xml
+qpid.broker_default_amqp_protocol_excludes=AMQP_1_0
+broker.virtualhosts-config=${QPID_HOME}/etc/virtualhosts-systests-bdb.xml
messagestore.class.name=org.apache.qpid.server.store.berkeleydb.BDBMessageStore
profile.excludes=JavaExcludes JavaPersistentExcludes Java010Excludes JavaBDBExcludes
broker.clean.between.tests=true
diff --git a/qpid/java/test-profiles/java-bdb.0-8.testprofile b/qpid/java/test-profiles/java-bdb.0-8.testprofile
index 87eea96dda..acf031040e 100644
--- a/qpid/java/test-profiles/java-bdb.0-8.testprofile
+++ b/qpid/java/test-profiles/java-bdb.0-8.testprofile
@@ -20,15 +20,15 @@
broker.language=java
broker.type=internal
#broker.command only used for the second broker during failover tests in this profile
-broker.command=build/bin/qpid-server -p @PORT -m @MPORT @EXCLUDES @INCLUDES -c @CONFIG_FILE -l @LOG_CONFIG_FILE
+broker.command=build/bin/qpid-server -sp @STORE_PATH -st @STORE_TYPE -l @LOG_CONFIG_FILE
broker.ready=BRK-1004
broker.stopped=Exception
-broker.config=build/etc/config-systests-bdb.xml
+qpid.broker_default_amqp_protocol_excludes=AMQP_1_0,AMQP_0_10,AMQP_0_9_1,AMQP_0_9
+broker.virtualhosts-config=${QPID_HOME}/etc/virtualhosts-systests-bdb.xml
messagestore.class.name=org.apache.qpid.server.store.berkeleydb.BDBMessageStore
profile.excludes=JavaExcludes JavaPersistentExcludes XAExcludes JavaPre010Excludes JavaBDBExcludes
broker.clean.between.tests=true
broker.persistent=true
-broker.protocol.excludes=--exclude-0-10 @PORT --exclude-0-10 @SSL_PORT --exclude-1-0 @PORT --exclude-1-0 @SSL_PORT --exclude-0-9-1 @PORT --exclude-0-9-1 @SSL_PORT --exclude-0-9 @PORT --exclude-0-9 @SSL_PORT
broker.version=v0_8
#
# Do not enable. Allow client to attempt 0-10 and negotiate downwards
diff --git a/qpid/java/test-profiles/java-bdb.0-9-1.testprofile b/qpid/java/test-profiles/java-bdb.0-9-1.testprofile
index 1339dc1dc7..fa86720bbb 100644
--- a/qpid/java/test-profiles/java-bdb.0-9-1.testprofile
+++ b/qpid/java/test-profiles/java-bdb.0-9-1.testprofile
@@ -20,15 +20,15 @@
broker.language=java
broker.type=internal
#broker.command only used for the second broker during failover tests in this profile
-broker.command=build/bin/qpid-server -p @PORT -m @MPORT @EXCLUDES @INCLUDES -c @CONFIG_FILE -l @LOG_CONFIG_FILE
+broker.command=build/bin/qpid-server -sp @STORE_PATH -st @STORE_TYPE -l @LOG_CONFIG_FILE
broker.ready=BRK-1004
broker.stopped=Exception
-broker.config=build/etc/config-systests-bdb.xml
+qpid.broker_default_amqp_protocol_excludes=AMQP_1_0,AMQP_0_10
+broker.virtualhosts-config=${QPID_HOME}/etc/virtualhosts-systests-bdb.xml
messagestore.class.name=org.apache.qpid.server.store.berkeleydb.BDBMessageStore
profile.excludes=JavaExcludes JavaPersistentExcludes XAExcludes JavaPre010Excludes JavaBDBExcludes
broker.clean.between.tests=true
broker.persistent=true
-broker.protocol.excludes=--exclude-0-10 @PORT --exclude-0-10 @SSL_PORT --exclude-1-0 @PORT --exclude-1-0 @SSL_PORT
broker.version=v0_9_1
#
# Do not enable. Allow client to attempt 0-10 and negotiate downwards
diff --git a/qpid/java/test-profiles/java-bdb.0-9.testprofile b/qpid/java/test-profiles/java-bdb.0-9.testprofile
index c097d53c85..ed3d7b2170 100644
--- a/qpid/java/test-profiles/java-bdb.0-9.testprofile
+++ b/qpid/java/test-profiles/java-bdb.0-9.testprofile
@@ -20,15 +20,15 @@
broker.language=java
broker.type=internal
#broker.command only used for the second broker during failover tests in this profile
-broker.command=build/bin/qpid-server -p @PORT -m @MPORT @EXCLUDES @INCLUDES -c @CONFIG_FILE -l @LOG_CONFIG_FILE
+broker.command=build/bin/qpid-server -sp @STORE_PATH -st @STORE_TYPE -l @LOG_CONFIG_FILE
broker.ready=BRK-1004
broker.stopped=Exception
-broker.config=build/etc/config-systests-bdb.xml
+qpid.broker_default_amqp_protocol_excludes=AMQP_1_0,AMQP_0_10,AMQP_0_9_1
+broker.virtualhosts-config=${QPID_HOME}/etc/virtualhosts-systests-bdb.xml
messagestore.class.name=org.apache.qpid.server.store.berkeleydb.BDBMessageStore
profile.excludes=JavaExcludes JavaPersistentExcludes XAExcludes JavaPre010Excludes JavaBDBExcludes
broker.clean.between.tests=true
broker.persistent=true
-broker.protocol.excludes=--exclude-0-10 @PORT --exclude-0-10 @SSL_PORT --exclude-1-0 @PORT --exclude-1-0 @SSL_PORT --exclude-0-9-1 @PORT --exclude-0-9-1 @SSL_PORT
broker.version=v0_9
#
# Do not enable. Allow client to attempt 0-10 and negotiate downwards
diff --git a/qpid/java/test-profiles/java-dby-mem.0-10.testprofile b/qpid/java/test-profiles/java-dby-mem.0-10.testprofile
index 33f9527c86..bfe031b338 100644
--- a/qpid/java/test-profiles/java-dby-mem.0-10.testprofile
+++ b/qpid/java/test-profiles/java-dby-mem.0-10.testprofile
@@ -20,12 +20,12 @@ broker.language=java
broker.version=v0_10
broker.type=internal
#broker.command only used for the second broker during failover tests in this profile
-broker.command=build/bin/qpid-server -p @PORT -m @MPORT @EXCLUDES @INCLUDES -c @CONFIG_FILE -l @LOG_CONFIG_FILE
+broker.command=build/bin/qpid-server -sp @STORE_PATH -st @STORE_TYPE -l @LOG_CONFIG_FILE
broker.ready=BRK-1004
broker.stopped=Exception
-broker.protocol.excludes=--exclude-1-0 @PORT --exclude-1-0 @SSL_PORT
-broker.config=build/etc/config-systests-derby-mem.xml
-messagestorefactory.class.name=org.apache.qpid.server.store.derby.DerbyMessageStoreFactory
+qpid.broker_default_amqp_protocol_excludes=AMQP_1_0
+broker.virtualhosts-config=${QPID_HOME}/etc/virtualhosts-systests-derby-mem.xml
+messagestore.class.name=org.apache.qpid.server.store.derby.DerbyMessageStore
profile.excludes=JavaPersistentExcludes JavaDerbyExcludes Java010Excludes
broker.clean.between.tests=true
broker.persistent=true
diff --git a/qpid/java/test-profiles/java-dby-mem.0-8.testprofile b/qpid/java/test-profiles/java-dby-mem.0-8.testprofile
index 89bad84769..28bce8e434 100644
--- a/qpid/java/test-profiles/java-dby-mem.0-8.testprofile
+++ b/qpid/java/test-profiles/java-dby-mem.0-8.testprofile
@@ -20,12 +20,12 @@ broker.version=v0_8
broker.language=java
broker.type=internal
#broker.command only used for the second broker during failover tests in this profile
-broker.command=build/bin/qpid-server -p @PORT -m @MPORT @EXCLUDES @INCLUDES -c @CONFIG_FILE -l @LOG_CONFIG_FILE
+broker.command=build/bin/qpid-server -sp @STORE_PATH -st @STORE_TYPE -l @LOG_CONFIG_FILE
broker.ready=BRK-1004
broker.stopped=Exception
-broker.config=build/etc/config-systests-derby-mem.xml
-broker.protocol.excludes=--exclude-0-10 @PORT --exclude-0-10 @SSL_PORT --exclude-1-0 @PORT --exclude-1-0 @SSL_PORT --exclude-0-9-1 @PORT --exclude-0-9-1 @SSL_PORT --exclude-0-9 @PORT --exclude-0-9 @SSL_PORT
-messagestorefactory.class.name=org.apache.qpid.server.store.derby.DerbyMessageStoreFactory
+qpid.broker_default_amqp_protocol_excludes=AMQP_1_0,AMQP_0_10,AMQP_0_9_1,AMQP_0_9
+broker.virtualhosts-config=${QPID_HOME}/etc/virtualhosts-systests-derby-mem.xml
+messagestore.class.name=org.apache.qpid.server.store.derby.DerbyMessageStore
profile.excludes=JavaPersistentExcludes JavaDerbyExcludes XAExcludes JavaPre010Excludes
broker.clean.between.tests=true
broker.persistent=true
diff --git a/qpid/java/test-profiles/java-dby-mem.0-9-1.testprofile b/qpid/java/test-profiles/java-dby-mem.0-9-1.testprofile
index 8deea281a4..0d2f82ebb5 100644
--- a/qpid/java/test-profiles/java-dby-mem.0-9-1.testprofile
+++ b/qpid/java/test-profiles/java-dby-mem.0-9-1.testprofile
@@ -20,12 +20,12 @@ broker.version=v0_9_1
broker.language=java
broker.type=internal
#broker.command only used for the second broker during failover tests in this profile
-broker.command=build/bin/qpid-server -p @PORT -m @MPORT @EXCLUDES @INCLUDES -c @CONFIG_FILE -l @LOG_CONFIG_FILE
+broker.command=build/bin/qpid-server -sp @STORE_PATH -st @STORE_TYPE -l @LOG_CONFIG_FILE
broker.ready=BRK-1004
broker.stopped=Exception
-broker.config=build/etc/config-systests-derby-mem.xml
-broker.protocol.excludes=--exclude-0-10 @PORT --exclude-0-10 @SSL_PORT --exclude-1-0 @PORT --exclude-1-0 @SSL_PORT
-messagestorefactory.class.name=org.apache.qpid.server.store.derby.DerbyMessageStoreFactory
+qpid.broker_default_amqp_protocol_excludes=AMQP_1_0,AMQP_0_10
+broker.virtualhosts-config=${QPID_HOME}/etc/virtualhosts-systests-derby-mem.xml
+messagestore.class.name=org.apache.qpid.server.store.derby.DerbyMessageStore
profile.excludes=JavaPersistentExcludes JavaDerbyExcludes XAExcludes JavaPre010Excludes
broker.clean.between.tests=true
broker.persistent=true
diff --git a/qpid/java/test-profiles/java-dby-mem.0-9.testprofile b/qpid/java/test-profiles/java-dby-mem.0-9.testprofile
index b691a7d153..4dd9fbb899 100644
--- a/qpid/java/test-profiles/java-dby-mem.0-9.testprofile
+++ b/qpid/java/test-profiles/java-dby-mem.0-9.testprofile
@@ -20,12 +20,12 @@ broker.version=v0_9
broker.language=java
broker.type=internal
#broker.command only used for the second broker during failover tests in this profile
-broker.command=build/bin/qpid-server -p @PORT -m @MPORT @EXCLUDES @INCLUDES -c @CONFIG_FILE -l @LOG_CONFIG_FILE
+broker.command=build/bin/qpid-server -sp @STORE_PATH -st @STORE_TYPE -l @LOG_CONFIG_FILE
broker.ready=BRK-1004
broker.stopped=Exception
-broker.config=build/etc/config-systests-derby-mem.xml
-broker.protocol.excludes=--exclude-0-10 @PORT --exclude-0-10 @SSL_PORT --exclude-1-0 @PORT --exclude-1-0 @SSL_PORT --exclude-0-9-1 @PORT --exclude-0-9-1 @SSL_PORT
-messagestorefactory.class.name=org.apache.qpid.server.store.derby.DerbyMessageStoreFactory
+qpid.broker_default_amqp_protocol_excludes=AMQP_1_0,AMQP_0_10,AMQP_0_9_1
+broker.virtualhosts-config=${QPID_HOME}/etc/virtualhosts-systests-derby-mem.xml
+messagestore.class.name=org.apache.qpid.server.store.derby.DerbyMessageStore
profile.excludes=JavaPersistentExcludes JavaDerbyExcludes XAExcludes JavaPre010Excludes
broker.clean.between.tests=true
broker.persistent=true
diff --git a/qpid/java/test-profiles/java-dby-spawn.0-10.testprofile b/qpid/java/test-profiles/java-dby-spawn.0-10.testprofile
index e2e2b44dae..9795533b52 100644
--- a/qpid/java/test-profiles/java-dby-spawn.0-10.testprofile
+++ b/qpid/java/test-profiles/java-dby-spawn.0-10.testprofile
@@ -19,11 +19,11 @@
broker.language=java
broker.version=v0_10
broker.type=spawned
-broker.command=build/bin/qpid-server -p @PORT -m @MPORT @EXCLUDES @INCLUDES -c @CONFIG_FILE -l @LOG_CONFIG_FILE
+broker.command=build/bin/qpid-server -sp @STORE_PATH -st @STORE_TYPE -l @LOG_CONFIG_FILE
broker.ready=BRK-1004
broker.stopped=Exception
-broker.protocol.excludes=--exclude-1-0 @PORT --exclude-1-0 @SSL_PORT
-broker.config=build/etc/config-systests-derby.xml
+qpid.broker_default_amqp_protocol_excludes=AMQP_1_0
+broker.virtualhosts-config=${QPID_HOME}/etc/virtualhosts-systests-derby.xml
messagestore.class.name=org.apache.qpid.server.store.derby.DerbyMessageStore
profile.excludes=JavaPersistentExcludes JavaDerbyExcludes Java010Excludes
broker.clean.between.tests=true
diff --git a/qpid/java/test-profiles/java-dby-spawn.0-8.testprofile b/qpid/java/test-profiles/java-dby-spawn.0-8.testprofile
index 3f609226e3..a980fd181d 100644
--- a/qpid/java/test-profiles/java-dby-spawn.0-8.testprofile
+++ b/qpid/java/test-profiles/java-dby-spawn.0-8.testprofile
@@ -19,11 +19,11 @@
broker.version=v0_8
broker.language=java
broker.type=spawned
-broker.command=build/bin/qpid-server -p @PORT -m @MPORT @EXCLUDES @INCLUDES -c @CONFIG_FILE -l @LOG_CONFIG_FILE
+broker.command=build/bin/qpid-server -sp @STORE_PATH -st @STORE_TYPE -l @LOG_CONFIG_FILE
broker.ready=BRK-1004
broker.stopped=Exception
-broker.config=build/etc/config-systests-derby.xml
-broker.protocol.excludes=--exclude-0-10 @PORT --exclude-0-10 @SSL_PORT --exclude-1-0 @PORT --exclude-1-0 @SSL_PORT --exclude-0-9-1 @PORT --exclude-0-9-1 @SSL_PORT --exclude-0-9 @PORT --exclude-0-9 @SSL_PORT
+qpid.broker_default_amqp_protocol_excludes=AMQP_1_0,AMQP_0_10,AMQP_0_9_1,AMQP_0_9
+broker.virtualhosts-config=${QPID_HOME}/etc/virtualhosts-systests-derby.xml
messagestore.class.name=org.apache.qpid.server.store.derby.DerbyMessageStore
profile.excludes=JavaPersistentExcludes JavaDerbyExcludes XAExcludes JavaPre010Excludes
broker.clean.between.tests=true
diff --git a/qpid/java/test-profiles/java-dby-spawn.0-9-1.testprofile b/qpid/java/test-profiles/java-dby-spawn.0-9-1.testprofile
index 80d40458fd..04428b5021 100644
--- a/qpid/java/test-profiles/java-dby-spawn.0-9-1.testprofile
+++ b/qpid/java/test-profiles/java-dby-spawn.0-9-1.testprofile
@@ -19,11 +19,11 @@
broker.version=v0_9_1
broker.language=java
broker.type=spawned
-broker.command=build/bin/qpid-server -p @PORT -m @MPORT @EXCLUDES @INCLUDES -c @CONFIG_FILE -l @LOG_CONFIG_FILE
+broker.command=build/bin/qpid-server -sp @STORE_PATH -st @STORE_TYPE -l @LOG_CONFIG_FILE
broker.ready=BRK-1004
broker.stopped=Exception
-broker.config=build/etc/config-systests-derby.xml
-broker.protocol.excludes=--exclude-0-10 @PORT --exclude-0-10 @SSL_PORT --exclude-1-0 @PORT --exclude-1-0 @SSL_PORT
+qpid.broker_default_amqp_protocol_excludes=AMQP_1_0,AMQP_0_10
+broker.virtualhosts-config=${QPID_HOME}/etc/virtualhosts-systests-derby.xml
messagestore.class.name=org.apache.qpid.server.store.derby.DerbyMessageStore
profile.excludes=JavaPersistentExcludes JavaDerbyExcludes XAExcludes JavaPre010Excludes
broker.clean.between.tests=true
diff --git a/qpid/java/test-profiles/java-dby-spawn.0-9.testprofile b/qpid/java/test-profiles/java-dby-spawn.0-9.testprofile
index 122eccdca1..4724eba660 100644
--- a/qpid/java/test-profiles/java-dby-spawn.0-9.testprofile
+++ b/qpid/java/test-profiles/java-dby-spawn.0-9.testprofile
@@ -19,11 +19,11 @@
broker.version=v0_9
broker.language=java
broker.type=spawned
-broker.command=build/bin/qpid-server -p @PORT -m @MPORT @EXCLUDES @INCLUDES -c @CONFIG_FILE -l @LOG_CONFIG_FILE
+broker.command=build/bin/qpid-server -sp @STORE_PATH -st @STORE_TYPE -l @LOG_CONFIG_FILE
broker.ready=BRK-1004
broker.stopped=Exception
-broker.config=build/etc/config-systests-derby.xml
-broker.protocol.excludes=--exclude-0-10 @PORT --exclude-0-10 @SSL_PORT --exclude-1-0 @PORT --exclude-1-0 @SSL_PORT --exclude-0-9-1 @PORT --exclude-0-9-1 @SSL_PORT
+qpid.broker_default_amqp_protocol_excludes=AMQP_1_0,AMQP_0_10,AMQP_0_9_1
+broker.virtualhosts-config=${QPID_HOME}/etc/virtualhosts-systests-derby.xml
messagestore.class.name=org.apache.qpid.server.store.derby.DerbyMessageStore
profile.excludes=JavaPersistentExcludes JavaDerbyExcludes XAExcludes JavaPre010Excludes
broker.clean.between.tests=true
diff --git a/qpid/java/test-profiles/java-dby.0-10.testprofile b/qpid/java/test-profiles/java-dby.0-10.testprofile
index d3b03054de..a2b1a41c31 100644
--- a/qpid/java/test-profiles/java-dby.0-10.testprofile
+++ b/qpid/java/test-profiles/java-dby.0-10.testprofile
@@ -20,11 +20,11 @@ broker.language=java
broker.version=v0_10
broker.type=internal
#broker.command only used for the second broker during failover tests in this profile
-broker.command=build/bin/qpid-server -p @PORT -m @MPORT @EXCLUDES @INCLUDES -c @CONFIG_FILE -l @LOG_CONFIG_FILE
+broker.command=build/bin/qpid-server -sp @STORE_PATH -st @STORE_TYPE -l @LOG_CONFIG_FILE
broker.ready=BRK-1004
broker.stopped=Exception
-broker.protocol.excludes=--exclude-1-0 @PORT --exclude-1-0 @SSL_PORT
-broker.config=build/etc/config-systests-derby.xml
+qpid.broker_default_amqp_protocol_excludes=AMQP_1_0
+broker.virtualhosts-config=${QPID_HOME}/etc/virtualhosts-systests-derby.xml
messagestore.class.name=org.apache.qpid.server.store.derby.DerbyMessageStore
profile.excludes=JavaPersistentExcludes JavaDerbyExcludes Java010Excludes
broker.clean.between.tests=true
diff --git a/qpid/java/test-profiles/java-dby.0-8.testprofile b/qpid/java/test-profiles/java-dby.0-8.testprofile
index 51580e6c7a..509796331f 100644
--- a/qpid/java/test-profiles/java-dby.0-8.testprofile
+++ b/qpid/java/test-profiles/java-dby.0-8.testprofile
@@ -20,11 +20,11 @@ broker.version=v0_8
broker.language=java
broker.type=internal
#broker.command only used for the second broker during failover tests in this profile
-broker.command=build/bin/qpid-server -p @PORT -m @MPORT @EXCLUDES @INCLUDES -c @CONFIG_FILE -l @LOG_CONFIG_FILE
+broker.command=build/bin/qpid-server -sp @STORE_PATH -st @STORE_TYPE -l @LOG_CONFIG_FILE
broker.ready=BRK-1004
broker.stopped=Exception
-broker.config=build/etc/config-systests-derby.xml
-broker.protocol.excludes=--exclude-0-10 @PORT --exclude-0-10 @SSL_PORT --exclude-1-0 @PORT --exclude-1-0 @SSL_PORT --exclude-0-9-1 @PORT --exclude-0-9-1 @SSL_PORT --exclude-0-9 @PORT --exclude-0-9 @SSL_PORT
+qpid.broker_default_amqp_protocol_excludes=AMQP_1_0,AMQP_0_10,AMQP_0_9_1,AMQP_0_9
+broker.virtualhosts-config=${QPID_HOME}/etc/virtualhosts-systests-derby.xml
messagestore.class.name=org.apache.qpid.server.store.derby.DerbyMessageStore
profile.excludes=JavaPersistentExcludes JavaDerbyExcludes XAExcludes JavaPre010Excludes
broker.clean.between.tests=true
diff --git a/qpid/java/test-profiles/java-dby.0-9-1.testprofile b/qpid/java/test-profiles/java-dby.0-9-1.testprofile
index b92397eae7..be087a6344 100644
--- a/qpid/java/test-profiles/java-dby.0-9-1.testprofile
+++ b/qpid/java/test-profiles/java-dby.0-9-1.testprofile
@@ -20,11 +20,11 @@ broker.version=v0_9_1
broker.language=java
broker.type=internal
#broker.command only used for the second broker during failover tests in this profile
-broker.command=build/bin/qpid-server -p @PORT -m @MPORT @EXCLUDES @INCLUDES -c @CONFIG_FILE -l @LOG_CONFIG_FILE
+broker.command=build/bin/qpid-server -sp @STORE_PATH -st @STORE_TYPE -l @LOG_CONFIG_FILE
broker.ready=BRK-1004
broker.stopped=Exception
-broker.config=build/etc/config-systests-derby.xml
-broker.protocol.excludes=--exclude-0-10 @PORT --exclude-0-10 @SSL_PORT --exclude-1-0 @PORT --exclude-1-0 @SSL_PORT
+qpid.broker_default_amqp_protocol_excludes=AMQP_1_0,AMQP_0_10
+broker.virtualhosts-config=${QPID_HOME}/etc/virtualhosts-systests-derby.xml
messagestore.class.name=org.apache.qpid.server.store.derby.DerbyMessageStore
profile.excludes=JavaPersistentExcludes JavaDerbyExcludes XAExcludes JavaPre010Excludes
broker.clean.between.tests=true
diff --git a/qpid/java/test-profiles/java-dby.0-9.testprofile b/qpid/java/test-profiles/java-dby.0-9.testprofile
index 17363b7e47..3b5e586ba4 100644
--- a/qpid/java/test-profiles/java-dby.0-9.testprofile
+++ b/qpid/java/test-profiles/java-dby.0-9.testprofile
@@ -20,11 +20,11 @@ broker.version=v0_9
broker.language=java
broker.type=internal
#broker.command only used for the second broker during failover tests in this profile
-broker.command=build/bin/qpid-server -p @PORT -m @MPORT @EXCLUDES @INCLUDES -c @CONFIG_FILE -l @LOG_CONFIG_FILE
+broker.command=build/bin/qpid-server -sp @STORE_PATH -st @STORE_TYPE -l @LOG_CONFIG_FILE
broker.ready=BRK-1004
broker.stopped=Exception
-broker.config=build/etc/config-systests-derby.xml
-broker.protocol.excludes=--exclude-0-10 @PORT --exclude-0-10 @SSL_PORT --exclude-1-0 @PORT --exclude-1-0 @SSL_PORT --exclude-0-9-1 @PORT --exclude-0-9-1 @SSL_PORT
+qpid.broker_default_amqp_protocol_excludes=AMQP_1_0,AMQP_0_10,AMQP_0_9_1
+broker.virtualhosts-config=${QPID_HOME}/etc/virtualhosts-systests-derby.xml
messagestore.class.name=org.apache.qpid.server.store.derby.DerbyMessageStore
profile.excludes=JavaPersistentExcludes JavaDerbyExcludes XAExcludes JavaPre010Excludes
broker.clean.between.tests=true
diff --git a/qpid/java/test-profiles/java-mms-spawn.0-10.testprofile b/qpid/java/test-profiles/java-mms-spawn.0-10.testprofile
index 57af5c4a41..71aaf48562 100644
--- a/qpid/java/test-profiles/java-mms-spawn.0-10.testprofile
+++ b/qpid/java/test-profiles/java-mms-spawn.0-10.testprofile
@@ -19,10 +19,11 @@
broker.version=v0_10
broker.language=java
broker.type=spawned
-broker.command=build/bin/qpid-server -p @PORT -m @MPORT @EXCLUDES @INCLUDES -c @CONFIG_FILE -l @LOG_CONFIG_FILE
+broker.command=build/bin/qpid-server -sp @STORE_PATH -st @STORE_TYPE -l @LOG_CONFIG_FILE
broker.ready=BRK-1004
broker.stopped=Exception
-broker.protocol.excludes=--exclude-1-0 @PORT --exclude-1-0 @SSL_PORT
+qpid.broker_default_amqp_protocol_excludes=AMQP_1_0
+broker.virtualhosts-config=${QPID_HOME}/etc/virtualhosts-systests.xml
#
# Do not enable. Allow client to attempt 0-10 and negotiate downwards
#
diff --git a/qpid/java/test-profiles/java-mms-spawn.0-8.testprofile b/qpid/java/test-profiles/java-mms-spawn.0-8.testprofile
index 24f088e0c5..6365fa20f0 100644
--- a/qpid/java/test-profiles/java-mms-spawn.0-8.testprofile
+++ b/qpid/java/test-profiles/java-mms-spawn.0-8.testprofile
@@ -19,10 +19,11 @@
broker.version=v0_8
broker.language=java
broker.type=spawned
-broker.command=build/bin/qpid-server -p @PORT -m @MPORT @EXCLUDES @INCLUDES -c @CONFIG_FILE -l @LOG_CONFIG_FILE
+broker.command=build/bin/qpid-server -sp @STORE_PATH -st @STORE_TYPE -l @LOG_CONFIG_FILE
broker.ready=BRK-1004
broker.stopped=Exception
-broker.protocol.excludes=--exclude-0-10 @PORT --exclude-0-10 @SSL_PORT --exclude-1-0 @PORT --exclude-1-0 @SSL_PORT --exclude-0-9-1 @PORT --exclude-0-9-1 @SSL_PORT --exclude-0-9 @PORT --exclude-0-9 @SSL_PORT
+qpid.broker_default_amqp_protocol_excludes=AMQP_1_0,AMQP_0_10,AMQP_0_9_1,AMQP_0_9
+broker.virtualhosts-config=${QPID_HOME}/etc/virtualhosts-systests.xml
#
# Do not enable. Allow client to attempt 0-10 and negotiate downwards
#
diff --git a/qpid/java/test-profiles/java-mms-spawn.0-9-1.testprofile b/qpid/java/test-profiles/java-mms-spawn.0-9-1.testprofile
index c1f6d10675..1eb4b00a1d 100644
--- a/qpid/java/test-profiles/java-mms-spawn.0-9-1.testprofile
+++ b/qpid/java/test-profiles/java-mms-spawn.0-9-1.testprofile
@@ -19,10 +19,11 @@
broker.version=v0_9_1
broker.language=java
broker.type=spawned
-broker.command=build/bin/qpid-server -p @PORT -m @MPORT @EXCLUDES @INCLUDES -c @CONFIG_FILE -l @LOG_CONFIG_FILE
+broker.command=build/bin/qpid-server -sp @STORE_PATH -st @STORE_TYPE -l @LOG_CONFIG_FILE
broker.ready=BRK-1004
broker.stopped=Exception
-broker.protocol.excludes=--exclude-0-10 @PORT --exclude-0-10 @SSL_PORT --exclude-1-0 @PORT --exclude-1-0 @SSL_PORT
+qpid.broker_default_amqp_protocol_excludes=AMQP_1_0,AMQP_0_10
+broker.virtualhosts-config=${QPID_HOME}/etc/virtualhosts-systests.xml
#
# Do not enable. Allow client to attempt 0-10 and negotiate downwards
#
diff --git a/qpid/java/test-profiles/java-mms-spawn.0-9.testprofile b/qpid/java/test-profiles/java-mms-spawn.0-9.testprofile
index 421ae7476e..4ebce66c05 100644
--- a/qpid/java/test-profiles/java-mms-spawn.0-9.testprofile
+++ b/qpid/java/test-profiles/java-mms-spawn.0-9.testprofile
@@ -19,10 +19,11 @@
broker.version=v0_9
broker.language=java
broker.type=spawned
-broker.command=build/bin/qpid-server -p @PORT -m @MPORT @EXCLUDES @INCLUDES -c @CONFIG_FILE -l @LOG_CONFIG_FILE
+broker.command=build/bin/qpid-server -sp @STORE_PATH -st @STORE_TYPE -l @LOG_CONFIG_FILE
broker.ready=BRK-1004
broker.stopped=Exception
-broker.protocol.excludes=--exclude-0-10 @PORT --exclude-0-10 @SSL_PORT --exclude-1-0 @PORT --exclude-1-0 @SSL_PORT --exclude-0-9-1 @PORT --exclude-0-9-1 @SSL_PORT
+qpid.broker_default_amqp_protocol_excludes=AMQP_1_0,AMQP_0_10,AMQP_0_9_1
+broker.virtualhosts-config=${QPID_HOME}/etc/virtualhosts-systests.xml
#
# Do not enable. Allow client to attempt 0-10 and negotiate downwards
#
diff --git a/qpid/java/test-profiles/java-mms.0-10.testprofile b/qpid/java/test-profiles/java-mms.0-10.testprofile
index 6dd40cff47..0de5ffea09 100644
--- a/qpid/java/test-profiles/java-mms.0-10.testprofile
+++ b/qpid/java/test-profiles/java-mms.0-10.testprofile
@@ -20,9 +20,10 @@ broker.language=java
broker.version=v0_10
broker.type=internal
#broker.command only used for the second broker during failover tests in this profile
-broker.command=build/bin/qpid-server -p @PORT -m @MPORT @EXCLUDES @INCLUDES -c @CONFIG_FILE -l @LOG_CONFIG_FILE
+broker.command=build/bin/qpid-server -sp @STORE_PATH -st @STORE_TYPE -l @LOG_CONFIG_FILE
broker.ready=BRK-1004
broker.stopped=Exception
-broker.protocol.excludes=--exclude-1-0 @PORT --exclude-1-0 @SSL_PORT
+qpid.broker_default_amqp_protocol_excludes=AMQP_1_0
+broker.virtualhosts-config=${QPID_HOME}/etc/virtualhosts-systests.xml
profile.excludes=JavaTransientExcludes Java010Excludes
diff --git a/qpid/java/test-profiles/java-mms.0-8.testprofile b/qpid/java/test-profiles/java-mms.0-8.testprofile
index f82bf8c473..dddad95157 100644
--- a/qpid/java/test-profiles/java-mms.0-8.testprofile
+++ b/qpid/java/test-profiles/java-mms.0-8.testprofile
@@ -20,10 +20,11 @@ broker.language=java
broker.version=v0_8
broker.type=internal
#broker.command only used for the second broker during failover tests in this profile
-broker.command=build/bin/qpid-server -p @PORT -m @MPORT @EXCLUDES @INCLUDES -c @CONFIG_FILE -l @LOG_CONFIG_FILE
+broker.command=build/bin/qpid-server -sp @STORE_PATH -st @STORE_TYPE -l @LOG_CONFIG_FILE
broker.ready=BRK-1004
broker.stopped=Exception
-broker.protocol.excludes=--exclude-0-10 @PORT --exclude-0-10 @SSL_PORT --exclude-1-0 @PORT --exclude-1-0 @SSL_PORT --exclude-0-9-1 @PORT --exclude-0-9-1 @SSL_PORT --exclude-0-9 @PORT --exclude-0-9 @SSL_PORT
+qpid.broker_default_amqp_protocol_excludes=AMQP_1_0,AMQP_0_10,AMQP_0_9_1,AMQP_0_9
+broker.virtualhosts-config=${QPID_HOME}/etc/virtualhosts-systests.xml
#
# Do not enable. Allow client to attempt 0-10 and negotiate downwards
#
diff --git a/qpid/java/test-profiles/java-mms.0-9-1.testprofile b/qpid/java/test-profiles/java-mms.0-9-1.testprofile
index 9b8baaa5a3..3c2f68a2c9 100644
--- a/qpid/java/test-profiles/java-mms.0-9-1.testprofile
+++ b/qpid/java/test-profiles/java-mms.0-9-1.testprofile
@@ -20,10 +20,11 @@ broker.language=java
broker.version=v0_9_1
broker.type=internal
#broker.command only used for the second broker during failover tests in this profile
-broker.command=build/bin/qpid-server -p @PORT -m @MPORT @EXCLUDES @INCLUDES -c @CONFIG_FILE -l @LOG_CONFIG_FILE
+broker.command=build/bin/qpid-server -sp @STORE_PATH -st @STORE_TYPE -l @LOG_CONFIG_FILE
broker.ready=BRK-1004
broker.stopped=Exception
-broker.protocol.excludes=--exclude-0-10 @PORT --exclude-0-10 @SSL_PORT --exclude-1-0 @PORT --exclude-1-0 @SSL_PORT
+qpid.broker_default_amqp_protocol_excludes=AMQP_1_0,AMQP_0_10
+broker.virtualhosts-config=${QPID_HOME}/etc/virtualhosts-systests.xml
#
# Do not enable. Allow client to attempt 0-10 and negotiate downwards
#
diff --git a/qpid/java/test-profiles/java-mms.0-9.testprofile b/qpid/java/test-profiles/java-mms.0-9.testprofile
index 56ace6d9e1..992168b044 100644
--- a/qpid/java/test-profiles/java-mms.0-9.testprofile
+++ b/qpid/java/test-profiles/java-mms.0-9.testprofile
@@ -20,10 +20,11 @@ broker.language=java
broker.version=v0_9
broker.type=internal
#broker.command only used for the second broker during failover tests in this profile
-broker.command=build/bin/qpid-server -p @PORT -m @MPORT @EXCLUDES @INCLUDES -c @CONFIG_FILE -l @LOG_CONFIG_FILE
+broker.command=build/bin/qpid-server -sp @STORE_PATH -st @STORE_TYPE -l @LOG_CONFIG_FILE
broker.ready=BRK-1004
broker.stopped=Exception
-broker.protocol.excludes=--exclude-0-10 @PORT --exclude-0-10 @SSL_PORT --exclude-1-0 @PORT --exclude-1-0 @SSL_PORT --exclude-0-9-1 @PORT --exclude-0-9-1 @SSL_PORT
+qpid.broker_default_amqp_protocol_excludes=AMQP_1_0,AMQP_0_10,AMQP_0_9_1
+broker.virtualhosts-config=${QPID_HOME}/etc/virtualhosts-systests.xml
#
# Do not enable. Allow client to attempt 0-10 and negotiate downwards
#
diff --git a/qpid/java/test-profiles/testprofile.defaults b/qpid/java/test-profiles/testprofile.defaults
index e205de2a18..033da12a97 100644
--- a/qpid/java/test-profiles/testprofile.defaults
+++ b/qpid/java/test-profiles/testprofile.defaults
@@ -20,7 +20,7 @@ java.naming.factory.initial=org.apache.qpid.jndi.PropertiesFileInitialContextFac
java.naming.provider.url=${test.profiles}/test-provider.properties
broker.ready=Listening on TCP
-broker.config=build/etc/config-systests.xml
+broker.config=build/etc/config-systests.json
messagestore.class.name=org.apache.qpid.server.store.MemoryMessageStore
broker.protocol.excludes=
broker.persistent=false
@@ -45,6 +45,8 @@ log4j.debug=false
# Keep in sync
test.port=15672
test.mport=18999
+test.cport=19099
+test.hport=18080
#Note : Management will start open second port on: mport + 100 : 19099
test.port.ssl=15671
test.port.alt=25672
@@ -60,5 +62,7 @@ haltonerror=no
exclude.modules=none
profile.clustered=false
+broker.config-store-type=json
+broker.virtualhosts-config="${QPID_HOME}/etc/virtualhosts-systests.xml"