Merge pull request #16 from brudo/fix-failover-dtaflin-reloc

Fix for NMS failover/TLS bug, AMQNET-572, by saving an Ssl context
diff --git a/src/Transport/Failover/FailoverTransport.cs b/src/Transport/Failover/FailoverTransport.cs
index 7fca5ae..c3faee0 100644
--- a/src/Transport/Failover/FailoverTransport.cs
+++ b/src/Transport/Failover/FailoverTransport.cs
@@ -90,6 +90,7 @@
 	 	private bool priorityBackup = false;
     	private List<Uri> priorityList = new List<Uri>();
     	private bool priorityBackupAvailable = false;
+        private String sslProtocol = null;
 
 		// Not Sure how to work these back in with all the changes.
 		//private int asyncTimeout = 45000;
@@ -1032,6 +1033,11 @@
 
         private bool DoConnect()
         {
+            if (this.sslProtocol != null)
+            {
+                Tcp.SslContext.GetCurrent().SslProtocol = this.sslProtocol;
+            }
+
             lock(reconnectMutex)
             {
 				if (disposed || connectionFailure != null)
@@ -1205,6 +1211,11 @@
 	                            }
 
 	                            connected = true;
+                                if (this.sslProtocol == null)
+                                {
+                                    this.sslProtocol = Tcp.SslContext.GetCurrent().SslProtocol;
+                                }
+
 	                            return false;
 	                        }
 							catch (Exception e) 
diff --git a/src/Transport/Tcp/SslContext.cs b/src/Transport/Tcp/SslContext.cs
new file mode 100644
index 0000000..d35e0e2
--- /dev/null
+++ b/src/Transport/Tcp/SslContext.cs
@@ -0,0 +1,41 @@
+using System;
+using System.Collections.Generic;
+namespace Apache.NMS.ActiveMQ.Transport.Tcp
+{
+    class SslContext
+    {
+        private String sslProtocol;
+
+        public SslContext() : this("Tls")
+        {
+        }
+
+        public SslContext(String protocol)
+        {
+            this.sslProtocol = protocol;
+        }
+
+        public String SslProtocol
+        {
+            get { return this.sslProtocol; }
+            set { this.sslProtocol = value; }
+        }
+
+        [ThreadStatic]
+        static private SslContext current;
+
+        static public SslContext GetCurrent()
+        {
+            if (current == null)
+            {
+                current = new SslContext();
+            }
+            return current;
+        }
+
+        static public void SetCurrent(SslContext context)
+        {
+            current = context;
+        }
+    }
+}
diff --git a/src/Transport/Tcp/SslTransportFactory.cs b/src/Transport/Tcp/SslTransportFactory.cs
index 080aac3..2fdb7a1 100644
--- a/src/Transport/Tcp/SslTransportFactory.cs
+++ b/src/Transport/Tcp/SslTransportFactory.cs
@@ -97,6 +97,16 @@
             Tracer.Debug("Creating new instance of the SSL Transport.");
 			SslTransport transport = new SslTransport(location, socket, wireFormat);
 
+            if (this.sslProtocol == null)
+            {
+                this.sslProtocol = SslContext.GetCurrent().SslProtocol;
+            }
+            else
+            {
+                SslContext.GetCurrent().SslProtocol = this.sslProtocol;
+            }
+            Tracer.DebugFormat("SslProtocol: {0}", this.sslProtocol);
+
             transport.ClientCertSubject = HttpUtility.UrlDecode(this.clientCertSubject);
             transport.ClientCertFilename = this.clientCertFilename;
             transport.ClientCertPassword = this.clientCertPassword;