You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by jg...@apache.org on 2015/07/08 20:14:58 UTC

svn commit: r1689927 - /activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.7.x/src/main/csharp/NetTxConnection.cs

Author: jgomes
Date: Wed Jul  8 18:14:57 2015
New Revision: 1689927

URL: http://svn.apache.org/r1689927
Log:
Apply patch to improve ID parsing to avoid mis-parsing hostnames with hyphens. Thanks, Andrea Montemaggio!
Fixes [AMQNET-398]. (See https://issues.apache.org/jira/browse/AMQNET-398)

Modified:
    activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.7.x/src/main/csharp/NetTxConnection.cs

Modified: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.7.x/src/main/csharp/NetTxConnection.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.7.x/src/main/csharp/NetTxConnection.cs?rev=1689927&r1=1689926&r2=1689927&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.7.x/src/main/csharp/NetTxConnection.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.7.x/src/main/csharp/NetTxConnection.cs Wed Jul  8 18:14:57 2015
@@ -16,6 +16,7 @@
  */
 
 using System;
+using System.Text.RegularExpressions;
 using System.Transactions;
 using Apache.NMS.ActiveMQ.Transport;
 using Apache.NMS.ActiveMQ.Util;
@@ -95,18 +96,20 @@ namespace Apache.NMS.ActiveMQ
 
         private static Guid GuidFromId(string id)
         {
-            // Remove the ID: prefix, that's non-unique to be sure
-            string resId = id.TrimStart("ID:".ToCharArray());
-
-            // Remaing parts should be host-port-timestamp-instance:sequence
-            string[] parts = resId.Split(":-".ToCharArray());
-
+            MatchCollection matches = Regex.Matches(id, @"(\d+)-(\d+)-(\d+):(\d+)$");
+            if(0 == matches.Count)
+            {
+                throw new FormatException(string.Format("Unable to extract a GUID from string '{0}'", id));
+            }
+ 
+            GroupCollection groups = matches[0].Groups;
+ 
             // We don't use the hostname here, just the remaining bits.
-            int a = Int32.Parse(parts[parts.Length-4]);
-            short b = Int16.Parse(parts[parts.Length-2]);
-            short c = Int16.Parse(parts[parts.Length-1]);
-            byte[] d = System.BitConverter.GetBytes(Int64.Parse(parts[parts.Length-3]));
-
+            int a = Int32.Parse(groups[1].Value);
+            short b = Int16.Parse(groups[3].Value);
+            short c = Int16.Parse(groups[4].Value);
+            byte[] d = BitConverter.GetBytes(Int64.Parse(groups[2].Value));
+ 
             return new Guid(a, b, c, d);
         }
     }