diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/ActiveMQServerControlImpl.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/ActiveMQServerControlImpl.java index 08facbf16a..03defb59aa 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/ActiveMQServerControlImpl.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/ActiveMQServerControlImpl.java @@ -779,13 +779,13 @@ public class ActiveMQServerControlImpl extends AbstractControl implements Active @Override public void createQueue(final String address, final String name, final String filterStr, final boolean durable) throws Exception { - createQueue(address, name, filterStr, durable, server.getAddressSettingsRepository().getMatch(address).getDefaultQueueRoutingType().toString()); + createQueue(address, name, filterStr, durable, server.getAddressSettingsRepository().getMatch(address == null ? name : address).getDefaultQueueRoutingType().toString()); } @Override public void createQueue(final String address, final String name, final String filterStr, final boolean durable, final String routingType) throws Exception { - AddressSettings addressSettings = server.getAddressSettingsRepository().getMatch(address); + AddressSettings addressSettings = server.getAddressSettingsRepository().getMatch(address == null ? name : address); createQueue(address, routingType, name, filterStr, durable, addressSettings.getDefaultMaxConsumers(), addressSettings.isDefaultPurgeOnNoConsumers(), addressSettings.isAutoCreateAddresses()); } diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java index 198ed454c2..018e370b11 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java @@ -1655,7 +1655,7 @@ public class ActiveMQServerImpl implements ActiveMQServer { final SimpleString filterString, final boolean durable, final boolean temporary) throws Exception { - AddressSettings as = getAddressSettingsRepository().getMatch(address.toString()); + AddressSettings as = getAddressSettingsRepository().getMatch(address == null ? queueName.toString() : address.toString()); return createQueue(address, routingType, queueName, filterString, durable, temporary, as.getDefaultMaxConsumers(), as.isDefaultPurgeOnNoConsumers(), as.isAutoCreateAddresses()); } @@ -1667,7 +1667,7 @@ public class ActiveMQServerImpl implements ActiveMQServer { final SimpleString filterString, final boolean durable, final boolean temporary) throws Exception { - AddressSettings as = getAddressSettingsRepository().getMatch(address.toString()); + AddressSettings as = getAddressSettingsRepository().getMatch(address == null ? queueName.toString() : address.toString()); return createQueue(address, routingType, queueName, filterString, user, durable, temporary, false, as.getDefaultMaxConsumers(), as.isDefaultPurgeOnNoConsumers(), as.isAutoCreateAddresses()); } @@ -1706,7 +1706,7 @@ public class ActiveMQServerImpl implements ActiveMQServer { final SimpleString filterString, final boolean durable, final boolean temporary) throws Exception { - return createQueue(address, getAddressSettingsRepository().getMatch(address.toString()).getDefaultQueueRoutingType(), queueName, filterString, durable, temporary); + return createQueue(address, getAddressSettingsRepository().getMatch(address == null ? queueName.toString() : address.toString()).getDefaultQueueRoutingType(), queueName, filterString, durable, temporary); } @Override @@ -1769,7 +1769,7 @@ public class ActiveMQServerImpl implements ActiveMQServer { final SimpleString filterString, final boolean durable, final boolean temporary) throws Exception { - return createQueue(address, getAddressSettingsRepository().getMatch(address.toString()).getDefaultQueueRoutingType(), resourceName, filterString, durable, temporary); + return createQueue(address, getAddressSettingsRepository().getMatch(address == null ? resourceName.toString() : address.toString()).getDefaultQueueRoutingType(), resourceName, filterString, durable, temporary); } @Deprecated @@ -2710,18 +2710,17 @@ public class ActiveMQServerImpl implements ActiveMQServer { final long queueID = storageManager.generateID(); final QueueConfig.Builder queueConfigBuilder; - if (address == null) { - queueConfigBuilder = QueueConfig.builderWith(queueID, queueName); - } else { - queueConfigBuilder = QueueConfig.builderWith(queueID, queueName, address); - } - AddressInfo info = postOffice.getAddressInfo(address); + final SimpleString addressToUse = address == null ? queueName : address; + + queueConfigBuilder = QueueConfig.builderWith(queueID, queueName, addressToUse); + + AddressInfo info = postOffice.getAddressInfo(addressToUse); if (autoCreateAddress) { RoutingType rt = (routingType == null ? ActiveMQDefaultConfiguration.getDefaultRoutingType() : routingType); if (info == null) { - final AddressInfo addressInfo = new AddressInfo(address, rt); + final AddressInfo addressInfo = new AddressInfo(addressToUse, rt); addressInfo.setAutoCreated(true); addAddressInfo(addressInfo); } else if (!info.getRoutingTypes().contains(routingType)) { @@ -2731,7 +2730,7 @@ public class ActiveMQServerImpl implements ActiveMQServer { updateAddressInfo(info.getName(), routingTypes); } } else if (info == null) { - throw ActiveMQMessageBundle.BUNDLE.addressDoesNotExist(address); + throw ActiveMQMessageBundle.BUNDLE.addressDoesNotExist(addressToUse); } else if (!info.getRoutingTypes().contains(routingType)) { throw ActiveMQMessageBundle.BUNDLE.invalidRoutingTypeForAddress(routingType, info.getName().toString(), info.getRoutingTypes()); } diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ActiveMQServerControlTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ActiveMQServerControlTest.java index 38b1682707..e3725d87ff 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ActiveMQServerControlTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ActiveMQServerControlTest.java @@ -206,6 +206,29 @@ public class ActiveMQServerControlTest extends ManagementTestBase { checkNoResource(ObjectNameBuilder.DEFAULT.getQueueObjectName(address, name, RoutingType.ANYCAST)); } + @Test + public void testCreateQueueWithNullAddress() throws Exception { + SimpleString address = RandomUtil.randomSimpleString(); + SimpleString name = address; + + ActiveMQServerControl serverControl = createManagementControl(); + + checkNoResource(ObjectNameBuilder.DEFAULT.getQueueObjectName(address, name, RoutingType.ANYCAST)); + serverControl.createQueue(null, name.toString(), "ANYCAST"); + + checkResource(ObjectNameBuilder.DEFAULT.getQueueObjectName(name, name, RoutingType.ANYCAST)); + QueueControl queueControl = ManagementControlHelper.createQueueControl(address, name, RoutingType.ANYCAST, mbeanServer); + Assert.assertEquals(address.toString(), queueControl.getAddress()); + Assert.assertEquals(name.toString(), queueControl.getName()); + Assert.assertNull(queueControl.getFilter()); + Assert.assertEquals(true, queueControl.isDurable()); + Assert.assertEquals(false, queueControl.isTemporary()); + + serverControl.destroyQueue(name.toString()); + + checkNoResource(ObjectNameBuilder.DEFAULT.getQueueObjectName(address, name, RoutingType.ANYCAST)); + } + @Test public void testCreateAndDestroyQueue_2() throws Exception { SimpleString address = RandomUtil.randomSimpleString();