qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rgodf...@apache.org
Subject svn commit: r1526887 - in /qpid/trunk/qpid/java: amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/type/codec/ broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/
Date Fri, 27 Sep 2013 12:59:38 GMT
Author: rgodfrey
Date: Fri Sep 27 12:59:37 2013
New Revision: 1526887

URL: http://svn.apache.org/r1526887
Log:
QPID-5127 : ClassCastException on message conversion to 1-0

Modified:
    qpid/trunk/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/type/codec/AMQPDescribedTypeRegistry.java
    qpid/trunk/qpid/java/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/MessageConverter_to_1_0.java

Modified: qpid/trunk/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/type/codec/AMQPDescribedTypeRegistry.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/type/codec/AMQPDescribedTypeRegistry.java?rev=1526887&r1=1526886&r2=1526887&view=diff
==============================================================================
--- qpid/trunk/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/type/codec/AMQPDescribedTypeRegistry.java
(original)
+++ qpid/trunk/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/type/codec/AMQPDescribedTypeRegistry.java
Fri Sep 27 12:59:37 2013
@@ -49,6 +49,7 @@ import org.apache.qpid.amqp_1_0.codec.Un
 import org.apache.qpid.amqp_1_0.codec.ValueWriter;
 
 
+import org.apache.qpid.amqp_1_0.type.Binary;
 import org.apache.qpid.amqp_1_0.type.RestrictedType;
 import org.apache.qpid.amqp_1_0.type.transport.*;
 import org.apache.qpid.amqp_1_0.type.transport.codec.*;

Modified: qpid/trunk/qpid/java/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/MessageConverter_to_1_0.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/MessageConverter_to_1_0.java?rev=1526887&r1=1526886&r2=1526887&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/MessageConverter_to_1_0.java
(original)
+++ qpid/trunk/qpid/java/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/MessageConverter_to_1_0.java
Fri Sep 27 12:59:37 2013
@@ -23,8 +23,12 @@ package org.apache.qpid.server.protocol.
 import java.io.EOFException;
 import java.nio.ByteBuffer;
 import java.util.ArrayList;
+import java.util.Iterator;
 import java.util.LinkedHashMap;
 import java.util.List;
+import java.util.ListIterator;
+import java.util.Map;
+
 import org.apache.qpid.amqp_1_0.messaging.SectionEncoder;
 import org.apache.qpid.amqp_1_0.messaging.SectionEncoderImpl;
 import org.apache.qpid.amqp_1_0.type.Binary;
@@ -92,6 +96,7 @@ public abstract class MessageConverter_t
                 {
                     String propName = reader.readStringImpl();
                     Object value = reader.readObject();
+
                     map.put(propName, value);
                 }
                 catch (EOFException e)
@@ -105,21 +110,23 @@ public abstract class MessageConverter_t
 
             }
 
-            return new AmqpValue(map);
+            return new AmqpValue(fixMapValues(map));
 
         }
         else if("amqp/map".equals(mimeType))
         {
             BBDecoder decoder = new BBDecoder();
             decoder.init(ByteBuffer.wrap(data));
-            return new AmqpValue(decoder.readMap());
+            final Map<String,Object> map = decoder.readMap();
+
+            return new AmqpValue(fixMapValues(map));
 
         }
         else if("amqp/list".equals(mimeType))
         {
             BBDecoder decoder = new BBDecoder();
             decoder.init(ByteBuffer.wrap(data));
-            return new AmqpValue(decoder.readList());
+            return new AmqpValue(fixListValues(decoder.readList()));
         }
         else if("jms/stream-message".equals(mimeType))
         {
@@ -130,7 +137,7 @@ public abstract class MessageConverter_t
             {
                 try
                 {
-                    list.add(reader.readObject());
+                    list.add(fixValue(reader.readObject()));
                 }
                 catch (TypedBytesFormatException e)
                 {
@@ -150,6 +157,47 @@ public abstract class MessageConverter_t
         }
     }
 
+    private static Map fixMapValues(final Map<String, Object> map)
+    {
+        for(Map.Entry<String,Object> entry : map.entrySet())
+        {
+            entry.setValue(fixValue(entry.getValue()));
+        }
+        return map;
+    }
+
+    private static Object fixValue(final Object value)
+    {
+        if(value instanceof byte[])
+        {
+            return new Binary((byte[])value);
+        }
+        else if(value instanceof Map)
+        {
+            return fixMapValues((Map)value);
+        }
+        else if(value instanceof List)
+        {
+            return fixListValues((List)value);
+        }
+        else
+        {
+            return value;
+        }
+    }
+
+    private static List fixListValues(final List list)
+    {
+        ListIterator iterator = list.listIterator();
+        while(iterator.hasNext())
+        {
+            Object value = iterator.next();
+            iterator.set(fixValue(value));
+
+        }
+        return list;
+    }
+
     private StoredMessage<MessageMetaData_1_0> convertServerMessage(final MessageMetaData_1_0
metaData,
                                                                       final ServerMessage
serverMessage,
                                                                       SectionEncoder sectionEncoder)



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message