You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by or...@apache.org on 2016/04/12 12:37:25 UTC

svn commit: r1738758 - in /qpid/java/branches/6.0.x: ./ client/src/main/java/org/apache/qpid/client/ common/src/main/java/org/apache/qpid/framing/ systests/src/test/java/org/apache/qpid/transport/

Author: orudyy
Date: Tue Apr 12 10:37:25 2016
New Revision: 1738758

URL: http://svn.apache.org/viewvc?rev=1738758&view=rev
Log:
QPID-7189: Fix creation of delegate for AMQP 0-9-1 in response to broker supported protocol on protocol negotiation

          Consistently name the connection delegates
          The previous inconsistency with the naming of 0-91's delegate was caused by the fact that
          AMQP 0-10 implementation misinterpreted 0-91 header.

          Merged from trunk
          svn merge -c 1738135,1738271 ^/qpid/java/trunk

Added:
    qpid/java/branches/6.0.x/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_0_91.java
      - copied unchanged from r1738271, qpid/java/trunk/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_0_91.java
Removed:
    qpid/java/branches/6.0.x/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_9_1.java
Modified:
    qpid/java/branches/6.0.x/   (props changed)
    qpid/java/branches/6.0.x/client/src/main/java/org/apache/qpid/client/AMQConnection.java
    qpid/java/branches/6.0.x/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_0_10.java
    qpid/java/branches/6.0.x/client/src/main/java/org/apache/qpid/client/AMQProtocolHandler.java
    qpid/java/branches/6.0.x/common/src/main/java/org/apache/qpid/framing/ProtocolInitiation.java
    qpid/java/branches/6.0.x/systests/src/test/java/org/apache/qpid/transport/ProtocolNegotiationTest.java

Propchange: qpid/java/branches/6.0.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Apr 12 10:37:25 2016
@@ -9,5 +9,5 @@
 /qpid/branches/java-broker-vhost-refactor/java:1493674-1494547
 /qpid/branches/java-network-refactor/qpid/java:805429-821809
 /qpid/branches/qpid-2935/qpid/java:1061302-1072333
-/qpid/java/trunk:1715445-1715447,1715586,1715940,1716086-1716087,1716127-1716128,1716141,1716153,1716155,1716194,1716204,1716209,1716227,1716277,1716357,1716368,1716370,1716374,1716432,1716444-1716445,1716455,1716461,1716474,1716489,1716497,1716515,1716555,1716602,1716606-1716610,1716619,1716636,1717269,1717299,1717401,1717446,1717449,1717626,1717691,1717735,1717780,1718744,1718889,1718893,1718918,1718922,1719026,1719028,1719033,1719037,1719047,1719051,1720340,1720664,1721151,1721198,1722019-1722020,1722246,1722339,1722416,1722674,1722678,1722683,1722711,1723064,1723194,1723563,1724216,1724251,1724257,1724292,1724375,1724397,1724432,1724582,1724603,1724780,1724843-1724844,1725295,1725569,1725760,1726176,1726244-1726246,1726249,1726358,1726436,1726449,1726456,1726646,1726653,1726755,1726778,1727532,1727555,1727608,1727951,1727954,1728089,1728167,1728302,1728497,1728501,1728524,1728639,1728651,1728772,1729215,1729297,1729347,1729356,1729406,1729408,1729412,1729515,1729638,1729656-1729
 657,1729783,1729828,1729832,1729841,1729851,1729886,1729904,1729973,1730019,1730025,1730052,1730072,1730088,1730494,1730499,1730547,1730559,1730567,1730578,1730585,1730651,1730697,1730712-1730713,1730805,1731029,1731110,1731210,1731225,1731444,1731551,1731612,1732184,1732452,1732461,1732525,1732812,1734452,1736478,1736751,1736838,1737804,1737835,1737853,1737984,1737992,1738119,1738231,1738610,1738731
+/qpid/java/trunk:1715445-1715447,1715586,1715940,1716086-1716087,1716127-1716128,1716141,1716153,1716155,1716194,1716204,1716209,1716227,1716277,1716357,1716368,1716370,1716374,1716432,1716444-1716445,1716455,1716461,1716474,1716489,1716497,1716515,1716555,1716602,1716606-1716610,1716619,1716636,1717269,1717299,1717401,1717446,1717449,1717626,1717691,1717735,1717780,1718744,1718889,1718893,1718918,1718922,1719026,1719028,1719033,1719037,1719047,1719051,1720340,1720664,1721151,1721198,1722019-1722020,1722246,1722339,1722416,1722674,1722678,1722683,1722711,1723064,1723194,1723563,1724216,1724251,1724257,1724292,1724375,1724397,1724432,1724582,1724603,1724780,1724843-1724844,1725295,1725569,1725760,1726176,1726244-1726246,1726249,1726358,1726436,1726449,1726456,1726646,1726653,1726755,1726778,1727532,1727555,1727608,1727951,1727954,1728089,1728167,1728302,1728497,1728501,1728524,1728639,1728651,1728772,1729215,1729297,1729347,1729356,1729406,1729408,1729412,1729515,1729638,1729656-1729
 657,1729783,1729828,1729832,1729841,1729851,1729886,1729904,1729973,1730019,1730025,1730052,1730072,1730088,1730494,1730499,1730547,1730559,1730567,1730578,1730585,1730651,1730697,1730712-1730713,1730805,1731029,1731110,1731210,1731225,1731444,1731551,1731612,1732184,1732452,1732461,1732525,1732812,1734452,1736478,1736751,1736838,1737804,1737835,1737853,1737984,1737992,1738119,1738135,1738231,1738271,1738610,1738731
 /qpid/trunk/qpid:796646-796653

Modified: qpid/java/branches/6.0.x/client/src/main/java/org/apache/qpid/client/AMQConnection.java
URL: http://svn.apache.org/viewvc/qpid/java/branches/6.0.x/client/src/main/java/org/apache/qpid/client/AMQConnection.java?rev=1738758&r1=1738757&r2=1738758&view=diff
==============================================================================
--- qpid/java/branches/6.0.x/client/src/main/java/org/apache/qpid/client/AMQConnection.java (original)
+++ qpid/java/branches/6.0.x/client/src/main/java/org/apache/qpid/client/AMQConnection.java Tue Apr 12 10:37:25 2016
@@ -57,6 +57,7 @@ import javax.naming.Reference;
 import javax.naming.Referenceable;
 import javax.naming.StringRefAddr;
 
+import org.apache.qpid.client.state.AMQState;
 import org.apache.qpid.jndi.ObjectFactory;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -433,7 +434,7 @@ public class AMQConnection extends Close
         }
         else if ("0-91".equals(amqpVersion) || "0-9-1".equals(amqpVersion))
         {
-            _delegate = new AMQConnectionDelegate_9_1(this);
+            _delegate = new AMQConnectionDelegate_0_91(this);
         }
         else
         {
@@ -626,15 +627,21 @@ public class AMQConnection extends Close
             Class partypes[] = new Class[1];
             partypes[0] = AMQConnection.class;
             _delegate = (AMQConnectionDelegate) c.getConstructor(partypes).newInstance(this);
-            //Update our session to use this new protocol version
-            _protocolHandler.getProtocolSession().setProtocolVersion(_delegate.getProtocolVersion());
 
+            if (!ProtocolVersion.v0_10.equals(_delegate.getProtocolVersion()))
+            {
+                _protocolHandler.getProtocolSession().setProtocolVersion(_delegate.getProtocolVersion());
+            }
+
+            // reset state waiter state
+            _protocolHandler.getStateManager().clearLastException();
+            _protocolHandler.getStateManager().changeState(AMQState.CONNECTION_NOT_STARTED);
         }
         catch (ClassNotFoundException e)
         {
             throw new AMQProtocolException
                 (AMQConstant.UNSUPPORTED_CLIENT_PROTOCOL_ERROR,
-                 String.format("Protocol: %s.%s is rquired by the broker but is not " +
+                 String.format("Protocol: %s.%s is required by the broker but is not " +
                                "currently supported by this client library implementation",
                                pe.getMajorVersion(), pe.getMinorVersion()),
                  e);

Modified: qpid/java/branches/6.0.x/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_0_10.java
URL: http://svn.apache.org/viewvc/qpid/java/branches/6.0.x/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_0_10.java?rev=1738758&r1=1738757&r2=1738758&view=diff
==============================================================================
--- qpid/java/branches/6.0.x/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_0_10.java (original)
+++ qpid/java/branches/6.0.x/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_0_10.java Tue Apr 12 10:37:25 2016
@@ -235,7 +235,16 @@ public class AMQConnectionDelegate_0_10
         }
         catch (ProtocolVersionException pe)
         {
-            return ProtocolVersion.get(pe.getMajor(), pe.getMinor());
+            if (pe.getMajor() == 9 && pe.getMinor() == 1)
+            {
+                // 0-10 misinterprets 0-91's header (major/minor/revision) by treating minor as the major, and
+                // revision as the minor. Correct this so that we find the correct delegate.
+                return ProtocolVersion.v0_91;
+            }
+            else
+            {
+                return ProtocolVersion.get(pe.getMajor(), pe.getMinor());
+            }
         }
         catch (ConnectionException ce)
         {

Modified: qpid/java/branches/6.0.x/client/src/main/java/org/apache/qpid/client/AMQProtocolHandler.java
URL: http://svn.apache.org/viewvc/qpid/java/branches/6.0.x/client/src/main/java/org/apache/qpid/client/AMQProtocolHandler.java?rev=1738758&r1=1738757&r2=1738758&view=diff
==============================================================================
--- qpid/java/branches/6.0.x/client/src/main/java/org/apache/qpid/client/AMQProtocolHandler.java (original)
+++ qpid/java/branches/6.0.x/client/src/main/java/org/apache/qpid/client/AMQProtocolHandler.java Tue Apr 12 10:37:25 2016
@@ -54,6 +54,7 @@ import org.apache.qpid.framing.AMQBody;
 import org.apache.qpid.framing.AMQDataBlock;
 import org.apache.qpid.framing.AMQFrame;
 import org.apache.qpid.framing.AMQMethodBody;
+import org.apache.qpid.framing.AMQProtocolHeaderException;
 import org.apache.qpid.framing.AMQShortString;
 import org.apache.qpid.framing.ConnectionCloseBody;
 import org.apache.qpid.framing.ConnectionCloseOkBody;
@@ -483,12 +484,21 @@ public class AMQProtocolHandler implemen
                     // We get here if the server sends a response to our initial protocol header
                     // suggesting an alternate ProtocolVersion; the server will then close the
                     // connection.
-                    ProtocolInitiation protocolInit = (ProtocolInitiation) message;
-                    _suggestedProtocolVersion = protocolInit.checkVersion();
-                    _logger.info("Broker suggested using protocol version: {} ", _suggestedProtocolVersion);
+                    try
+                    {
+                        ProtocolInitiation protocolInit = (ProtocolInitiation) message;
+                        _suggestedProtocolVersion = protocolInit.checkVersion();
+                        _logger.debug("Broker suggested using protocol version: {} ", _suggestedProtocolVersion);
+
+                        // get round a bug in old versions of qpid whereby the connection is not closed
+                        _stateManager.changeState(AMQState.CONNECTION_CLOSED);
 
-                    // get round a bug in old versions of qpid whereby the connection is not closed
-                    _stateManager.changeState(AMQState.CONNECTION_CLOSED);
+                    }
+                    catch (AMQProtocolHeaderException e)
+                    {
+                        _stateManager.error(e);
+                        throw e;
+                    }
                 }
             }
         }

Modified: qpid/java/branches/6.0.x/common/src/main/java/org/apache/qpid/framing/ProtocolInitiation.java
URL: http://svn.apache.org/viewvc/qpid/java/branches/6.0.x/common/src/main/java/org/apache/qpid/framing/ProtocolInitiation.java?rev=1738758&r1=1738757&r2=1738758&view=diff
==============================================================================
--- qpid/java/branches/6.0.x/common/src/main/java/org/apache/qpid/framing/ProtocolInitiation.java (original)
+++ qpid/java/branches/6.0.x/common/src/main/java/org/apache/qpid/framing/ProtocolInitiation.java Tue Apr 12 10:37:25 2016
@@ -214,8 +214,9 @@ public class ProtocolInitiation extends
         if (!pv.isSupported())
         {
             // TODO: add list of available versions in list to msg...
-            throw new AMQProtocolVersionException("Protocol version " +
-                                                  _protocolMajor + "." + _protocolMinor + " not suppoerted by this version of the Qpid broker.", null);
+            throw new AMQProtocolVersionException("Protocol version " + _protocolMajor + "."
+                                                  + _protocolMinor
+                                                  + " not supported.", null);
         }
         return pv;
     }

Modified: qpid/java/branches/6.0.x/systests/src/test/java/org/apache/qpid/transport/ProtocolNegotiationTest.java
URL: http://svn.apache.org/viewvc/qpid/java/branches/6.0.x/systests/src/test/java/org/apache/qpid/transport/ProtocolNegotiationTest.java?rev=1738758&r1=1738757&r2=1738758&view=diff
==============================================================================
--- qpid/java/branches/6.0.x/systests/src/test/java/org/apache/qpid/transport/ProtocolNegotiationTest.java (original)
+++ qpid/java/branches/6.0.x/systests/src/test/java/org/apache/qpid/transport/ProtocolNegotiationTest.java Tue Apr 12 10:37:25 2016
@@ -29,25 +29,54 @@ import java.net.SocketTimeoutException;
 import java.nio.ByteBuffer;
 import java.util.concurrent.atomic.AtomicBoolean;
 
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 import org.apache.qpid.bytebuffer.QpidByteBuffer;
 import org.apache.qpid.framing.ByteArrayDataInput;
+import org.apache.qpid.client.AMQConnection;
+import org.apache.qpid.configuration.ClientProperties;
 import org.apache.qpid.framing.HeartbeatBody;
 import org.apache.qpid.framing.ProtocolInitiation;
 import org.apache.qpid.framing.ProtocolVersion;
+import org.apache.qpid.server.configuration.BrokerProperties;
+import org.apache.qpid.server.model.Broker;
 import org.apache.qpid.server.model.Port;
 import org.apache.qpid.server.model.Protocol;
 import org.apache.qpid.server.protocol.v0_10.ServerDisassembler;
 import org.apache.qpid.test.utils.QpidBrokerTestCase;
+import org.apache.qpid.test.utils.TestBrokerConfiguration;
 import org.apache.qpid.transport.network.Frame;
 
 public class ProtocolNegotiationTest extends QpidBrokerTestCase
 {
+    private static final Logger LOGGER = LoggerFactory.getLogger(ProtocolNegotiationTest.class);
     private static final int SO_TIMEOUT = 5000;
     public static final int AMQP_HEADER_LEN = 8;
     private ProtocolVersion _expectedProtocolInit;
 
     public void setUp() throws Exception
     {
+        // restrict broker to support only single protocol
+        TestBrokerConfiguration config = getBrokerConfiguration();
+        config.setObjectAttribute(Port.class,
+                                  TestBrokerConfiguration.ENTRY_NAME_AMQP_PORT,
+                                  Port.PROTOCOLS,
+                                  Arrays.asList(getBrokerProtocol()));
+        config.setObjectAttribute(Port.class,
+                                  TestBrokerConfiguration.ENTRY_NAME_AMQP_PORT,
+                                  Port.CONTEXT,
+                                  Collections.singletonMap(BrokerProperties.PROPERTY_DEFAULT_SUPPORTED_PROTOCOL_REPLY, null));
+        config.setBrokerAttribute(Broker.CONTEXT,
+                                  Collections.singletonMap(BrokerProperties.PROPERTY_DEFAULT_SUPPORTED_PROTOCOL_REPLY, null));
+
         super.setUp();
         _expectedProtocolInit = convertProtocolToProtocolVersion(getBrokerProtocol());
     }
@@ -190,6 +219,33 @@ public class ProtocolNegotiationTest ext
         }
     }
 
+    public void testProtocolNegotiationFromUnsupportedVersion() throws Exception
+    {
+        Protocol testProtocol = getBrokerProtocol();
+        String testSupportedProtocols = System.getProperty("test.amqp_port_protocols");
+        if (testSupportedProtocols!= null)
+        {
+            Set<Protocol> availableProtocols = new HashSet<>();
+            List<Object> protocols = new ObjectMapper().readValue(testSupportedProtocols, List.class);
+            for (Object protocol : protocols)
+            {
+                availableProtocols.add(Protocol.valueOf(String.valueOf(protocol)));
+            }
+            availableProtocols.remove(testProtocol);
+
+            for (Protocol protocol: availableProtocols)
+            {
+                String version = protocol.name().substring(5).replace('_', '-');
+                LOGGER.debug("Negotiation version {} represented as {}", protocol.name(), version);
+                setTestSystemProperty(ClientProperties.AMQP_VERSION, version);
+                AMQConnection connection = (AMQConnection)getConnection();
+                LOGGER.debug("Negotiated version {}", connection.getProtocolVersion());
+                assertEquals("Unexpected version negotiated: " + connection.getProtocolVersion(), _expectedProtocolInit, connection.getProtocolVersion());
+                connection.close();
+            }
+        }
+    }
+
     private boolean writeHeartbeat(final DataOutputStream dataOutputStream)
             throws IOException
     {



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org