From 8e826873ca227ef52a9593eb2006cf1129c6d766 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Thu, 15 Jul 2010 17:05:30 +0000 Subject: [PATCH] fixed JMS CachingConnectionFactory to correctly cache a producer without fixed destination as well (SPR-7148) git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@3485 50f2f4bb-b051-0410-bef5-90022cba6387 --- .../connection/CachingConnectionFactory.java | 35 +++++++++++++------ 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/org.springframework.jms/src/main/java/org/springframework/jms/connection/CachingConnectionFactory.java b/org.springframework.jms/src/main/java/org/springframework/jms/connection/CachingConnectionFactory.java index fc6bdefbd71..bf7a08e6545 100644 --- a/org.springframework.jms/src/main/java/org/springframework/jms/connection/CachingConnectionFactory.java +++ b/org.springframework.jms/src/main/java/org/springframework/jms/connection/CachingConnectionFactory.java @@ -314,18 +314,30 @@ public class CachingConnectionFactory extends SingleConnectionFactory { } else { this.transactionOpen = true; - if ((methodName.equals("createProducer") || methodName.equals("createSender") || - methodName.equals("createPublisher")) && isCacheProducers()) { + if (isCacheProducers() && (methodName.equals("createProducer") || + methodName.equals("createSender") || methodName.equals("createPublisher"))) { + // Destination argument being null is ok for a producer return getCachedProducer((Destination) args[0]); } - else if ((methodName.equals("createConsumer") || methodName.equals("createReceiver") || - methodName.equals("createSubscriber")) && isCacheConsumers()) { - return getCachedConsumer((Destination) args[0], (args.length > 1 ? (String) args[1] : null), - (args.length > 2 && (Boolean) args[2]), null); - } - else if (methodName.equals("createDurableSubscriber") && isCacheConsumers()) { - return getCachedConsumer((Destination) args[0], (args.length > 2 ? (String) args[2] : null), - (args.length > 3 && (Boolean) args[3]), (String) args[1]); + else if (isCacheConsumers()) { + // let raw JMS invocation throw an exception if Destination (i.e. args[0]) is null + if ((methodName.equals("createConsumer") || methodName.equals("createReceiver") || + methodName.equals("createSubscriber"))) { + if (args[0] != null) { + return getCachedConsumer((Destination) args[0], + (args.length > 1 ? (String) args[1] : null), + (args.length > 2 && (Boolean) args[2]), + null); + } + } + else if (methodName.equals("createDurableSubscriber")) { + if (args[0] != null) { + return getCachedConsumer((Destination) args[0], + (args.length > 2 ? (String) args[2] : null), + (args.length > 3 && (Boolean) args[3]), + (String) args[1]); + } + } } } try { @@ -337,7 +349,7 @@ public class CachingConnectionFactory extends SingleConnectionFactory { } private MessageProducer getCachedProducer(Destination dest) throws JMSException { - DestinationCacheKey cacheKey = new DestinationCacheKey(dest); + DestinationCacheKey cacheKey = (dest != null ? new DestinationCacheKey(dest) : null); MessageProducer producer = this.cachedProducers.get(cacheKey); if (producer != null) { if (logger.isTraceEnabled()) { @@ -439,6 +451,7 @@ public class CachingConnectionFactory extends SingleConnectionFactory { private String destinationString; public DestinationCacheKey(Destination destination) { + Assert.notNull(destination, "Destination must not be null"); this.destination = destination; }