From c6af867113dd3f967e7c4beeb3f024378e06baf1 Mon Sep 17 00:00:00 2001 From: Robert Davies Date: Mon, 19 Jul 2010 16:10:22 +0000 Subject: [PATCH] Patch applied for https://issues.apache.org/activemq/browse/AMQ-2833 git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@965542 13f79535-47bb-0310-9956-ffa450edef68 --- .../stomp/LegacyFrameTranslator.java | 23 ++++++++++++++++++- .../activemq/transport/stomp/Stomp.java | 5 ++++ 2 files changed, 27 insertions(+), 1 deletion(-) 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 866bfaeb15..733115e03b 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 @@ -37,7 +37,28 @@ public class LegacyFrameTranslator implements FrameTranslator { public ActiveMQMessage convertFrame(ProtocolConverter converter, StompFrame command) throws JMSException, ProtocolException { final Map headers = command.getHeaders(); final ActiveMQMessage msg; - if (headers.containsKey(Stomp.Headers.CONTENT_LENGTH)) { + /* + * To reduce the complexity of this method perhaps a Chain of Responsibility + * would be a better implementation + */ + if (headers.containsKey(Stomp.Headers.AMQ_MESSAGE_TYPE)) { + String intendedType = (String)headers.get(Stomp.Headers.AMQ_MESSAGE_TYPE); + if(intendedType.equalsIgnoreCase("text")){ + ActiveMQTextMessage text = new ActiveMQTextMessage(); + try { + text.setText(new String(command.getContent(), "UTF-8")); + } catch (Throwable e) { + throw new ProtocolException("Text could not bet set: " + e, false, e); + } + msg = text; + } else if(intendedType.equalsIgnoreCase("bytes")) { + ActiveMQBytesMessage byteMessage = new ActiveMQBytesMessage(); + byteMessage.writeBytes(command.getContent()); + msg = byteMessage; + } else { + throw new ProtocolException("Unsupported message type '"+intendedType+"'",false); + } + }else if (headers.containsKey(Stomp.Headers.CONTENT_LENGTH)) { headers.remove(Stomp.Headers.CONTENT_LENGTH); ActiveMQBytesMessage bm = new ActiveMQBytesMessage(); bm.writeBytes(command.getContent()); diff --git a/activemq-core/src/main/java/org/apache/activemq/transport/stomp/Stomp.java b/activemq-core/src/main/java/org/apache/activemq/transport/stomp/Stomp.java index f2622d1693..bbb40cc1e7 100644 --- a/activemq-core/src/main/java/org/apache/activemq/transport/stomp/Stomp.java +++ b/activemq-core/src/main/java/org/apache/activemq/transport/stomp/Stomp.java @@ -50,6 +50,11 @@ public interface Stomp { String CONTENT_LENGTH = "content-length"; String TRANSFORMATION = "transformation"; String TRANSFORMATION_ERROR = "transformation-error"; + /** + * This header is used to instruct ActiveMQ to construct the message + * based with a specific type. + */ + String AMQ_MESSAGE_TYPE = "amq-msg-type"; public interface Response { String RECEIPT_ID = "receipt-id";