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 2010/09/03 15:37:05 UTC

svn commit: r992293 - in /camel/trunk/components/camel-jms/src: main/java/org/apache/camel/component/jms/ test/java/org/apache/camel/component/jms/

Author: davsclaus
Date: Fri Sep  3 13:37:05 2010
New Revision: 992293

URL: http://svn.apache.org/viewvc?rev=992293&view=rev
Log:
CAMEL-3092: Durable subscribers (topics) must provided a clientId. Camel now fail fast if not provided.

Added:
    camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsDurableTopicInvalidConfigurationTest.java
    camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsDurableTopicTest.java   (contents, props changed)
      - copied, changed from r992224, camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsInOnlyWithReplyToHeaderTest.java
Modified:
    camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsComponent.java
    camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsConfiguration.java

Modified: camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsComponent.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsComponent.java?rev=992293&r1=992292&r2=992293&view=diff
==============================================================================
--- camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsComponent.java (original)
+++ camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsComponent.java Fri Sep  3 13:37:05 2010
@@ -275,6 +275,7 @@ public class JmsComponent extends Defaul
         getConfiguration().setRecoveryInterval(recoveryInterval);
     }
 
+    @Deprecated
     public void setSubscriptionDurable(boolean subscriptionDurable) {
         getConfiguration().setSubscriptionDurable(subscriptionDurable);
     }

Modified: camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsConfiguration.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsConfiguration.java?rev=992293&r1=992292&r2=992293&view=diff
==============================================================================
--- camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsConfiguration.java (original)
+++ camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsConfiguration.java Fri Sep  3 13:37:05 2010
@@ -455,10 +455,12 @@ public class JmsConfiguration implements
         this.exceptionListener = exceptionListener;
     }
 
+    @Deprecated
     public boolean isSubscriptionDurable() {
         return subscriptionDurable;
     }
 
+    @Deprecated
     public void setSubscriptionDurable(boolean subscriptionDurable) {
         this.subscriptionDurable = subscriptionDurable;
     }
@@ -820,20 +822,16 @@ public class JmsConfiguration implements
         }
         container.setAutoStartup(autoStartup);
 
-        if (clientId != null) {
-            container.setClientId(clientId);
-        }
-        container.setSubscriptionDurable(subscriptionDurable);
         if (durableSubscriptionName != null) {
             container.setDurableSubscriptionName(durableSubscriptionName);
-        }
-
-        // lets default to durable subscription if the subscriber name and
-        // client ID are specified (as there's
-        // no reason to specify them if not! :)
-        if (durableSubscriptionName != null && clientId != null) {
             container.setSubscriptionDurable(true);
         }
+        if (durableSubscriptionName != null && clientId == null) {
+            throw new IllegalArgumentException("ClientId must be configured when subscription is durable for " + endpoint);
+        }
+        if (clientId != null) {
+            container.setClientId(clientId);
+        }
 
         if (exceptionListener != null) {
             container.setExceptionListener(exceptionListener);

Added: camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsDurableTopicInvalidConfigurationTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsDurableTopicInvalidConfigurationTest.java?rev=992293&view=auto
==============================================================================
--- camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsDurableTopicInvalidConfigurationTest.java (added)
+++ camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsDurableTopicInvalidConfigurationTest.java Fri Sep  3 13:37:05 2010
@@ -0,0 +1,64 @@
+/**
+ * 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.activemq.ActiveMQConnectionFactory;
+import org.apache.camel.CamelContext;
+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.jmsComponentClientAcknowledge;
+
+/**
+ * @version $Revision: 992224 $
+ */
+public class JmsDurableTopicInvalidConfigurationTest extends CamelTestSupport {
+
+    @Override
+    public void setUp() throws Exception {
+        deleteDirectory("./activemq-data");
+        super.setUp();
+    }
+
+    @Test
+    public void testDurableTopicInvalidConfiguration() throws Exception {
+        try {
+            context.addRoutes(new RouteBuilder() {
+                @Override
+                public void configure() throws Exception {
+                    from("activemq:topic:foo?durableSubscriptionName=bar")
+                        .to("mock:result");
+                }
+            });
+            fail("Should have thrown exception");
+        } catch (IllegalArgumentException e) {
+            assertEquals("ClientId must be configured when subscription is durable for"
+                + " Endpoint[activemq://topic:foo?durableSubscriptionName=bar]", e.getMessage());
+        }
+    }
+
+    protected CamelContext createCamelContext() throws Exception {
+        CamelContext camelContext = super.createCamelContext();
+        ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=true");
+        camelContext.addComponent("activemq", jmsComponentClientAcknowledge(connectionFactory));
+        return camelContext;
+    }
+
+}
\ No newline at end of file

Copied: camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsDurableTopicTest.java (from r992224, camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsInOnlyWithReplyToHeaderTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsDurableTopicTest.java?p2=camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsDurableTopicTest.java&p1=camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsInOnlyWithReplyToHeaderTest.java&r1=992224&r2=992293&rev=992293&view=diff
==============================================================================
--- camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsInOnlyWithReplyToHeaderTest.java (original)
+++ camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsDurableTopicTest.java Fri Sep  3 13:37:05 2010
@@ -20,8 +20,6 @@ import javax.jms.ConnectionFactory;
 
 import org.apache.activemq.ActiveMQConnectionFactory;
 import org.apache.camel.CamelContext;
-import org.apache.camel.Exchange;
-import org.apache.camel.Processor;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.test.junit4.CamelTestSupport;
@@ -32,31 +30,33 @@ import static org.apache.camel.component
 /**
  * @version $Revision$
  */
-public class JmsInOnlyWithReplyToHeaderTest extends CamelTestSupport {
+public class JmsDurableTopicTest extends CamelTestSupport {
+
+    @Override
+    public void setUp() throws Exception {
+        deleteDirectory("./activemq-data");
+        super.setUp();
+    }
 
     @Test
-    public void testJmsInOnlyWithReplyToHeader() throws Exception {
+    public void testDurableTopic() throws Exception {
         MockEndpoint mock = getMockEndpoint("mock:result");
         mock.expectedBodiesReceived("Hello World");
-        mock.expectedHeaderReceived("JMSReplyTo", "queue://bar");
 
-        template.send("activemq:queue:foo?preserveMessageQos=true", new Processor() {
-            public void process(Exchange exchange) throws Exception {
-                exchange.getIn().setBody("World");
-                exchange.getIn().setHeader("JMSReplyTo", "bar");
-            }
-        });
+        MockEndpoint mock2 = getMockEndpoint("mock:result2");
+        mock2.expectedBodiesReceived("Hello World");
 
-        assertMockEndpointsSatisfied();
+        // wait a bit and send the message
+        Thread.sleep(1000);
+
+        template.sendBody("activemq:topic:foo", "Hello World");
 
-        // reply is in bar queue so lets consume it
-        String reply = consumer.receiveBody("activemq:queue:bar", 5000, String.class);
-        assertEquals("Hello World", reply);
+        assertMockEndpointsSatisfied();
     }
 
     protected CamelContext createCamelContext() throws Exception {
         CamelContext camelContext = super.createCamelContext();
-        ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false");
+        ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=true");
         camelContext.addComponent("activemq", jmsComponentClientAcknowledge(connectionFactory));
         return camelContext;
     }
@@ -66,9 +66,11 @@ public class JmsInOnlyWithReplyToHeaderT
         return new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-                from("activemq:queue:foo")
-                    .transform(body().prepend("Hello "))
+                from("activemq:topic:foo?clientId=123&durableSubscriptionName=bar")
                     .to("mock:result");
+
+                from("activemq:topic:foo?clientId=456&durableSubscriptionName=bar")
+                    .to("mock:result2");
             }
         };
     }

Propchange: camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsDurableTopicTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsDurableTopicTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date