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.
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
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(); + } }
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(); + } }
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
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