Bug 621395 - Cannot create a durable subscription using a destination created with an addressing string
Summary: Cannot create a durable subscription using a destination created with an addr...
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise MRG
Classification: Red Hat
Component: qpid-java
Version: Development
Hardware: All
OS: Linux
high
high
Target Milestone: 1.3
: ---
Assignee: Rajith Attapattu
QA Contact: Jeff Needle
URL:
Whiteboard:
Keywords:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2010-08-04 22:39 UTC by Rajith Attapattu
Modified: 2014-06-23 14:31 UTC (History)
3 users (show)

(edit)
Clone Of:
(edit)
Last Closed: 2010-10-20 11:29:32 UTC


Attachments (Terms of Use)

Description Rajith Attapattu 2010-08-04 22:39:01 UTC
Description of problem:
If you pass in a topic created using an addressing string, to createDurableSubscriber method, the JMS client throws an exception complaining that the exchange and routing key fields are null.
The code needs to take into account the destination syntax and retrieve the appropriate information.

Version-Release number of selected component (if applicable):
All previous versions

How reproducible:
Always

Steps to Reproduce:
1. Try to create durable subscriber with a topic (amq.topic/news.us).
   Ex MessageConsumer cons = ssn.createDurableSubscriber(ssn.createTopic("amq.topic/news.us"), "my-sub");

2. Observe the exception being thrown saying exchange name is null.
  
Actual results:
Exception thrown saying exchange name is null.

Expected results:
Should succeed without any issue.

Comment 1 Rajith Attapattu 2010-08-05 15:06:25 UTC
The following patch contains the initial fix.

--- qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQTopic.java (original)
+++ qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQTopic.java Wed Aug  4 19:44:17 2010
@@ -106,8 +106,20 @@ public class AMQTopic extends AMQDestina
    public static AMQTopic createDurable010Topic(AMQTopic topic, String subscriptionName, AMQConnection connection)
            throws JMSException
    {
-        return new AMQTopic(topic.getExchangeName(), ExchangeDefaults.TOPIC_EXCHANGE_CLASS, topic.getRoutingKey(), true, false,
+        if (topic.getDestSyntax() == AMQDestination.DestSyntax.BURL)
+        {
+            return new AMQTopic(topic.getExchangeName(), ExchangeDefaults.TOPIC_EXCHANGE_CLASS, topic.getRoutingKey(), true, false,
              getDurableTopicQueueName(subscriptionName, connection), true);
+        }
+        else
+        {
+            return new AMQTopic(new AMQShortString(topic.getAddressName()),
+                                ExchangeDefaults.TOPIC_EXCHANGE_CLASS,
+                                new AMQShortString(topic.getSubject()),
+                                true,
+                                false,
+                                getDurableTopicQueueName(subscriptionName, connection), true);
+        }
    }

    public static AMQShortString getDurableTopicQueueName(String subscriptionName, AMQConnection connection) throws JMSException

Comment 2 Rajith Attapattu 2010-08-05 15:08:36 UTC
The patch below reverts the above commit and adds a more simple fix to avoid checking dest style in createDurable010Topic, hashcode and equals methods.

--- qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQTopic.java (original)
+++ qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQTopic.java Thu Aug  5 15:03:40 2010
@@ -106,20 +106,8 @@ public class AMQTopic extends AMQDestina
    public static AMQTopic createDurable010Topic(AMQTopic topic, String subscriptionName, AMQConnection connection)
            throws JMSException
    {
-        if (topic.getDestSyntax() == AMQDestination.DestSyntax.BURL)
-        {
-            return new AMQTopic(topic.getExchangeName(), ExchangeDefaults.TOPIC_EXCHANGE_CLASS, topic.getRoutingKey(), true, false,
-              getDurableTopicQueueName(subscriptionName, connection), true);
-        }
-        else
-        {
-            return new AMQTopic(new AMQShortString(topic.getAddressName()),
-                                ExchangeDefaults.TOPIC_EXCHANGE_CLASS,
-                                new AMQShortString(topic.getSubject()),
-                                true,
-                                false,
-                                getDurableTopicQueueName(subscriptionName, connection), true);
-        }
+        return new AMQTopic(topic.getExchangeName(), ExchangeDefaults.TOPIC_EXCHANGE_CLASS, topic.getRoutingKey(), true, false,
+                getDurableTopicQueueName(subscriptionName, connection), true);
    }

    public static AMQShortString getDurableTopicQueueName(String subscriptionName, AMQConnection connection) throws JMSException
@@ -129,12 +117,39 @@ public class AMQTopic extends AMQDestina

    public String getTopicName() throws JMSException
    {
-        return super.getRoutingKey().toString();
+        if (super.getRoutingKey() == null && super.getSubject() != null)
+        {
+            return super.getSubject();
+        }
+        else
+        {
+            return super.getRoutingKey().toString();
+        }
+    }
+
+    @Override
+    public AMQShortString getExchangeName()
+    {
+        if (super.getExchangeName() == null && super.getAddressName() != null)
+        {
+            return new AMQShortString(super.getAddressName());
+        }
+        else
+        {
+            return _exchangeName;
+        }
    }

    public AMQShortString getRoutingKey()
    {
-        return super.getRoutingKey();
+        if (super.getRoutingKey() == null && super.getSubject() != null)
+        {
+            return new AMQShortString(super.getSubject());
+        }
+        else
+        {
+            return super.getRoutingKey();
+        }
    }

Comment 3 Rajith Attapattu 2010-08-12 19:22:29 UTC
The following shows the exact code segment that will get changed.
In summary,

If the exchange name is null, and address name name is not null, it will return the address name.

If the routing key is null, and subject is not null, it will return the subject.


@@ -129,12 +117,39 @@ public class AMQTopic extends AMQDestina

    public String getTopicName() throws JMSException
    {
-        return super.getRoutingKey().toString();
+        if (super.getRoutingKey() == null && super.getSubject() != null)
+        {
+            return super.getSubject();
+        }
+        else
+        {
+            return super.getRoutingKey().toString();
+        }
+    }
+
+    @Override
+    public AMQShortString getExchangeName()
+    {
+        if (super.getExchangeName() == null && super.getAddressName() != null)
+        {
+            return new AMQShortString(super.getAddressName());
+        }
+        else
+        {
+            return _exchangeName;
+        }
    }

    public AMQShortString getRoutingKey()
    {
-        return super.getRoutingKey();
+        if (super.getRoutingKey() == null && super.getSubject() != null)
+        {
+            return new AMQShortString(super.getSubject());
+        }
+        else
+        {
+            return super.getRoutingKey();
+        }
    }

Comment 4 Rajith Attapattu 2010-08-31 22:10:39 UTC
This is tracked in upstream via QPID-2786 and fixed in rev 982652 in Qpid trunk.
I have ported the fix to the internal git repo under the following commit.

http://mrg1.lab.bos.redhat.com/cgit/qpid.git/commit/?id=e6f1a55eff9c7e4552aa49a9058ba9d43393f334

Comment 5 Jiri Kolar 2010-09-06 13:35:12 UTC
this appear on 1.2 and
is fixed on qpid-java-client-0.7.946106-8
validated on RHEL5.5/RHEL4  i386 / x86_64  

packages:

# rpm -qa | grep -E '(qpid|openais|rhm)' | sort -u
openais-0.80.6-16.el5_5.7
openais-devel-0.80.6-16.el5_5.7
python-qpid-0.7.946106-12.el5
qpid-cpp-client-0.7.946106-12.el5
qpid-cpp-client-devel-0.7.946106-12.el5
qpid-cpp-client-devel-docs-0.7.946106-12.el5
qpid-cpp-client-ssl-0.7.946106-12.el5
qpid-cpp-mrg-debuginfo-0.7.946106-11.el5
qpid-cpp-server-0.7.946106-12.el5
qpid-cpp-server-cluster-0.7.946106-12.el5
qpid-cpp-server-devel-0.7.946106-12.el5
qpid-cpp-server-ssl-0.7.946106-12.el5
qpid-cpp-server-store-0.7.946106-12.el5
qpid-cpp-server-xml-0.7.946106-12.el5
qpid-java-client-0.7.946106-8.el5
qpid-java-common-0.7.946106-8.el5
qpid-tools-0.7.946106-8.el5
rhm-docs-0.7.946106-4.el5
rh-tests-distribution-MRG-Messaging-qpid_common-1.6-53


->VERIFIED


Note You need to log in before you can comment on or make changes to this bug.