camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject [1/2] camel git commit: CAMEL-8270 exchangeName in the URI is optional
Date Thu, 30 Apr 2015 07:03:02 GMT
Repository: camel
Updated Branches:
  refs/heads/camel-2.14.x 2f175cb68 -> 329666bd1
  refs/heads/camel-2.15.x a9c3ff8c8 -> 0b9d33f11


CAMEL-8270 exchangeName in the URI is optional

CAMEL-8270 Added an unit test for it


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/0b9d33f1
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/0b9d33f1
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/0b9d33f1

Branch: refs/heads/camel-2.15.x
Commit: 0b9d33f11920e565419a4573131bc5d90fd4356f
Parents: a9c3ff8
Author: Willem Jiang <willem.jiang@gmail.com>
Authored: Thu Apr 30 14:40:00 2015 +0800
Committer: Willem Jiang <willem.jiang@gmail.com>
Committed: Thu Apr 30 15:02:20 2015 +0800

----------------------------------------------------------------------
 .../camel/component/rabbitmq/RabbitMQComponent.java     |  6 +++---
 .../camel/component/rabbitmq/RabbitMQEndpointTest.java  | 12 ++++++++++++
 2 files changed, 15 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/0b9d33f1/components/camel-rabbitmq/src/main/java/org/apache/camel/component/rabbitmq/RabbitMQComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-rabbitmq/src/main/java/org/apache/camel/component/rabbitmq/RabbitMQComponent.java
b/components/camel-rabbitmq/src/main/java/org/apache/camel/component/rabbitmq/RabbitMQComponent.java
index 5f97f49..54dd2bf 100644
--- a/components/camel-rabbitmq/src/main/java/org/apache/camel/component/rabbitmq/RabbitMQComponent.java
+++ b/components/camel-rabbitmq/src/main/java/org/apache/camel/component/rabbitmq/RabbitMQComponent.java
@@ -45,10 +45,10 @@ public class RabbitMQComponent extends UriEndpointComponent {
         URI host = new URI("http://" + remaining);
         String hostname = host.getHost();
         int portNumber = host.getPort();
-        if (host.getPath().trim().length() <= 1) {
-            throw new IllegalArgumentException("No URI path as the exchangeName for the RabbitMQEndpoint,
the URI is " + uri);
+        String exchangeName = ""; // We need to support the exchange to be "" the path is
empty
+        if (host.getPath().trim().length() > 1) {
+            exchangeName = host.getPath().substring(1);
         }
-        String exchangeName = host.getPath().substring(1);
 
         // ConnectionFactory reference
         ConnectionFactory connectionFactory = resolveAndRemoveReferenceParameter(params,
"connectionFactory", ConnectionFactory.class);

http://git-wip-us.apache.org/repos/asf/camel/blob/0b9d33f1/components/camel-rabbitmq/src/test/java/org/apache/camel/component/rabbitmq/RabbitMQEndpointTest.java
----------------------------------------------------------------------
diff --git a/components/camel-rabbitmq/src/test/java/org/apache/camel/component/rabbitmq/RabbitMQEndpointTest.java
b/components/camel-rabbitmq/src/test/java/org/apache/camel/component/rabbitmq/RabbitMQEndpointTest.java
index df12e65..52e76c8 100644
--- a/components/camel-rabbitmq/src/test/java/org/apache/camel/component/rabbitmq/RabbitMQEndpointTest.java
+++ b/components/camel-rabbitmq/src/test/java/org/apache/camel/component/rabbitmq/RabbitMQEndpointTest.java
@@ -73,6 +73,18 @@ public class RabbitMQEndpointTest extends CamelTestSupport {
         assertEquals(tag, exchange.getIn().getHeader(RabbitMQConstants.DELIVERY_TAG));
         assertEquals(body, exchange.getIn().getBody());
     }
+    
+    @Test
+    public void testExchangeNameIsOptional() throws Exception {
+        RabbitMQEndpoint endpoint1 = context.getEndpoint("rabbitmq:localhost/", RabbitMQEndpoint.class);
+        assertEquals("Get a wrong exchange name", "", endpoint1.getExchangeName());
+
+        RabbitMQEndpoint endpoint2 = context.getEndpoint("rabbitmq:localhost?autoAck=false",
RabbitMQEndpoint.class);
+        assertEquals("Get a wrong exchange name", "", endpoint2.getExchangeName());
+        
+        RabbitMQEndpoint endpoint3 = context.getEndpoint("rabbitmq:localhost/exchange", RabbitMQEndpoint.class);
+        assertEquals("Get a wrong exchange name", "exchange", endpoint3.getExchangeName());
+    }
 
     @Test
     public void testCreatingRabbitExchangeSetsCustomHeaders() throws Exception {


Mime
View raw message