activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jgo...@apache.org
Subject svn commit: r807861 - in /activemq/activemq-dotnet/Apache.NMS.MSMQ/trunk/src/main/csharp: DefaultMessageConverter.cs Destination.cs MapMessage.cs MessageConsumer.cs Session.cs
Date Wed, 26 Aug 2009 01:21:53 GMT
Author: jgomes
Date: Wed Aug 26 01:21:52 2009
New Revision: 807861

URL: http://svn.apache.org/viewvc?rev=807861&view=rev
Log:
Fixed null pointer exception.  Major improvements to MSMQ support.  Many unit tests are now
passing.
Fixes [AMQNET-168]. (See https://issues.apache.org/activemq/browse/AMQNET-168)

Modified:
    activemq/activemq-dotnet/Apache.NMS.MSMQ/trunk/src/main/csharp/DefaultMessageConverter.cs
    activemq/activemq-dotnet/Apache.NMS.MSMQ/trunk/src/main/csharp/Destination.cs
    activemq/activemq-dotnet/Apache.NMS.MSMQ/trunk/src/main/csharp/MapMessage.cs
    activemq/activemq-dotnet/Apache.NMS.MSMQ/trunk/src/main/csharp/MessageConsumer.cs
    activemq/activemq-dotnet/Apache.NMS.MSMQ/trunk/src/main/csharp/Session.cs

Modified: activemq/activemq-dotnet/Apache.NMS.MSMQ/trunk/src/main/csharp/DefaultMessageConverter.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.MSMQ/trunk/src/main/csharp/DefaultMessageConverter.cs?rev=807861&r1=807860&r2=807861&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.MSMQ/trunk/src/main/csharp/DefaultMessageConverter.cs
(original)
+++ activemq/activemq-dotnet/Apache.NMS.MSMQ/trunk/src/main/csharp/DefaultMessageConverter.cs
Wed Aug 26 01:21:52 2009
@@ -17,9 +17,17 @@
 using System;
 using System.IO;
 using System.Messaging;
+using System.Text;
 
 namespace Apache.NMS.MSMQ
 {
+	public enum NMSMessageType
+	{
+		BytesMessage,
+		TextMessage,
+		MapMessage
+	}
+
 	public class DefaultMessageConverter : IMessageConverter
 	{
 		public virtual Message ToMsmqMessage(IMessage message)
@@ -92,8 +100,22 @@
 		{
 			if(message is IBytesMessage)
 			{
-				byte[] bytes = (message as IBytesMessage).Content;
-				answer.BodyStream.Write(bytes, 0, bytes.Length);
+				IBytesMessage bytesMessage = message as IBytesMessage;
+				answer.BodyStream.Write(bytesMessage.Content, 0, bytesMessage.Content.Length);
+				answer.AppSpecific = (int) NMSMessageType.BytesMessage;
+			}
+			else if(message is ITextMessage)
+			{
+				ITextMessage textMessage = message as ITextMessage;
+				byte[] buf = Encoding.UTF8.GetBytes(textMessage.Text);
+				answer.BodyStream.Write(buf, 0, buf.Length);
+				answer.AppSpecific = (int) NMSMessageType.TextMessage;
+			}
+			else if(message is IMapMessage)
+			{
+				IMapMessage mapMessage = message as IMapMessage;
+				answer.Body = mapMessage.Body;
+				answer.AppSpecific = (int) NMSMessageType.MapMessage;
 			}
 			else
 			{
@@ -101,6 +123,55 @@
 			}
 		}
 
+		protected virtual BaseMessage CreateNmsMessage(Message message)
+		{
+			BaseMessage result = null;
+
+			if((int) NMSMessageType.BytesMessage == message.AppSpecific)
+			{
+				byte[] buf = null;
+
+				if(message.BodyStream != null && message.BodyStream.Length > 0)
+				{
+					buf = new byte[message.BodyStream.Length];
+					message.BodyStream.Read(buf, 0, buf.Length);
+				}
+
+				BytesMessage bytesMessage = new BytesMessage();
+				bytesMessage.Content = buf;
+				result = bytesMessage;
+			}
+			else if((int) NMSMessageType.TextMessage == message.AppSpecific)
+			{
+				TextMessage textMessage = new TextMessage();
+				string content = String.Empty;
+
+				if(message.BodyStream != null && message.BodyStream.Length > 0)
+				{
+					byte[] buf = null;
+					buf = new byte[message.BodyStream.Length];
+					message.BodyStream.Read(buf, 0, buf.Length);
+					content = Encoding.UTF8.GetString(buf);
+				}
+
+				textMessage.Text = content;
+				result = textMessage;
+			}
+			else if((int) NMSMessageType.MapMessage == message.AppSpecific)
+			{
+				MapMessage mapMessage = new MapMessage();
+
+				mapMessage.Body = message.Body as IPrimitiveMap;
+				result = mapMessage;
+			}
+			else
+			{
+				result = new BaseMessage();
+			}
+
+			return result;
+		}
+
 		public virtual IMessage ToNmsMessage(Message message)
 		{
 			BaseMessage answer = CreateNmsMessage(message);
@@ -108,6 +179,7 @@
 			try
 			{
 				answer.NMSCorrelationID = message.CorrelationId;
+				answer.NMSDeliveryMode = (message.Recoverable ? MsgDeliveryMode.Persistent : MsgDeliveryMode.NonPersistent);
 			}
 			catch(InvalidOperationException)
 			{
@@ -147,20 +219,5 @@
 			}
 			return new Queue(destinationQueue.Path);
 		}
-
-		protected virtual BaseMessage CreateNmsMessage(Message message)
-		{
-			Stream stream = message.BodyStream;
-			if(stream == null || stream.Length == 0)
-			{
-				return new BaseMessage();
-			}
-			byte[] buf = new byte[stream.Length];
-			stream.Read(buf, 0, buf.Length);
-			// TODO: how to recognise other flavors of message?
-			BytesMessage result = new BytesMessage();
-			result.Content = buf;
-			return result;
-		}
 	}
 }

Modified: activemq/activemq-dotnet/Apache.NMS.MSMQ/trunk/src/main/csharp/Destination.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.MSMQ/trunk/src/main/csharp/Destination.cs?rev=807861&r1=807860&r2=807861&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.MSMQ/trunk/src/main/csharp/Destination.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.MSMQ/trunk/src/main/csharp/Destination.cs Wed Aug
26 01:21:52 2009
@@ -40,13 +40,22 @@
 		 */
 		protected Destination(String name)
 		{
-			this.path = name;
+			Path = name;
 		}
 
 		public String Path
 		{
 			get { return this.path; }
-			set { this.path = value; }
+			set
+			{
+				this.path = value;
+				if(!this.path.Contains("\\"))
+				{
+					// Queues must have paths in them.  If no path specified, then
+					// default to local machine.
+					this.path = ".\\" + this.path;
+				}
+			}
 		}
 
 

Modified: activemq/activemq-dotnet/Apache.NMS.MSMQ/trunk/src/main/csharp/MapMessage.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.MSMQ/trunk/src/main/csharp/MapMessage.cs?rev=807861&r1=807860&r2=807861&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.MSMQ/trunk/src/main/csharp/MapMessage.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.MSMQ/trunk/src/main/csharp/MapMessage.cs Wed Aug 26
01:21:52 2009
@@ -20,11 +20,12 @@
 {
 	public class MapMessage : BaseMessage, IMapMessage
 	{
-		private PrimitiveMap body = new PrimitiveMap();
+		private IPrimitiveMap body = new PrimitiveMap();
 
 		public IPrimitiveMap Body
 		{
 			get { return body; }
+			set { body = value; }
 		}
 	}
 }

Modified: activemq/activemq-dotnet/Apache.NMS.MSMQ/trunk/src/main/csharp/MessageConsumer.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.MSMQ/trunk/src/main/csharp/MessageConsumer.cs?rev=807861&r1=807860&r2=807861&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.MSMQ/trunk/src/main/csharp/MessageConsumer.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.MSMQ/trunk/src/main/csharp/MessageConsumer.cs Wed
Aug 26 01:21:52 2009
@@ -39,6 +39,10 @@
 			this.session = session;
 			this.acknowledgementMode = acknowledgementMode;
 			this.messageQueue = messageQueue;
+			if(null != this.messageQueue)
+			{
+				this.messageQueue.MessageReadPropertyFilter.SetAll();
+			}
 		}
 
 		public event MessageListener Listener
@@ -74,13 +78,17 @@
 
 		public void Dispose()
 		{
-			throw new NotImplementedException();
+			Close();
 		}
 
 		public void Close()
 		{
 			StopAsyncDelivery();
-			Dispose();
+			if(messageQueue != null)
+			{
+				messageQueue.Dispose();
+				messageQueue = null;
+			}
 		}
 
 		public void StopAsyncDelivery()

Modified: activemq/activemq-dotnet/Apache.NMS.MSMQ/trunk/src/main/csharp/Session.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.MSMQ/trunk/src/main/csharp/Session.cs?rev=807861&r1=807860&r2=807861&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.MSMQ/trunk/src/main/csharp/Session.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.MSMQ/trunk/src/main/csharp/Session.cs Wed Aug 26 01:21:52
2009
@@ -207,8 +207,12 @@
 		{
 			get
 			{
-				if(messageQueueTransaction.Status != MessageQueueTransactionStatus.Pending)
+				if(null != messageQueueTransaction
+					&& messageQueueTransaction.Status != MessageQueueTransactionStatus.Pending)
+				{
 					messageQueueTransaction.Begin();
+				}
+
 				return messageQueueTransaction;
 			}
 			set { messageQueueTransaction = value; }
@@ -224,6 +228,5 @@
 		{
 			Dispose();
 		}
-
 	}
 }



Mime
View raw message