From f220607e3361429250d11015ec84714c6bb77bdc Mon Sep 17 00:00:00 2001 From: "Timothy A. Bish" Date: Fri, 3 Feb 2012 18:46:03 +0000 Subject: [PATCH] fix for: https://issues.apache.org/jira/browse/AMQ-3586 Trim whitespace from destination names git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1240287 13f79535-47bb-0310-9956-ffa450edef68 --- .../activemq/command/ActiveMQDestination.java | 10 ++-- .../apache/activemq/broker/jmx/MBeanTest.java | 50 ++++++++++++++++++- 2 files changed, 55 insertions(+), 5 deletions(-) diff --git a/activemq-core/src/main/java/org/apache/activemq/command/ActiveMQDestination.java b/activemq-core/src/main/java/org/apache/activemq/command/ActiveMQDestination.java index 3c05404ab3..2a519f8c30 100755 --- a/activemq-core/src/main/java/org/apache/activemq/command/ActiveMQDestination.java +++ b/activemq-core/src/main/java/org/apache/activemq/command/ActiveMQDestination.java @@ -42,9 +42,9 @@ import org.apache.activemq.util.URISupport; /** * @openwire:marshaller - * + * */ -public abstract class ActiveMQDestination extends JNDIBaseStorable implements DataStructure, Destination, Externalizable, Comparable { +public abstract class ActiveMQDestination extends JNDIBaseStorable implements DataStructure, Destination, Externalizable, Comparable { public static final String PATH_SEPERATOR = "."; public static final char COMPOSITE_SEPERATOR = ','; @@ -73,7 +73,7 @@ public abstract class ActiveMQDestination extends JNDIBaseStorable implements Da protected Map options; protected static UnresolvedDestinationTransformer unresolvableDestinationTransformer = new DefaultUnresolvedDestinationTransformer(); - + public ActiveMQDestination() { } @@ -121,7 +121,7 @@ public abstract class ActiveMQDestination extends JNDIBaseStorable implements Da if (dest instanceof ActiveMQDestination) { return (ActiveMQDestination)dest; } - + if (dest instanceof Queue && dest instanceof Topic) { String queueName = ((Queue) dest).getQueueName(); String topicName = ((Topic) dest).getTopicName(); @@ -165,6 +165,7 @@ public abstract class ActiveMQDestination extends JNDIBaseStorable implements Da } } + @Override public int compareTo(Object that) { if (that instanceof ActiveMQDestination) { return compare(this, (ActiveMQDestination)that); @@ -221,6 +222,7 @@ public abstract class ActiveMQDestination extends JNDIBaseStorable implements Da } public void setPhysicalName(String physicalName) { + physicalName = physicalName.trim(); final int len = physicalName.length(); // options offset int p = -1; diff --git a/activemq-core/src/test/java/org/apache/activemq/broker/jmx/MBeanTest.java b/activemq-core/src/test/java/org/apache/activemq/broker/jmx/MBeanTest.java index eaf303d7a9..7007774215 100644 --- a/activemq-core/src/test/java/org/apache/activemq/broker/jmx/MBeanTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/broker/jmx/MBeanTest.java @@ -334,6 +334,45 @@ public class MBeanTest extends EmbeddedBrokerTestSupport { assertEquals("dest has no memory usage", 0, queue.getMemoryPercentUsage()); } + public void testCreateDestinationWithSpacesAtEnds() throws Exception { + ObjectName brokerName = assertRegisteredObjectName(domain + ":Type=Broker,BrokerName=localhost"); + BrokerViewMBean broker = (BrokerViewMBean)MBeanServerInvocationHandler.newProxyInstance(mbeanServer, brokerName, BrokerViewMBean.class, true); + + assertTrue("broker is not a slave", !broker.isSlave()); + // create 2 topics + broker.addTopic(getDestinationString() + "1 "); + broker.addTopic(" " + getDestinationString() + "2"); + broker.addTopic(" " + getDestinationString() + "3 "); + + assertNotRegisteredObjectName(domain + ":Type=Topic,BrokerName=localhost,Destination=" + getDestinationString() + "1 "); + assertNotRegisteredObjectName(domain + ":Type=Topic,BrokerName=localhost,Destination= " + getDestinationString() + "2"); + assertNotRegisteredObjectName(domain + ":Type=Topic,BrokerName=localhost,Destination= " + getDestinationString() + "3 "); + + ObjectName topicObjName1 = assertRegisteredObjectName(domain + ":Type=Topic,BrokerName=localhost,Destination=" + getDestinationString() + "1"); + ObjectName topicObjName2 = assertRegisteredObjectName(domain + ":Type=Topic,BrokerName=localhost,Destination=" + getDestinationString() + "2"); + ObjectName topicObjName3 = assertRegisteredObjectName(domain + ":Type=Topic,BrokerName=localhost,Destination=" + getDestinationString() + "3"); + + TopicViewMBean topic1 = (TopicViewMBean)MBeanServerInvocationHandler.newProxyInstance(mbeanServer, topicObjName1, TopicViewMBean.class, true); + TopicViewMBean topic2 = (TopicViewMBean)MBeanServerInvocationHandler.newProxyInstance(mbeanServer, topicObjName2, TopicViewMBean.class, true); + TopicViewMBean topic3 = (TopicViewMBean)MBeanServerInvocationHandler.newProxyInstance(mbeanServer, topicObjName3, TopicViewMBean.class, true); + + assertEquals("topic1 Durable subscriber count", 0, topic1.getConsumerCount()); + assertEquals("topic2 Durable subscriber count", 0, topic2.getConsumerCount()); + assertEquals("topic3 Durable subscriber count", 0, topic3.getConsumerCount()); + + String topicName = getDestinationString(); + String selector = null; + + // create 1 subscriber for each topic + broker.createDurableSubscriber(clientID, "topic1.subscriber1", topicName + "1", selector); + broker.createDurableSubscriber(clientID, "topic2.subscriber1", topicName + "2", selector); + broker.createDurableSubscriber(clientID, "topic3.subscriber1", topicName + "3", selector); + + assertEquals("topic1 Durable subscriber count", 1, topic1.getConsumerCount()); + assertEquals("topic2 Durable subscriber count", 1, topic2.getConsumerCount()); + assertEquals("topic3 Durable subscriber count", 1, topic3.getConsumerCount()); + } + @SuppressWarnings("rawtypes") protected void assertSendViaMBean() throws Exception { String queueName = getDestinationString() + ".SendMBBean"; @@ -415,7 +454,6 @@ public class MBeanTest extends EmbeddedBrokerTestSupport { assertEquals("Message " + messageIndex + " CData field: " + name, expected, value); } - protected void assertQueueBrowseWorks() throws Exception { Integer mbeancnt = mbeanServer.getMBeanCount(); echo("Mbean count :" + mbeancnt); @@ -630,6 +668,16 @@ public class MBeanTest extends EmbeddedBrokerTestSupport { return objectName; } + protected ObjectName assertNotRegisteredObjectName(String name) throws MalformedObjectNameException, NullPointerException { + ObjectName objectName = new ObjectName(name); + if (mbeanServer.isRegistered(objectName)) { + fail("Found the MBean!: " + objectName); + } else { + echo("Bean not registered Registered: " + objectName); + } + return objectName; + } + protected void setUp() throws Exception { bindAddress = "tcp://localhost:0"; useTopic = false;