From 46251b8a6322a90715d0165845c16b377869a645 Mon Sep 17 00:00:00 2001 From: Rajith Muditha Attapattu Date: Tue, 1 Mar 2011 20:09:56 +0000 Subject: 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 --- .../org/apache/qpid/client/AMQBrokerDetails.java | 15 +++++++++++ .../client/connectionurl/ConnectionURLTest.java | 31 ++++++++++++++++++++++ 2 files changed, 46 insertions(+) (limited to 'qpid/java') 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); -- cgit v1.2.1