From commits-return-75924-archive-asf-public=cust-asf.ponee.io@camel.apache.org Mon Aug 5 09:33:40 2019 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [207.244.88.153]) by mx-eu-01.ponee.io (Postfix) with SMTP id E9E98180181 for ; Mon, 5 Aug 2019 11:33:39 +0200 (CEST) Received: (qmail 32114 invoked by uid 500); 5 Aug 2019 09:33:39 -0000 Mailing-List: contact commits-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list commits@camel.apache.org Received: (qmail 32105 invoked by uid 99); 5 Aug 2019 09:33:39 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 05 Aug 2019 09:33:39 +0000 Received: by gitbox.apache.org (ASF Mail Server at gitbox.apache.org, from userid 33) id 37CBB85EE3; Mon, 5 Aug 2019 09:33:34 +0000 (UTC) Date: Mon, 05 Aug 2019 09:33:33 +0000 To: "commits@camel.apache.org" Subject: [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. MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Message-ID: <156499761373.30723.3905743180732457610@gitbox.apache.org> From: davsclaus@apache.org X-Git-Host: gitbox.apache.org X-Git-Repo: camel X-Git-Refname: refs/heads/master X-Git-Reftype: branch X-Git-Oldrev: 467500f2a79c21d25fd895ba7d496ce7da5db015 X-Git-Newrev: c0cb9e9a3eeffbd27155377eea30adbf04451158 X-Git-Rev: c0cb9e9a3eeffbd27155377eea30adbf04451158 X-Git-NotificationType: ref_changed_plus_diff X-Git-Multimail-Version: 1.5.dev Auto-Submitted: auto-generated 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 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")); + } + } + +}