activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r956013 - in /activemq/activemq-dotnet: Apache.NMS.ActiveMQ/trunk/src/main/csharp/Commands/ Apache.NMS.Stomp/trunk/src/main/csharp/Commands/ Apache.NMS/trunk/src/main/csharp/ Apache.NMS/trunk/src/main/csharp/Util/ Apache.NMS/trunk/src/test/...
Date Fri, 18 Jun 2010 14:32:04 GMT
Author: tabish
Date: Fri Jun 18 14:32:04 2010
New Revision: 956013

URL: http://svn.apache.org/viewvc?rev=956013&view=rev
Log:
https://issues.apache.org/activemq/browse/AMQNET-257

Add SetBytes and GetBytes to the IPrimitiveMap and implement in PrimitiveMap.    

Modified:
    activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Commands/ActiveMQMessage.cs
    activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/Commands/Message.cs
    activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/IPrimitiveMap.cs
    activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/Util/PrimitiveMap.cs
    activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/Util/PrimitiveMapInterceptor.cs
    activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/MapMessageTest.cs
    activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/MessageTest.cs

Modified: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Commands/ActiveMQMessage.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Commands/ActiveMQMessage.cs?rev=956013&r1=956012&r2=956013&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Commands/ActiveMQMessage.cs
(original)
+++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Commands/ActiveMQMessage.cs
Fri Jun 18 14:32:04 2010
@@ -145,6 +145,10 @@ namespace Apache.NMS.ActiveMQ.Commands
 				{
 					properties = PrimitiveMap.Unmarshal(MarshalledProperties);
 					propertyHelper = new MessagePropertyIntercepter(this, properties, this.ReadOnlyProperties);
+					
+					// Since JMS doesn't define a Byte array interface for properties we
+					// disable them here to prevent sending invalid data to the broker.
+					propertyHelper.AllowByteArrays = false;
 				}
 
 				return propertyHelper;

Modified: activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/Commands/Message.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/Commands/Message.cs?rev=956013&r1=956012&r2=956013&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/Commands/Message.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/Commands/Message.cs Fri
Jun 18 14:32:04 2010
@@ -142,6 +142,7 @@ namespace Apache.NMS.Stomp.Commands
                 {
                     properties = PrimitiveMap.Unmarshal(MarshalledProperties);
                     propertyHelper = new MessagePropertyIntercepter(this, properties, this.ReadOnlyProperties);
+                    propertyHelper.AllowByteArrays = false;
                 }
 
                 return propertyHelper;

Modified: activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/IPrimitiveMap.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/IPrimitiveMap.cs?rev=956013&r1=956012&r2=956013&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/IPrimitiveMap.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/IPrimitiveMap.cs Fri Jun 18
14:32:04 2010
@@ -67,6 +67,10 @@ namespace Apache.NMS
 
 		IList GetList(string key);
 		void SetList(string key, IList list);
+		
+		void SetBytes(string key, byte[] value);
+		void SetBytes(string key, byte[] value, int offset, int length);
+		byte[] GetBytes(string key);
 
 		IDictionary GetDictionary(string key);
 		void SetDictionary(string key, IDictionary dictionary);

Modified: activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/Util/PrimitiveMap.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/Util/PrimitiveMap.cs?rev=956013&r1=956012&r2=956013&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/Util/PrimitiveMap.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/Util/PrimitiveMap.cs Fri Jun
18 14:32:04 2010
@@ -203,13 +203,35 @@ namespace Apache.NMS.Util
 				throw new NMSException("Property: " + key + " is not an IList but is: " + value);
 			}
 			return (IList) value;
-		}
-
+		}		
+		
 		public void SetList(String key, IList value)
 		{
 			SetValue(key, value);
 		}
 
+		public void SetBytes(String key, byte[] value) 
+		{
+			this.SetBytes(key, value, 0, value.Length);
+		}
+		
+		public void SetBytes(String key, byte[] value, int offset, int length)
+		{
+			byte[] copy = new byte[length];
+			Array.Copy(value, offset, copy, 0, length);
+			SetValue(key, copy);
+		}
+		
+		public byte[] GetBytes(string key)
+		{
+			Object value = GetValue(key);
+			if(value != null && !(value is Byte[]))
+			{
+				throw new NMSException("Property: " + key + " is not an byte[] but is: " + value);
+			}
+			return (byte[]) value;
+		}
+		
 		public IDictionary GetDictionary(String key)
 		{
 			Object value = GetValue(key);

Modified: activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/Util/PrimitiveMapInterceptor.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/Util/PrimitiveMapInterceptor.cs?rev=956013&r1=956012&r2=956013&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/Util/PrimitiveMapInterceptor.cs
(original)
+++ activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/Util/PrimitiveMapInterceptor.cs
Fri Jun 18 14:32:04 2010
@@ -29,8 +29,8 @@ namespace Apache.NMS.Util
     /// Be default this class enforces the standard conversion policy for primitive
     /// types in NMS shown in the table below:
     ///
-    ///   |        | boolean byte short char int long float double String
-    ///   |--------------------------------------------------------------
+    ///   |        | boolean byte short char int long float double String byte[]
+    ///   |----------------------------------------------------------------------
     ///   |boolean |    X                                            X
     ///   |byte    |          X     X         X   X                  X
     ///   |short   |                X         X   X                  X
@@ -40,7 +40,8 @@ namespace Apache.NMS.Util
     ///   |float   |                                    X     X      X
     ///   |double  |                                          X      X
     ///   |String  |    X     X     X         X   X     X     X      X
-    ///   |--------------------------------------------------------------
+    ///   |byte[]  |                                                       X
+    ///   |----------------------------------------------------------------------
     ///
     /// </summary>
     public class PrimitiveMapInterceptor : IPrimitiveMap
@@ -48,6 +49,7 @@ namespace Apache.NMS.Util
         protected IMessage message;
         protected IPrimitiveMap properties;
         private bool readOnly = false;
+		private bool allowByteArrays = true;
 
         public PrimitiveMapInterceptor(IMessage message, IPrimitiveMap properties)
         {
@@ -62,6 +64,14 @@ namespace Apache.NMS.Util
             this.readOnly = readOnly;
         }
         
+        public PrimitiveMapInterceptor(IMessage message, IPrimitiveMap properties, bool readOnly,
bool allowByteArrays)
+        {
+            this.message = message;
+            this.properties = properties;
+            this.readOnly = readOnly;
+			this.allowByteArrays = allowByteArrays;
+        }
+		
         protected virtual object GetObjectProperty(string name)
         {
             return this.properties[name];
@@ -73,6 +83,11 @@ namespace Apache.NMS.Util
 
             try
             {
+				if(!this.allowByteArrays && (value is byte[]))
+				{
+					throw new NotSupportedException("Byte Arrays not allowed in this PrimitiveMap");
+				}
+				
                 this.properties[name] = value;
             }
             catch(Exception ex)
@@ -378,6 +393,39 @@ namespace Apache.NMS.Util
             SetObjectProperty(key, value);
         }
 
+		public void SetBytes(String key, byte[] value) 
+		{
+			this.SetBytes(key, value, 0, value.Length);
+		}
+		
+		public void SetBytes(String key, byte[] value, int offset, int length)
+		{
+			byte[] copy = new byte[length];
+			Array.Copy(value, offset, copy, 0, length);
+            SetObjectProperty(key, value);
+		}
+		
+		public byte[] GetBytes(string key)
+		{
+            Object value = GetObjectProperty(key);
+			
+            try
+            {
+                if(value is Byte[])
+                {
+                    return (byte[]) value;
+                }
+                else
+                {
+                    throw new MessageFormatException(" cannot read a byte[] from " + value.GetType().Name);
+                }
+            }
+            catch(FormatException ex)
+            {
+                throw NMSExceptionSupport.CreateMessageFormatException(ex);
+            }
+		}
+		
         public System.Collections.IList GetList(string key)
         {
             return (System.Collections.IList) GetObjectProperty(key);
@@ -406,6 +454,12 @@ namespace Apache.NMS.Util
             set{ this.readOnly = value; }
         }
 
+        public bool AllowByteArrays
+        {
+            get{ return this.allowByteArrays; }
+            set{ this.allowByteArrays = value; }
+        }
+		
         protected virtual void FailIfReadOnly()
         {
             if(this.ReadOnly == true)

Modified: activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/MapMessageTest.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/MapMessageTest.cs?rev=956013&r1=956012&r2=956013&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/MapMessageTest.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/MapMessageTest.cs Fri Jun 18
14:32:04 2010
@@ -43,6 +43,7 @@ namespace Apache.NMS.Test
 		protected long l = -0x1234567812345678;
 		protected float m = 2.1F;
 		protected double n = 2.3;
+		protected byte[] o = {1, 2, 3, 4, 5};
 
 		[RowTest]
 		[Row(MsgDeliveryMode.Persistent)]
@@ -75,6 +76,7 @@ namespace Apache.NMS.Test
 						request.Body["l"] = l;
 						request.Body["m"] = m;
 						request.Body["n"] = n;
+						request.Body["o"] = o;
 						producer.Send(request);
 
 						IMapMessage message = consumer.Receive(receiveTimeout) as IMapMessage;
@@ -98,7 +100,8 @@ namespace Apache.NMS.Test
 						Assert.AreEqual(l, message.Body["l"], "generic map entry: l");
 						Assert.AreEqual(m, message.Body["m"], "generic map entry: m");
 						Assert.AreEqual(n, message.Body["n"], "generic map entry: n");
-
+						Assert.AreEqual(o, message.Body["o"], "generic map entry: o");
+						
 						// use type safe APIs
 						Assert.AreEqual(a, message.Body.GetBool("a"), "map entry: a");
 						Assert.AreEqual(b, message.Body.GetByte("b"), "map entry: b");
@@ -114,6 +117,7 @@ namespace Apache.NMS.Test
 						Assert.AreEqual(l, message.Body.GetLong("l"), "map entry: l");
 						Assert.AreEqual(m, message.Body.GetFloat("m"), "map entry: m");
 						Assert.AreEqual(n, message.Body.GetDouble("n"), "map entry: n");
+						Assert.AreEqual(o, message.Body.GetBytes("o"), "map entry: o");
 					}
 				}
 			}

Modified: activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/MessageTest.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/MessageTest.cs?rev=956013&r1=956012&r2=956013&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/MessageTest.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/MessageTest.cs Fri Jun 18 14:32:04
2010
@@ -41,6 +41,7 @@ namespace Apache.NMS.Test
 		protected long		l = -0x1234567812345678;
 		protected float		m = 2.1F;
 		protected double	n = 2.3;
+		protected byte[]    o = {1, 2, 3, 4, 5};
 
 		[RowTest]
 		[Row(MsgDeliveryMode.Persistent)]
@@ -73,6 +74,27 @@ namespace Apache.NMS.Test
 						request.Properties["l"] = l;
 						request.Properties["m"] = m;
 						request.Properties["n"] = n;
+						
+						try
+						{
+							request.Properties["o"] = o;
+							Assert.Fail("Should not be able to add a Byte[] to the Properties of a Message.");
+						}
+						catch
+						{
+							// Expected
+						}
+						
+						try
+						{
+							request.Properties.SetBytes("o", o);
+							Assert.Fail("Should not be able to add a Byte[] to the Properties of a Message.");
+						}
+						catch
+						{
+							// Expected
+						}						
+						
 						producer.Send(request);
 
 						IMessage message = consumer.Receive(receiveTimeout);



Mime
View raw message