Updated Branches: refs/heads/master b72f9c0ee -> 138fa46d6
CAMEL-7049: Fixed jms JMSReplyTo header with a topic did not work correctly. Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/138fa46d Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/138fa46d Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/138fa46d Branch: refs/heads/master Commit: 138fa46d62a4b29bc3330b2b3ae12803d524726c Parents: b72f9c0 Author: Claus Ibsen <davscl...@apache.org> Authored: Tue Jan 28 09:04:21 2014 +0100 Committer: Claus Ibsen <davscl...@apache.org> Committed: Tue Jan 28 09:29:36 2014 +0100 ---------------------------------------------------------------------- .../camel/component/jms/JmsMessageHelper.java | 28 ++++++++++++++++++++ .../apache/camel/component/jms/JmsProducer.java | 22 ++++++++------- 2 files changed, 41 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/138fa46d/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsMessageHelper.java ---------------------------------------------------------------------- diff --git a/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsMessageHelper.java b/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsMessageHelper.java index 52f6af5..eb125b3 100644 --- a/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsMessageHelper.java +++ b/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsMessageHelper.java @@ -171,6 +171,34 @@ public final class JmsMessageHelper { } /** + * Whether the destination name has either queue or temp queue prefix. + * + * @param destination the destination + * @return <tt>true</tt> if queue or temp-queue prefix, <tt>false</tt> otherwise + */ + public static boolean isQueuePrefix(String destination) { + if (ObjectHelper.isEmpty(destination)) { + return false; + } + + return destination.startsWith(QUEUE_PREFIX) || destination.startsWith(TEMP_QUEUE_PREFIX); + } + + /** + * Whether the destination name has either topic or temp topic prefix. + * + * @param destination the destination + * @return <tt>true</tt> if topic or temp-topic prefix, <tt>false</tt> otherwise + */ + public static boolean isTopicPrefix(String destination) { + if (ObjectHelper.isEmpty(destination)) { + return false; + } + + return destination.startsWith(TOPIC_PREFIX) || destination.startsWith(TEMP_TOPIC_PREFIX); + } + + /** * Normalizes the destination name. * <p/> * This ensures the destination name is correct, and we do not create queues as <tt>queue://queue:foo</tt>, which http://git-wip-us.apache.org/repos/asf/camel/blob/138fa46d/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsProducer.java ---------------------------------------------------------------------- diff --git a/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsProducer.java b/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsProducer.java index 067b5bd..a30c4f3 100644 --- a/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsProducer.java +++ b/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsProducer.java @@ -44,6 +44,8 @@ import org.springframework.jms.core.JmsOperations; import org.springframework.jms.core.MessageCreator; import org.springframework.jms.support.JmsUtils; +import static org.apache.camel.component.jms.JmsMessageHelper.isQueuePrefix; +import static org.apache.camel.component.jms.JmsMessageHelper.isTopicPrefix; import static org.apache.camel.component.jms.JmsMessageHelper.normalizeDestinationName; /** @@ -332,24 +334,26 @@ public class JmsProducer extends DefaultAsyncProducer { // the reply to is a String, so we need to look up its Destination instance // and if needed create the destination using the session if needed to if (jmsReplyTo != null && jmsReplyTo instanceof String) { - // must normalize the destination name - String before = (String) jmsReplyTo; - String replyTo = normalizeDestinationName(before); + String replyTo = (String) jmsReplyTo; // we need to null it as we use the String to resolve it as a Destination instance jmsReplyTo = null; - LOG.trace("Normalized JMSReplyTo destination name {} -> {}", before, replyTo); - + boolean isPubSub = isTopicPrefix(replyTo) || (!isQueuePrefix(replyTo) && endpoint.isPubSubDomain()); // try using destination resolver to lookup the destination if (endpoint.getDestinationResolver() != null) { - jmsReplyTo = endpoint.getDestinationResolver().resolveDestinationName(session, replyTo, endpoint.isPubSubDomain()); + jmsReplyTo = endpoint.getDestinationResolver().resolveDestinationName(session, replyTo, isPubSub); if (LOG.isDebugEnabled()) { LOG.debug("Resolved JMSReplyTo destination {} using DestinationResolver {} as PubSubDomain {} -> {}", - new Object[]{replyTo, endpoint.getDestinationResolver(), endpoint.isPubSubDomain(), jmsReplyTo}); + new Object[]{replyTo, endpoint.getDestinationResolver(), isPubSub, jmsReplyTo}); } } if (jmsReplyTo == null) { - // okay then fallback and create the queue - if (endpoint.isPubSubDomain()) { + // must normalize the destination name + String before = replyTo; + replyTo = normalizeDestinationName(replyTo); + LOG.trace("Normalized JMSReplyTo destination name {} -> {}", before, replyTo); + + // okay then fallback and create the queue/topic + if (isPubSub) { LOG.debug("Creating JMSReplyTo topic: {}", replyTo); jmsReplyTo = session.createTopic(replyTo); } else {