diff options
author | Rajith Muditha Attapattu <rajith@apache.org> | 2011-05-11 18:03:36 +0000 |
---|---|---|
committer | Rajith Muditha Attapattu <rajith@apache.org> | 2011-05-11 18:03:36 +0000 |
commit | f59425c33e4902bdac5c095e21511093466663e2 (patch) | |
tree | 027e448d5eac1257e70d82bf50531412907f74a4 | |
parent | fd743d3aac6390aeb367e5601317a4397f682ce7 (diff) | |
download | qpid-python-f59425c33e4902bdac5c095e21511093466663e2.tar.gz |
QPID-3254
Added logic to resolve the address to ensure corner cases such addresses without subjects are handled properly.
The address resolotuion code will determine the defaults for subject (and routing key) by querying the name specified in the address.
I also added null checks for getRoutingKey() method and getTopicName() method in both AMQTopic and AMQAnyDestination classes.
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1102002 13f79535-47bb-0310-9956-ffa450edef68
3 files changed, 46 insertions, 15 deletions
diff --git a/qpid/java/client/src/main/java/org/apache/qpid/client/AMQAnyDestination.java b/qpid/java/client/src/main/java/org/apache/qpid/client/AMQAnyDestination.java index a201f7d61e..999b22299c 100644 --- a/qpid/java/client/src/main/java/org/apache/qpid/client/AMQAnyDestination.java +++ b/qpid/java/client/src/main/java/org/apache/qpid/client/AMQAnyDestination.java @@ -72,6 +72,17 @@ public class AMQAnyDestination extends AMQDestination implements Queue, Topic public String getTopicName() throws JMSException { - return super.getRoutingKey().toString(); + if (getRoutingKey() != null) + { + return getRoutingKey().asString(); + } + else if (getSubject() != null) + { + return getSubject(); + } + else + { + return null; + } } } diff --git a/qpid/java/client/src/main/java/org/apache/qpid/client/AMQSession.java b/qpid/java/client/src/main/java/org/apache/qpid/client/AMQSession.java index d1e7aae94a..f85b1e655d 100644 --- a/qpid/java/client/src/main/java/org/apache/qpid/client/AMQSession.java +++ b/qpid/java/client/src/main/java/org/apache/qpid/client/AMQSession.java @@ -1050,7 +1050,23 @@ public abstract class AMQSession<C extends BasicMessageConsumer, P extends Basic { checkNotClosed(); Topic origTopic = checkValidTopic(topic, true); + AMQTopic dest = AMQTopic.createDurableTopic(origTopic, name, _connection); + if (dest.getDestSyntax() == DestSyntax.ADDR && + !dest.isAddressResolved()) + { + try + { + handleAddressBasedDestination(dest,false,true); + } + catch(AMQException e) + { + JMSException ex = new JMSException("Error when verifying destination"); + ex.initCause(e); + ex.setLinkedException(e); + throw ex; + } + } String messageSelector = ((selector == null) || (selector.trim().length() == 0)) ? null : selector; @@ -1062,15 +1078,9 @@ public abstract class AMQSession<C extends BasicMessageConsumer, P extends Basic // Not subscribed to this name in the current session if (subscriber == null) { - AMQShortString topicName; - if (topic instanceof AMQTopic) - { - topicName = ((AMQTopic) topic).getRoutingKey(); - } else - { - topicName = new AMQShortString(topic.getTopicName()); - } - + // After the address is resolved routing key will not be null. + AMQShortString topicName = dest.getRoutingKey(); + if (_strictAMQP) { if (_strictAMQPFATAL) diff --git a/qpid/java/client/src/main/java/org/apache/qpid/client/AMQTopic.java b/qpid/java/client/src/main/java/org/apache/qpid/client/AMQTopic.java index c573da9def..79624a774f 100644 --- a/qpid/java/client/src/main/java/org/apache/qpid/client/AMQTopic.java +++ b/qpid/java/client/src/main/java/org/apache/qpid/client/AMQTopic.java @@ -147,13 +147,17 @@ public class AMQTopic extends AMQDestination implements Topic public String getTopicName() throws JMSException { - if (super.getRoutingKey() == null && super.getSubject() != null) + if (getRoutingKey() != null) { - return super.getSubject(); + return getRoutingKey().asString(); + } + else if (getSubject() != null) + { + return getSubject(); } else { - return super.getRoutingKey().toString(); + return null; } } @@ -172,12 +176,18 @@ public class AMQTopic extends AMQDestination implements Topic public AMQShortString getRoutingKey() { - if (super.getRoutingKey() == null && super.getSubject() != null) + if (super.getRoutingKey() != null) + { + return super.getRoutingKey(); + } + else if (getSubject() != null) { - return new AMQShortString(super.getSubject()); + return new AMQShortString(getSubject()); } else { + setRoutingKey(new AMQShortString("#")); + setSubject("#"); return super.getRoutingKey(); } } |