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 2019/08/05 09:33:33 UTC

[camel] branch master updated: CAMEL-5832: camel-jms - JMS consumer should detect JMSReplyTo being sending to itself to avoid circular looping. Thanks to Devendra Khanolkar for the sample unit test.

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/master by this push:
     new c0cb9e9  CAMEL-5832: camel-jms - JMS consumer should detect JMSReplyTo being sending to itself to avoid circular looping. Thanks to Devendra Khanolkar for the sample unit test.
c0cb9e9 is described below

commit c0cb9e9a3eeffbd27155377eea30adbf04451158
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Mon Aug 5 10:17:13 2019 +0200

    CAMEL-5832: camel-jms - JMS consumer should detect JMSReplyTo being sending to itself to avoid circular looping. Thanks to Devendra Khanolkar for the sample unit test.
---
 .../apache/camel/component/jms/JmsEndpoint.java    |  8 +++
 .../issues/JmsReplyToComponentEndlessLoopTest.java | 61 ++++++++++++++++++++++
 2 files changed, 69 insertions(+)

diff --git a/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsEndpoint.java b/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsEndpoint.java
index b1629e6..4d02c57 100644
--- a/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsEndpoint.java
+++ b/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsEndpoint.java
@@ -285,6 +285,14 @@ public class JmsEndpoint extends DefaultEndpoint implements AsyncEndpoint, Heade
         JmsConsumer consumer = new JmsConsumer(this, processor, listenerContainer);
         configureListenerContainer(listenerContainer, consumer);
         configureConsumer(consumer);
+
+        String replyTo = consumer.getEndpoint().getReplyTo();
+        if (replyTo != null && consumer.getEndpoint().getDestinationName().equals(replyTo)) {
+            throw new IllegalArgumentException("Invalid Endpoint configuration: " + consumer.getEndpoint()
+                    + ". ReplyTo=" + replyTo + " cannot be the same as the destination name on the JmsConsumer as that"
+                    + " would lead to the consumer sending reply messages to itself in an endless loop.");
+        }
+
         return consumer;
     }
 
diff --git a/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsReplyToComponentEndlessLoopTest.java b/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsReplyToComponentEndlessLoopTest.java
new file mode 100644
index 0000000..2f402be
--- /dev/null
+++ b/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsReplyToComponentEndlessLoopTest.java
@@ -0,0 +1,61 @@
+/*
+ * 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.issues;
+
+import javax.jms.ConnectionFactory;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.jms.CamelJmsTestHelper;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+import static org.apache.camel.component.jms.JmsComponent.jmsComponentAutoAcknowledge;
+
+public class JmsReplyToComponentEndlessLoopTest extends CamelTestSupport {
+
+    @Override
+    public boolean isUseRouteBuilder() {
+        return false;
+    }
+
+    @Override
+    protected CamelContext createCamelContext() throws Exception {
+        CamelContext camelContext = super.createCamelContext();
+        ConnectionFactory connectionFactory = CamelJmsTestHelper.createConnectionFactory();
+        camelContext.addComponent("activemq", jmsComponentAutoAcknowledge(connectionFactory));
+        return camelContext;
+    }
+
+    @Test
+    public void testReplyToInvalid() throws Exception {
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("activemq:queue:foo?replyTo=foo").to("mock:result");
+            }
+        });
+        try {
+            context.start();
+            fail("Should throw exception");
+        } catch (Exception e) {
+            IllegalArgumentException iae = assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
+            assertTrue(iae.getMessage().contains("ReplyTo=foo cannot be the same as the destination name"));
+        }
+    }
+
+}