activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject [21/50] [abbrv] activemq-nms-openwire git commit: 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)
Date Wed, 08 Mar 2017 23:12:23 GMT
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)



Project: http://git-wip-us.apache.org/repos/asf/activemq-nms-openwire/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-nms-openwire/commit/66662a53
Tree: http://git-wip-us.apache.org/repos/asf/activemq-nms-openwire/tree/66662a53
Diff: http://git-wip-us.apache.org/repos/asf/activemq-nms-openwire/diff/66662a53

Branch: refs/heads/1.7.x
Commit: 66662a53648e86dc9b07ba63f66c2dcdae69a5db
Parents: 8e6479f
Author: Jim Gomes <jgomes@apache.org>
Authored: Wed Jul 8 18:14:57 2015 +0000
Committer: Jim Gomes <jgomes@apache.org>
Committed: Wed Jul 8 18:14:57 2015 +0000

----------------------------------------------------------------------
 src/main/csharp/NetTxConnection.cs | 25 ++++++++++++++-----------
 1 file changed, 14 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-nms-openwire/blob/66662a53/src/main/csharp/NetTxConnection.cs
----------------------------------------------------------------------
diff --git a/src/main/csharp/NetTxConnection.cs b/src/main/csharp/NetTxConnection.cs
index 8f1976c..8005e2c 100644
--- a/src/main/csharp/NetTxConnection.cs
+++ b/src/main/csharp/NetTxConnection.cs
@@ -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);
         }
     }


Mime
View raw message