You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2013/07/28 08:50:58 UTC

[2/3] git commit: CAMEL-6580: camel-jms - Dont allow CACHE_NONE for replyToCacheLevelName for temporary queues

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/d3c07055
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/d3c07055
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/d3c07055

Branch: refs/heads/master
Commit: d3c07055a250cc377042b43899d686b0cb774385
Parents: 0fc542c
Author: Claus Ibsen <da...@apache.org>
Authored: Sun Jul 28 08:48:54 2013 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Sun Jul 28 08:48:54 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/d3c07055/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/d3c07055/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