You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ta...@apache.org on 2010/01/14 16:34:03 UTC

svn commit: r899241 - in /activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src: main/csharp/Commands/MapMessage.cs main/csharp/Protocol/StompWireFormat.cs main/csharp/Protocol/XmlPrimitiveMapMarshaler.cs test/csharp/Protocol/XmlPrimitiveMapMarshalerTest.cs

Author: tabish
Date: Thu Jan 14 15:34:03 2010
New Revision: 899241

URL: http://svn.apache.org/viewvc?rev=899241&view=rev
Log:
Add some tests for the XmlPrimitiveMapMarshaler and a couple fixes to the marshaler.  Can now read marshaled XML maps

Modified:
    activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/Commands/MapMessage.cs
    activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/Protocol/StompWireFormat.cs
    activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/Protocol/XmlPrimitiveMapMarshaler.cs
    activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/Protocol/XmlPrimitiveMapMarshalerTest.cs

Modified: activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/Commands/MapMessage.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/Commands/MapMessage.cs?rev=899241&r1=899240&r2=899241&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/Commands/MapMessage.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/Commands/MapMessage.cs Thu Jan 14 15:34:03 2010
@@ -28,6 +28,16 @@
         private PrimitiveMap body;
         private PrimitiveMapInterceptor typeConverter;
 
+        public MapMessage() : base()
+        {
+        }
+
+        public MapMessage(PrimitiveMap body) : base()
+        {
+            this.body = body;
+            this.typeConverter = new PrimitiveMapInterceptor(this, this.body);
+        }
+
         public override byte GetDataStructureType()
         {
             return DataStructureTypes.MapMessageType;

Modified: activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/Protocol/StompWireFormat.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/Protocol/StompWireFormat.cs?rev=899241&r1=899240&r2=899241&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/Protocol/StompWireFormat.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/Protocol/StompWireFormat.cs Thu Jan 14 15:34:03 2010
@@ -17,6 +17,7 @@
 using Apache.NMS.Stomp.Commands;
 using Apache.NMS.Stomp.Transport;
 using Apache.NMS;
+using Apache.NMS.Util;
 using System;
 using System.Collections;
 using System.IO;
@@ -192,11 +193,17 @@
         protected virtual Command ReadMessage(StompFrame frame)
         {
             Message message = null;
+            string transformation = frame.RemoveProperty("transformation");
+
             if(frame.HasProperty("content-length"))
             {
                 message = new BytesMessage();
                 message.Content = frame.Content;
             }
+            else if(transformation == "jms-map-xml")
+            {
+                message = new MapMessage(this.mapMarshaler.Unmarshal(frame.Content) as PrimitiveMap);
+            }
             else
             {
                 message = new TextMessage(encoder.GetString(frame.Content, 0, frame.Content.Length));

Modified: activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/Protocol/XmlPrimitiveMapMarshaler.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/Protocol/XmlPrimitiveMapMarshaler.cs?rev=899241&r1=899240&r2=899241&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/Protocol/XmlPrimitiveMapMarshaler.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/Protocol/XmlPrimitiveMapMarshaler.cs Thu Jan 14 15:34:03 2010
@@ -26,7 +26,7 @@
 namespace Apache.NMS.Stomp.Protocol
 {
     /// <summary>
-    /// Reads / Writes an IPrimitveMap as XML.
+    /// Reads / Writes an IPrimitveMap as XML compatible with XStream.
     /// </summary>
     public class XmlPrimitiveMapMarshaler : IPrimitiveMapMarshaler
     {
@@ -121,60 +121,51 @@
                 {
                 case "char":
                     value = Convert.ToChar(reader.ReadElementContentAsString());
+                    reader.ReadEndElement();
                     break;
                 case "double":
                     value = Convert.ToDouble(reader.ReadElementContentAsString());
+                    reader.ReadEndElement();
                     break;
                 case "float":
                     value = Convert.ToSingle(reader.ReadElementContentAsString());
+                    reader.ReadEndElement();
                     break;
                 case "long":
                     value = Convert.ToInt64(reader.ReadElementContentAsString());
+                    reader.ReadEndElement();
                     break;
                 case "int":
                     value = Convert.ToInt32(reader.ReadElementContentAsString());
+                    reader.ReadEndElement();
                     break;
                 case "short":
                     value = Convert.ToInt16(reader.ReadElementContentAsString());
+                    reader.ReadEndElement();
                     break;
                 case "byte":
                     value = Convert.ToByte(reader.ReadElementContentAsString());
+                    reader.ReadEndElement();
                     break;
                 case "boolean":
                     value = Convert.ToBoolean(reader.ReadElementContentAsString());
+                    reader.ReadEndElement();
                     break;
                 case "byte-array":
-
-                    byte[] buffer = new byte[1024];
-                    MemoryStream array = new MemoryStream();
-
-                    int bytesRead = 0;
-
-                    do
-                    {
-                        bytesRead = reader.ReadElementContentAsBase64(buffer, 0, buffer.Length);
-                        array.Write(buffer, 0, bytesRead);
-                    }
-                    while(bytesRead != 0);
-
-                    array.Close();
-
-                    value = array.ToArray();
-
-                    // Jump out here since this one reads past the EndElement for us.
-                    continue;
+                    value = Convert.FromBase64String(reader.ReadElementContentAsString());
+                    reader.ReadEndElement();
+                    break;
                 default:
-                    Console.WriteLine("Key = " + reader.ReadElementContentAsString());
+                    value = reader.ReadElementContentAsString();
+                    reader.ReadEndElement();
                     break;
                 };
 
                 // Now store the value into our new PrimitiveMap.
+                Console.WriteLine("result[{0}] = {1}", key, value);
                 result[key] = value;
-
-                reader.ReadEndElement();
             }
 
-            reader.ReadEndElement();
             reader.Close();
 
             return result;

Modified: activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/Protocol/XmlPrimitiveMapMarshalerTest.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/Protocol/XmlPrimitiveMapMarshalerTest.cs?rev=899241&r1=899240&r2=899241&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/Protocol/XmlPrimitiveMapMarshalerTest.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/Protocol/XmlPrimitiveMapMarshalerTest.cs Thu Jan 14 15:34:03 2010
@@ -30,9 +30,13 @@
     [TestFixture]
     public class XmlPrimitiveMapMarshalerTest
     {
-        private static String xmlString =
+        private const String xmlString =
                 @"<map>
                       <entry>
+                        <string>BYTES</string>
+                        <byte-array>CgoKFBQU</byte-array>
+                      </entry>
+                      <entry>
                         <string>CHAR</string>
                         <char>a</char>
                       </entry>
@@ -65,10 +69,6 @@
                         <string>FOO</string>
                       </entry>
                       <entry>
-                        <string>BYTES</string>
-                        <byte-array>CgoKFBQU</byte-array>
-                      </entry>
-                      <entry>
                         <string>BOOL</string>
                         <boolean>true</boolean>
                       </entry>
@@ -105,7 +105,24 @@
         public void TestUnmarshalPrimitiveMap()
         {
             XmlPrimitiveMapMarshaler marshaler = new XmlPrimitiveMapMarshaler();
-        }
 
+            byte[] rawBytes = Encoding.UTF8.GetBytes(xmlString);
+
+            IPrimitiveMap result = marshaler.Unmarshal(rawBytes);
+
+            Assert.IsNotNull(result);
+
+            Assert.IsTrue(result.Contains("BOOL"));
+            Assert.IsTrue(result.Contains("BYTES"));
+            Assert.IsTrue(result.Contains("STRING"));
+            Assert.IsTrue(result.Contains("LONG"));
+            Assert.IsTrue(result.Contains("FLOAT"));
+            Assert.IsTrue(result.Contains("INT"));
+            Assert.IsTrue(result.Contains("BYTE"));
+            Assert.IsTrue(result.Contains("SHORT"));
+            Assert.IsTrue(result.Contains("DOUBLE"));
+            Assert.IsTrue(result.Contains("CHAR"));
+
+        }
     }
 }