You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ta...@apache.org on 2010/07/16 01:18:43 UTC

svn commit: r964638 - in /activemq/activemq-dotnet: Apache.NMS.ActiveMQ/trunk/src/main/csharp/ Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Discovery/ Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Failover/ Apache.NMS.ActiveMQ/trunk/src/te...

Author: tabish
Date: Thu Jul 15 23:18:43 2010
New Revision: 964638

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

Updates to the Uri Parsing and Composite Uri handling.  Allows most of the various forms of URIs that the AMQ docs call out.  

Added several new unit tests for URISupport and Tests in NMS.ActiveMQ to ensure that the Connection params are getting set even when a composite Uri is used for Failover transport.  

Added:
    activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/ConnectionFactoryTest.cs   (with props)
    activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/URISupportTest.cs   (with props)
Modified:
    activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Connection.cs
    activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/ConnectionFactory.cs
    activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Discovery/DiscoveryTransportFactory.cs
    activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Failover/FailoverTransportFactory.cs
    activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/ExclusiveConsumerTest.cs
    activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/NMSConnectionFactoryTest.cs
    activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/Connection.cs
    activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/ConnectionFactory.cs
    activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/Transport/Failover/FailoverTransportFactory.cs
    activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/vs2008-stomp-test.csproj
    activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/vs2008-stomp.csproj
    activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/NMSConnectionFactory.cs
    activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/Util/URISupport.cs
    activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/ProducerTest.cs

Modified: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Connection.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Connection.cs?rev=964638&r1=964637&r2=964638&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Connection.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Connection.cs Thu Jul 15 23:18:43 2010
@@ -405,7 +405,7 @@ namespace Apache.NMS.ActiveMQ
             Session session = new Session(this, info, sessionAcknowledgementMode, this.dispatchAsync);
 
             // Set properties on session using parameters prefixed with "session."
-            URISupport.CompositeData c = URISupport.parseComposite(this.brokerUri);
+            URISupport.CompositeData c = URISupport.ParseComposite(this.brokerUri);
             URISupport.SetProperties(session, c.Parameters, "session.");
 
             if(IsStarted)

Modified: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/ConnectionFactory.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/ConnectionFactory.cs?rev=964638&r1=964637&r2=964638&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/ConnectionFactory.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/ConnectionFactory.cs Thu Jul 15 23:18:43 2010
@@ -16,6 +16,8 @@
  */
 
 using System;
+using System.Collections;
+using System.Collections.Specialized;
 using Apache.NMS.ActiveMQ.Util;
 using Apache.NMS.ActiveMQ.Commands;
 using Apache.NMS.ActiveMQ.Transport;
@@ -80,7 +82,7 @@ namespace Apache.NMS.ActiveMQ
 		}
 
 		public ConnectionFactory(string brokerUri, string clientID)
-			: this(new Uri(brokerUri), clientID)
+			: this(URISupport.CreateCompatibleUri(brokerUri), clientID)
 		{
 		}
 
@@ -106,14 +108,11 @@ namespace Apache.NMS.ActiveMQ
 
             try
             {
-    			// Strip off the activemq prefix, if it exists.
-    			Uri uri = new Uri(URISupport.stripPrefix(brokerUri.OriginalString, "activemq:"));
+    			Tracer.InfoFormat("Connecting to: {0}", brokerUri.ToString());
     
-    			Tracer.InfoFormat("Connecting to: {0}", uri.ToString());
+                ITransport transport = TransportFactory.CreateTransport(brokerUri);
     
-                ITransport transport = TransportFactory.CreateTransport(uri);
-    
-                connection = new Connection(uri, transport, this.ClientIdGenerator);
+                connection = new Connection(brokerUri, transport, this.ClientIdGenerator);
     
                 ConfigureConnection(connection);
     
@@ -165,14 +164,28 @@ namespace Apache.NMS.ActiveMQ
 			get { return brokerUri; }
 			set
             {
-                brokerUri = value;
+                brokerUri = new Uri(URISupport.StripPrefix(value.OriginalString, "activemq:"));
 
-                Uri uri = new Uri(URISupport.stripPrefix(brokerUri.OriginalString, "activemq:"));
+                if(brokerUri.Query != null)
+                {
+                    StringDictionary properties = URISupport.ParseQuery(brokerUri.Query);
+				
+    				StringDictionary connection = URISupport.ExtractProperties(properties, "connection.");
+    				StringDictionary nms = URISupport.ExtractProperties(properties, "nms.");
+    				
+    				if(connection != null)
+    				{
+                    	URISupport.SetProperties(this, connection, "connection.");
+    				}
+    				
+    				if(nms != null)
+    				{
+                    	URISupport.SetProperties(this.PrefetchPolicy, nms, "nms.PrefetchPolicy.");
+                    	URISupport.SetProperties(this.RedeliveryPolicy, nms, "nms.RedeliveryPolicy.");
+    				}
 
-                URISupport.CompositeData c = URISupport.parseComposite(uri);
-                URISupport.SetProperties(this, c.Parameters, "connection.");
-                URISupport.SetProperties(this.PrefetchPolicy, c.Parameters, "nms.PrefetchPolicy.");
-                URISupport.SetProperties(this.RedeliveryPolicy, c.Parameters, "nms.RedeliveryPolicy.");
+                    brokerUri = URISupport.CreateRemainingUri(brokerUri, properties);
+                }
             }
 		}
 

Modified: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Discovery/DiscoveryTransportFactory.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Discovery/DiscoveryTransportFactory.cs?rev=964638&r1=964637&r2=964638&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Discovery/DiscoveryTransportFactory.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Discovery/DiscoveryTransportFactory.cs Thu Jul 15 23:18:43 2010
@@ -87,7 +87,7 @@ namespace Apache.NMS.ActiveMQ.Transport.
 
 		public ITransport CreateTransport(Uri location)
 		{
-			URISupport.CompositeData cd = URISupport.parseComposite(location);
+			URISupport.CompositeData cd = URISupport.ParseComposite(location);
 
 			if(cd.Components.Length > 0)
 			{

Modified: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Failover/FailoverTransportFactory.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Failover/FailoverTransportFactory.cs?rev=964638&r1=964637&r2=964638&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Failover/FailoverTransportFactory.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Transport/Failover/FailoverTransportFactory.cs Thu Jul 15 23:18:43 2010
@@ -25,7 +25,7 @@ namespace Apache.NMS.ActiveMQ.Transport.
 	{
 		private ITransport doConnect(Uri location)
 		{
-			ITransport transport = CreateTransport(URISupport.parseComposite(location));
+			ITransport transport = CreateTransport(URISupport.ParseComposite(location));
 			transport = new MutexTransport(transport);
 			transport = new ResponseCorrelator(transport);
 			return transport;
@@ -33,7 +33,7 @@ namespace Apache.NMS.ActiveMQ.Transport.
 
 		public ITransport CompositeConnect(Uri location)
 		{
-			return CreateTransport(URISupport.parseComposite(location));
+			return CreateTransport(URISupport.ParseComposite(location));
 		}
 
 		public ITransport CompositeConnect(Uri location, SetTransport setTransport)

Added: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/ConnectionFactoryTest.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/ConnectionFactoryTest.cs?rev=964638&view=auto
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/ConnectionFactoryTest.cs (added)
+++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/ConnectionFactoryTest.cs Thu Jul 15 23:18:43 2010
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+
+using Apache.NMS.Test;
+using Apache.NMS.ActiveMQ;
+
+using NUnit.Framework;
+using NUnit.Framework.Extensions;
+
+namespace Apache.NMS.ActiveMQ.Test
+{
+	[TestFixture]
+	public class ConnectionFactoryTest : NMSTestSupport
+	{
+		[Test]
+		public void TestConnectionFactorySetParams()
+		{
+			string connectionURI = "tcp://${activemqhost}:61616";
+			ConnectionFactory factory = new ConnectionFactory(NMSTestSupport.ReplaceEnvVar(connectionURI));
+			
+			factory.AcknowledgementMode = AcknowledgementMode.ClientAcknowledge;
+			factory.AsyncSend = true;
+			factory.AlwaysSyncSend = true;
+			factory.AsyncClose = false;
+			factory.CopyMessageOnSend = false;
+			factory.RequestTimeout = 3000;
+			factory.SendAcksAsync = true;
+			factory.DispatchAsync = false;
+			
+			using(Connection connection = factory.CreateConnection() as Connection)
+			{
+				Assert.AreEqual(AcknowledgementMode.ClientAcknowledge, connection.AcknowledgementMode);
+				Assert.IsTrue(connection.AsyncSend);
+				Assert.IsTrue(connection.AlwaysSyncSend);
+				Assert.IsFalse(connection.AsyncClose);
+				Assert.IsFalse(connection.CopyMessageOnSend);
+				Assert.AreEqual(3000, connection.RequestTimeout.TotalMilliseconds);
+				Assert.IsTrue(connection.SendAcksAsync);
+				Assert.IsFalse(connection.DispatchAsync);
+			}
+			
+			factory.SendAcksAsync = false;
+			
+			using(Connection connection = factory.CreateConnection() as Connection)
+			{
+				Assert.AreEqual(AcknowledgementMode.ClientAcknowledge, connection.AcknowledgementMode);
+				Assert.IsTrue(connection.AsyncSend);
+				Assert.IsTrue(connection.AlwaysSyncSend);
+				Assert.IsFalse(connection.AsyncClose);
+				Assert.IsFalse(connection.CopyMessageOnSend);
+				Assert.AreEqual(3000, connection.RequestTimeout.TotalMilliseconds);
+				Assert.IsFalse(connection.SendAcksAsync);
+				Assert.IsFalse(connection.DispatchAsync);
+			}			
+		}
+	
+		[Test]
+		public void TestConnectionFactoryParseParams()
+		{
+			string connectionURI = "tcp://${activemqhost}:61616?" +
+								   "connection.AckMode=ClientAcknowledge&" +
+								   "connection.AsyncSend=true&" +
+								   "connection.AlwaysSyncSend=true&" +
+								   "connection.AsyncClose=false&" +
+								   "connection.CopyMessageOnSend=false&" +
+								   "connection.RequestTimeout=3000&" +
+								   "connection.SendAcksAsync=true&" +
+								   "connection.DispatchAsync=true";
+			
+			ConnectionFactory factory = new ConnectionFactory(NMSTestSupport.ReplaceEnvVar(connectionURI));
+			
+			using(Connection connection = factory.CreateConnection() as Connection)
+			{
+				Assert.AreEqual(AcknowledgementMode.ClientAcknowledge, connection.AcknowledgementMode);
+				Assert.IsTrue(connection.AsyncSend);
+				Assert.IsTrue(connection.AlwaysSyncSend);
+				Assert.IsFalse(connection.AsyncClose);
+				Assert.IsFalse(connection.CopyMessageOnSend);
+				Assert.AreEqual(3000, connection.RequestTimeout.TotalMilliseconds);
+				Assert.IsTrue(connection.SendAcksAsync);
+				Assert.IsTrue(connection.DispatchAsync);
+			}
+		}
+		
+	}	
+}
+

Propchange: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/ConnectionFactoryTest.cs
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/ExclusiveConsumerTest.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/ExclusiveConsumerTest.cs?rev=964638&r1=964637&r2=964638&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/ExclusiveConsumerTest.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/ExclusiveConsumerTest.cs Thu Jul 15 23:18:43 2010
@@ -26,7 +26,7 @@ namespace Apache.NMS.ActiveMQ.Test
     [TestFixture]   
     public class ExclusiveConsumerTest : NMSTestSupport
     {
-        protected static string DESTINATION_NAME = "TestDestination";
+        protected static string DESTINATION_NAME = "ExclusiveConsumerTestDestination";
         protected static string TEST_CLIENT_ID = "ExclusiveConsumerTestClientId";
         
         private IConnection createConnection(bool start) 

Modified: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/NMSConnectionFactoryTest.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/NMSConnectionFactoryTest.cs?rev=964638&r1=964637&r2=964638&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/NMSConnectionFactoryTest.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/NMSConnectionFactoryTest.cs Thu Jul 15 23:18:43 2010
@@ -41,6 +41,10 @@ namespace Apache.NMS.ActiveMQ.Test
 		[Row("activemq:failover:tcp://${activemqhost}:61616")]
 		[Row("activemq:failover:(tcp://${activemqhost}:61616)")]
 		[Row("activemq:failover:(tcp://${activemqhost}:61616,tcp://${activemqhost}:61616)")]
+        [Row("activemq:failover://(tcp://${activemqhost}:61616)?initialReconnectDelay=100")]
+        [Row("activemq:failover:(tcp://${activemqhost}:61616)?connection.asyncSend=true")]
+        [Row("activemq:failover:(tcp://${activemqhost}:61616)?timeout=100&connection.asyncSend=true")]
+
 #if false
 		[Row("activemq:discovery:multicast://default")]
 		[Row("activemq:discovery:(multicast://default)")]
@@ -66,7 +70,7 @@ namespace Apache.NMS.ActiveMQ.Test
 		[Row("discovery://${activemqhost}:6155", ExpectedException = typeof(NMSConnectionException))]
 		[Row("sms://${activemqhost}:61616", ExpectedException = typeof(NMSConnectionException))]
 		[Row("activemq:multicast://${activemqhost}:6155", ExpectedException = typeof(NMSConnectionException))]
-		[Row("activemq:(tcp://${activemqhost}:61616)?connection.asyncClose=false", ExpectedException = typeof(NMSConnectionException))]
+        [Row("activemq:(tcp://${activemqhost}:61616)?connection.asyncClose=false", ExpectedException = typeof(NMSConnectionException))]
 
         [Row("(tcp://${activemqhost}:61616,tcp://${activemqhost}:61616)", ExpectedException = typeof(UriFormatException))]
 		[Row("tcp://${activemqhost}:61616,tcp://${activemqhost}:61616", ExpectedException = typeof(UriFormatException))]

Modified: activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/Connection.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/Connection.cs?rev=964638&r1=964637&r2=964638&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/Connection.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/Connection.cs Thu Jul 15 23:18:43 2010
@@ -337,7 +337,7 @@ namespace Apache.NMS.Stomp
 			Session session = new Session(this, info, sessionAcknowledgementMode, this.dispatchAsync);
 
 			// Set properties on session using parameters prefixed with "session."
-			URISupport.CompositeData c = URISupport.parseComposite(this.brokerUri);
+			URISupport.CompositeData c = URISupport.ParseComposite(this.brokerUri);
 			URISupport.SetProperties(session, c.Parameters, "session.");
 
 			if(IsStarted)

Modified: activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/ConnectionFactory.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/ConnectionFactory.cs?rev=964638&r1=964637&r2=964638&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/ConnectionFactory.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/ConnectionFactory.cs Thu Jul 15 23:18:43 2010
@@ -16,6 +16,7 @@
  */
 
 using System;
+using System.Collections.Specialized;
 using Apache.NMS.Stomp.Util;
 using Apache.NMS.Stomp.Commands;
 using Apache.NMS.Stomp.Transport;
@@ -77,7 +78,7 @@ namespace Apache.NMS.Stomp
         }
 
         public ConnectionFactory(string brokerUri, string clientID)
-            : this(new Uri(brokerUri), clientID)
+            : this(URISupport.CreateCompatibleUri(brokerUri), clientID)
         {
         }
 
@@ -103,14 +104,11 @@ namespace Apache.NMS.Stomp
 
             try
             {
-                // Strip off the activemq prefix, if it exists.
-                Uri uri = new Uri(URISupport.stripPrefix(brokerUri.OriginalString, "stomp:"));
+                Tracer.InfoFormat("Connecting to: {0}", brokerUri.ToString());
 
-                Tracer.InfoFormat("Connecting to: {0}", uri.ToString());
+                ITransport transport = TransportFactory.CreateTransport(brokerUri);
 
-                ITransport transport = TransportFactory.CreateTransport(uri);
-
-                connection = new Connection(uri, transport, this.ClientIdGenerator);
+                connection = new Connection(brokerUri, transport, this.ClientIdGenerator);
 
                 connection.UserName = userName;
                 connection.Password = password;
@@ -162,17 +160,30 @@ namespace Apache.NMS.Stomp
             get { return brokerUri; }
             set
             {
-                brokerUri = value;
+                brokerUri = new Uri(URISupport.StripPrefix(value.OriginalString, "stomp:"));
 
-                Uri uri = new Uri(URISupport.stripPrefix(brokerUri.OriginalString, "stomp:"));
+                if(brokerUri.Query != null)
+                {
+                    StringDictionary properties = URISupport.ParseQuery(brokerUri.Query);
+                
+                    StringDictionary connection = URISupport.ExtractProperties(properties, "connection.");
+                    StringDictionary nms = URISupport.ExtractProperties(properties, "nms.");
+                    
+                    if(connection != null)
+                    {
+                        URISupport.SetProperties(this, connection, "connection.");
+                    }
+                    
+                    if(nms != null)
+                    {
+                        URISupport.SetProperties(this.PrefetchPolicy, nms, "nms.PrefetchPolicy.");
+                        URISupport.SetProperties(this.RedeliveryPolicy, nms, "nms.RedeliveryPolicy.");
+                    }
 
-                URISupport.CompositeData c = URISupport.parseComposite(uri);
-                URISupport.SetProperties(this, c.Parameters, "connection.");
-                URISupport.SetProperties(this.PrefetchPolicy, c.Parameters, "nms.PrefetchPolicy.");
-                URISupport.SetProperties(this.RedeliveryPolicy, c.Parameters, "nms.RedeliveryPolicy.");
+                    brokerUri = URISupport.CreateRemainingUri(brokerUri, properties);
+                }
             }
         }
-
         public string UserName
         {
             get { return connectionUserName; }

Modified: activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/Transport/Failover/FailoverTransportFactory.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/Transport/Failover/FailoverTransportFactory.cs?rev=964638&r1=964637&r2=964638&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/Transport/Failover/FailoverTransportFactory.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/Transport/Failover/FailoverTransportFactory.cs Thu Jul 15 23:18:43 2010
@@ -25,7 +25,7 @@ namespace Apache.NMS.Stomp.Transport.Fai
 	{
 		private ITransport doConnect(Uri location)
 		{
-			ITransport transport = CreateTransport(URISupport.parseComposite(location));
+			ITransport transport = CreateTransport(URISupport.ParseComposite(location));
 			transport = new MutexTransport(transport);
 			transport = new ResponseCorrelator(transport);
 			return transport;
@@ -33,7 +33,7 @@ namespace Apache.NMS.Stomp.Transport.Fai
 
 		public ITransport CompositeConnect(Uri location)
 		{
-			return CreateTransport(URISupport.parseComposite(location));
+			return CreateTransport(URISupport.ParseComposite(location));
 		}
 
 		public ITransport CompositeConnect(Uri location, SetTransport setTransport)

Modified: activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/vs2008-stomp-test.csproj
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/vs2008-stomp-test.csproj?rev=964638&r1=964637&r2=964638&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/vs2008-stomp-test.csproj (original)
+++ activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/vs2008-stomp-test.csproj Thu Jul 15 23:18:43 2010
@@ -57,21 +57,20 @@
       <SpecificVersion>False</SpecificVersion>
       <HintPath>lib\NUnit\net-2.0\nunit.framework.dll</HintPath>
     </Reference>
-    <Reference Include="nunit.framework.extensions, Version=2.4.8.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
-      <SpecificVersion>False</SpecificVersion>
-      <HintPath>lib\NUnit\net-2.0\nunit.framework.extensions.dll</HintPath>
-      <Package>mono-nunit</Package>
-    </Reference>
     <Reference Include="System" />
     <Reference Include="System.Xml" />
-    <Reference Include="Apache.NMS, Version=1.4.0.2007, Culture=neutral, PublicKeyToken=82756feee3957618">
+    <Reference Include="Apache.NMS, Version=1.4.0.2013, Culture=neutral, PublicKeyToken=82756feee3957618">
       <SpecificVersion>False</SpecificVersion>
       <HintPath>build\mono-2.0\debug\Apache.NMS.dll</HintPath>
     </Reference>
-    <Reference Include="Apache.NMS.Stomp, Version=1.4.0.2010, Culture=neutral, PublicKeyToken=82756feee3957618">
+    <Reference Include="Apache.NMS.Stomp, Version=1.4.0.2015, Culture=neutral, PublicKeyToken=82756feee3957618">
       <SpecificVersion>False</SpecificVersion>
       <HintPath>build\mono-2.0\debug\Apache.NMS.Stomp.dll</HintPath>
     </Reference>
+    <Reference Include="nunit.framework.extensions, Version=2.4.8.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77">
+      <SpecificVersion>False</SpecificVersion>
+      <HintPath>lib\NUnit\mono-2.0\nunit.framework.extensions.dll</HintPath>
+    </Reference>
   </ItemGroup>
   <ItemGroup>
     <BootstrapperPackage Include="Microsoft.Net.Framework.2.0">

Modified: activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/vs2008-stomp.csproj
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/vs2008-stomp.csproj?rev=964638&r1=964637&r2=964638&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/vs2008-stomp.csproj (original)
+++ activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/vs2008-stomp.csproj Thu Jul 15 23:18:43 2010
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="utf-8"?>
+<?xml version="1.0" encoding="utf-8"?>
 <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
   <PropertyGroup>
     <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -55,9 +55,9 @@
   <ItemGroup>
     <Reference Include="System" />
     <Reference Include="System.Xml" />
-    <Reference Include="Apache.NMS, Version=1.4.0.2007, Culture=neutral, PublicKeyToken=82756feee3957618">
+    <Reference Include="Apache.NMS, Version=1.4.0.2021, Culture=neutral, PublicKeyToken=82756feee3957618">
       <SpecificVersion>False</SpecificVersion>
-      <HintPath>build\mono-2.0\debug\Apache.NMS.dll</HintPath>
+      <HintPath>lib\Apache.NMS\mono-2.0\Apache.NMS.dll</HintPath>
     </Reference>
   </ItemGroup>
   <ItemGroup>

Modified: activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/NMSConnectionFactory.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/NMSConnectionFactory.cs?rev=964638&r1=964637&r2=964638&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/NMSConnectionFactory.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/NMSConnectionFactory.cs Thu Jul 15 23:18:43 2010
@@ -21,6 +21,8 @@ using System.Collections.Generic;
 using System.IO;
 using System.Reflection;
 using System.Xml;
+
+using Apache.NMS.Util;
 
 namespace Apache.NMS
 {
@@ -68,8 +70,8 @@ namespace Apache.NMS
 		/// <param name="providerURI">The URI for the ActiveMQ provider.</param>
 		/// <param name="constructorParams">Optional parameters to use when creating the ConnectionFactory.</param>
 		public NMSConnectionFactory(string providerURI, params object[] constructorParams)
-			: this(new Uri(providerURI), constructorParams)
-		{
+			: this(URISupport.CreateCompatibleUri(providerURI), constructorParams)
+		{
 		}
 
 		/// <summary>

Modified: activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/Util/URISupport.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/Util/URISupport.cs?rev=964638&r1=964637&r2=964638&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/Util/URISupport.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/Util/URISupport.cs Thu Jul 15 23:18:43 2010
@@ -16,6 +16,7 @@
  */
 using System;
 using System.Collections;
+using System.Collections.Generic;
 using System.Collections.Specialized;
 using System.Globalization;
 using System.Reflection;
@@ -32,6 +33,23 @@ namespace Apache.NMS.Util
 	/// </summary>
 	public class URISupport
 	{
+        /// <summary>
+        /// Given a string that could be a Composite Uri that uses syntax not compatible
+        /// with the .NET Uri class such as an ActiveMQ failover Uri formatted as
+        /// "failover://(tcp://localhost:61616)", the initial '://' must be changed
+        /// to ':(' so that the Uri class doesn't attempt to parse the '(tcp:' as
+        /// the Uri's Authority as that is not a valid host name.
+        /// </summary>
+        /// <param name="uriString">
+        /// A string that could be a Composite Uri that uses syntax not compatible
+        /// with the .NET Uri class
+        /// </param>
+        public static Uri CreateCompatibleUri(string uriString)
+        {
+            string sanitized = uriString.Replace("://(", ":(");
+            return new Uri(sanitized);
+        }
+
 		/// <summary>
 		/// Parse a Uri query string of the form ?x=y&amp;z=0
 		/// into a map of name/value pairs.
@@ -71,8 +89,8 @@ namespace Apache.NMS.Util
 		public static StringDictionary ParseParameters(Uri uri)
 		{
 			return (uri.Query == null
-					? emptyMap
-					: ParseQuery(stripPrefix(uri.Query, "?")));
+					? EmptyMap
+					: ParseQuery(StripPrefix(uri.Query, "?")));
 		}
 
 		/// <summary>
@@ -87,6 +105,8 @@ namespace Apache.NMS.Util
 		public static void SetProperties(object target, StringDictionary map, string prefix)
 		{
 			Type type = target.GetType();
+			
+			List<String> matches = new List<String>();
 
 			foreach(string key in map.Keys)
 			{
@@ -119,10 +139,47 @@ namespace Apache.NMS.Util
 							throw new NMSException(string.Format("No such property or field: {0} on class: {1}", bareKey, target.GetType().Name));
 						}
 					}
+					
+					// store for later removal.
+					matches.Add(key);
 				}
 			}
+			
+			// Remove all the properties we set so they are used again later.
+			foreach(string match in matches)
+			{
+				map.Remove(match);
+			}
 		}
 
+	    public static StringDictionary ExtractProperties(StringDictionary props, string prefix) {
+	        
+			if(props == null) 
+			{
+	            throw new Exception("Properties Object was null");
+	        }
+			
+			StringDictionary result = new StringDictionary();
+			List<String> matches = new List<String>();
+		
+			foreach(string key in props.Keys)
+			{
+				if(key.StartsWith(prefix))
+				{
+					String value = props[key];
+					result[key] = value;
+					matches.Add(key);
+				}
+			}
+			
+			foreach(string match in matches)
+			{
+				props.Remove(match);
+			}
+					
+	        return result;
+	    }
+		
 		public static String UrlDecode(String s)
 		{
 #if !NETCF
@@ -141,9 +198,9 @@ namespace Apache.NMS.Util
 #endif
 		}
 
-		public static String createQueryString(StringDictionary options)
+		public static String CreateQueryString(StringDictionary options)
 		{
-			if(options.Count > 0)
+			if(options != null && options.Count > 0)
 			{
 				StringBuilder rc = new StringBuilder();
 				bool first = true;
@@ -174,6 +231,18 @@ namespace Apache.NMS.Util
 			}
 		}
 
+        public static Uri CreateRemainingUri(Uri originalUri, StringDictionary parameters)
+        {
+            string s = CreateQueryString(parameters);
+
+            if(String.IsNullOrEmpty(s))
+            {
+                s = null;
+            }
+
+            return CreateUriWithQuery(originalUri, s);
+        }
+
 		public class CompositeData
 		{
 			private String host;
@@ -221,54 +290,50 @@ namespace Apache.NMS.Util
 
 			public Uri toUri()
 			{
-				StringBuilder sb = new StringBuilder();
-				if(scheme != null)
-				{
-					sb.Append(scheme);
-					sb.Append(':');
-				}
-
-				if(host != null && host.Length != 0)
-				{
-					sb.Append(host);
-				}
-				else
-				{
-					sb.Append('(');
-					for(int i = 0; i < components.Length; i++)
-					{
-						if(i != 0)
-						{
-							sb.Append(',');
-						}
-						sb.Append(components[i].ToString());
-					}
-					sb.Append(')');
-				}
-
-				if(path != null)
-				{
-					sb.Append('/');
-					sb.Append(path);
-				}
+                UriBuilder builder = new UriBuilder();
 
-				if(parameters.Count != 0)
-				{
-					sb.Append("?");
-					sb.Append(createQueryString(parameters));
-				}
-
-				if(fragment != null)
-				{
-					sb.Append("#");
-					sb.Append(fragment);
-				}
+                builder.Scheme = scheme;
+                builder.Host = host;
+                builder.Fragment = fragment;
+
+                if(components.Length > 0)
+                {
+                    StringBuilder sb = new StringBuilder();
+
+                    sb.Append('(');
+                    for(int i = 0; i < components.Length; i++)
+                    {
+                        if(i != 0)
+                        {
+                            sb.Append(',');
+                        }
+                        sb.Append(components[i].ToString());
+                    }
+                    sb.Append(')');
+
+                    if(path != null)
+                    {
+                        sb.Append('/');
+                        sb.Append(path);
+                    }
+
+                    builder.Path = sb.ToString();
+                }
+                else
+                {
+                    builder.Path = path;
+                }
+
+                if(parameters.Count > 0)
+                {
+                    builder.Query = CreateQueryString(parameters);
+                }
 
-				return new Uri(sb.ToString());
+				return builder.Uri;
 			}
 		}
 
-		public static String stripPrefix(String value, String prefix)
+		public static String StripPrefix(String value, String prefix)
 		{
 			if(value.StartsWith(prefix))
 			{
@@ -278,46 +343,72 @@ namespace Apache.NMS.Util
 			return value;
 		}
 
-		public static CompositeData parseComposite(Uri uri)
+        public static Uri CreateUriWithQuery(Uri uri, string query)
+        {
+            if(!String.IsNullOrEmpty(query) && !query.StartsWith("?"))
+            {
+                query = "?" + query;
+            }
+
+            if(String.IsNullOrEmpty(uri.Query))
+            {
+                return new Uri(uri.OriginalString + query);
+            }
+            else
+            {
+                string originalUri = uri.OriginalString;
+
+                int queryDelimPos = originalUri.LastIndexOf('?');
+                int compositeDelimPos = originalUri.LastIndexOf(')');
+
+                if(queryDelimPos <= compositeDelimPos)
+                {
+                    // No Query or the Query is part of an inner Composite.
+                    return new Uri(originalUri + query);
+                }
+                else
+                {
+                    // Outer Uri has a Query or not a Composite Uri with a Query
+                    string strippedUri = originalUri.Substring(0, queryDelimPos);
+                    return new Uri(strippedUri + query);
+                }
+            }
+        }
+
+        public static Uri RemoveQuery(Uri original)
+        {
+            return CreateUriWithQuery(original, null);
+        }
+
+		public static CompositeData ParseComposite(Uri uri)
 		{
 			CompositeData rc = new CompositeData();
 			rc.Scheme = uri.Scheme;
 
-			// URI is one of these formats:
-			//     scheme://host:port/path?query
-			//     scheme://host/path(URI_1,URI_2,...,URI_N)?query
-			// where URI_x can be any valid URI (including a composite one).
-			// Host and port and path are optional.
-			// This does mean that a URI containing balanced parenthesis are considered
-			// to be composite. This can be a problem if parenthesis are used in another context.
-			//
-			// This routine constructs CompositeData reflecting either of
-			// these forms. Each of the URI_x are stored into the components
-			// of the CompositeData.
-			//
-			// Sample valid URI that should be accepted:
-			//
-			// tcp://192.168.1.1
-			// tcp://192.168.1.1/
-			// tcp://192.168.1.1:61616
-			// tcp://192.168.1.1:61616/
-			// tcp://machine:61616
-			// tcp://host:61616/
-			// failover:(tcp://192.168.1.1:61616?trace=true,tcp://machine:61616?trace=false)?random=true
-
-			// If this is a composite URI, then strip the scheme
-			// and break up the URI into components. If not, then pass the URI directly.
-			// We detect "compositeness" by the existence of a "(" in the URI containing
-			// balanced parenthesis
-
 			// Start with original URI
-			String ssp = uri.OriginalString.Trim();
+			//String ssp = uri.Authority + uri.PathAndQuery;
+            String ssp = uri.OriginalString;
+
+            ssp = StripPrefix(ssp, rc.Scheme + ":");
+            ssp = StripPrefix(ssp, "//");
+
+            int lastPoundPos = ssp.LastIndexOf("#");
+            int lastParendPos = ssp.LastIndexOf(")");
 
-			ssp = stripPrefix(ssp, "failover:");
+            // Only include a Fragment that's outside any Composte sections.
+            if(lastPoundPos > lastParendPos)
+            {
+                rc.Fragment = ssp.Substring(lastPoundPos);
+                ssp = ssp.Substring(0, lastPoundPos);
+            }
+
+            // Ensure any embedded URIs don't have malformed authority's by changing
+            // them from '://(' which would cause the .NET Uri class to attempt to validate
+            // the authority as a hostname with, ':(' which is valid.
+            ssp = ssp.Replace("://(", ":(");
 
 			// Handle the composite components
-			parseComposite(uri, rc, ssp);
-			rc.Fragment = uri.Fragment;
+			ParseComposite(uri, rc, ssp);
 			return rc;
 		}
 
@@ -326,12 +417,12 @@ namespace Apache.NMS.Util
 		/// <param name="uri"></param>
 		/// <param name="rc"></param>
 		/// <param name="ssp"></param>
-		private static void parseComposite(Uri uri, CompositeData rc, String ssp)
+		private static void ParseComposite(Uri uri, CompositeData rc, String ssp)
 		{
 			String componentString;
 			String parms;
 
-			if(!checkParenthesis(ssp))
+			if(!CheckParenthesis(ssp))
 			{
 				throw new NMSException(uri.ToString() + ": Not a matching number of '(' and ')' parenthesis");
 			}
@@ -357,24 +448,29 @@ namespace Apache.NMS.Util
 			}
 			else
 			{
-				p = ssp.IndexOf("?");
-				if(p >= 0)
-				{
-					componentString = ssp.Substring(0, p);
-					parms = ssp.Substring(p);
-				}
-				else
-				{
-					componentString = ssp;
-					parms = "";
-				}
+			    componentString = ssp;
+				parms = "";
 			}
 
-			String[] components = splitComponents(componentString);
+			String[] components = SplitComponents(componentString);
 			rc.Components = new Uri[components.Length];
 			for(int i = 0; i < components.Length; i++)
 			{
-				rc.Components[i] = new Uri(components[i].Trim());
+                if(components.Length == 1 && components[0] == ssp)
+                {
+                    String[] parts = components[0].Split('?');
+                    UriBuilder builder = new UriBuilder();
+                    builder.Path = parts[0];
+                    if(parts.Length == 2)
+                    {
+                        builder.Query = parts[1];
+                    }
+                    rc.Components[i] = builder.Uri;
+                }
+                else
+                {
+				    rc.Components[i] = new Uri(components[i].Trim());
+                }
 			}
 
 			p = parms.IndexOf("?");
@@ -382,7 +478,7 @@ namespace Apache.NMS.Util
 			{
 				if(p > 0)
 				{
-					rc.Path = stripPrefix(parms.Substring(0, p), "/");
+					rc.Path = StripPrefix(parms.Substring(0, p), "/");
 				}
 
 				rc.Parameters = ParseQuery(parms.Substring(p + 1));
@@ -391,14 +487,14 @@ namespace Apache.NMS.Util
 			{
 				if(parms.Length > 0)
 				{
-					rc.Path = stripPrefix(parms, "/");
+					rc.Path = StripPrefix(parms, "/");
 				}
 
-				rc.Parameters = emptyMap;
+				rc.Parameters = EmptyMap;
 			}
 		}
 
-		private static StringDictionary emptyMap
+		private static StringDictionary EmptyMap
 		{
 			get { return new StringDictionary(); }
 		}
@@ -406,7 +502,7 @@ namespace Apache.NMS.Util
 		/// <summary>
 		/// </summary>
 		/// <param name="componentString"></param>
-		private static String[] splitComponents(String componentString)
+		private static String[] SplitComponents(String componentString)
 		{
 			ArrayList l = new ArrayList();
 
@@ -450,7 +546,7 @@ namespace Apache.NMS.Util
 			return rc;
 		}
 
-		public static bool checkParenthesis(String str)
+		public static bool CheckParenthesis(String str)
 		{
 			bool result = true;
 

Modified: activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/ProducerTest.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/ProducerTest.cs?rev=964638&r1=964637&r2=964638&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/ProducerTest.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/ProducerTest.cs Thu Jul 15 23:18:43 2010
@@ -33,8 +33,6 @@ namespace Apache.NMS.Test
                 connection.Start();
                 using(ISession session = connection.CreateSession())
                 {
-                    IDestination unusedDest = session.CreateTemporaryQueue();
-
                     IMessageProducer producer = session.CreateProducer(null);
 
                     try

Added: activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/URISupportTest.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/URISupportTest.cs?rev=964638&view=auto
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/URISupportTest.cs (added)
+++ activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/URISupportTest.cs Thu Jul 15 23:18:43 2010
@@ -0,0 +1,271 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+using System.Collections.Specialized;
+
+using Apache.NMS.Util;
+
+using NUnit.Framework;
+using NUnit.Framework.Extensions;
+
+namespace Apache.NMS.Test
+{
+	[TestFixture()]
+	public class URISupportTest
+	{
+	    protected void AssertMapKey(StringDictionary map, String key, Object expected)
+        {
+	        Assert.AreEqual(expected, map[key], "Map key: " + key);
+	    }
+
+        [RowTest]
+        [Row("tcp://127.0.0.1:61616")]
+        [Row("tcp:127.0.0.1:61616")]
+        [Row("failover:tcp://127.0.0.1:61616")]
+        [Row("failover:(tcp://127.0.0.1:61616)")]
+        [Row("failover://(tcp://127.0.0.1:61616)")]
+        [Row("failover://(tcp://127.0.0.1:61616,tcp:192.168.0.1:61616)")]
+        [Row("activemq:failover:(tcp://localhost:61616)")]
+        [Row("activemq:failover:(tcp://${activemqhost}:61616)")]
+        public void TestCreateSupportedUriVariations(string uriString)
+        {
+            Uri result = URISupport.CreateCompatibleUri(NMSTestSupport.ReplaceEnvVar(uriString));
+
+            Assert.IsNotNull(result);
+        }
+
+        [Test]
+        public void TestParseCompositeWithFragment()
+        {
+            string uriString =
+                "failover:(tcp://localhost:61616,ssl://remotehost:61617?param=true#fragment)#fragment";
+
+            URISupport.CompositeData rc = URISupport.ParseComposite(new Uri(uriString));
+
+            Assert.IsTrue(rc.Components.Length == 2);
+            Assert.AreEqual("failover", rc.Scheme);
+            Assert.AreEqual("#fragment", rc.Fragment);
+
+            Uri uri1 = rc.Components[0];
+            Uri uri2 = rc.Components[1];
+
+            Assert.AreEqual("tcp", uri1.Scheme);
+            Assert.AreEqual("ssl", uri2.Scheme);
+            Assert.AreEqual("localhost", uri1.Host);
+            Assert.AreEqual("remotehost", uri2.Host);
+            Assert.AreEqual(61616, uri1.Port);
+            Assert.AreEqual(61617, uri2.Port);
+            Assert.IsTrue(String.IsNullOrEmpty(uri1.Fragment));
+            Assert.IsNotNull(uri2.Fragment);
+            Assert.AreEqual("#fragment", uri2.Fragment);
+            Assert.AreEqual("?param=true", uri2.Query);
+        }
+
+        [Test]
+        public void TestCreateRemainingUriNonComposite()
+        {
+            string uriStringNoParams = "tcp://localhost:61616";
+            string uriStringWithParams = "tcp://localhost:61616?param1=true&param2=false";
+
+            Uri uriNoParams = new Uri(uriStringNoParams);
+            Uri uriWithParams = new Uri(uriStringWithParams);
+
+            Uri result = URISupport.CreateRemainingUri(uriNoParams, null);
+            Assert.AreEqual(uriStringNoParams, result.OriginalString);
+
+            result = URISupport.CreateRemainingUri(uriWithParams, null);
+            Assert.AreEqual(uriStringNoParams, result.OriginalString);
+
+            StringDictionary parameters = new StringDictionary();
+            parameters.Add("param1", "true");
+            parameters.Add("param2", "false");
+
+            result = URISupport.CreateRemainingUri(uriNoParams, parameters);
+            Assert.AreEqual(uriWithParams, result.OriginalString);
+        }
+
+        [Test]
+        public void TestCreateRemainingUriComposite()
+        {
+            string uriStringNoParams = "failover:tcp://localhost:61616";
+            string uriStringWithParams = "failover:tcp://localhost:61616?param1=true&param2=false";
+
+            Uri uriNoParams = new Uri(uriStringNoParams);
+            Uri uriWithParams = new Uri(uriStringWithParams);
+
+            Uri result = URISupport.CreateRemainingUri(uriNoParams, null);
+            Assert.AreEqual(uriStringNoParams, result.OriginalString);
+
+            result = URISupport.CreateRemainingUri(uriWithParams, null);
+            Assert.AreEqual(uriStringNoParams, result.OriginalString);
+
+            StringDictionary parameters = new StringDictionary();
+            parameters.Add("param1", "true");
+            parameters.Add("param2", "false");
+
+            result = URISupport.CreateRemainingUri(uriNoParams, parameters);
+            Assert.AreEqual(uriWithParams, result.OriginalString);
+
+            // Now test a Comopsoite with parends.
+
+            uriStringNoParams = "failover:(tcp://localhost:61616)";
+            uriStringWithParams = "failover:(tcp://localhost:61616?param1=true&param2=false)";
+
+            uriNoParams = new Uri(uriStringNoParams);
+            uriWithParams = new Uri(uriStringWithParams);
+
+            result = URISupport.CreateRemainingUri(uriNoParams, null);
+            Assert.AreEqual(uriStringNoParams, result.OriginalString);
+
+            result = URISupport.CreateRemainingUri(uriWithParams, null);
+            Assert.AreNotEqual(uriStringNoParams, result.OriginalString);
+
+            result = URISupport.CreateRemainingUri(uriNoParams, parameters);
+            Assert.AreNotEqual(uriWithParams, result.OriginalString);
+
+            string queryString = URISupport.CreateQueryString(parameters);
+            Assert.AreEqual(uriNoParams.OriginalString + "?" + queryString, result.OriginalString);
+        }
+
+		[Test]
+	    public void TestEmptyCompositePath()
+		{
+	        URISupport.CompositeData data = URISupport.ParseComposite(
+                new Uri("broker:()/localhost?persistent=false"));
+
+	        Assert.AreEqual(0, data.Components.Length);
+	    }
+
+		[Test]
+	    public void TestCompositePath()
+		{
+	        URISupport.CompositeData data = URISupport.ParseComposite(new Uri("test:(test:path)/path"));
+	        Assert.AreEqual("path", data.Path);
+	        data = URISupport.ParseComposite(new Uri("test:path"));
+	        Assert.IsNull(data.Path);
+	    }
+
+		[Test]
+	    public void TestSimpleComposite()
+		{
+	        URISupport.CompositeData data = URISupport.ParseComposite(new Uri("test:part1"));
+	        Assert.AreEqual(1, data.Components.Length);
+	    }
+
+		[Test]
+	    public void TestComposite()
+        {
+	        URISupport.CompositeData data = URISupport.ParseComposite(
+                new Uri("test:(part1://host,part2://(sub1://part,sube2:part))"));
+	        Assert.AreEqual(2, data.Components.Length);
+	    }
+
+		[Test]
+	    public void TestCompositeWithComponentParam()
+		{
+	        URISupport.CompositeData data = URISupport.ParseComposite(new Uri("test:(part1://host?part1=true)?outside=true"));
+	        Assert.AreEqual(1, data.Components.Length);
+	        Assert.AreEqual(1, data.Parameters.Count);
+	        StringDictionary part1Params = URISupport.ParseParameters(data.Components[0]);
+	        Assert.AreEqual(1, part1Params.Count);
+	        Assert.IsTrue(part1Params.ContainsKey("part1"));
+	    }
+
+		[Test]
+	    public void TestParsingURI()
+		{
+	        Uri source = new Uri("tcp://localhost:61626/foo/bar?cheese=Edam&x=123");
+
+	        StringDictionary map = URISupport.ParseParameters(source);
+
+	        Assert.AreEqual(2, map.Count, "Size: " + map);
+	        AssertMapKey(map, "cheese", "Edam");
+	        AssertMapKey(map, "x", "123");
+
+	        Uri result = URISupport.RemoveQuery(source);
+
+	        Assert.AreEqual(new Uri("tcp://localhost:61626/foo/bar"), result);
+	    }
+
+		[Test]
+	    public void TestParsingCompositeURI()
+		{
+	        URISupport.CompositeData data = URISupport.ParseComposite(
+                URISupport.CreateCompatibleUri("failover://(tcp://localhost:61616)?name=foo"));
+
+	        Assert.AreEqual(1, data.Components.Length, "one component");
+            Assert.AreEqual("localhost", data.Components[0].Host, "Component Host is incorrect");
+            Assert.AreEqual(61616, data.Components[0].Port, "Component Port is incorrect");
+	        Assert.AreEqual(1, data.Parameters.Count, "Size: " + data.Parameters);
+	    }
+
+		[Test]
+	    public void TestCheckParenthesis()
+		{
+	        String str = "fred:(((ddd))";
+	        Assert.IsFalse(URISupport.CheckParenthesis(str));
+	        str += ")";
+	        Assert.IsTrue(URISupport.CheckParenthesis(str));
+	    }
+
+        [Test]
+        public void TestParseQueury()
+        {
+            String query1 = "?param1=false&param2=true";
+            String query2 = "param3=false&param4=true&param5=foo";
+
+            StringDictionary results = URISupport.ParseQuery(query1);
+
+            Assert.IsTrue(results.Count == 2);
+            Assert.AreEqual("false", results["param1"]);
+            Assert.AreEqual("true", results["param2"]);
+
+            results = URISupport.ParseQuery(query2);
+
+            Assert.IsTrue(results.Count == 3);
+            Assert.AreEqual("false", results["param3"]);
+            Assert.AreEqual("true", results["param4"]);
+            Assert.AreEqual("foo", results["param5"]);
+
+            String query3 = "?param";
+
+            try
+            {
+                URISupport.ParseQuery(query3);
+                Assert.Fail("Should have thrown an Exception on invalid parameter.");
+            }
+            catch
+            {
+            }
+        }
+
+		[Test]
+	    public void TestCreateWithQuery()
+		{
+	        Uri source = new Uri("vm://localhost");
+	        Uri dest = URISupport.CreateUriWithQuery(source, "network=true&one=two");
+
+	        Assert.AreEqual(2, URISupport.ParseParameters(dest).Count, "correct param count");
+	        Assert.AreEqual(source.Host, dest.Host, "same uri, host");
+	        Assert.AreEqual(source.Scheme, dest.Scheme, "same uri, scheme");
+	        Assert.IsFalse(dest.Query.Equals(source.Query), "same uri, ssp");
+	    }
+
+	}
+}
+

Propchange: activemq/activemq-dotnet/Apache.NMS/trunk/src/test/csharp/URISupportTest.cs
------------------------------------------------------------------------------
    svn:eol-style = native