From eb887f1545123e5743ae67aa4ed44ca0524a6021 Mon Sep 17 00:00:00 2001 From: "Timothy A. Bish" Date: Thu, 31 May 2012 20:26:28 +0000 Subject: [PATCH] fix for: https://issues.apache.org/jira/browse/AMQ-3836 Make a best effort to find the correct destination name even if space padded before falling back to the fallback conversion config. git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1344894 13f79535-47bb-0310-9956-ffa450edef68 --- .../transport/stomp/LegacyFrameTranslator.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 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 87b6ad8165..54894fce53 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 @@ -54,7 +54,6 @@ public class LegacyFrameTranslator implements FrameTranslator { if(intendedType.equalsIgnoreCase("text")){ ActiveMQTextMessage text = new ActiveMQTextMessage(); try { - //text.setText(new String(command.getContent(), "UTF-8")); ByteArrayOutputStream bytes = new ByteArrayOutputStream(command.getContent().length + 4); DataOutputStream data = new DataOutputStream(bytes); data.writeInt(command.getContent().length); @@ -79,7 +78,6 @@ public class LegacyFrameTranslator implements FrameTranslator { } else { ActiveMQTextMessage text = new ActiveMQTextMessage(); try { - //text.setText(new String(command.getContent(), "UTF-8")); ByteArrayOutputStream bytes = new ByteArrayOutputStream(command.getContent().length + 4); DataOutputStream data = new DataOutputStream(bytes); data.writeInt(command.getContent().length); @@ -173,7 +171,14 @@ public class LegacyFrameTranslator implements FrameTranslator { public ActiveMQDestination convertDestination(ProtocolConverter converter, String name, boolean forceFallback) throws ProtocolException { if (name == null) { return null; - } else if (name.startsWith("/queue/")) { + } + + // in case of space padding by a client we trim for the initial detection, on fallback use + // the un-trimmed value. + String originalName = name; + name = name.trim(); + + if (name.startsWith("/queue/")) { String qName = name.substring("/queue/".length(), name.length()); return ActiveMQDestination.createDestination(qName, ActiveMQDestination.QUEUE_TYPE); } else if (name.startsWith("/topic/")) { @@ -192,16 +197,16 @@ public class LegacyFrameTranslator implements FrameTranslator { } else { if (forceFallback) { try { - ActiveMQDestination fallback = ActiveMQDestination.getUnresolvableDestinationTransformer().transform(name); + ActiveMQDestination fallback = ActiveMQDestination.getUnresolvableDestinationTransformer().transform(originalName); if (fallback != null) { return fallback; } } catch (JMSException e) { - throw new ProtocolException("Illegal destination name: [" + name + "] -- ActiveMQ STOMP destinations " + throw new ProtocolException("Illegal destination name: [" + originalName + "] -- ActiveMQ STOMP destinations " + "must begin with one of: /queue/ /topic/ /temp-queue/ /temp-topic/", false, e); } } - throw new ProtocolException("Illegal destination name: [" + name + "] -- ActiveMQ STOMP destinations " + throw new ProtocolException("Illegal destination name: [" + originalName + "] -- ActiveMQ STOMP destinations " + "must begin with one of: /queue/ /topic/ /temp-queue/ /temp-topic/"); } }