[camel-amqp] Added AMQP connection details.

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

Branch: refs/heads/camel-2.16.x
Commit: 6987fb909b2880eacda9fff22e936358d71497fa
Parents: 160f02d
Author: Henryk Konsek <hekon...@gmail.com>
Authored: Thu Dec 3 13:16:30 2015 +0100
Committer: Andrea Cosentino <anco...@gmail.com>
Committed: Mon Feb 29 09:29:40 2016 +0100

----------------------------------------------------------------------
 .../camel/component/amqp/AMQPComponent.java     | 13 ++++++
 .../component/amqp/AMQPConnectionDetails.java   | 49 ++++++++++++++++++++
 .../camel/component/amqp/AMQPRouteTest.java     | 36 +++++++++-----
 3 files changed, 86 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/6987fb90/components/camel-amqp/src/main/java/org/apache/camel/component/amqp/AMQPComponent.java
----------------------------------------------------------------------
diff --git 
a/components/camel-amqp/src/main/java/org/apache/camel/component/amqp/AMQPComponent.java
 
b/components/camel-amqp/src/main/java/org/apache/camel/component/amqp/AMQPComponent.java
index 8dcf7e6..dc4c2ed 100644
--- 
a/components/camel-amqp/src/main/java/org/apache/camel/component/amqp/AMQPComponent.java
+++ 
b/components/camel-amqp/src/main/java/org/apache/camel/component/amqp/AMQPComponent.java
@@ -17,6 +17,7 @@
 package org.apache.camel.component.amqp;
 
 import java.net.MalformedURLException;
+import java.util.Set;
 import javax.jms.ConnectionFactory;
 
 import org.apache.camel.CamelContext;
@@ -47,6 +48,18 @@ public class AMQPComponent extends JmsComponent {
         setConnectionFactory(connectionFactory);
     }
 
+    // Life-cycle
+
+    @Override
+    protected void doStart() throws Exception {
+        Set<AMQPConnectionDetails> connectionDetails = 
getCamelContext().getRegistry().findByType(AMQPConnectionDetails.class);
+        if (connectionDetails.size() == 1) {
+            AMQPConnectionDetails details = 
connectionDetails.iterator().next();
+            setConnectionFactory(new JmsConnectionFactory(details.username(), 
details.password(), details.uri()));
+        }
+        super.doStart();
+    }
+
     // Factory methods
 
     /**

http://git-wip-us.apache.org/repos/asf/camel/blob/6987fb90/components/camel-amqp/src/main/java/org/apache/camel/component/amqp/AMQPConnectionDetails.java
----------------------------------------------------------------------
diff --git 
a/components/camel-amqp/src/main/java/org/apache/camel/component/amqp/AMQPConnectionDetails.java
 
b/components/camel-amqp/src/main/java/org/apache/camel/component/amqp/AMQPConnectionDetails.java
new file mode 100644
index 0000000..545bd27
--- /dev/null
+++ 
b/components/camel-amqp/src/main/java/org/apache/camel/component/amqp/AMQPConnectionDetails.java
@@ -0,0 +1,49 @@
+/**
+ * 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.amqp;
+
+public class AMQPConnectionDetails {
+
+    private final String uri;
+
+    private final String username;
+
+    private final String password;
+
+    public AMQPConnectionDetails(String uri, String username, String password) 
{
+        this.uri = uri;
+        this.username = username;
+        this.password = password;
+    }
+
+    public AMQPConnectionDetails(String uri) {
+        this(uri, null, null);
+    }
+
+    public String uri() {
+        return uri;
+    }
+
+    public String username() {
+        return username;
+    }
+
+    public String password() {
+        return password;
+    }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/6987fb90/components/camel-amqp/src/test/java/org/apache/camel/component/amqp/AMQPRouteTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-amqp/src/test/java/org/apache/camel/component/amqp/AMQPRouteTest.java
 
b/components/camel-amqp/src/test/java/org/apache/camel/component/amqp/AMQPRouteTest.java
index 3ed0935..fa7319d 100644
--- 
a/components/camel-amqp/src/test/java/org/apache/camel/component/amqp/AMQPRouteTest.java
+++ 
b/components/camel-amqp/src/test/java/org/apache/camel/component/amqp/AMQPRouteTest.java
@@ -20,8 +20,8 @@ import org.apache.activemq.broker.BrokerService;
 import org.apache.camel.CamelContext;
 import org.apache.camel.EndpointInject;
 import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.jms.JmsConstants;
 import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.impl.JndiRegistry;
 import org.apache.camel.test.AvailablePortFinder;
 import org.apache.camel.test.junit4.CamelTestSupport;
 import org.junit.AfterClass;
@@ -58,13 +58,13 @@ public class AMQPRouteTest extends CamelTestSupport {
     public void testJmsQueue() throws Exception {
         resultEndpoint.expectedMessageCount(1);
         resultEndpoint.message(0).header("cheese").isEqualTo(123);
-        template.sendBodyAndHeader("amqp:queue:ping", expectedBody, "cheese", 
123);
+        template.sendBodyAndHeader("amqp-customized:queue:ping", expectedBody, 
"cheese", 123);
         resultEndpoint.assertIsSatisfied();
     }
 
     @Test
     public void testRequestReply() {
-        String response = template.requestBody("amqp:queue:inOut", 
expectedBody, String.class);
+        String response = template.requestBody("amqp-customized:queue:inOut", 
expectedBody, String.class);
         assertEquals("response", response);
     }
 
@@ -72,14 +72,14 @@ public class AMQPRouteTest extends CamelTestSupport {
     public void testJmsTopic() throws Exception {
         resultEndpoint.expectedMessageCount(2);
         resultEndpoint.message(0).header("cheese").isEqualTo(123);
-        template.sendBodyAndHeader("amqp:topic:ping", expectedBody, "cheese", 
123);
+        template.sendBodyAndHeader("amqp-customized:topic:ping", expectedBody, 
"cheese", 123);
         resultEndpoint.assertIsSatisfied();
     }
 
     @Test
     public void testPrefixWildcard() throws Exception {
         resultEndpoint.expectedMessageCount(1);
-        template.sendBody("amqp:wildcard.foo.bar", expectedBody);
+        template.sendBody("amqp-customized:wildcard.foo.bar", expectedBody);
         resultEndpoint.assertIsSatisfied();
     }
 
@@ -87,37 +87,49 @@ public class AMQPRouteTest extends CamelTestSupport {
     public void testIncludeDestination() throws Exception {
         resultEndpoint.expectedMessageCount(1);
         resultEndpoint.message(0).header("JMSDestination").isEqualTo("ping");
-        template.sendBody("amqp:queue:ping", expectedBody);
+        template.sendBody("amqp-customized:queue:ping", expectedBody);
         resultEndpoint.assertIsSatisfied();
     }
 
     // Routes fixtures
 
+
+    @Override
+    protected JndiRegistry createRegistry() throws Exception {
+        JndiRegistry registry = super.createRegistry();
+        registry.bind("amqpConnection", new 
AMQPConnectionDetails("amqp://localhost:" + amqpPort));
+        return registry;
+    }
+
     protected CamelContext createCamelContext() throws Exception {
         CamelContext camelContext = super.createCamelContext();
-        camelContext.addComponent("amqp", amqpComponent("amqp://localhost:" + 
amqpPort));
+        camelContext.addComponent("amqp-customized", 
amqpComponent("amqp://localhost:" + amqpPort));
         return camelContext;
     }
 
     protected RouteBuilder createRouteBuilder() throws Exception {
         return new RouteBuilder() {
             public void configure() throws Exception {
-                from("amqp:queue:ping")
+                from("amqp-customized:queue:ping")
                     .to("log:routing")
                     .to("mock:result");
 
-                from("amqp:queue:inOut")
+                from("amqp-customized:queue:inOut")
                         .setBody().constant("response");
 
-                from("amqp:topic:ping")
+                from("amqp-customized:topic:ping")
+                        .to("log:routing")
+                        .to("mock:result");
+
+                from("amqp-customized:topic:ping")
                         .to("log:routing")
                         .to("mock:result");
 
-                from("amqp:topic:ping")
+                from("amqp-customized:queue:wildcard.>")
                         .to("log:routing")
                         .to("mock:result");
 
-                from("amqp:queue:wildcard.>")
+                from("amqp:queue:uriEndpoint")
                         .to("log:routing")
                         .to("mock:result");
             }

Reply via email to