From e426de8c32fc60e1fbe89262d6887fca724ea60b Mon Sep 17 00:00:00 2001 From: "Timothy A. Bish" Date: Mon, 27 Feb 2012 21:37:03 +0000 Subject: [PATCH] fix for: https://issues.apache.org/jira/browse/AMQ-3742 with supplied unit test patch applied. git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1294342 13f79535-47bb-0310-9956-ffa450edef68 --- .../stomp/LegacyFrameTranslator.java | 29 ++++++---- .../activemq/transport/stomp/StompTest.java | 57 ++++++++++++++----- 2 files changed, 63 insertions(+), 23 deletions(-) diff --git a/activemq-core/src/main/java/org/apache/activemq/transport/stomp/LegacyFrameTranslator.java b/activemq-core/src/main/java/org/apache/activemq/transport/stomp/LegacyFrameTranslator.java index c2cb47a11b..87b6ad8165 100644 --- a/activemq-core/src/main/java/org/apache/activemq/transport/stomp/LegacyFrameTranslator.java +++ b/activemq-core/src/main/java/org/apache/activemq/transport/stomp/LegacyFrameTranslator.java @@ -16,20 +16,26 @@ */ package org.apache.activemq.transport.stomp; -import com.thoughtworks.xstream.XStream; -import com.thoughtworks.xstream.io.json.JsonHierarchicalStreamDriver; -import org.apache.activemq.advisory.AdvisorySupport; -import org.apache.activemq.command.*; -import org.apache.activemq.util.ByteArrayOutputStream; -import org.apache.activemq.util.ByteSequence; - -import javax.jms.Destination; -import javax.jms.JMSException; import java.io.DataOutputStream; import java.io.IOException; import java.util.HashMap; import java.util.Map; +import javax.jms.Destination; +import javax.jms.JMSException; + +import org.apache.activemq.advisory.AdvisorySupport; +import org.apache.activemq.command.ActiveMQBytesMessage; +import org.apache.activemq.command.ActiveMQDestination; +import org.apache.activemq.command.ActiveMQMessage; +import org.apache.activemq.command.ActiveMQTextMessage; +import org.apache.activemq.command.DataStructure; +import org.apache.activemq.util.ByteArrayOutputStream; +import org.apache.activemq.util.ByteSequence; + +import com.thoughtworks.xstream.XStream; +import com.thoughtworks.xstream.io.json.JsonHierarchicalStreamDriver; + /** * Implements ActiveMQ 4.0 translations */ @@ -107,7 +113,10 @@ public class LegacyFrameTranslator implements FrameTranslator { } } else { ActiveMQTextMessage msg = (ActiveMQTextMessage)message.copy(); - command.setContent(msg.getText().getBytes("UTF-8")); + String messageText = msg.getText(); + if (messageText != null) { + command.setContent(msg.getText().getBytes("UTF-8")); + } } } else if (message.getDataStructureType() == ActiveMQBytesMessage.DATA_STRUCTURE_TYPE) { 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 b8ebf01438..a8d67c1e09 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 @@ -16,6 +16,32 @@ */ package org.apache.activemq.transport.stomp; +import java.io.IOException; +import java.net.Socket; +import java.net.SocketTimeoutException; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.UnknownHostException; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; +import java.util.concurrent.TimeUnit; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import javax.jms.BytesMessage; +import javax.jms.Connection; +import javax.jms.JMSException; +import javax.jms.MapMessage; +import javax.jms.MessageConsumer; +import javax.jms.MessageProducer; +import javax.jms.ObjectMessage; +import javax.jms.Session; +import javax.jms.TextMessage; +import javax.management.MalformedObjectNameException; +import javax.management.ObjectName; + import org.apache.activemq.ActiveMQConnectionFactory; import org.apache.activemq.CombinationTestSupport; import org.apache.activemq.broker.BrokerFactory; @@ -28,19 +54,6 @@ import org.apache.activemq.util.Wait; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.jms.*; -import javax.management.MalformedObjectNameException; -import javax.management.ObjectName; -import java.io.IOException; -import java.net.*; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; -import java.util.concurrent.TimeUnit; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - public class StompTest extends CombinationTestSupport { private static final Logger LOG = LoggerFactory.getLogger(StompTest.class); @@ -1765,6 +1778,24 @@ public class StompTest extends CombinationTestSupport { doTestActiveMQReplyToTempDestination("queue"); } + public void testSendNullBodyTextMessage() throws Exception { + String frame = "CONNECT\n" + "login: system\n" + "passcode: manager\n\n" + Stomp.NULL; + stompConnection.sendFrame(frame); + + frame = stompConnection.receiveFrame(); + assertTrue(frame.startsWith("CONNECTED")); + + frame = "SUBSCRIBE\n" + "destination:/queue/" + getQueueName() + "\n" + "ack:auto\n\n" + Stomp.NULL; + stompConnection.sendFrame(frame); + + sendMessage(null); + frame = stompConnection.receiveFrame(); + assertNotNull("Message not received", frame); + + frame = "DISCONNECT\n" + "\n\n" + Stomp.NULL; + stompConnection.sendFrame(frame); + } + private void doTestActiveMQReplyToTempDestination(String type) throws Exception { LOG.info("Starting test on Temp Destinations using a temporary: " + type);