summaryrefslogtreecommitdiff
path: root/qpid/java/client
diff options
context:
space:
mode:
authorRajith Muditha Attapattu <rajith@apache.org>2011-03-01 20:09:56 +0000
committerRajith Muditha Attapattu <rajith@apache.org>2011-03-01 20:09:56 +0000
commit46251b8a6322a90715d0165845c16b377869a645 (patch)
tree21eaf855c20b4c984fd8b18296b1dbeeeff1a24b /qpid/java/client
parent14a92b99b1d72871883754459147b81b830c819b (diff)
downloadqpid-python-46251b8a6322a90715d0165845c16b377869a645.tar.gz
QPID-3099
Added logic to look for the 'host' in the authority field if getHost returns null. Looking at the code that follows, you could definitely make more improvements. However since we are close to the 0.10 release I'd leave things as it is for the time being. I have also added test cases to cover the issues highlighted by the respective JIRA. git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1076011 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java/client')
-rw-r--r--qpid/java/client/src/main/java/org/apache/qpid/client/AMQBrokerDetails.java15
-rw-r--r--qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/connectionurl/ConnectionURLTest.java31
2 files changed, 46 insertions, 0 deletions
diff --git a/qpid/java/client/src/main/java/org/apache/qpid/client/AMQBrokerDetails.java b/qpid/java/client/src/main/java/org/apache/qpid/client/AMQBrokerDetails.java
index ee52cd50af..b31dd2bc91 100644
--- a/qpid/java/client/src/main/java/org/apache/qpid/client/AMQBrokerDetails.java
+++ b/qpid/java/client/src/main/java/org/apache/qpid/client/AMQBrokerDetails.java
@@ -105,6 +105,21 @@ public class AMQBrokerDetails implements BrokerDetails
if (host == null)
{
host = "";
+
+ String auth = connection.getAuthority();
+ if (auth != null)
+ {
+ // contains both host & port myhost:5672
+ if (auth.contains(":"))
+ {
+ host = auth.substring(0,auth.indexOf(":"));
+ }
+ else
+ {
+ host = auth;
+ }
+ }
+
}
setHost(host);
diff --git a/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/connectionurl/ConnectionURLTest.java b/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/connectionurl/ConnectionURLTest.java
index 2be3720c20..2c5fa0112e 100644
--- a/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/connectionurl/ConnectionURLTest.java
+++ b/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/connectionurl/ConnectionURLTest.java
@@ -549,6 +549,37 @@ public class ConnectionURLTest extends TestCase
assertTrue("String representation should contain options and values", url.toString().contains("maxprefetch='12345'"));
}
+ public void testHostNamesWithUnderScore() throws URLSyntaxException
+ {
+ String url = "amqp://guest:guest@clientid/test?brokerlist='tcp://under_score:6672'";
+
+ ConnectionURL connectionurl = new AMQConnectionURL(url);
+
+ assertTrue(connectionurl.getUsername().equals("guest"));
+ assertTrue(connectionurl.getPassword().equals("guest"));
+ assertTrue(connectionurl.getVirtualHost().equals("/test"));
+
+ assertTrue(connectionurl.getBrokerCount() == 1);
+ BrokerDetails service = connectionurl.getBrokerDetails(0);
+ assertTrue(service.getTransport().equals("tcp"));
+ assertTrue(service.getHost().equals("under_score"));
+ assertTrue(service.getPort() == 6672);
+
+ url = "amqp://guest:guest@clientid/test?brokerlist='tcp://under_score'";
+
+ connectionurl = new AMQConnectionURL(url);
+
+ assertTrue(connectionurl.getUsername().equals("guest"));
+ assertTrue(connectionurl.getPassword().equals("guest"));
+ assertTrue(connectionurl.getVirtualHost().equals("/test"));
+
+ assertTrue(connectionurl.getBrokerCount() == 1);
+ service = connectionurl.getBrokerDetails(0);
+ assertTrue(service.getTransport().equals("tcp"));
+ assertTrue(service.getHost().equals("under_score"));
+ assertTrue(service.getPort() == 5672);
+ }
+
public static junit.framework.Test suite()
{
return new junit.framework.TestSuite(ConnectionURLTest.class);