summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--dotnet/Qpid.Client.Tests/Qpid.Client.Tests.csproj1
-rw-r--r--dotnet/Qpid.Client.Tests/url/ConnectionUrlTest.cs38
-rw-r--r--dotnet/Qpid.Client/Client/AmqBrokerInfo.cs37
-rw-r--r--dotnet/Qpid.Client/Client/QpidConnectionInfo.cs66
4 files changed, 93 insertions, 49 deletions
diff --git a/dotnet/Qpid.Client.Tests/Qpid.Client.Tests.csproj b/dotnet/Qpid.Client.Tests/Qpid.Client.Tests.csproj
index 819d43b5b0..49145022b7 100644
--- a/dotnet/Qpid.Client.Tests/Qpid.Client.Tests.csproj
+++ b/dotnet/Qpid.Client.Tests/Qpid.Client.Tests.csproj
@@ -45,6 +45,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="bio\BlockingIo.cs" />
+ <Compile Include="BrokerDetails\BrokerDetailsTest.cs" />
<Compile Include="connection\ConnectionTest.cs" />
<Compile Include="connection\SslConnectionTest.cs" />
<Compile Include="failover\FailoverTest.cs" />
diff --git a/dotnet/Qpid.Client.Tests/url/ConnectionUrlTest.cs b/dotnet/Qpid.Client.Tests/url/ConnectionUrlTest.cs
index 4ab6dd5736..b3ee0272b4 100644
--- a/dotnet/Qpid.Client.Tests/url/ConnectionUrlTest.cs
+++ b/dotnet/Qpid.Client.Tests/url/ConnectionUrlTest.cs
@@ -404,5 +404,43 @@ namespace Qpid.Client.Tests.url
Assert.AreEqual("Unterminated option", e.Message);
}
}
+
+ [Test]
+ public void ValidateQpidConnectionInfoFromToString()
+ {
+ String url = "amqp://ritchiem:bob@default/temp?brokerlist='tcp://localhost:5672;tcp://fancyserver:3000/',failover='roundrobin'";
+
+ IConnectionInfo connectionInfo = QpidConnectionInfo.FromUrl(url);
+ IConnectionInfo connectionInfo1 = QpidConnectionInfo.FromUrl(connectionInfo.ToString());
+
+ Console.WriteLine(connectionInfo.ToString());
+ Console.WriteLine(connectionInfo1.ToString());
+
+ Assert.AreEqual(connectionInfo.Username, connectionInfo1.Username);
+ Assert.AreEqual(connectionInfo.Password, connectionInfo1.Password);
+ Assert.AreEqual(connectionInfo.VirtualHost, connectionInfo1.VirtualHost);
+
+ Assert.IsTrue((connectionInfo1.GetAllBrokerInfos().Count == 2));
+ Assert.IsTrue(connectionInfo.GetBrokerInfo(0).Equals(connectionInfo1.GetBrokerInfo(0)));
+ Assert.IsTrue(connectionInfo.GetBrokerInfo(1).Equals(connectionInfo1.GetBrokerInfo(1)));
+
+ }
+
+ [Test]
+ public void EnsureVirtualHostStartsWithSlash()
+ {
+ IConnectionInfo connection = new QpidConnectionInfo();
+ connection.VirtualHost = "test";
+ Assert.AreEqual("/test", connection.VirtualHost);
+
+ connection.VirtualHost = "/mytest";
+ Assert.AreEqual("/mytest", connection.VirtualHost);
+
+ connection.VirtualHost = "";
+ Assert.AreEqual("/", connection.VirtualHost);
+
+ connection.VirtualHost = null;
+ Assert.AreEqual("/", connection.VirtualHost);
+ }
}
}
diff --git a/dotnet/Qpid.Client/Client/AmqBrokerInfo.cs b/dotnet/Qpid.Client/Client/AmqBrokerInfo.cs
index 9ae1a49473..90e3788f5a 100644
--- a/dotnet/Qpid.Client/Client/AmqBrokerInfo.cs
+++ b/dotnet/Qpid.Client/Client/AmqBrokerInfo.cs
@@ -260,7 +260,7 @@ namespace Qpid.Client
sb.Append(_transport);
sb.Append("://");
- if (!(_transport.ToLower().Equals("vm")))
+ if (!(StringEqualsIgnoreCase(_transport, "vm")))
{
sb.Append(_host);
}
@@ -268,8 +268,7 @@ namespace Qpid.Client
sb.Append(':');
sb.Append(_port);
- // XXX
-// sb.Append(printOptionsURL());
+ sb.Append(URLHelper.printOptions(_options));
return sb.ToString();
}
@@ -284,7 +283,8 @@ namespace Qpid.Client
IBrokerInfo bd = (IBrokerInfo) obj;
return StringEqualsIgnoreCase(_host, bd.Host) &&
_port == bd.Port &&
- _transport == bd.Transport;
+ StringEqualsIgnoreCase(_transport, bd.Transport) &&
+ UseSSL == bd.UseSSL;
}
public override int GetHashCode()
@@ -298,35 +298,6 @@ namespace Qpid.Client
return one.ToLower().Equals(two.ToLower());
}
-// private string printOptionsURL()
-// {
-// stringBuffer optionsURL = new stringBuffer();
-//
-// optionsURL.Append('?');
-//
-// if (!(_options.isEmpty()))
-// {
-//
-// for (string key : _options.keySet())
-// {
-// optionsURL.Append(key);
-//
-// optionsURL.Append("='");
-//
-// optionsURL.Append(_options.get(key));
-//
-// optionsURL.Append("'");
-//
-// optionsURL.Append(URLHelper.DEFAULT_OPTION_SEPERATOR);
-// }
-// }
-//
-// //remove the extra DEFAULT_OPTION_SEPERATOR or the '?' if there are no options
-// optionsURL.deleteCharAt(optionsURL.length() - 1);
-//
-// return optionsURL.tostring();
-// }
-
public bool UseSSL
{
get
diff --git a/dotnet/Qpid.Client/Client/QpidConnectionInfo.cs b/dotnet/Qpid.Client/Client/QpidConnectionInfo.cs
index 914170467a..d88683f7d5 100644
--- a/dotnet/Qpid.Client/Client/QpidConnectionInfo.cs
+++ b/dotnet/Qpid.Client/Client/QpidConnectionInfo.cs
@@ -171,19 +171,10 @@ namespace Qpid.Client
sb.Append('?');
foreach (String key in options.Keys)
{
- sb.Append(key);
-
- sb.Append("='");
-
- sb.Append(options[key]);
-
- sb.Append("'");
- sb.Append(DEFAULT_OPTION_SEPERATOR);
+ sb.AppendFormat("{0}='{1}'{2}", key, options[key], DEFAULT_OPTION_SEPERATOR);
}
sb.Remove(sb.Length - 1, 1);
- // sb.deleteCharAt(sb.length() - 1);
-
return sb.ToString();
}
}
@@ -358,9 +349,10 @@ namespace Qpid.Client
public class QpidConnectionInfo : IConnectionInfo
{
+ const string DEFAULT_VHOST = "/";
string _username = "guest";
string _password = "guest";
- string _virtualHost = "/";
+ string _virtualHost = DEFAULT_VHOST;
string _failoverMethod = null;
IDictionary _failoverOptions = new Hashtable();
@@ -385,15 +377,51 @@ namespace Qpid.Client
public string AsUrl()
{
- string result = "amqp://";
- foreach (IBrokerInfo info in _brokerInfos)
+ StringBuilder sb = new StringBuilder();
+ sb.AppendFormat("{0}://", ConnectionUrlConstants.AMQ_PROTOCOL);
+
+ if (_username != null)
{
- result += info.ToString();
+ sb.Append(_username);
+ if (_password != null)
+ {
+ sb.AppendFormat(":{0}", _password);
+ }
+ sb.Append("@");
}
- return result;
+ sb.Append(_clientName);
+ sb.Append(_virtualHost);
+ sb.Append(OptionsToString());
+
+ return sb.ToString();
}
+ private String OptionsToString()
+ {
+ StringBuilder sb = new StringBuilder();
+ sb.AppendFormat("?{0}='", ConnectionUrlConstants.OPTIONS_BROKERLIST);
+
+ foreach (IBrokerInfo broker in _brokerInfos)
+ {
+ sb.AppendFormat("{0};", broker);
+ }
+
+ sb.Remove(sb.Length - 1, 1);
+ sb.Append("'");
+
+ if (_failoverMethod != null)
+ {
+ sb.AppendFormat("{0}{1}='{2}{3}'", URLHelper.DEFAULT_OPTION_SEPERATOR,
+ ConnectionUrlConstants.OPTIONS_FAILOVER,
+ _failoverMethod,
+ URLHelper.printOptions((Hashtable)_failoverOptions));
+ }
+
+ return sb.ToString();
+ }
+
+
public string FailoverMethod
{
get { return _failoverMethod; }
@@ -449,7 +477,13 @@ namespace Qpid.Client
public string VirtualHost
{
get { return _virtualHost; }
- set { _virtualHost = value; }
+ set {
+ _virtualHost = value;
+ if ( _virtualHost == null || _virtualHost.Length == 0 )
+ _virtualHost = DEFAULT_VHOST;
+ if ( _virtualHost[0] != '/' )
+ _virtualHost = '/' + _virtualHost;
+ }
}
public string GetOption(string key)