diff options
author | Steven Shaw <steshaw@apache.org> | 2006-12-04 16:35:07 +0000 |
---|---|---|
committer | Steven Shaw <steshaw@apache.org> | 2006-12-04 16:35:07 +0000 |
commit | 9bbc2fb73926209434894bdb6b8f74a02e1d5fd7 (patch) | |
tree | 68c1b51d963aa8b4cd92dade264fee12aa367971 | |
parent | bfe3152312b1a6cd89fadd3f1c23e8bd37e1226d (diff) | |
download | qpid-python-9bbc2fb73926209434894bdb6b8f74a02e1d5fd7.tar.gz |
QPID-153 Initial port of URL parsing from Java client. Due to .NET Uri parser must support "host" name. Use "default" when you don't want to really supply one.
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@482237 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | dotnet/Qpid.Client.Tests/Qpid.Client.Tests.csproj | 1 | ||||
-rw-r--r-- | dotnet/Qpid.Client.Tests/connection/ConnectionTest.cs | 2 | ||||
-rw-r--r-- | dotnet/Qpid.Client.Tests/failover/FailoverTxTest.cs | 2 | ||||
-rw-r--r-- | dotnet/Qpid.Client.Tests/url/ConnectionUrlTest.cs | 409 | ||||
-rw-r--r-- | dotnet/Qpid.Client/Client/AMQConnection.cs | 10 | ||||
-rw-r--r-- | dotnet/Qpid.Client/Client/AMQDestination.cs | 1 | ||||
-rw-r--r-- | dotnet/Qpid.Client/Client/AmqBrokerInfo.cs | 238 | ||||
-rw-r--r-- | dotnet/Qpid.Client/Client/QpidConnectionInfo.cs | 384 | ||||
-rw-r--r-- | dotnet/Qpid.Client/Qpid.Client.csproj | 1 | ||||
-rw-r--r-- | dotnet/Qpid.Client/qms/BrokerInfo.cs | 2 | ||||
-rw-r--r-- | dotnet/Qpid.Client/qms/ConnectionInfo.cs | 25 | ||||
-rw-r--r-- | dotnet/Qpid.Client/qms/FailoverPolicy.cs | 6 | ||||
-rw-r--r-- | dotnet/Qpid.Client/qms/UrlSyntaxException.cs | 116 | ||||
-rw-r--r-- | dotnet/Qpid.Client/qms/failover/FailoverRoundRobin.cs | 36 | ||||
-rw-r--r-- | dotnet/Qpid.Client/qms/failover/FailoverSingleServer.cs | 6 |
15 files changed, 1073 insertions, 166 deletions
diff --git a/dotnet/Qpid.Client.Tests/Qpid.Client.Tests.csproj b/dotnet/Qpid.Client.Tests/Qpid.Client.Tests.csproj index c3e957ae09..00c3d54a82 100644 --- a/dotnet/Qpid.Client.Tests/Qpid.Client.Tests.csproj +++ b/dotnet/Qpid.Client.Tests/Qpid.Client.Tests.csproj @@ -55,6 +55,7 @@ <Compile Include="requestreply1\ServiceProvidingClient.cs" />
<Compile Include="requestreply1\ServiceRequestingClient.cs" />
<Compile Include="undeliverable\UndeliverableTest.cs" />
+ <Compile Include="url\ConnectionUrlTest.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Qpid.Client.Transport.Socket.Blocking\Qpid.Client.Transport.Socket.Blocking.csproj">
diff --git a/dotnet/Qpid.Client.Tests/connection/ConnectionTest.cs b/dotnet/Qpid.Client.Tests/connection/ConnectionTest.cs index d6d7639c21..5aa6773e53 100644 --- a/dotnet/Qpid.Client.Tests/connection/ConnectionTest.cs +++ b/dotnet/Qpid.Client.Tests/connection/ConnectionTest.cs @@ -43,7 +43,7 @@ namespace Qpid.Client.Tests.connection public void passwordFailureConnection() { ConnectionInfo connectionInfo = new QpidConnectionInfo(); - connectionInfo.setPassword("rubbish"); + connectionInfo.SetPassword("rubbish"); connectionInfo.AddBrokerInfo(new AmqBrokerInfo()); try { diff --git a/dotnet/Qpid.Client.Tests/failover/FailoverTxTest.cs b/dotnet/Qpid.Client.Tests/failover/FailoverTxTest.cs index 4e95c12290..4538fca148 100644 --- a/dotnet/Qpid.Client.Tests/failover/FailoverTxTest.cs +++ b/dotnet/Qpid.Client.Tests/failover/FailoverTxTest.cs @@ -103,7 +103,7 @@ namespace Qpid.Client.Tests.failover _connection.ConnectionListener = this; _log.Info("connection = " + _connection); _log.Info("connectionInfo = " + connectionInfo); - _log.Info("connection.asUrl = " + _connection.toURL()); + _log.Info("connection.AsUrl = " + _connection.toURL()); _log.Info("AcknowledgeMode is " + _acknowledgeMode); IChannel receivingChannel = _connection.CreateChannel(false, _acknowledgeMode); diff --git a/dotnet/Qpid.Client.Tests/url/ConnectionUrlTest.cs b/dotnet/Qpid.Client.Tests/url/ConnectionUrlTest.cs new file mode 100644 index 0000000000..5f06c38c78 --- /dev/null +++ b/dotnet/Qpid.Client.Tests/url/ConnectionUrlTest.cs @@ -0,0 +1,409 @@ +/* + * + * 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.Net; +using System.Text.RegularExpressions; +using NUnit.Framework; +using Qpid.Client.qms; + +namespace Qpid.Client.Tests.url +{ + [TestFixture] + public class connectionUrlTests + { + [Test] + public void FailoverURL() + { + //String url = "amqp://ritchiem:bob@/temp?brokerlist='tcp://localhost:5672;tcp://fancyserver:3000/',failover='roundrobin'"; + String url = "amqp://ritchiem:bob@default/temp?brokerlist='tcp://localhost:5672;tcp://fancyserver:3000/',failover='roundrobin'"; + + ConnectionInfo connectionurl = QpidConnectionInfo.FromUrl(url); + + Assert.AreEqual("roundrobin", connectionurl.GetFailoverMethod()); + Assert.IsTrue(connectionurl.GetUsername().Equals("ritchiem")); + Assert.IsTrue(connectionurl.GetPassword().Equals("bob")); + Assert.IsTrue(connectionurl.GetVirtualHost().Equals("/temp")); + + Assert.IsTrue(connectionurl.GetBrokerCount() == 2); + + BrokerInfo service = connectionurl.GetBrokerInfo(0); + + Assert.IsTrue(service.getTransport().Equals("tcp")); + Assert.IsTrue(service.getHost().Equals("localhost")); + Assert.IsTrue(service.getPort() == 5672); + + service = connectionurl.GetBrokerInfo(1); + + Assert.IsTrue(service.getTransport().Equals("tcp")); + Assert.IsTrue(service.getHost().Equals("fancyserver")); + Assert.IsTrue(service.getPort() == 3000); + + } + + [Test] + public void SingleTransportUsernamePasswordURL() + { + String url = "amqp://ritchiem:bob@default/temp?brokerlist='tcp://localhost:5672'"; + + ConnectionInfo connectionurl = QpidConnectionInfo.FromUrl(url); + + Assert.IsTrue(connectionurl.GetFailoverMethod() == null); + Assert.IsTrue(connectionurl.GetUsername().Equals("ritchiem")); + Assert.IsTrue(connectionurl.GetPassword().Equals("bob")); + Assert.IsTrue(connectionurl.GetVirtualHost().Equals("/temp")); + + Assert.IsTrue(connectionurl.GetBrokerCount() == 1); + + BrokerInfo service = connectionurl.GetBrokerInfo(0); + + Assert.IsTrue(service.getTransport().Equals("tcp")); + Assert.IsTrue(service.getHost().Equals("localhost")); + Assert.IsTrue(service.getPort() == 5672); + } + + [Test] + public void SingleTransportUsernameBlankPasswordURL() + { + String url = "amqp://ritchiem:@default/temp?brokerlist='tcp://localhost:5672'"; + + ConnectionInfo connectionurl = QpidConnectionInfo.FromUrl(url); + + Assert.IsTrue(connectionurl.GetFailoverMethod() == null); + Assert.IsTrue(connectionurl.GetUsername().Equals("ritchiem")); + Assert.IsTrue(connectionurl.GetPassword().Equals("")); + Assert.IsTrue(connectionurl.GetVirtualHost().Equals("/temp")); + + Assert.IsTrue(connectionurl.GetBrokerCount() == 1); + + BrokerInfo service = connectionurl.GetBrokerInfo(0); + + Assert.IsTrue(service.getTransport().Equals("tcp")); + Assert.IsTrue(service.getHost().Equals("localhost")); + Assert.IsTrue(service.getPort() == 5672); + } + + [Test] + public void FailedURLNullPassword() + { + String url = "amqp://ritchiem@default/temp?brokerlist='tcp://localhost:5672'"; + + try + { + QpidConnectionInfo.FromUrl(url); + Assert.Fail("URL has null password"); + } + catch (UrlSyntaxException e) + { + Assert.AreEqual("Null password in user information not allowed.", e.Message); + Assert.IsTrue(e.GetIndex() == 7); + } + } + + [Test] + public void SingleTransportURL() + { + String url = "amqp://guest:guest@default/test?brokerlist='tcp://localhost:5672'"; + + ConnectionInfo connectionurl = QpidConnectionInfo.FromUrl(url); + + + Assert.IsTrue(connectionurl.GetFailoverMethod() == null); + Assert.IsTrue(connectionurl.GetUsername().Equals("guest")); + Assert.IsTrue(connectionurl.GetPassword().Equals("guest")); + Assert.IsTrue(connectionurl.GetVirtualHost().Equals("/test")); + + + Assert.IsTrue(connectionurl.GetBrokerCount() == 1); + + + BrokerInfo service = connectionurl.GetBrokerInfo(0); + + Assert.IsTrue(service.getTransport().Equals("tcp")); + Assert.IsTrue(service.getHost().Equals("localhost")); + Assert.IsTrue(service.getPort() == 5672); + } + + [Test] + public void SingleTransportWithClientURLURL() + { + String url = "amqp://guest:guest@clientname/temp?brokerlist='tcp://localhost:5672'"; + + ConnectionInfo connectionurl = QpidConnectionInfo.FromUrl(url); + + + Assert.IsTrue(connectionurl.GetFailoverMethod() == null); + Assert.IsTrue(connectionurl.GetUsername().Equals("guest")); + Assert.IsTrue(connectionurl.GetPassword().Equals("guest")); + Assert.IsTrue(connectionurl.GetVirtualHost().Equals("/temp")); + Assert.IsTrue(connectionurl.GetClientName().Equals("clientname")); + + + Assert.IsTrue(connectionurl.GetBrokerCount() == 1); + + + BrokerInfo service = connectionurl.GetBrokerInfo(0); + + Assert.IsTrue(service.getTransport().Equals("tcp")); + Assert.IsTrue(service.getHost().Equals("localhost")); + Assert.IsTrue(service.getPort() == 5672); + } + + [Test] + public void SingleTransport1OptionURL() + { + String url = "amqp://guest:guest@default/temp?brokerlist='tcp://localhost:5672',routingkey='jim'"; + + ConnectionInfo connectionurl = QpidConnectionInfo.FromUrl(url); + + Assert.IsTrue(connectionurl.GetFailoverMethod() == null); + Assert.IsTrue(connectionurl.GetUsername().Equals("guest")); + Assert.IsTrue(connectionurl.GetPassword().Equals("guest")); + Assert.IsTrue(connectionurl.GetVirtualHost().Equals("/temp")); + + + Assert.IsTrue(connectionurl.GetBrokerCount() == 1); + + BrokerInfo service = connectionurl.GetBrokerInfo(0); + + Assert.IsTrue(service.getTransport().Equals("tcp")); + + Assert.IsTrue(service.getHost().Equals("localhost")); + Assert.IsTrue(service.getPort() == 5672); + Assert.IsTrue(connectionurl.GetOption("routingkey").Equals("jim")); + } + + [Test] + public void SingleTransportDefaultedBroker() + { + String url = "amqp://guest:guest@default/temp?brokerlist='localhost:'"; + + ConnectionInfo connectionurl = QpidConnectionInfo.FromUrl(url); + + Assert.IsTrue(connectionurl.GetFailoverMethod() == null); + Assert.IsTrue(connectionurl.GetUsername().Equals("guest")); + Assert.IsTrue(connectionurl.GetPassword().Equals("guest")); + Assert.IsTrue(connectionurl.GetVirtualHost().Equals("/temp")); + + + Assert.IsTrue(connectionurl.GetBrokerCount() == 1); + + BrokerInfo service = connectionurl.GetBrokerInfo(0); + + Assert.IsTrue(service.getTransport().Equals("tcp")); + + Assert.IsTrue(service.getHost().Equals("localhost")); + Assert.IsTrue(service.getPort() == 5672); + } + + [Test] + public void SingleTransportMultiOptionURL() + { + String url = "amqp://guest:guest@default/temp?brokerlist='tcp://localhost:5672',routingkey='jim',timeout='200',immediatedelivery='true'"; + + ConnectionInfo connectionurl = QpidConnectionInfo.FromUrl(url); + + Assert.IsTrue(connectionurl.GetFailoverMethod() == null); + Assert.IsTrue(connectionurl.GetUsername().Equals("guest")); + Assert.IsTrue(connectionurl.GetPassword().Equals("guest")); + Assert.IsTrue(connectionurl.GetVirtualHost().Equals("/temp")); + + Assert.IsTrue(connectionurl.GetBrokerCount() == 1); + + BrokerInfo service = connectionurl.GetBrokerInfo(0); + + Assert.IsTrue(service.getTransport().Equals("tcp")); + + Assert.IsTrue(service.getHost().Equals("localhost")); + Assert.IsTrue(service.getPort() == 5672); + + Assert.IsTrue(connectionurl.GetOption("routingkey").Equals("jim")); + Assert.IsTrue(connectionurl.GetOption("timeout").Equals("200")); + Assert.IsTrue(connectionurl.GetOption("immediatedelivery").Equals("true")); + } + + [Test] + public void SinglevmURL() + { + String url = "amqp://guest:guest@default/messages?brokerlist='vm://default:2'"; + + ConnectionInfo connectionurl = QpidConnectionInfo.FromUrl(url); + + Assert.IsTrue(connectionurl.GetFailoverMethod() == null); + Assert.IsTrue(connectionurl.GetUsername().Equals("guest")); + Assert.IsTrue(connectionurl.GetPassword().Equals("guest")); + Assert.IsTrue(connectionurl.GetVirtualHost().Equals("/messages")); + + Assert.IsTrue(connectionurl.GetBrokerCount() == 1); + + BrokerInfo service = connectionurl.GetBrokerInfo(0); + + Assert.IsTrue(service.getTransport().Equals("vm")); + Assert.AreEqual("localhost", service.getHost()); + Assert.AreEqual(2, service.getPort()); + } + + [Test] + public void FailoverVMURL() + { + String url = "amqp://ritchiem:bob@default/temp?brokerlist='vm://default:2;vm://default:3',failover='roundrobin'"; + + ConnectionInfo connectionurl = QpidConnectionInfo.FromUrl(url); + + Assert.IsTrue(connectionurl.GetFailoverMethod().Equals("roundrobin")); + Assert.IsTrue(connectionurl.GetUsername().Equals("ritchiem")); + Assert.IsTrue(connectionurl.GetPassword().Equals("bob")); + Assert.IsTrue(connectionurl.GetVirtualHost().Equals("/temp")); + + Assert.AreEqual(2, connectionurl.GetBrokerCount()); + + BrokerInfo service = connectionurl.GetBrokerInfo(0); + + Assert.IsTrue(service.getTransport().Equals("vm")); + Assert.AreEqual("localhost", service.getHost()); + Assert.IsTrue(service.getPort() == 2); + + service = connectionurl.GetBrokerInfo(1); + Assert.IsTrue(service.getTransport().Equals("vm")); + Assert.AreEqual("localhost", service.getHost()); + Assert.IsTrue(service.getPort() == 3); + } + + [Test] + public void NoVirtualHostURL() + { + String url = "amqp://user@default?brokerlist='tcp://localhost:5672'"; + + try + { + QpidConnectionInfo.FromUrl(url); + Assert.Fail("URL has no virtual host should not parse"); + } + catch (UrlSyntaxException e) + { + // This should occur. + } + } + + [Test] + public void NoClientID() + { + String url = "amqp://user:@default/test?brokerlist='tcp://localhost:5672'"; + + ConnectionInfo connectionurl = QpidConnectionInfo.FromUrl(url); + + Assert.IsTrue(connectionurl.GetUsername().Equals("user")); + Assert.IsTrue(connectionurl.GetPassword().Equals("")); + Assert.IsTrue(connectionurl.GetVirtualHost().Equals("/test")); + Assert.IsTrue(connectionurl.GetClientName().StartsWith(Dns.GetHostName())); + + Assert.IsTrue(connectionurl.GetBrokerCount() == 1); + } + + [Test] + public void WrongOptionSeparatorInOptions() + { + String url = "amqp://guest:guest@default/test?brokerlist='tcp://localhost:5672;tcp://localhost:5673'+failover='roundrobin'"; + try + { + QpidConnectionInfo.FromUrl(url); + Assert.Fail("URL Should not parse"); + } + catch (UrlSyntaxException urise) + { + Assert.IsTrue(urise.Message.Equals("Unterminated option. Possible illegal option separator:'+'")); + } + + } + + [Test] + public void NoUserDetailsProvidedWithClientID() + + { + String url = "amqp://clientID/test?brokerlist='tcp://localhost:5672;tcp://localhost:5673'"; + try + { + QpidConnectionInfo.FromUrl(url); + Assert.Fail("URL Should not parse"); + } + catch (UrlSyntaxException urise) + { + Assert.IsTrue(urise.Message.StartsWith("User information not found on url")); + } + + } + + [Test] + public void NoUserDetailsProvidedNOClientID() + + { + String url = "amqp:///test@default?brokerlist='tcp://localhost:5672;tcp://localhost:5673'"; + try + { + QpidConnectionInfo.FromUrl(url); + Assert.Fail("URL Should not parse"); + } + catch (UrlSyntaxException urise) + { + + Assert.IsTrue(urise.Message.StartsWith("User information not found on url")); + } + + } + + [Test] + public void CheckVirtualHostFormat() + { + String url = "amqp://guest:guest@default/t.-_+!=:?brokerlist='tcp://localhost:5672'"; + + ConnectionInfo connection = QpidConnectionInfo.FromUrl(url); + Assert.IsTrue(connection.GetVirtualHost().Equals("/t.-_+!=:")); + } + + [Test] + public void CheckDefaultPort() + { + String url = "amqp://guest:guest@default/test=:?brokerlist='tcp://localhost'"; + + ConnectionInfo connection = QpidConnectionInfo.FromUrl(url); + + BrokerInfo broker = connection.GetBrokerInfo(0); + Assert.IsTrue(broker.getPort() == BrokerInfoConstants.DEFAULT_PORT); + + } + + [Test] + public void CheckMissingFinalQuote() + { + String url = "amqp://guest:guest@id/test" + "?brokerlist='tcp://localhost:5672"; + + try + { + QpidConnectionInfo.FromUrl(url); + } + catch (UrlSyntaxException e) + { +// Assert.AreEqual("Unterminated option at index 32: brokerlist='tcp://localhost:5672", +// e.Message); + Assert.AreEqual("Unterminated option", e.Message); + } + } + } +} diff --git a/dotnet/Qpid.Client/Client/AMQConnection.cs b/dotnet/Qpid.Client/Client/AMQConnection.cs index 5c0537429e..1bfa3b4c26 100644 --- a/dotnet/Qpid.Client/Client/AMQConnection.cs +++ b/dotnet/Qpid.Client/Client/AMQConnection.cs @@ -128,7 +128,7 @@ namespace Qpid.Client } _log.Info("ConnectionInfo: " + connectionInfo); _connectionInfo = connectionInfo; - _log.Info("password = " + _connectionInfo.getPassword()); + _log.Info("password = " + _connectionInfo.GetPassword()); _failoverPolicy = new FailoverPolicy(connectionInfo); // We are not currently connected. @@ -503,7 +503,7 @@ namespace Qpid.Client { get { - return _connectionInfo.getUsername(); + return _connectionInfo.GetUsername(); } } @@ -511,7 +511,7 @@ namespace Qpid.Client { get { - return _connectionInfo.getPassword(); + return _connectionInfo.GetPassword(); } } @@ -519,7 +519,7 @@ namespace Qpid.Client { get { - return _connectionInfo.getVirtualHost(); + return _connectionInfo.GetVirtualHost(); } } @@ -796,7 +796,7 @@ namespace Qpid.Client public String toURL() { - return _connectionInfo.asUrl(); + return _connectionInfo.AsUrl(); } class HeartBeatThread diff --git a/dotnet/Qpid.Client/Client/AMQDestination.cs b/dotnet/Qpid.Client/Client/AMQDestination.cs index 7ea6db4ee8..e2c4778a28 100644 --- a/dotnet/Qpid.Client/Client/AMQDestination.cs +++ b/dotnet/Qpid.Client/Client/AMQDestination.cs @@ -33,6 +33,7 @@ namespace Qpid.Client public bool IsDurable { + get { return _isDurable; } } diff --git a/dotnet/Qpid.Client/Client/AmqBrokerInfo.cs b/dotnet/Qpid.Client/Client/AmqBrokerInfo.cs index 88569b4fc0..3fc2512efb 100644 --- a/dotnet/Qpid.Client/Client/AmqBrokerInfo.cs +++ b/dotnet/Qpid.Client/Client/AmqBrokerInfo.cs @@ -28,7 +28,7 @@ namespace Qpid.Client public class AmqBrokerInfo : BrokerInfo { public readonly string URL_FORMAT_EXAMPLE = - "<transport>://<hostname>[:<port Default=\""+BrokerDetailsConstants.DEFAULT_PORT+"\">][?<option>='<value>'[,<option>='<value>']]"; + "<transport>://<hostname>[:<port Default=\""+BrokerInfoConstants.DEFAULT_PORT+"\">][?<option>='<value>'[,<option>='<value>']]"; public const long DEFAULT_CONNECT_TIMEOUT = 30000L; @@ -41,106 +41,133 @@ namespace Qpid.Client { } - // TODO: port URL parsing. public AmqBrokerInfo(string url) { - throw new NotImplementedException(); -// this(); -// // URL should be of format tcp://host:port?option='value',option='value' -// try -// { -// URI connection = new URI(url); -// -// string transport = connection.getScheme(); -// -// // Handles some defaults to minimise changes to existing broker URLS e.g. localhost -// if (transport != null) -// { -// //todo this list of valid transports should be enumerated somewhere -// if ((!(transport.equalsIgnoreCase("vm") || -// transport.equalsIgnoreCase("tcp")))) -// { -// if (transport.equalsIgnoreCase("localhost")) -// { -// connection = new URI(DEFAULT_TRANSPORT + "://" + url); -// transport = connection.getScheme(); -// } -// else -// { -// if (url.charAt(transport.length()) == ':' && url.charAt(transport.length()+1) != '/' ) -// { -// //Then most likely we have a host:port value -// connection = new URI(DEFAULT_TRANSPORT + "://" + url); -// transport = connection.getScheme(); -// } -// else -// { -// URLHelper.parseError(0, transport.length(), "Unknown transport", url); -// } -// } -// } -// } -// else -// { -// //Default the transport -// connection = new URI(DEFAULT_TRANSPORT + "://" + url); -// transport = connection.getScheme(); -// } -// -// if (transport == null) -// { -// URLHelper.parseError(-1, "Unknown transport:'" + transport + "'" + -// " In broker URL:'" + url + "' Format: " + URL_FORMAT_EXAMPLE, ""); -// } -// -// setTransport(transport); -// -// string host = connection.getHost(); -// -// // Fix for Java 1.5 -// if (host == null) -// { -// host = ""; -// } -// -// setHost(host); -// -// int port = connection.getPort(); -// -// if (port == -1) -// { -// // Another fix for Java 1.5 URI handling -// string auth = connection.getAuthority(); -// -// if (auth != null && auth.startsWith(":")) -// { -// setPort(Integer.parseInt(auth.substring(1))); -// } -// else -// { -// setPort(DEFAULT_PORT); -// } -// } -// else -// { -// setPort(port); -// } -// -// string querystring = connection.getQuery(); -// -// URLHelper.parseOptions(_options, querystring); -// -// //Fragment is #string (not used) -// } -// catch (URISyntaxException uris) -// { -// if (uris instanceof URLSyntaxException) + // URL should be of format tcp://host:port?option='value',option='value' + try + { + Uri connection = new Uri(url); + + String transport = connection.Scheme; + + // Handles some defaults to minimise changes to existing broker URLS e.g. localhost + if (transport != null) + { + transport = transport.ToLower(); + //todo this list of valid transports should be enumerated somewhere + if ((!(transport.Equals("vm") || transport.Equals("tcp")))) + { + if (transport.Equals("localhost")) + { + connection = new Uri(BrokerInfoConstants.DEFAULT_TRANSPORT + "://" + url); + transport = connection.Scheme; + } + else + { + if (url[transport.Length] == ':' && url[transport.Length + 1] != '/') + { + //Then most likely we have a host:port value + connection = new Uri(BrokerInfoConstants.DEFAULT_TRANSPORT + "://" + url); + transport = connection.Scheme; + } + else + { + URLHelper.parseError(0, transport.Length, "Unknown transport", url); + } + } + } + } + else + { + //Default the transport + connection = new Uri(BrokerInfoConstants.DEFAULT_TRANSPORT + "://" + url); + transport = connection.Scheme; + } + + if (transport == null) + { + URLHelper.parseError(-1, "Unknown transport:'" + transport + "'" + + " In broker URL:'" + url + "' Format: " + URL_FORMAT_EXAMPLE, ""); + } + + setTransport(transport); + + String host = connection.Host; + if (!host.Equals("default")) setHost(host); + + int port = connection.Port; + + if (port == -1) + { + // Fix for when there is port data but it is not automatically parseable by getPort(). + String auth = connection.Authority; + + if (auth != null && auth.Contains(":")) + { + int start = auth.IndexOf(":") + 1; + int end = start; + bool looking = true; + bool found = false; + //Walk the authority looking for a port value. + while (looking) + { + try + { + end++; + int.Parse(auth.Substring(start, end-start+1)); + + if (end >= auth.Length) + { + looking = false; + found = true; + } + } + catch (Exception nfe) // XXX: should catch only "NumberFormatException" here + { + looking = false; + } + + } + if (found) + { + setPort(int.Parse(auth.Substring(start, end-start+1))); + } + else + { + URLHelper.parseError(connection.ToString().IndexOf(connection.Authority) + end - 1, + "Illegal character in port number", connection.ToString()); + } + } + else + { + setPort(BrokerInfoConstants.DEFAULT_PORT); + } + } + else + { + setPort(port); + } + + String queryString = connection.Query; + if (queryString.Length > 0 && queryString[0] == '?') + { + queryString = queryString.Substring(1); + } + + URLHelper.parseOptions(_options, queryString); + + //Fragment is #string (not used) + } + catch (UriFormatException uris) + { + throw uris; +// if (uris is UrlSyntaxException) // { -// throw (URLSyntaxException) uris; +// throw uris; // } // // URLHelper.parseError(uris.getIndex(), uris.getReason(), uris.getInput()); -// } + } } public AmqBrokerInfo(string transport, string host, int port, bool useSSL) : this() @@ -151,7 +178,7 @@ namespace Qpid.Client if (useSSL) { - setOption(BrokerDetailsConstants.OPTIONS_SSL, "true"); + setOption(BrokerInfoConstants.OPTIONS_SSL, "true"); } } @@ -197,11 +224,11 @@ namespace Qpid.Client public long getTimeout() { - if (_options.ContainsKey(BrokerDetailsConstants.OPTIONS_CONNECT_TIMEOUT)) + if (_options.ContainsKey(BrokerInfoConstants.OPTIONS_CONNECT_TIMEOUT)) { try { - return long.Parse((string)_options[BrokerDetailsConstants.OPTIONS_CONNECT_TIMEOUT]); + return long.Parse((string)_options[BrokerInfoConstants.OPTIONS_CONNECT_TIMEOUT]); } catch (FormatException) { @@ -209,12 +236,12 @@ namespace Qpid.Client } } - return BrokerDetailsConstants.DEFAULT_CONNECT_TIMEOUT; + return BrokerInfoConstants.DEFAULT_CONNECT_TIMEOUT; } public void setTimeout(long timeout) { - setOption(BrokerDetailsConstants.OPTIONS_CONNECT_TIMEOUT, timeout.ToString()); + setOption(BrokerInfoConstants.OPTIONS_CONNECT_TIMEOUT, timeout.ToString()); } public override string ToString() @@ -247,8 +274,9 @@ namespace Qpid.Client BrokerInfo bd = (BrokerInfo) obj; return StringEqualsIgnoreCase(_host, bd.getHost()) && - _port == bd.getPort(); - } + _port == bd.getPort() && + _transport == bd.getTransport(); + } public override int GetHashCode() { @@ -296,9 +324,9 @@ namespace Qpid.Client // or simply force users to conform to OPTIONS_SSL // todo make case insensitive by trying ssl Ssl sSl ssL SSl SsL sSL SSL - if (_options.ContainsKey(BrokerDetailsConstants.OPTIONS_SSL)) + if (_options.ContainsKey(BrokerInfoConstants.OPTIONS_SSL)) { - return StringEqualsIgnoreCase((string)_options[BrokerDetailsConstants.OPTIONS_SSL], "true"); + return StringEqualsIgnoreCase((string)_options[BrokerInfoConstants.OPTIONS_SSL], "true"); } return false; @@ -306,7 +334,7 @@ namespace Qpid.Client public void useSSL(bool ssl) { - setOption(BrokerDetailsConstants.OPTIONS_SSL, ssl.ToString()); + setOption(BrokerInfoConstants.OPTIONS_SSL, ssl.ToString()); } } } diff --git a/dotnet/Qpid.Client/Client/QpidConnectionInfo.cs b/dotnet/Qpid.Client/Client/QpidConnectionInfo.cs index f0c4c91db8..6c49a6c7ff 100644 --- a/dotnet/Qpid.Client/Client/QpidConnectionInfo.cs +++ b/dotnet/Qpid.Client/Client/QpidConnectionInfo.cs @@ -21,11 +21,341 @@ using System; using System.Collections; using System.Net; +using System.Text; +using System.Text.RegularExpressions; using log4net; using Qpid.Client.qms; namespace Qpid.Client { + + public class URLHelper + { + public static char DEFAULT_OPTION_SEPERATOR = '&'; + public static char ALTERNATIVE_OPTION_SEPARATOR = ','; + public static char BROKER_SEPARATOR = ';'; + + /// <summary> + /// + /// </summary> + /// <param name="optionMap"></param> + /// <param name="options"></param> + public static void parseOptions(IDictionary optionMap, string options) + { + //options looks like this + //brokerlist='tcp://host:port?option='value',option='value';vm://:3/virtualpath?option='value'',failover='method?option='value',option='value'' + + if (options == null || options.IndexOf('=') == -1) + { + return; + } + + int optionIndex = options.IndexOf('='); + + String option = options.Substring(0, optionIndex); + + int length = options.Length; + + int nestedQuotes = 0; + + // to store index of final "'" + int valueIndex = optionIndex; + + //Walk remainder of url. + while (nestedQuotes > 0 || valueIndex < length) + { + valueIndex++; + + if (valueIndex >= length) + { + break; + } + + if (options[valueIndex] == '\'') + { + if (valueIndex + 1 < options.Length) + { + if (options[valueIndex + 1] == DEFAULT_OPTION_SEPERATOR || + options[valueIndex + 1] == ALTERNATIVE_OPTION_SEPARATOR || + options[valueIndex + 1] == BROKER_SEPARATOR || + options[valueIndex + 1] == '\'') + { + nestedQuotes--; + // System.out.println( + // options + "\n" + "-" + nestedQuotes + ":" + getPositionString(valueIndex - 2, 1)); + if (nestedQuotes == 0) + { + //We've found the value of an option + break; + } + } + else + { + nestedQuotes++; + // System.out.println( + // options + "\n" + "+" + nestedQuotes + ":" + getPositionString(valueIndex - 2, 1)); + } + } + else + { + // We are at the end of the string + // Check to see if we are corectly closing quotes + if (options[valueIndex] == '\'') + { + nestedQuotes--; + } + + break; + } + } + } + + if (nestedQuotes != 0 || valueIndex < (optionIndex + 2)) + { + int sepIndex = 0; + + //Try and identify illegal separator character + if (nestedQuotes > 1) + { + for (int i = 0; i < nestedQuotes; i++) + { + sepIndex = options.IndexOf('\'', sepIndex); + sepIndex++; + } + } + + if (sepIndex >= options.Length || sepIndex == 0) + { + parseError(valueIndex, "Unterminated option", options); + } + else + { + parseError(sepIndex, "Unterminated option. Possible illegal option separator:'" + + options[sepIndex] + "'", options); + } + } + + // optionIndex +2 to skip "='" + int sublen = valueIndex - (optionIndex + 2); + String value = options.Substring(optionIndex + 2, sublen); + + optionMap.Add(option, value); + + if (valueIndex < (options.Length - 1)) + { + //Recurse to get remaining options + parseOptions(optionMap, options.Substring(valueIndex + 2)); + } + } + + + public static void parseError(int index, String error, String url) + { + parseError(index, 1, error, url); + } + + public static void parseError(int index, int length, String error, String url) + { + throw new UrlSyntaxException(url, error, index, length); + } + + public static String printOptions(Hashtable options) + { + if (options.Count == 0) + { + return ""; + } + else + { + StringBuilder sb = new StringBuilder(); + 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.Remove(sb.Length - 1, 1); + // sb.deleteCharAt(sb.length() - 1); + + return sb.ToString(); + } + } + + } + + public class QpidConnectionUrl + { + internal static ConnectionInfo FromUrl(string fullURL) + { + //_url = fullURL; + ConnectionInfo connectionInfo = new QpidConnectionInfo(); + + + // _options = new HashMap<String, String>(); + // _brokers = new LinkedList(); + // _failoverOptions = new HashMap<String, String>(); + + // Connection URL format + //amqp://[user:pass@][clientid]/virtualhost?brokerlist='tcp://host:port?option=\'value\',option=\'value\';vm://:3/virtualpath?option=\'value\'',failover='method?option=\'value\',option='value''" + // Options are of course optional except for requiring a single broker in the broker list. + try + { + Uri connection = new Uri(fullURL); + + if (connection.Scheme == null || !(connection.Scheme.Equals(ConnectionUrlConstants.AMQ_PROTOCOL))) + { + throw new UrlSyntaxException(fullURL, "Not an AMQP URL"); + } + + if (connection.Host != null && connection.Host.Length > 0 && !connection.Host.Equals("default")) + { + connectionInfo.SetClientName(connection.Host); + } + + String userInfo = connection.UserInfo; + if (userInfo == null || userInfo.Length == 0) + { + URLHelper.parseError(ConnectionUrlConstants.AMQ_PROTOCOL.Length + 3, + "User information not found on url", fullURL); + } + else + { + parseUserInfo(userInfo, fullURL, connectionInfo); + } + String virtualHost = connection.AbsolutePath; // XXX: is AbsolutePath corrrect? + + if (virtualHost != null && (!virtualHost.Equals(""))) + { + connectionInfo.SetVirtualHost(virtualHost); + } + else + { + int authLength = connection.Authority.Length; + int start = ConnectionUrlConstants.AMQ_PROTOCOL.Length + 3; + int testIndex = start + authLength; + if (testIndex < fullURL.Length && fullURL[testIndex] == '?') + { + URLHelper.parseError(start, testIndex - start, "Virtual host found", fullURL); + } + else + { + URLHelper.parseError(-1, "Virtual host not specified", fullURL); + } + + } + + QpidConnectionInfo qci = (QpidConnectionInfo)connectionInfo; + string query = connection.Query; + if (query[0] == '?') query = query.Substring(1); + URLHelper.parseOptions(qci.GetOptions(), query); + + processOptions(connectionInfo); + + //Fragment is #string (not used) + //System.out.println(connection.getFragment()); + return connectionInfo; + } + catch (UriFormatException uris) + { + throw uris; + // if (uris is UrlSyntaxException) + // { + // throw uris; + // } + // + // int slash = fullURL.IndexOf("\\"); + // + // if (slash == -1) + // { + // URLHelper.parseError(uris.GetIndex(), uris.getReason(), uris.getInput()); + // } + // else + // { + // if (slash != 0 && fullURL.charAt(slash - 1) == ':') + // { + // URLHelper.parseError(slash - 2, fullURL.indexOf('?') - slash + 2, "Virtual host looks like a windows path, forward slash not allowed in URL", fullURL); + // } + // else + // { + // URLHelper.parseError(slash, "Forward slash not allowed in URL", fullURL); + // } + // } + } + } + + private static void parseUserInfo(String userinfo, string fullUrl, ConnectionInfo connectionInfo) + { + //user info = user:pass + + int colonIndex = userinfo.IndexOf(':'); + + if (colonIndex == -1) + { + URLHelper.parseError(ConnectionUrlConstants.AMQ_PROTOCOL.Length + 3, + userinfo.Length, "Null password in user information not allowed.", fullUrl); + } + else + { + connectionInfo.setUsername(userinfo.Substring(0, colonIndex)); + connectionInfo.SetPassword(userinfo.Substring(colonIndex + 1)); + } + } + + private static void processOptions(ConnectionInfo connectionInfo) + { + string brokerlist = connectionInfo.GetOption(ConnectionUrlConstants.OPTIONS_BROKERLIST); + if (brokerlist != null) + { + //brokerlist tcp://host:port?option='value',option='value';vm://:3/virtualpath?option='value' + Regex splitter = new Regex("" + URLHelper.BROKER_SEPARATOR); + + foreach (string broker in splitter.Split(brokerlist)) + { + connectionInfo.AddBrokerInfo(new AmqBrokerInfo(broker)); + } + + connectionInfo.SetOption(ConnectionUrlConstants.OPTIONS_BROKERLIST, null); + // _options.remove(OPTIONS_BROKERLIST); + } + + string failover = connectionInfo.GetOption(ConnectionUrlConstants.OPTIONS_FAILOVER); + if (failover != null) + { + // failover='method?option='value',option='value'' + + int methodIndex = failover.IndexOf('?'); + + if (methodIndex > -1) + { + connectionInfo.SetFailoverMethod(failover.Substring(0, methodIndex)); + QpidConnectionInfo qpidConnectionInfo = (QpidConnectionInfo)connectionInfo; + URLHelper.parseOptions(qpidConnectionInfo.GetFailoverOptions(), + failover.Substring(methodIndex + 1)); + } + else + { + connectionInfo.SetFailoverMethod(failover); + } + + connectionInfo.SetOption(ConnectionUrlConstants.OPTIONS_FAILOVER, null); + // _options.remove(OPTIONS_FAILOVER); + } + } + + internal static ConnectionInfo FromUri(Uri uri) + { + return null; // FIXME + + } + } + public class QpidConnectionInfo : ConnectionInfo { private static readonly ILog _logger = LogManager.GetLogger(typeof(QpidConnectionInfo)); @@ -40,7 +370,22 @@ namespace Qpid.Client IList _brokerInfos = new ArrayList(); // List<BrokerInfo> string _clientName = String.Format("{0}{1:G}", Dns.GetHostName(), DateTime.Now.Ticks); - public string asUrl() + public IDictionary GetFailoverOptions() + { + return _failoverOptions; + } + + public IDictionary GetOptions() + { + return _options; + } + + public static ConnectionInfo FromUrl(String url) + { + return QpidConnectionUrl.FromUrl(url); + } + + public string AsUrl() { string result = "amqp://"; foreach (BrokerInfo info in _brokerInfos) @@ -48,25 +393,30 @@ namespace Qpid.Client result += info.ToString(); } return result; - + } - public string getFailoverMethod() + public string GetFailoverMethod() { return _failoverMethod; } - public string getFailoverOption(string key) + public void SetFailoverMethod(string failoverMethod) + { + _failoverMethod = failoverMethod; + } + + public string GetFailoverOption(string key) { - return (string) _failoverOptions[key]; + return (string)_failoverOptions[key]; } - public int getBrokerCount() + public int GetBrokerCount() { return _brokerInfos.Count; } - public BrokerInfo GetBrokerDetails(int index) + public BrokerInfo GetBrokerInfo(int index) { return (BrokerInfo)_brokerInfos[index]; } @@ -94,7 +444,7 @@ namespace Qpid.Client _clientName = clientName; } - public string getUsername() + public string GetUsername() { return _username; } @@ -104,39 +454,39 @@ namespace Qpid.Client _username = username; } - public string getPassword() + public string GetPassword() { return _password; } - public void setPassword(string password) + public void SetPassword(string password) { _password = password; } - public string getVirtualHost() + public string GetVirtualHost() { return _virtualHost; } - public void setVirtualHost(string virtualHost) + public void SetVirtualHost(string virtualHost) { _virtualHost = virtualHost; } - public string getOption(string key) + public string GetOption(string key) { - return (string) _options[key]; + return (string)_options[key]; } - public void setOption(string key, string value) + public void SetOption(string key, string value) { _options[key] = value; } - + public override string ToString() { - return asUrl(); + return AsUrl(); } } } diff --git a/dotnet/Qpid.Client/Qpid.Client.csproj b/dotnet/Qpid.Client/Qpid.Client.csproj index eb84402e1f..b3a17a7a6d 100644 --- a/dotnet/Qpid.Client/Qpid.Client.csproj +++ b/dotnet/Qpid.Client/Qpid.Client.csproj @@ -103,6 +103,7 @@ <Compile Include="qms\failover\FailoverMethod.cs" />
<Compile Include="qms\failover\FailoverRoundRobin.cs" />
<Compile Include="qms\failover\FailoverSingleServer.cs" />
+ <Compile Include="qms\UrlSyntaxException.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Qpid.Codec\Qpid.Codec.csproj">
diff --git a/dotnet/Qpid.Client/qms/BrokerInfo.cs b/dotnet/Qpid.Client/qms/BrokerInfo.cs index dd0504968e..6fe02403b7 100644 --- a/dotnet/Qpid.Client/qms/BrokerInfo.cs +++ b/dotnet/Qpid.Client/qms/BrokerInfo.cs @@ -26,7 +26,7 @@ namespace Qpid.Client.qms /// Know URL option names. /// <seealso cref="ConnectionInfo"/> /// </summary> - public class BrokerDetailsConstants + public class BrokerInfoConstants { public const String OPTIONS_RETRY = "retries"; public const String OPTIONS_SSL = ConnectionUrlConstants.OPTIONS_SSL; diff --git a/dotnet/Qpid.Client/qms/ConnectionInfo.cs b/dotnet/Qpid.Client/qms/ConnectionInfo.cs index 1d099daa3e..8ac11ec1ab 100644 --- a/dotnet/Qpid.Client/qms/ConnectionInfo.cs +++ b/dotnet/Qpid.Client/qms/ConnectionInfo.cs @@ -39,15 +39,16 @@ namespace Qpid.Client.qms */ public interface ConnectionInfo { - string asUrl(); + string AsUrl(); - string getFailoverMethod(); + string GetFailoverMethod(); + void SetFailoverMethod(string failoverMethod); - string getFailoverOption(string key); + string GetFailoverOption(string key); - int getBrokerCount(); + int GetBrokerCount(); - BrokerInfo GetBrokerDetails(int index); + BrokerInfo GetBrokerInfo(int index); void AddBrokerInfo(BrokerInfo broker); @@ -57,20 +58,20 @@ namespace Qpid.Client.qms void SetClientName(string clientName); - string getUsername(); + string GetUsername(); void setUsername(string username); - string getPassword(); + string GetPassword(); - void setPassword(string password); + void SetPassword(string password); - string getVirtualHost(); + string GetVirtualHost(); - void setVirtualHost(string virtualHost); + void SetVirtualHost(string virtualHost); - string getOption(string key); + string GetOption(string key); - void setOption(string key, string value); + void SetOption(string key, string value); } } diff --git a/dotnet/Qpid.Client/qms/FailoverPolicy.cs b/dotnet/Qpid.Client/qms/FailoverPolicy.cs index 15d52491df..5d3eceb58e 100644 --- a/dotnet/Qpid.Client/qms/FailoverPolicy.cs +++ b/dotnet/Qpid.Client/qms/FailoverPolicy.cs @@ -56,9 +56,9 @@ namespace Qpid.Client.qms _methodsRetries = 0; - if (connectionInfo.getFailoverMethod() == null) + if (connectionInfo.GetFailoverMethod() == null) { - if (connectionInfo.getBrokerCount() > 1) + if (connectionInfo.GetBrokerCount() > 1) { method = new FailoverRoundRobin(connectionInfo); } @@ -69,7 +69,7 @@ namespace Qpid.Client.qms } else { - string failoverMethod = connectionInfo.getFailoverMethod(); + string failoverMethod = connectionInfo.GetFailoverMethod(); /* if (failoverMethod.equals(FailoverMethod.RANDOM)) diff --git a/dotnet/Qpid.Client/qms/UrlSyntaxException.cs b/dotnet/Qpid.Client/qms/UrlSyntaxException.cs new file mode 100644 index 0000000000..f7aaf56085 --- /dev/null +++ b/dotnet/Qpid.Client/qms/UrlSyntaxException.cs @@ -0,0 +1,116 @@ +/* + * + * 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.Text; + +namespace Qpid.Client.qms +{ + public class UrlSyntaxException : UriFormatException + { + private string _url; + private int _index; + private int _length; + + public int GetIndex() + { + return _index; + } + + public UrlSyntaxException(String input, String reason) + : this(input, reason, -1) + { + } + + private UrlSyntaxException(string input, string reason, int index) + : + this(input, reason, index, input.Length) + { + } + + public UrlSyntaxException(String url, String error, int index, int length) + : base(error) + { + _url = url; + _index = index; + _length = length; + } + + private static String getPositionString(int index, int length) + { + StringBuilder sb = new StringBuilder(index + 1); + + for (int i = 0; i < index; i++) + { + sb.Append(" "); + } + + if (length > -1) + { + for (int i = 0; i < length; i++) + { + sb.Append('^'); + } + } + + return sb.ToString(); + } + + + public String toString() + { + StringBuilder sb = new StringBuilder(); + +// sb.Append(getReason()); + + if (_index > -1) + { + if (_length != -1) + { + sb.Append(" between indicies "); + sb.Append(_index); + sb.Append(" and "); + sb.Append(_length); + } + else + { + sb.Append(" at index "); + sb.Append(_index); + } + } + + sb.Append(" "); + if (_index != -1) + { + sb.Append("\n"); + } + + sb.Append(_url); + + if (_index != -1) + { + sb.Append("\n"); + sb.Append(getPositionString(_index, _length)); + } + + return sb.ToString(); + } + } +} diff --git a/dotnet/Qpid.Client/qms/failover/FailoverRoundRobin.cs b/dotnet/Qpid.Client/qms/failover/FailoverRoundRobin.cs index c0e832ce21..aac16a40fa 100644 --- a/dotnet/Qpid.Client/qms/failover/FailoverRoundRobin.cs +++ b/dotnet/Qpid.Client/qms/failover/FailoverRoundRobin.cs @@ -65,7 +65,7 @@ namespace Qpid.Client.qms.failover public FailoverRoundRobin(ConnectionInfo connectionDetails) { - if (!(connectionDetails.getBrokerCount() > 0)) + if (!(connectionDetails.GetBrokerCount() > 0)) { throw new ArgumentException("At least one broker details must be specified."); } @@ -75,7 +75,7 @@ namespace Qpid.Client.qms.failover //There is no current broker at startup so set it to -1. _currentBrokerIndex = -1; - String cycleRetries = _connectionDetails.getFailoverOption(ConnectionUrlConstants.OPTIONS_FAILOVER_CYCLE); + String cycleRetries = _connectionDetails.GetFailoverOption(ConnectionUrlConstants.OPTIONS_FAILOVER_CYCLE); if (cycleRetries != null) { @@ -106,7 +106,7 @@ namespace Qpid.Client.qms.failover { return ((_currentCycleRetries < _cycleRetries) || (_currentServerRetry < _serverRetries) - || (_currentBrokerIndex < (_connectionDetails.getBrokerCount() - 1))); + || (_currentBrokerIndex < (_connectionDetails.GetBrokerCount() - 1))); } public void attainedConnection() @@ -122,12 +122,12 @@ namespace Qpid.Client.qms.failover return null; } - return _connectionDetails.GetBrokerDetails(_currentBrokerIndex); + return _connectionDetails.GetBrokerInfo(_currentBrokerIndex); } public BrokerInfo getNextBrokerDetails() { - if (_currentBrokerIndex == (_connectionDetails.getBrokerCount() - 1)) + if (_currentBrokerIndex == (_connectionDetails.GetBrokerCount() - 1)) { if (_currentServerRetry < _serverRetries) { @@ -135,13 +135,13 @@ namespace Qpid.Client.qms.failover { _currentBrokerIndex = 0; - setBroker(_connectionDetails.GetBrokerDetails(_currentBrokerIndex )); + setBroker(_connectionDetails.GetBrokerInfo(_currentBrokerIndex )); - _logger.Info("First Run using " + _connectionDetails.GetBrokerDetails(_currentBrokerIndex)); + _logger.Info("First Run using " + _connectionDetails.GetBrokerInfo(_currentBrokerIndex)); } else { - _logger.Info("Retrying " + _connectionDetails.GetBrokerDetails(_currentBrokerIndex)); + _logger.Info("Retrying " + _connectionDetails.GetBrokerInfo(_currentBrokerIndex)); } _currentServerRetry++; @@ -152,7 +152,7 @@ namespace Qpid.Client.qms.failover //failed to connect to first broker _currentBrokerIndex = 0; - setBroker(_connectionDetails.GetBrokerDetails(_currentBrokerIndex )); + setBroker(_connectionDetails.GetBrokerInfo(_currentBrokerIndex )); // This is zero rather than -1 as we are already retrieving the details. _currentServerRetry = 0; @@ -167,13 +167,13 @@ namespace Qpid.Client.qms.failover { _currentBrokerIndex = 0; - setBroker(_connectionDetails.GetBrokerDetails(_currentBrokerIndex )); + setBroker(_connectionDetails.GetBrokerInfo(_currentBrokerIndex )); - _logger.Info("First Run using " + _connectionDetails.GetBrokerDetails(_currentBrokerIndex)); + _logger.Info("First Run using " + _connectionDetails.GetBrokerInfo(_currentBrokerIndex)); } else { - _logger.Info("Retrying " + _connectionDetails.GetBrokerDetails(_currentBrokerIndex)); + _logger.Info("Retrying " + _connectionDetails.GetBrokerInfo(_currentBrokerIndex)); } _currentServerRetry++; } @@ -181,13 +181,13 @@ namespace Qpid.Client.qms.failover { _currentBrokerIndex++; - setBroker(_connectionDetails.GetBrokerDetails(_currentBrokerIndex )); + setBroker(_connectionDetails.GetBrokerInfo(_currentBrokerIndex )); // This is zero rather than -1 as we are already retrieving the details. _currentServerRetry = 0; } } - return _connectionDetails.GetBrokerDetails(_currentBrokerIndex); + return _connectionDetails.GetBrokerInfo(_currentBrokerIndex); } public void setBroker(BrokerInfo broker) @@ -196,7 +196,7 @@ namespace Qpid.Client.qms.failover int index = _connectionDetails.GetAllBrokerInfos().IndexOf(broker); - String serverRetries = broker.getOption(BrokerDetailsConstants.OPTIONS_RETRY); + String serverRetries = broker.getOption(BrokerInfoConstants.OPTIONS_RETRY); if (serverRetries != null) { @@ -230,7 +230,7 @@ namespace Qpid.Client.qms.failover sb.Append(GetType().Name).Append("\n"); - sb.Append("Broker count: ").Append(_connectionDetails.getBrokerCount()); + sb.Append("Broker count: ").Append(_connectionDetails.GetBrokerCount()); sb.Append("\ncurrent broker index: ").Append(_currentBrokerIndex); sb.Append("\nCycle Retries: ").Append(_cycleRetries); @@ -239,13 +239,13 @@ namespace Qpid.Client.qms.failover sb.Append("\nCurrent Retry:").Append(_currentServerRetry); sb.Append("\n"); - for(int i=0; i < _connectionDetails.getBrokerCount() ; i++) + for(int i=0; i < _connectionDetails.GetBrokerCount() ; i++) { if (i == _currentBrokerIndex) { sb.Append(">"); } - sb.Append(_connectionDetails.GetBrokerDetails(i)); + sb.Append(_connectionDetails.GetBrokerInfo(i)); sb.Append("\n"); } diff --git a/dotnet/Qpid.Client/qms/failover/FailoverSingleServer.cs b/dotnet/Qpid.Client/qms/failover/FailoverSingleServer.cs index 60e4c24987..be29429035 100644 --- a/dotnet/Qpid.Client/qms/failover/FailoverSingleServer.cs +++ b/dotnet/Qpid.Client/qms/failover/FailoverSingleServer.cs @@ -45,9 +45,9 @@ namespace Qpid.Client.qms.failover public FailoverSingleServer(ConnectionInfo connectionDetails) { - if (connectionDetails.getBrokerCount() > 0) + if (connectionDetails.GetBrokerCount() > 0) { - setBroker(connectionDetails.GetBrokerDetails(0)); + setBroker(connectionDetails.GetBrokerInfo(0)); } else { @@ -105,7 +105,7 @@ namespace Qpid.Client.qms.failover } _brokerDetail = broker; - String retries = broker.getOption(BrokerDetailsConstants.OPTIONS_RETRY); + String retries = broker.getOption(BrokerInfoConstants.OPTIONS_RETRY); if (retries != null) { try |