activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r1564046 - /activemq/activemq-dotnet/Apache.NMS.AMQP/trunk/src/main/csharp/DefaultMessageConverter.cs
Date Mon, 03 Feb 2014 20:19:35 GMT
Author: tabish
Date: Mon Feb  3 20:19:35 2014
New Revision: 1564046

URL: http://svn.apache.org/r1564046
Log:
https://issues.apache.org/jira/browse/AMQNET-454

applied:
https://issues.apache.org/jira/secure/attachment/12626730/Apache.NMS.AMQP-fix-list-message-body-15.patch

Modified:
    activemq/activemq-dotnet/Apache.NMS.AMQP/trunk/src/main/csharp/DefaultMessageConverter.cs

Modified: activemq/activemq-dotnet/Apache.NMS.AMQP/trunk/src/main/csharp/DefaultMessageConverter.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.AMQP/trunk/src/main/csharp/DefaultMessageConverter.cs?rev=1564046&r1=1564045&r2=1564046&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.AMQP/trunk/src/main/csharp/DefaultMessageConverter.cs
(original)
+++ activemq/activemq-dotnet/Apache.NMS.AMQP/trunk/src/main/csharp/DefaultMessageConverter.cs
Mon Feb  3 20:19:35 2014
@@ -17,6 +17,7 @@
 using System;
 using System.Collections;
 using System.Collections.Generic;
+using System.Collections.ObjectModel;
 using System.IO;
 using System.Text;
 using Apache.NMS.Util;
@@ -189,7 +190,10 @@ namespace Apache.NMS.Amqp
             else if (message is ObjectMessage)
             {
                 ObjectMessage objectMessage = message as ObjectMessage;
-                Message result = new Message(objectMessage.Body);
+                Collection<object> objs = new Collection<object>();
+                objs = ConvertObjectToAmqpList(objectMessage.Body);
+
+                Message result = new Message(objs);
                 return result;
             }
             else if (message is MapMessage)
@@ -234,7 +238,11 @@ namespace Apache.NMS.Amqp
             }
             else if ("amqp/list" == message.ContentType)
             {
-                // TODO: Return list message 
+                Collection<object> coll = new Collection<object>();
+                message.GetContent(coll);
+                ObjectMessage objMessage = new ObjectMessage();
+                objMessage.Body = ConvertAmqpListToObject(coll);
+                result = objMessage;
             }
             else
             {
@@ -298,5 +306,60 @@ namespace Apache.NMS.Amqp
             return dict;
         }
         #endregion
+
+        #region AMQP List Conversion Methods
+
+        /// <summary>
+        /// Convert NMS Object message body into form used by amqp/list
+        /// </summary>
+        /// <param name="objectMessageBody">The generic object from NMS</param>
+        /// <returns>A collection of supported AMQP primitive types.
+        /// Throws if objectMessageBody is not an array.</returns>
+        public Collection<object> ConvertObjectToAmqpList(Object objectMessageBody)
+        {
+            Collection<object> result = null;
+
+            if (objectMessageBody.GetType().IsArray)
+            {
+                result = new Collection<object>();
+                Array valueArray = (Array)objectMessageBody;
+                foreach (object val in valueArray)
+                {
+                    result.Add(val);
+                }
+            }
+            else
+            {
+                throw new NMSException("NMS ObjectMessage body must be an array");
+            }
+            return result;
+        }
+
+
+        /// <summary>
+        /// Convert amqp/list to  NMS Object message body
+        /// </summary>
+        /// <param name="amqpList">A collection of AMQP primitive types</param>
+        /// <returns>An array object holding the AMPQ list.</returns>
+        public Object ConvertAmqpListToObject(Collection<object> amqpList)
+        {
+            object result = new object();
+
+            if (amqpList.Count > 0)
+            {
+                Type t = amqpList[0].GetType();
+
+                Array objs = Array.CreateInstance(t, amqpList.Count);
+                for (int i = 0; i < amqpList.Count; i++)
+                {
+                    objs.SetValue(amqpList[i], i);
+                }
+
+                result = objs;
+            }
+            return result;
+        }
+
+        #endregion
     }
 }



Mime
View raw message