From cc6176cfb9c22ae2cdf56b03d33aca8975b7cd71 Mon Sep 17 00:00:00 2001 From: Keith Wall Date: Wed, 9 Nov 2011 08:58:59 +0000 Subject: QPID-3518: Introduce client side ability to detect server side support. Applied patch from Oleksandr Rudyy and myself. git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@1199662 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/org/apache/qpid/client/AMQConnection.java | 13 ++++++++ .../apache/qpid/client/AMQConnectionDelegate.java | 12 +++++++ .../qpid/client/AMQConnectionDelegate_0_10.java | 38 +++++++++++++++++----- .../qpid/client/AMQConnectionDelegate_8_0.java | 14 ++++++-- .../java/org/apache/qpid/client/AMQSession.java | 4 +-- .../org/apache/qpid/client/AMQSession_0_10.java | 19 ++--------- .../qpid/client/BasicMessageConsumer_0_10.java | 10 ++++-- .../test/unit/message/MessageConverterTest.java | 7 +++- .../qpid/test/unit/message/TestAMQSession.java | 6 ++-- 9 files changed, 88 insertions(+), 35 deletions(-) (limited to 'java/client/src') diff --git a/java/client/src/main/java/org/apache/qpid/client/AMQConnection.java b/java/client/src/main/java/org/apache/qpid/client/AMQConnection.java index 941534c7ff..ad7885f195 100644 --- a/java/client/src/main/java/org/apache/qpid/client/AMQConnection.java +++ b/java/client/src/main/java/org/apache/qpid/client/AMQConnection.java @@ -1402,6 +1402,19 @@ public class AMQConnection extends Closeable implements Connection, QueueConnect return null; } } + + /** + * Tests whether the Broker has advertised support for the named feature. + * + * @param featureName + * + * @return true if the feature is supported, or false otherwise. + */ + boolean isSupportedServerFeature(final String featureName) + { + return _delegate.isSupportedServerFeature(featureName); + } + public boolean isFailingOver() { return (_protocolHandler.getFailoverLatch() != null); diff --git a/java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate.java b/java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate.java index 8768f93c8c..afb0e45f7a 100644 --- a/java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate.java +++ b/java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate.java @@ -65,4 +65,16 @@ public interface AMQConnectionDelegate ProtocolVersion getProtocolVersion(); boolean verifyClientID() throws JMSException, AMQException; + + /** + * Tests whether the server has advertised support for the specified feature + * via the qpid.features server connection property. By convention the feature name + * with begin qpid. followed by one or more words separated by minus signs + * e.g. qpid.jms-selector. + * + * @param featureName name of feature. + * + * @return true if the feature is supported by the server + */ + boolean isSupportedServerFeature(final String featureName); } diff --git a/java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_0_10.java b/java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_0_10.java index 0d48dd5822..5e4f84ce9f 100644 --- a/java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_0_10.java +++ b/java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_0_10.java @@ -1,4 +1,3 @@ -package org.apache.qpid.client; /* * * Licensed to the Apache Software Foundation (ASF) under one @@ -20,6 +19,7 @@ package org.apache.qpid.client; * */ +package org.apache.qpid.client; import java.io.IOException; import java.util.ArrayList; @@ -36,6 +36,7 @@ import org.apache.qpid.AMQException; import org.apache.qpid.client.failover.FailoverException; import org.apache.qpid.client.failover.FailoverProtectedOperation; import org.apache.qpid.client.transport.ClientConnectionDelegate; +import org.apache.qpid.common.ServerPropertyNames; import org.apache.qpid.configuration.ClientProperties; import org.apache.qpid.framing.ProtocolVersion; import org.apache.qpid.jms.BrokerDetails; @@ -62,17 +63,13 @@ public class AMQConnectionDelegate_0_10 implements AMQConnectionDelegate, Connec */ private static final Logger _logger = LoggerFactory.getLogger(AMQConnectionDelegate_0_10.class); - /** - * The name of the UUID property - */ - private static final String UUID_NAME = "qpid.federation_tag"; /** * The AMQ Connection. */ - private AMQConnection _conn; + private final AMQConnection _conn; /** - * The QpidConeection instance that is mapped with thie JMS connection. + * The QpidConeection instance that is mapped with this JMS connection. */ org.apache.qpid.transport.Connection _qpidConnection; private ConnectionException exception = null; @@ -369,7 +366,32 @@ public class AMQConnectionDelegate_0_10 implements AMQConnectionDelegate, Connec public String getUUID() { - return (String)_qpidConnection.getServerProperties().get(UUID_NAME); + return (String)_qpidConnection.getServerProperties().get(ServerPropertyNames.FEDERATION_TAG); + } + + /* + * @see org.apache.qpid.client.AMQConnectionDelegate#isSupportedServerFeature(java.lang.String) + */ + public boolean isSupportedServerFeature(final String featureName) + { + if (featureName == null) + { + throw new IllegalArgumentException("featureName cannot be null"); + } + final Map serverProperties = _qpidConnection.getServerProperties(); + boolean featureSupported = false; + if (serverProperties != null && serverProperties.containsKey(ServerPropertyNames.QPID_FEATURES)) + { + final Object supportServerFeatures = serverProperties.get(ServerPropertyNames.QPID_FEATURES); + featureSupported = supportServerFeatures instanceof List && ((List)supportServerFeatures).contains(featureName); + } + + if (_logger.isDebugEnabled()) + { + _logger.debug("Server support for feature '" + featureName + "' : " + featureSupported); + } + + return featureSupported; } private ConnectionSettings retriveConnectionSettings(BrokerDetails brokerDetail) diff --git a/java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_8_0.java b/java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_8_0.java index b1a22155d6..bff4df0e93 100644 --- a/java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_8_0.java +++ b/java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_8_0.java @@ -24,7 +24,6 @@ import java.io.IOException; import java.net.ConnectException; import java.nio.channels.UnresolvedAddressException; import java.security.GeneralSecurityException; -import java.security.Security; import java.text.MessageFormat; import java.util.ArrayList; import java.util.EnumSet; @@ -44,6 +43,7 @@ import org.apache.qpid.client.protocol.AMQProtocolSession; import org.apache.qpid.client.state.AMQState; import org.apache.qpid.client.state.AMQStateManager; import org.apache.qpid.client.state.StateWaiter; +import org.apache.qpid.common.ServerPropertyNames; import org.apache.qpid.framing.BasicQosBody; import org.apache.qpid.framing.BasicQosOkBody; import org.apache.qpid.framing.ChannelOpenBody; @@ -66,7 +66,7 @@ import org.slf4j.LoggerFactory; public class AMQConnectionDelegate_8_0 implements AMQConnectionDelegate { private static final Logger _logger = LoggerFactory.getLogger(AMQConnectionDelegate_8_0.class); - private AMQConnection _conn; + private final AMQConnection _conn; public void closeConnection(long timeout) throws JMSException, AMQException @@ -379,4 +379,14 @@ public class AMQConnectionDelegate_8_0 implements AMQConnectionDelegate { return true; } + + /* + * @see org.apache.qpid.client.AMQConnectionDelegate#isSupportedServerFeature(java.lang.String) + */ + public boolean isSupportedServerFeature(String featureName) + { + // The Qpid Java Broker 0-8..0-9-1 does not advertise features by the qpid.features property, so for now + // we just hardcode JMS selectors as supported. + return ServerPropertyNames.FEATURE_QPID_JMS_SELECTOR.equals(featureName); + } } diff --git a/java/client/src/main/java/org/apache/qpid/client/AMQSession.java b/java/client/src/main/java/org/apache/qpid/client/AMQSession.java index e8508a62bc..4c4d2c75b1 100644 --- a/java/client/src/main/java/org/apache/qpid/client/AMQSession.java +++ b/java/client/src/main/java/org/apache/qpid/client/AMQSession.java @@ -535,7 +535,7 @@ public abstract class AMQSession map) - { - StringBuilder sb = new StringBuilder(); - sb.append("<"); - if (map != null) - { - for(String key : map.keySet()) - { - sb.append(key).append(" = ").append(map.get(key)).append(" "); - } - } - sb.append(">"); - return sb.toString(); - } - protected void acknowledgeImpl() { RangeSet range = gatherUnackedRangeSet(); diff --git a/java/client/src/main/java/org/apache/qpid/client/BasicMessageConsumer_0_10.java b/java/client/src/main/java/org/apache/qpid/client/BasicMessageConsumer_0_10.java index 0e9c81f2f6..ae2068b75b 100644 --- a/java/client/src/main/java/org/apache/qpid/client/BasicMessageConsumer_0_10.java +++ b/java/client/src/main/java/org/apache/qpid/client/BasicMessageConsumer_0_10.java @@ -20,10 +20,10 @@ package org.apache.qpid.client; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.apache.qpid.client.AMQDestination.AddressOption; -import org.apache.qpid.client.AMQDestination.DestSyntax; import org.apache.qpid.client.failover.FailoverException; import org.apache.qpid.client.message.*; import org.apache.qpid.client.protocol.AMQProtocolHandler; +import org.apache.qpid.common.ServerPropertyNames; import org.apache.qpid.framing.FieldTable; import org.apache.qpid.AMQException; import org.apache.qpid.protocol.AMQConstant; @@ -66,6 +66,9 @@ public class BasicMessageConsumer_0_10 extends BasicMessageConsumer session, AMQProtocolHandler protocolHandler, @@ -80,6 +83,8 @@ public class BasicMessageConsumer_0_10 extends BasicMessageConsumer { - public TestAMQSession() + public TestAMQSession(AMQConnection connection) { - super(null, 0, false, AUTO_ACKNOWLEDGE, null, 0, 0); + super(connection, 0, false, AUTO_ACKNOWLEDGE, null, 0, 0); } public void acknowledgeMessage(long deliveryTag, boolean multiple) -- cgit v1.2.1