From 5cf4ada14afeaad7d560f2c652aaa59e697f0c8d Mon Sep 17 00:00:00 2001 From: Claus Ibsen Date: Wed, 14 Sep 2011 13:20:52 +0000 Subject: [PATCH] AMQ-3498: Added support for using ActiveMQ Destination Options in the Camel endpoint uris, by specifing the options with destination. prefix. git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1170599 13f79535-47bb-0310-9956-ffa450edef68 --- .../camel/component/ActiveMQComponent.java | 27 ++++++++++++ ...CamelDestinationExclusiveConsumerTest.java | 43 +++++++++++++++++++ ...stinationExclusiveConsumerTest-context.xml | 43 +++++++++++++++++++ 3 files changed, 113 insertions(+) create mode 100644 activemq-camel/src/test/java/org/apache/activemq/camel/CamelDestinationExclusiveConsumerTest.java create mode 100644 activemq-camel/src/test/resources/org/apache/activemq/camel/CamelDestinationExclusiveConsumerTest-context.xml diff --git a/activemq-camel/src/main/java/org/apache/activemq/camel/component/ActiveMQComponent.java b/activemq-camel/src/main/java/org/apache/activemq/camel/component/ActiveMQComponent.java index 7f842cf9f6..38491740d0 100644 --- a/activemq-camel/src/main/java/org/apache/activemq/camel/component/ActiveMQComponent.java +++ b/activemq-camel/src/main/java/org/apache/activemq/camel/component/ActiveMQComponent.java @@ -16,6 +16,8 @@ */ package org.apache.activemq.camel.component; +import java.net.URISyntaxException; +import java.util.Map; import java.util.concurrent.CopyOnWriteArrayList; import org.apache.activemq.ActiveMQConnectionFactory; @@ -23,6 +25,9 @@ import org.apache.activemq.Service; import org.apache.camel.CamelContext; import org.apache.camel.component.jms.JmsComponent; import org.apache.camel.component.jms.JmsConfiguration; +import org.apache.camel.util.IntrospectionSupport; +import org.apache.camel.util.ObjectHelper; +import org.apache.camel.util.URISupport; import org.springframework.jms.connection.SingleConnectionFactory; /** @@ -130,6 +135,28 @@ public class ActiveMQComponent extends JmsComponent { singleConnectionFactoryList.add(singleConnectionFactory); } + @Override + @SuppressWarnings("unchecked") + protected String convertPathToActualDestination(String path, Map parameters) { + // support ActiveMQ destination options using the destination. prefix + // http://activemq.apache.org/destination-options.html + Map options = IntrospectionSupport.extractProperties(parameters, "destination."); + + String query; + try { + query = URISupport.createQueryString(options); + } catch (URISyntaxException e) { + throw ObjectHelper.wrapRuntimeCamelException(e); + } + + // if we have destination options then append them to the destination name + if (ObjectHelper.isNotEmpty(query)) { + return path + "?" + query; + } else { + return path; + } + } + @Override protected void doStart() throws Exception { super.doStart(); diff --git a/activemq-camel/src/test/java/org/apache/activemq/camel/CamelDestinationExclusiveConsumerTest.java b/activemq-camel/src/test/java/org/apache/activemq/camel/CamelDestinationExclusiveConsumerTest.java new file mode 100644 index 0000000000..bf6c01336a --- /dev/null +++ b/activemq-camel/src/test/java/org/apache/activemq/camel/CamelDestinationExclusiveConsumerTest.java @@ -0,0 +1,43 @@ +/** + * + * 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.activemq.camel; + +import org.apache.camel.CamelContext; +import org.apache.camel.EndpointInject; +import org.apache.camel.component.mock.MockEndpoint; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit38.AbstractJUnit38SpringContextTests; + +/** + * + */ +@ContextConfiguration +public class CamelDestinationExclusiveConsumerTest extends AbstractJUnit38SpringContextTests { + + @Autowired + protected CamelContext camelContext; + + @EndpointInject(uri = "mock:results") + protected MockEndpoint expectedEndpoint; + + public void testMocksAreValid() throws Exception { + expectedEndpoint.expectedMessageCount(1); + MockEndpoint.assertIsSatisfied(camelContext); + } +} diff --git a/activemq-camel/src/test/resources/org/apache/activemq/camel/CamelDestinationExclusiveConsumerTest-context.xml b/activemq-camel/src/test/resources/org/apache/activemq/camel/CamelDestinationExclusiveConsumerTest-context.xml new file mode 100644 index 0000000000..7782b9e8a1 --- /dev/null +++ b/activemq-camel/src/test/resources/org/apache/activemq/camel/CamelDestinationExclusiveConsumerTest-context.xml @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + +