activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gtu...@apache.org
Subject svn commit: r1172572 - in /activemq/trunk/activemq-core/src: main/java/org/apache/activemq/transport/stomp/StompWireFormat.java test/java/org/apache/activemq/transport/stomp/Stomp11Test.java
Date Mon, 19 Sep 2011 11:30:14 GMT
Author: gtully
Date: Mon Sep 19 11:30:14 2011
New Revision: 1172572

URL: http://svn.apache.org/viewvc?rev=1172572&view=rev
Log:
https://issues.apache.org/jira/browse/AMQ-3501 - make use of the encoded string! and add some
tests

Modified:
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/stomp/StompWireFormat.java
    activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/stomp/Stomp11Test.java

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/stomp/StompWireFormat.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/stomp/StompWireFormat.java?rev=1172572&r1=1172571&r2=1172572&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/stomp/StompWireFormat.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/stomp/StompWireFormat.java
Mon Sep 19 11:30:14 2011
@@ -254,6 +254,7 @@ public class StompWireFormat implements 
                     stream.write(val);
                 }
             }
+            result =  new String(stream.toByteArray(), "UTF-8");
         }
 
         return result;

Modified: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/stomp/Stomp11Test.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/stomp/Stomp11Test.java?rev=1172572&r1=1172571&r2=1172572&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/stomp/Stomp11Test.java
(original)
+++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/stomp/Stomp11Test.java
Mon Sep 19 11:30:14 2011
@@ -24,9 +24,17 @@ import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.UnknownHostException;
 
+import javax.jms.Connection;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import org.apache.activemq.ActiveMQConnectionFactory;
 import org.apache.activemq.CombinationTestSupport;
 import org.apache.activemq.broker.BrokerFactory;
 import org.apache.activemq.broker.BrokerService;
+import org.apache.activemq.command.ActiveMQQueue;
+import org.apache.activemq.command.ActiveMQTextMessage;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -40,6 +48,9 @@ public class Stomp11Test extends Combina
 
     private BrokerService broker;
     private StompConnection stompConnection = new StompConnection();
+    private Connection connection;
+    private Session session;
+    private ActiveMQQueue queue;
 
     @Override
     protected void setUp() throws Exception {
@@ -49,6 +60,13 @@ public class Stomp11Test extends Combina
         broker.waitUntilStarted();
 
         stompConnect();
+
+        ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory(jmsUri);
+        connection = cf.createConnection("system", "manager");
+        session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+        queue = new ActiveMQQueue(getQueueName());
+        connection.start();
+
     }
 
     private void stompConnect() throws IOException, URISyntaxException, UnknownHostException
{
@@ -347,8 +365,8 @@ public class Stomp11Test extends Combina
                        "id:12345\n" + "ack:auto\n\n" + Stomp.NULL;
         stompConnection.sendFrame(frame);
 
-        frame = stompConnection.receiveFrame();
-        assertTrue(frame.startsWith("MESSAGE"));
+        StompFrame stompFrame = stompConnection.receive();
+        assertTrue(stompFrame.getAction().equals("MESSAGE"));
 
         frame = "UNSUBSCRIBE\n" + "destination:/queue/" + getQueueName() + "\n" +
                 "id:12345\n\n" + Stomp.NULL;
@@ -570,4 +588,65 @@ public class Stomp11Test extends Combina
         String frame = "DISCONNECT\n" + "\n\n" + Stomp.NULL;
         stompConnection.sendFrame(frame);
     }
+
+
+    public void testSendMessageWithStandardHeadersEncoded() throws Exception {
+
+        MessageConsumer consumer = session.createConsumer(queue);
+
+        String frame = "CONNECT\n" + "login: system\n" + "passcode: manager\n" +
+                "accept-version:1.1" + "\n\n" + Stomp.NULL;
+        stompConnection.sendFrame(frame);
+
+        frame = stompConnection.receiveFrame();
+        assertTrue(frame.startsWith("CONNECTED"));
+
+        frame = "SEND\n" + "correlation-id:c1\\:\\n\\23\n" + "priority:3\n" + "type:t34:5\n"
+ "JMSXGroupID:abc\n" + "foo:a\\bc\n" + "bar:123\n" + "destination:/queue/" + getQueueName()
+ "\n\n" + "Hello World"
+                + Stomp.NULL;
+
+        stompConnection.sendFrame(frame);
+
+        TextMessage message = (TextMessage)consumer.receive(2500);
+        assertNotNull(message);
+        assertEquals("Hello World", message.getText());
+        assertEquals("JMSCorrelationID", "c1\\:\n\\23", message.getJMSCorrelationID());
+        assertEquals("getJMSType", "t34:5", message.getJMSType());
+        assertEquals("getJMSPriority", 3, message.getJMSPriority());
+        assertEquals("foo", "a\\bc", 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 testSubscribeWithMessageSentWithEncodedProperties() throws Exception {
+
+        String frame = "CONNECT\n" + "login: system\n" + "passcode: manager\n" +  "accept-version:1.1"
+ "\n\n" + Stomp.NULL;
+        stompConnection.sendFrame(frame);
+
+        frame = stompConnection.receiveFrame();
+        assertTrue(frame.startsWith("CONNECTED"));
+
+        frame = "SUBSCRIBE\n" + "destination:/queue/" + getQueueName() + "\n" + "id:12345\n"
+ "ack:auto\n\n" + Stomp.NULL;
+        stompConnection.sendFrame(frame);
+
+        MessageProducer producer = session.createProducer(queue);
+        TextMessage message = session.createTextMessage("Hello World");
+        message.setStringProperty("s", "\\value:");
+        producer.send(message);
+
+        frame = stompConnection.receiveFrame();
+        assertTrue("" + frame, frame.startsWith("MESSAGE"));
+
+        int start =  frame.indexOf("\ns:") + 3;
+        final String expectedEncoded = "\\\\value\\c";
+        final String headerVal = frame.substring(start, start + expectedEncoded.length());
+        assertEquals("" + frame, expectedEncoded, headerVal);
+
+        frame = "DISCONNECT\n" + "\n\n" + Stomp.NULL;
+        stompConnection.sendFrame(frame);
+    }
+
 }



Mime
View raw message