Author: tabish
Date: Thu May 31 20:26:28 2012
New Revision: 1344894

URL: http://svn.apache.org/viewvc?rev=1344894&view=rev
Log:
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. 

Modified:
    
activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/stomp/LegacyFrameTranslator.java

Modified: 
activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/stomp/LegacyFrameTranslator.java
URL: 
http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/stomp/LegacyFrameTranslator.java?rev=1344894&r1=1344893&r2=1344894&view=diff
==============================================================================
--- 
activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/stomp/LegacyFrameTranslator.java
 (original)
+++ 
activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/stomp/LegacyFrameTranslator.java
 Thu May 31 20:26:28 2012
@@ -54,7 +54,6 @@ public class LegacyFrameTranslator imple
             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 imple
         } 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 imple
     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 imple
         } 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/");
         }
     }


Reply via email to