CAMEL-6580: camel-jms - Dont allow CACHE_NONE for replyToCacheLevelName for temporary queues
Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/d37b8fa1 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/d37b8fa1 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/d37b8fa1 Branch: refs/heads/camel-2.11.x Commit: d37b8fa193c3c9ca139fe1ee831a048b705c6b3e Parents: b0e83a7 Author: Claus Ibsen <davscl...@apache.org> Authored: Sun Jul 28 08:48:54 2013 +0200 Committer: Claus Ibsen <davscl...@apache.org> Committed: Sun Jul 28 08:49:14 2013 +0200 ---------------------------------------------------------------------- .../jms/reply/TemporaryQueueReplyManager.java | 3 + .../JmsRequestReplyTemporaryCacheNoneTest.java | 77 ++++++++++++++++++++ 2 files changed, 80 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/d37b8fa1/components/camel-jms/src/main/java/org/apache/camel/component/jms/reply/TemporaryQueueReplyManager.java ---------------------------------------------------------------------- diff --git a/components/camel-jms/src/main/java/org/apache/camel/component/jms/reply/TemporaryQueueReplyManager.java b/components/camel-jms/src/main/java/org/apache/camel/component/jms/reply/TemporaryQueueReplyManager.java index fbfbf5c..8f9084e 100644 --- a/components/camel-jms/src/main/java/org/apache/camel/component/jms/reply/TemporaryQueueReplyManager.java +++ b/components/camel-jms/src/main/java/org/apache/camel/component/jms/reply/TemporaryQueueReplyManager.java @@ -120,6 +120,9 @@ public class TemporaryQueueReplyManager extends ReplyManagerSupport { // we use CACHE_CONSUMER by default to cling to the consumer as long as we can, since we can only consume // msgs from the JMS Connection that created the temp destination in the first place if (endpoint.getReplyToCacheLevelName() != null) { + if ("CACHE_NONE".equals(endpoint.getReplyToCacheLevelName())) { + throw new IllegalArgumentException("ReplyToCacheLevelName cannot be CACHE_NONE when using temporary reply queues. The value must be either CACHE_CONSUMER, or CACHE_SESSION"); + } answer.setCacheLevelName(endpoint.getReplyToCacheLevelName()); } else { answer.setCacheLevel(DefaultMessageListenerContainer.CACHE_CONSUMER); http://git-wip-us.apache.org/repos/asf/camel/blob/d37b8fa1/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsRequestReplyTemporaryCacheNoneTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsRequestReplyTemporaryCacheNoneTest.java b/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsRequestReplyTemporaryCacheNoneTest.java new file mode 100644 index 0000000..afa691e --- /dev/null +++ b/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsRequestReplyTemporaryCacheNoneTest.java @@ -0,0 +1,77 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.jms; + +import javax.jms.ConnectionFactory; + +import org.apache.camel.CamelContext; +import org.apache.camel.CamelExecutionException; +import org.apache.camel.Exchange; +import org.apache.camel.Processor; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.test.junit4.CamelTestSupport; +import org.junit.Test; + +import static org.apache.camel.component.jms.JmsComponent.jmsComponentAutoAcknowledge; + +/** + * + */ +public class JmsRequestReplyTemporaryCacheNoneTest extends CamelTestSupport { + + protected String componentName = "activemq"; + + protected CamelContext createCamelContext() throws Exception { + CamelContext camelContext = super.createCamelContext(); + + ConnectionFactory connectionFactory = CamelJmsTestHelper.createConnectionFactory(); + camelContext.addComponent(componentName, jmsComponentAutoAcknowledge(connectionFactory)); + + return camelContext; + } + + @Override + public boolean isUseRouteBuilder() { + return false; + } + + @Test + public void testNotAllowed() throws Exception { + context.addRoutes(new RouteBuilder() { + @Override + public void configure() throws Exception { + from("direct:start").to("activemq:queue:hello?replyToCacheLevelName=CACHE_NONE"); + + from("activemq:queue:hello").process(new Processor() { + public void process(Exchange exchange) throws Exception { + exchange.getIn().setBody("Bye World"); + assertNotNull(exchange.getIn().getHeader("JMSReplyTo")); + } + }).to("mock:result"); + } + }); + context.start(); + + try { + template.requestBody("direct:start", "Hello World"); + fail("Should throw exception"); + } catch (CamelExecutionException e) { + IllegalArgumentException iae = assertIsInstanceOf(IllegalArgumentException.class, e.getCause().getCause()); + assertEquals("ReplyToCacheLevelName cannot be CACHE_NONE when using temporary reply queues. The value must be either CACHE_CONSUMER, or CACHE_SESSION", iae.getMessage()); + } + } +} \ No newline at end of file