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 2017/03/15 14:42:21 UTC

svn commit: r1787056 - in /qpid/java/branches/6.1.x: ./ client/src/main/java/org/apache/qpid/client/ systests/src/test/java/org/apache/qpid/test/client/destination/ test-profiles/

Author: orudyy
Date: Wed Mar 15 14:42:21 2017
New Revision: 1787056

URL: http://svn.apache.org/viewvc?rev=1787056&view=rev
Log:
QPID-7692: [Java Client] Allow routingKey/subject to be null in addresses

merged changes from client trunk using
svn merge -c 1785989  ^/qpid/qpid-jms-amqp-0-x/trunk
merged tests from broker trunk using
svn merge -c 1785988 ^/qpid/java/trunk

Modified:
    qpid/java/branches/6.1.x/   (props changed)
    qpid/java/branches/6.1.x/client/src/main/java/org/apache/qpid/client/AMQAnyDestination.java
    qpid/java/branches/6.1.x/client/src/main/java/org/apache/qpid/client/AMQDestination.java
    qpid/java/branches/6.1.x/client/src/main/java/org/apache/qpid/client/AMQSession_0_10.java
    qpid/java/branches/6.1.x/client/src/main/java/org/apache/qpid/client/AMQTopic.java
    qpid/java/branches/6.1.x/systests/src/test/java/org/apache/qpid/test/client/destination/AddressBasedDestinationTest.java
    qpid/java/branches/6.1.x/test-profiles/JavaPre010Excludes   (props changed)

Propchange: qpid/java/branches/6.1.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Mar 15 14:42:21 2017
@@ -9,5 +9,6 @@
 /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:1766544,1766547,1766553,1766666,1766796-1766797,1766806,1767251,1767267-1767268,1767275,1767310,1767326,1767329,1767332,1767514,1767523,1767738,1767825,1767847-1767849,1767882,1767909,1767914,1768016-1768017,1768065,1768643,1768704,1768854,1768875,1768914,1768963,1768967,1768976,1769007,1769009,1769087,1769138-1769139,1769597,1769879,1770236,1770716,1772050,1772241,1772365,1772574,1773057,1774039,1774446,1774564,1774885,1775087,1775100,1777939,1780947,1782302,1782735,1785117,1785158,1785269-1785270,1785311,1785675,1785679,1785854,1785936,1785950,1786188-1786189,1786342,1786657,1786690,1786723,1786914,1786923
+/qpid/java/trunk:1766544,1766547,1766553,1766666,1766796-1766797,1766806,1767251,1767267-1767268,1767275,1767310,1767326,1767329,1767332,1767514,1767523,1767738,1767825,1767847-1767849,1767882,1767909,1767914,1768016-1768017,1768065,1768643,1768704,1768854,1768875,1768914,1768963,1768967,1768976,1769007,1769009,1769087,1769138-1769139,1769597,1769879,1770236,1770716,1772050,1772241,1772365,1772574,1773057,1774039,1774446,1774564,1774885,1775087,1775100,1777939,1780947,1782302,1782735,1785117,1785158,1785269-1785270,1785311,1785675,1785679,1785854,1785936,1785950,1785988,1786188-1786189,1786342,1786657,1786690,1786723,1786914,1786923
+/qpid/qpid-jms-amqp-0-x/trunk:1785989
 /qpid/trunk/qpid:796646-796653

Modified: qpid/java/branches/6.1.x/client/src/main/java/org/apache/qpid/client/AMQAnyDestination.java
URL: http://svn.apache.org/viewvc/qpid/java/branches/6.1.x/client/src/main/java/org/apache/qpid/client/AMQAnyDestination.java?rev=1787056&r1=1787055&r2=1787056&view=diff
==============================================================================
--- qpid/java/branches/6.1.x/client/src/main/java/org/apache/qpid/client/AMQAnyDestination.java (original)
+++ qpid/java/branches/6.1.x/client/src/main/java/org/apache/qpid/client/AMQAnyDestination.java Wed Mar 15 14:42:21 2017
@@ -77,6 +77,7 @@ public class AMQAnyDestination extends A
         return getAMQQueueName() == null;
     }
 
+    @Override
     public String getTopicName() throws JMSException
     {
         if (getRoutingKey() != null)

Modified: qpid/java/branches/6.1.x/client/src/main/java/org/apache/qpid/client/AMQDestination.java
URL: http://svn.apache.org/viewvc/qpid/java/branches/6.1.x/client/src/main/java/org/apache/qpid/client/AMQDestination.java?rev=1787056&r1=1787055&r2=1787056&view=diff
==============================================================================
--- qpid/java/branches/6.1.x/client/src/main/java/org/apache/qpid/client/AMQDestination.java (original)
+++ qpid/java/branches/6.1.x/client/src/main/java/org/apache/qpid/client/AMQDestination.java Wed Mar 15 14:42:21 2017
@@ -372,12 +372,6 @@ public abstract class AMQDestination imp
     protected AMQDestination(String exchangeName, String exchangeClass, String routingKey, boolean isExclusive,
                              boolean isAutoDelete, String queueName, boolean isDurable, String[] bindingKeys, boolean browseOnly)
     {
-        if ( (ExchangeDefaults.DIRECT_EXCHANGE_CLASS.equals(exchangeClass) ||
-              ExchangeDefaults.TOPIC_EXCHANGE_CLASS.equals(exchangeClass))
-              && routingKey == null)
-        {
-            throw new IllegalArgumentException("routing/binding key  must not be null");
-        }
         if (exchangeName == null)
         {
             throw new IllegalArgumentException("Exchange name must not be null");
@@ -515,12 +509,16 @@ public abstract class AMQDestination imp
         {
             return _bindingKeys;
         }
-        else
+        else if (_routingKey != null)
         {
             // catering to the common use case where the
             //routingKey is the same as the bindingKey.
             return new String[]{_routingKey};
         }
+        else
+        {
+            return new String[0];
+        }
     }
 
     public boolean isExclusive()
@@ -571,7 +569,12 @@ public abstract class AMQDestination imp
             sb.append("://");
             sb.append(_exchangeName);
 
-            sb.append("/"+_routingKey+"/");
+            sb.append("/");
+            if (_routingKey != null)
+            {
+                sb.append(_routingKey);
+            }
+            sb.append("/");
 
             if (_queueName != null)
             {
@@ -660,6 +663,7 @@ public abstract class AMQDestination imp
         return url;
     }
 
+    @Override
     public boolean equals(Object o)
     {
         if (this == o)
@@ -719,6 +723,7 @@ public abstract class AMQDestination imp
         return true;
     }
 
+    @Override
     public int hashCode()
     {
         int result;

Modified: qpid/java/branches/6.1.x/client/src/main/java/org/apache/qpid/client/AMQSession_0_10.java
URL: http://svn.apache.org/viewvc/qpid/java/branches/6.1.x/client/src/main/java/org/apache/qpid/client/AMQSession_0_10.java?rev=1787056&r1=1787055&r2=1787056&view=diff
==============================================================================
--- qpid/java/branches/6.1.x/client/src/main/java/org/apache/qpid/client/AMQSession_0_10.java (original)
+++ qpid/java/branches/6.1.x/client/src/main/java/org/apache/qpid/client/AMQSession_0_10.java Wed Mar 15 14:42:21 2017
@@ -949,12 +949,12 @@ public class AMQSession_0_10 extends AMQ
                         // Generate the queue name if the destination indicates that a client generated name is to be used.
                         if (amqd.isNameRequired())
                         {
-                            String binddingKey = "";
+                            String bindingKey = "";
                             for(String key : amqd.getBindingKeys())
                             {
-                               binddingKey = binddingKey + "_" + key;
+                               bindingKey = bindingKey + "_" + key;
                             }
-                            amqd.setQueueName(binddingKey + "@"
+                            amqd.setQueueName(bindingKey + "@"
                                     + amqd.getExchangeName() + "_" + UUID.randomUUID());
                         }
                         return send0_10QueueDeclare(amqd, noLocal, nowait, passive);

Modified: qpid/java/branches/6.1.x/client/src/main/java/org/apache/qpid/client/AMQTopic.java
URL: http://svn.apache.org/viewvc/qpid/java/branches/6.1.x/client/src/main/java/org/apache/qpid/client/AMQTopic.java?rev=1787056&r1=1787055&r2=1787056&view=diff
==============================================================================
--- qpid/java/branches/6.1.x/client/src/main/java/org/apache/qpid/client/AMQTopic.java (original)
+++ qpid/java/branches/6.1.x/client/src/main/java/org/apache/qpid/client/AMQTopic.java Wed Mar 15 14:42:21 2017
@@ -39,16 +39,28 @@ public class AMQTopic extends AMQDestina
     public AMQTopic(String address) throws URISyntaxException
     {
         super(address);
+        if (super.getRoutingKey() == null)
+        {
+            setRoutingKey("");
+        }
     }
 
     public AMQTopic(Address address)
     {
         super(address);
+        if (super.getRoutingKey() == null)
+        {
+            setRoutingKey("");
+        }
     }
 
     public AMQTopic()
     {
         super();
+        if (super.getRoutingKey() == null)
+        {
+            setRoutingKey("");
+        }
     }
 
     /**
@@ -59,16 +71,20 @@ public class AMQTopic extends AMQDestina
     public AMQTopic(BindingURL binding)
     {
         super(binding);
+        if (super.getRoutingKey() == null)
+        {
+            setRoutingKey("");
+        }
     }
 
     public AMQTopic(String exchange, String routingKey, String queueName)
     {
-        super(exchange, ExchangeDefaults.TOPIC_EXCHANGE_CLASS, routingKey, true, true, queueName, false);
+        this(exchange, ExchangeDefaults.TOPIC_EXCHANGE_CLASS, routingKey, true, true, queueName, false);
     }
 
     public AMQTopic(String exchange, String routingKey, String queueName, String[] bindingKeys)
     {
-        super(exchange, ExchangeDefaults.TOPIC_EXCHANGE_CLASS, routingKey, true, true, queueName, false, bindingKeys);
+        this(exchange, ExchangeDefaults.TOPIC_EXCHANGE_CLASS, routingKey, true, true, queueName, false, bindingKeys);
     }
 
     public AMQTopic(AMQConnection conn, String routingKey)
@@ -83,25 +99,25 @@ public class AMQTopic extends AMQDestina
 
     public AMQTopic(String exchangeName, String name, boolean isAutoDelete, String queueName, boolean isDurable)
     {
-        super(exchangeName, ExchangeDefaults.TOPIC_EXCHANGE_CLASS, name, true, isAutoDelete, queueName, isDurable);
+        this(exchangeName, ExchangeDefaults.TOPIC_EXCHANGE_CLASS, name, true, isAutoDelete, queueName, isDurable);
     }
 
 
     protected AMQTopic(String exchangeName, String exchangeClass, String name, boolean isAutoDelete, String queueName, boolean isDurable)
     {
-        super(exchangeName, exchangeClass, name, true, isAutoDelete, queueName, isDurable);
+        this(exchangeName, exchangeClass, name, true, isAutoDelete, queueName, isDurable);
     }
 
     protected AMQTopic(String exchangeName, String exchangeClass, String routingKey, boolean isExclusive,
                                boolean isAutoDelete, String queueName, boolean isDurable)
     {
-        super(exchangeName, exchangeClass, routingKey, isExclusive, isAutoDelete, queueName, isDurable );
+        this(exchangeName, exchangeClass, routingKey, isExclusive, isAutoDelete, queueName, isDurable, null );
     }
 
     protected AMQTopic(String exchangeName, String exchangeClass, String routingKey, boolean isExclusive,
             boolean isAutoDelete, String queueName, boolean isDurable, String[] bindingKeys)
     {
-        super(exchangeName, exchangeClass, routingKey, isExclusive, isAutoDelete, queueName, isDurable, bindingKeys);
+        super(exchangeName, exchangeClass, routingKey == null ? "" : routingKey, isExclusive, isAutoDelete, queueName, isDurable, bindingKeys);
     }
 
     public static AMQTopic createDurableTopic(Topic topic, String subscriptionName, AMQConnection connection)
@@ -150,6 +166,7 @@ public class AMQTopic extends AMQDestina
         return connection.getClientID() + ":" + subscriptionName;
     }
 
+    @Override
     public String getTopicName() throws JMSException
     {
         if (getRoutingKey() != null)
@@ -179,6 +196,7 @@ public class AMQTopic extends AMQDestina
         }
     }
 
+    @Override
     public String getRoutingKey()
     {
         if (super.getRoutingKey() != null)
@@ -191,17 +209,19 @@ public class AMQTopic extends AMQDestina
         }
         else
         {
-            setRoutingKey("");
+            setRoutingKey("");  // Side effect
             setSubject("");
             return super.getRoutingKey();
         }
     }
 
+    @Override
     public boolean isNameRequired()
     {
         return !isDurable();
     }
 
+    @Override
     public boolean equals(Object o)
     {
         if (getDestSyntax() == DestSyntax.ADDR)
@@ -216,6 +236,7 @@ public class AMQTopic extends AMQDestina
         }
     }
 
+    @Override
     public int hashCode()
     {
         if (getDestSyntax() == DestSyntax.ADDR)

Modified: qpid/java/branches/6.1.x/systests/src/test/java/org/apache/qpid/test/client/destination/AddressBasedDestinationTest.java
URL: http://svn.apache.org/viewvc/qpid/java/branches/6.1.x/systests/src/test/java/org/apache/qpid/test/client/destination/AddressBasedDestinationTest.java?rev=1787056&r1=1787055&r2=1787056&view=diff
==============================================================================
--- qpid/java/branches/6.1.x/systests/src/test/java/org/apache/qpid/test/client/destination/AddressBasedDestinationTest.java (original)
+++ qpid/java/branches/6.1.x/systests/src/test/java/org/apache/qpid/test/client/destination/AddressBasedDestinationTest.java Wed Mar 15 14:42:21 2017
@@ -54,6 +54,7 @@ import org.apache.qpid.client.AMQConnect
 import org.apache.qpid.client.AMQDestination;
 import org.apache.qpid.client.AMQSession;
 import org.apache.qpid.client.message.QpidMessageProperties;
+import org.apache.qpid.configuration.ClientProperties;
 import org.apache.qpid.jndi.PropertiesFileInitialContextFactory;
 import org.apache.qpid.messaging.Address;
 import org.apache.qpid.protocol.AMQConstant;
@@ -1606,4 +1607,51 @@ public class AddressBasedDestinationTest
         prod.close();
         ((AMQSession)ssn).isQueueExist(verifyDest, true);
     }
+
+    /**
+     * QPID-7692: Receiving a message sent using a destination which has no subject fails when client is in BURL dest syntax mode.
+     */
+    public void testJMSDestination_DestinationWithoutSubject() throws Exception
+    {
+        _connection.close();
+
+        doTestJMSDestiation_DestinationWithoutSubject("BURL");
+        doTestJMSDestiation_DestinationWithoutSubject("ADDR");
+    }
+
+    private void doTestJMSDestiation_DestinationWithoutSubject(final String clientDestSyntaxDefault) throws Exception
+    {
+        // The client uses the default destination syntax when processing the destination on received messages
+        setTestClientSystemProperty(ClientProperties.DEST_SYNTAX, clientDestSyntaxDefault);
+
+        String exchange = "myfanout";
+        Connection connection = getConnection();
+        connection.start();
+        Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
+
+        String publisher = String.format("ADDR:%s; {create: always, node: {type: topic, x-declare: { type: fanout }}}",
+                             exchange);
+        String subscriber = String.format("ADDR:sub1; {create: always, node : {type : queue, x-bindings: [{ exchange: '%s', key: sub1 }]}}",
+                             exchange);
+
+        Destination pubDest = session.createQueue(publisher);
+        Destination subDest  = session.createQueue(subscriber);
+
+        MessageProducer producer = session.createProducer(pubDest);
+        MessageConsumer consumer = session.createConsumer(subDest);
+
+        Message m = session.createMessage();
+        producer.send(m);
+        session.commit();
+
+        Message receivedMessage = consumer.receive(getReceiveTimeout());
+        assertNotNull("Message did not arrive",  receivedMessage);
+        AMQDestination jmsDestination = (AMQDestination) receivedMessage.getJMSDestination();
+        assertNotNull("Received message should have JMSDestination", jmsDestination);
+
+        assertEquals("Unexpected exchange within JMSDestination", exchange, jmsDestination.getExchangeName());
+        assertNull("Unexpected subject within JMSDestination", jmsDestination.getSubject());
+        session.commit();
+        connection.close();
+    }
 }

Propchange: qpid/java/branches/6.1.x/test-profiles/JavaPre010Excludes
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Mar 15 14:42:21 2017
@@ -4,3 +4,4 @@
 /qpid/branches/java-broker-vhost-refactor/java/test-profiles/JavaPre010Excludes:1493674-1494547
 /qpid/branches/java-network-refactor/qpid/java/test-profiles/08StandaloneExcludes:805429-821809
 /qpid/branches/qpid-2935/qpid/java/test-profiles/08StandaloneExcludes:1061302-1072333
+/qpid/java/trunk/test-profiles/JavaPre010Excludes:1785988



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