From b5bba0920785d56de9707021767bf42b517805fe Mon Sep 17 00:00:00 2001 From: James Strachan Date: Wed, 1 Mar 2006 17:05:17 +0000 Subject: [PATCH] test case and patch to ensure that the JMSXGroupID can be specified in Stomp together with testing for the use of correlation-id git-svn-id: https://svn.apache.org/repos/asf/incubator/activemq/trunk@382083 13f79535-47bb-0310-9956-ffa450edef68 --- .../activemq/command/ActiveMQMessage.java | 12 ++++++ .../org/apache/activemq/command/Message.java | 6 +-- .../activemq/transport/stomp/StompTest.java | 43 ++++++++++++++++++- 3 files changed, 55 insertions(+), 6 deletions(-) diff --git a/activemq-core/src/main/java/org/apache/activemq/command/ActiveMQMessage.java b/activemq-core/src/main/java/org/apache/activemq/command/ActiveMQMessage.java index 9045e14873..8e17dc2774 100755 --- a/activemq-core/src/main/java/org/apache/activemq/command/ActiveMQMessage.java +++ b/activemq-core/src/main/java/org/apache/activemq/command/ActiveMQMessage.java @@ -20,6 +20,8 @@ import java.io.IOException; import java.io.UnsupportedEncodingException; import java.util.Enumeration; import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; import java.util.Vector; import javax.jms.DeliveryMode; @@ -322,6 +324,16 @@ public class ActiveMQMessage extends Message implements javax.jms.Message { } } } + + public void setProperties(Map properties) throws JMSException { + for (Iterator iter = properties.entrySet().iterator(); iter.hasNext();) { + Map.Entry entry = (Map.Entry) iter.next(); + + // Lets use the object property method as we may contain standard extension headers like JMSXGroupID + setObjectProperty((String) entry.getKey(), entry.getValue()); + } + } + private void checkValidObject(Object value) throws MessageFormatException { if(!(value instanceof Boolean || value instanceof Byte || value instanceof Short || value instanceof Integer || diff --git a/activemq-core/src/main/java/org/apache/activemq/command/Message.java b/activemq-core/src/main/java/org/apache/activemq/command/Message.java index 2e8c44214a..dcd73c41b0 100755 --- a/activemq-core/src/main/java/org/apache/activemq/command/Message.java +++ b/activemq-core/src/main/java/org/apache/activemq/command/Message.java @@ -140,11 +140,7 @@ abstract public class Message extends BaseCommand implements MarshallAware, Mess properties=null; } - public void setProperties(Map properties) throws IOException { - lazyCreateProperties(); - this.properties.putAll(properties); - } - + public void setProperty(String name, Object value) throws IOException { lazyCreateProperties(); properties.put(name, value); diff --git a/activemq-core/src/test/java/org/apache/activemq/transport/stomp/StompTest.java b/activemq-core/src/test/java/org/apache/activemq/transport/stomp/StompTest.java index 8303f58b8e..0ae561f9c7 100644 --- a/activemq-core/src/test/java/org/apache/activemq/transport/stomp/StompTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/transport/stomp/StompTest.java @@ -21,6 +21,7 @@ import org.apache.activemq.CombinationTestSupport; import org.apache.activemq.broker.BrokerService; import org.apache.activemq.broker.TransportConnector; import org.apache.activemq.command.ActiveMQQueue; +import org.apache.activemq.command.ActiveMQTextMessage; import javax.jms.Connection; import javax.jms.JMSException; @@ -155,7 +156,7 @@ public class StompTest extends CombinationTestSupport { } - public void testSendMessageWithHeaders() throws Exception { + public void testSendMessageWithCustomHeadersAndSelector() throws Exception { MessageConsumer consumer = session.createConsumer(queue, "foo = 'abc'"); @@ -182,6 +183,46 @@ public class StompTest extends CombinationTestSupport { TextMessage message = (TextMessage) consumer.receive(1000); assertNotNull(message); assertEquals("Hello World", message.getText()); + assertEquals("foo", "abc", message.getStringProperty("foo")); + assertEquals("bar", "123", message.getStringProperty("bar")); + } + + public void testSendMessageWithStandardHeaders() throws Exception { + + MessageConsumer consumer = session.createConsumer(queue); + + String frame = + "CONNECT\n" + + "login: brianm\n" + + "passcode: wombats\n\n"+ + Stomp.NULL; + sendFrame(frame); + + frame = receiveFrame(10000); + assertTrue(frame.startsWith("CONNECTED")); + + frame = + "SEND\n" + + "correlation-id:c123\n" + + "JMSXGroupID:abc\n" + + "foo:abc\n" + + "bar:123\n" + + "destination:/queue/" + getQueueName() + "\n\n" + + "Hello World" + + Stomp.NULL; + + sendFrame(frame); + + TextMessage message = (TextMessage) consumer.receive(1000); + assertNotNull(message); + assertEquals("Hello World", message.getText()); + assertEquals("JMSCorrelationID", "c123", message.getJMSCorrelationID()); + assertEquals("foo", "abc", message.getStringProperty("foo")); + assertEquals("bar", "123", message.getStringProperty("bar")); + + assertEquals("JMSXGroupID", "abc", message.getStringProperty("JMSXGroupID")); + ActiveMQTextMessage amqMessage = (ActiveMQTextMessage) message; + assertEquals("GroupID", "abc", amqMessage.getGroupID()); } public void testSubscribeWithAutoAck() throws Exception {