diff options
Diffstat (limited to 'qpid')
3 files changed, 54 insertions, 8 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 f051450260..fefb78d681 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 @@ -26,6 +26,7 @@ import java.util.HashMap; import java.util.Map; import org.apache.qpid.jms.BrokerDetails; +import org.apache.qpid.jms.ConnectionURL; import org.apache.qpid.url.URLHelper; import org.apache.qpid.url.URLSyntaxException; @@ -35,18 +36,28 @@ public class AMQBrokerDetails implements BrokerDetails private int _port; private String _transport; - private Map<String, String> _options; + private Map<String, String> _options = new HashMap<String, String>(); private SSLConfiguration _sslConfiguration; - public AMQBrokerDetails() - { - _options = new HashMap<String, String>(); + public AMQBrokerDetails(){} + + public AMQBrokerDetails(String url)throws URLSyntaxException + { + this(url,null); } - public AMQBrokerDetails(String url) throws URLSyntaxException - { - this(); + public AMQBrokerDetails(String url,Map<String, String> options) throws URLSyntaxException + { + /* According to the wiki the AMQBroker options should default to connection level options. + unless overridden by broker specific options. + Currently there seems to be only one such option (SSL). + */ + if (options != null) + { + _options.put(ConnectionURL.OPTIONS_SSL,options.get(ConnectionURL.OPTIONS_SSL)); + } + // URL should be of format tcp://host:port?option='value',option='value' try { @@ -252,6 +263,23 @@ public class AMQBrokerDetails implements BrokerDetails return BrokerDetails.DEFAULT_CONNECT_TIMEOUT; } + + public boolean useSSL() + { + if (_options.containsKey(ConnectionURL.OPTIONS_SSL)) + { + try + { + return Boolean.parseBoolean(_options.get(ConnectionURL.OPTIONS_SSL)); + } + catch (NumberFormatException nfe) + { + //Do nothing as we will use the default below. + } + } + + return false; + } public void setTimeout(long timeout) { diff --git a/qpid/java/client/src/main/java/org/apache/qpid/jms/BrokerDetails.java b/qpid/java/client/src/main/java/org/apache/qpid/jms/BrokerDetails.java index 0316255b2c..07e1be95dc 100644 --- a/qpid/java/client/src/main/java/org/apache/qpid/jms/BrokerDetails.java +++ b/qpid/java/client/src/main/java/org/apache/qpid/jms/BrokerDetails.java @@ -94,6 +94,8 @@ public interface BrokerDetails SSLConfiguration getSSLConfiguration(); void setSSLConfiguration(SSLConfiguration sslConfiguration); + + boolean useSSL(); String toString(); diff --git a/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/BrokerDetails/BrokerDetailsTest.java b/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/BrokerDetails/BrokerDetailsTest.java index 7bf96b99c1..c3175317e6 100644 --- a/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/BrokerDetails/BrokerDetailsTest.java +++ b/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/BrokerDetails/BrokerDetailsTest.java @@ -20,14 +20,19 @@ */ package org.apache.qpid.test.unit.client.BrokerDetails; +import java.util.HashMap; +import java.util.Map; + import junit.framework.TestCase; import org.apache.qpid.client.AMQBrokerDetails; +import org.apache.qpid.client.AMQConnectionURL; +import org.apache.qpid.jms.ConnectionURL; +import org.apache.qpid.jms.BrokerDetails; import org.apache.qpid.url.URLSyntaxException; public class BrokerDetailsTest extends TestCase { - public void testMultiParameters() throws URLSyntaxException { String url = "tcp://localhost:5672?timeout='200',immediatedelivery='true'"; @@ -86,6 +91,17 @@ public class BrokerDetailsTest extends TestCase } } + + public void testBrokerDefaultsToTopLevelOptions() throws URLSyntaxException + { + String url = "amqp://guest:guest@clientid/test?ssl='false'&brokerlist='tcp://localhost:5672?ssl='true';tcp://myhost:5672'"; + ConnectionURL connectionurl = new AMQConnectionURL(url); + BrokerDetails bd1 = connectionurl.getBrokerDetails(0); + BrokerDetails bd2 = connectionurl.getBrokerDetails(1); + + assertTrue("Broker option should override the top level option",bd1.useSSL()); + assertFalse("Broker options should default to the top level options",bd2.useSSL()); + } public static junit.framework.Test suite() { |