You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by cs...@apache.org on 2012/06/27 12:20:31 UTC
svn commit: r1354406 - in /camel/trunk/components: ./ camel-dynamicep/
camel-dynamicep/src/ camel-dynamicep/src/main/
camel-dynamicep/src/main/java/ camel-dynamicep/src/main/java/org/
camel-dynamicep/src/main/java/org/apache/ camel-dynamicep/src/main/j...
Author: cschneider
Date: Wed Jun 27 10:20:29 2012
New Revision: 1354406
URL: http://svn.apache.org/viewvc?rev=1354406&view=rev
Log: (empty)
Added:
camel/trunk/components/camel-dynamicep/ (with props)
camel/trunk/components/camel-dynamicep/ReadMe.txt
camel/trunk/components/camel-dynamicep/pom.xml
camel/trunk/components/camel-dynamicep/src/
camel/trunk/components/camel-dynamicep/src/main/
camel/trunk/components/camel-dynamicep/src/main/java/
camel/trunk/components/camel-dynamicep/src/main/java/org/
camel/trunk/components/camel-dynamicep/src/main/java/org/apache/
camel/trunk/components/camel-dynamicep/src/main/java/org/apache/camel/
camel/trunk/components/camel-dynamicep/src/main/java/org/apache/camel/dynamicep/
camel/trunk/components/camel-dynamicep/src/main/java/org/apache/camel/dynamicep/DynamicComponent.java
camel/trunk/components/camel-dynamicep/src/main/java/org/apache/camel/dynamicep/DynamicConsumer.java
camel/trunk/components/camel-dynamicep/src/main/java/org/apache/camel/dynamicep/DynamicEndpoint.java
camel/trunk/components/camel-dynamicep/src/main/resources/
camel/trunk/components/camel-dynamicep/src/main/resources/META-INF/
camel/trunk/components/camel-dynamicep/src/main/resources/META-INF/services/
camel/trunk/components/camel-dynamicep/src/main/resources/META-INF/services/org/
camel/trunk/components/camel-dynamicep/src/main/resources/META-INF/services/org/apache/
camel/trunk/components/camel-dynamicep/src/main/resources/META-INF/services/org/apache/camel/
camel/trunk/components/camel-dynamicep/src/main/resources/META-INF/services/org/apache/camel/component/
camel/trunk/components/camel-dynamicep/src/main/resources/META-INF/services/org/apache/camel/component/dynamicep
camel/trunk/components/camel-dynamicep/src/test/
camel/trunk/components/camel-dynamicep/src/test/java/
camel/trunk/components/camel-dynamicep/src/test/java/org/
camel/trunk/components/camel-dynamicep/src/test/java/org/apache/
camel/trunk/components/camel-dynamicep/src/test/java/org/apache/camel/
camel/trunk/components/camel-dynamicep/src/test/java/org/apache/camel/camel_dynamicep/
camel/trunk/components/camel-dynamicep/src/test/java/org/apache/camel/camel_dynamicep/DynamicComponentTest.java
camel/trunk/components/camel-dynamicep/src/test/resources/
camel/trunk/components/camel-dynamicep/src/test/resources/dynamicep_manual_test.xml
camel/trunk/components/camel-dynamicep/src/test/resources/log4j.properties
Modified:
camel/trunk/components/pom.xml
Propchange: camel/trunk/components/camel-dynamicep/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Wed Jun 27 10:20:29 2012
@@ -0,0 +1,4 @@
+.classpath
+.project
+.settings
+target
Added: camel/trunk/components/camel-dynamicep/ReadMe.txt
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-dynamicep/ReadMe.txt?rev=1354406&view=auto
==============================================================================
--- camel/trunk/components/camel-dynamicep/ReadMe.txt (added)
+++ camel/trunk/components/camel-dynamicep/ReadMe.txt Wed Jun 27 10:20:29 2012
@@ -0,0 +1,12 @@
+Dynamic Endpoint Component
+==========================
+
+Provides a component that can install a dynamic number of consumers.
+
+Example:
+
+from("dynamicep:file:/test,jetty:http://localhost:9000").to("log:test");
+
+This route listens on both file:/test as well as jetty:http://localhost:900. Any messages coming in will be forwarded to the rest of the route.
+As the list of endpoints can come from a configuration this allows to configure at runtime on which endpoints the route should listen.
+
\ No newline at end of file
Added: camel/trunk/components/camel-dynamicep/pom.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-dynamicep/pom.xml?rev=1354406&view=auto
==============================================================================
--- camel/trunk/components/camel-dynamicep/pom.xml (added)
+++ camel/trunk/components/camel-dynamicep/pom.xml Wed Jun 27 10:20:29 2012
@@ -0,0 +1,95 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- 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. -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-parent</artifactId>
+ <version>2.11-SNAPSHOT</version>
+ <relativePath>../../parent</relativePath>
+ </parent>
+
+ <artifactId>dynamicep</artifactId>
+ <name>Camel :: Dynamic Endpoint</name>
+ <description>Supports a list of dynamically configurable endpoint in the from part of a route</description>
+
+ <packaging>bundle</packaging>
+
+ <properties>
+ <camel.osgi.export.pkg>org.apache.camel.dynamicep</camel.osgi.export.pkg>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-core</artifactId>
+ </dependency>
+
+ <!-- for testing -->
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-test</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-jetty</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <!-- logging -->
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <!-- <build> -->
+ <!-- <defaultGoal>install</defaultGoal> -->
+
+ <!-- <plugins> -->
+ <!-- <plugin> -->
+ <!-- <groupId>org.apache.maven.plugins</groupId> -->
+ <!-- <artifactId>maven-compiler-plugin</artifactId> -->
+ <!-- <version>2.3.2</version> -->
+ <!-- <configuration> -->
+ <!-- <source>1.6</source> -->
+ <!-- <target>1.6</target> -->
+ <!-- </configuration> -->
+ <!-- </plugin> -->
+ <!-- <plugin> -->
+ <!-- <groupId>org.apache.felix</groupId> -->
+ <!-- <artifactId>maven-bundle-plugin</artifactId> -->
+ <!-- <version>2.3.7</version> -->
+ <!-- <extensions>true</extensions> -->
+ <!-- <configuration> -->
+ <!-- <instructions> -->
+ <!-- <Bundle-SymbolicName>${project.groupId}.${project.artifactId}</Bundle-SymbolicName> -->
+ <!-- <Export-Package></Export-Package> -->
+ <!-- </instructions> -->
+ <!-- </configuration> -->
+ <!-- </plugin> -->
+ <!-- </plugins> -->
+ <!-- </build> -->
+</project>
Added: camel/trunk/components/camel-dynamicep/src/main/java/org/apache/camel/dynamicep/DynamicComponent.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-dynamicep/src/main/java/org/apache/camel/dynamicep/DynamicComponent.java?rev=1354406&view=auto
==============================================================================
--- camel/trunk/components/camel-dynamicep/src/main/java/org/apache/camel/dynamicep/DynamicComponent.java (added)
+++ camel/trunk/components/camel-dynamicep/src/main/java/org/apache/camel/dynamicep/DynamicComponent.java Wed Jun 27 10:20:29 2012
@@ -0,0 +1,39 @@
+/**
+ * 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.dynamicep;
+
+import java.util.Map;
+
+import org.apache.camel.Endpoint;
+import org.apache.camel.impl.DefaultComponent;
+
+/**
+ * Represents the component that manages {@link DynamicEndpoint}.
+ */
+public class DynamicComponent extends DefaultComponent {
+
+ public Endpoint createEndpoint(String uri) throws Exception {
+ Endpoint endpoint = new DynamicEndpoint(uri, this);
+ return endpoint;
+ }
+
+ @Override
+ protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
+ // TODO Auto-generated method stub
+ return null;
+ }
+}
Added: camel/trunk/components/camel-dynamicep/src/main/java/org/apache/camel/dynamicep/DynamicConsumer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-dynamicep/src/main/java/org/apache/camel/dynamicep/DynamicConsumer.java?rev=1354406&view=auto
==============================================================================
--- camel/trunk/components/camel-dynamicep/src/main/java/org/apache/camel/dynamicep/DynamicConsumer.java (added)
+++ camel/trunk/components/camel-dynamicep/src/main/java/org/apache/camel/dynamicep/DynamicConsumer.java Wed Jun 27 10:20:29 2012
@@ -0,0 +1,69 @@
+/**
+ * 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.dynamicep;
+
+
+import java.net.URLDecoder;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.camel.Consumer;
+import org.apache.camel.Endpoint;
+import org.apache.camel.Processor;
+import org.apache.camel.impl.DefaultConsumer;
+
+/**
+ * Parses the endpoint uri and creates one consumer for each
+ * endpopint to listen on
+ */
+public class DynamicConsumer extends DefaultConsumer {
+ Set<Consumer> consumers;
+
+ public DynamicConsumer(DynamicEndpoint endpoint, Processor processor) {
+ super(endpoint, processor);
+ consumers = new HashSet<Consumer>();
+ String uris = endpoint.getEndpointUri().substring("dynamicep://".length());
+ String[] uriAr = uris.split(",|%2C");
+ for (String epUri : uriAr) {
+ try {
+ epUri = URLDecoder.decode(epUri, "UTF-8");
+ Endpoint ep = this.getEndpoint().getCamelContext().getEndpoint(epUri);
+ Consumer consumer = ep.createConsumer(getProcessor());
+ consumers.add(consumer);
+ } catch (Exception e) {
+ throw new RuntimeException("Error initializing endpoint dynamic endpoint from " + uris + " at " + epUri, e);
+ }
+ }
+ }
+
+ @Override
+ protected void doStart() throws Exception {
+ super.doStart();
+ for (Consumer consumer : consumers) {
+ consumer.start();
+ }
+ }
+
+ @Override
+ protected void doStop() throws Exception {
+ for (Consumer consumer : consumers) {
+ consumer.stop();
+ }
+ super.doStop();
+ }
+
+}
Added: camel/trunk/components/camel-dynamicep/src/main/java/org/apache/camel/dynamicep/DynamicEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-dynamicep/src/main/java/org/apache/camel/dynamicep/DynamicEndpoint.java?rev=1354406&view=auto
==============================================================================
--- camel/trunk/components/camel-dynamicep/src/main/java/org/apache/camel/dynamicep/DynamicEndpoint.java (added)
+++ camel/trunk/components/camel-dynamicep/src/main/java/org/apache/camel/dynamicep/DynamicEndpoint.java Wed Jun 27 10:20:29 2012
@@ -0,0 +1,59 @@
+/**
+ * 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.dynamicep;
+
+import org.apache.camel.Consumer;
+import org.apache.camel.Processor;
+import org.apache.camel.Producer;
+import org.apache.camel.impl.DefaultEndpoint;
+
+/**
+ * Dynamic Endpoint
+ *
+ * Allows to create a list of consumers that feed into the same route.
+ * Example: from("dynamicep:jms:myQueue,file:myDir").to("log:test)
+ *
+ * As it is possible to use properties in the endpoint definition this
+ * allows to define a dynamical list of endpoints a route should listen on
+ */
+public class DynamicEndpoint extends DefaultEndpoint {
+
+ public DynamicEndpoint() {
+ }
+
+ public DynamicEndpoint(String uri, DynamicComponent component) {
+ super(uri, component);
+ }
+
+ @SuppressWarnings("deprecation")
+ public DynamicEndpoint(String endpointUri) {
+ super(endpointUri);
+ }
+
+ public Producer createProducer() throws Exception {
+ throw new IllegalArgumentException("This component only supports consumers");
+ }
+
+ public Consumer createConsumer(Processor processor) throws Exception {
+ return new DynamicConsumer(this, processor);
+ }
+
+ public boolean isSingleton() {
+ return true;
+ }
+
+}
Added: camel/trunk/components/camel-dynamicep/src/main/resources/META-INF/services/org/apache/camel/component/dynamicep
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-dynamicep/src/main/resources/META-INF/services/org/apache/camel/component/dynamicep?rev=1354406&view=auto
==============================================================================
--- camel/trunk/components/camel-dynamicep/src/main/resources/META-INF/services/org/apache/camel/component/dynamicep (added)
+++ camel/trunk/components/camel-dynamicep/src/main/resources/META-INF/services/org/apache/camel/component/dynamicep Wed Jun 27 10:20:29 2012
@@ -0,0 +1,18 @@
+#
+# 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.
+#
+
+class=org.apache.camel.dynamicep.DynamicComponent
Added: camel/trunk/components/camel-dynamicep/src/test/java/org/apache/camel/camel_dynamicep/DynamicComponentTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-dynamicep/src/test/java/org/apache/camel/camel_dynamicep/DynamicComponentTest.java?rev=1354406&view=auto
==============================================================================
--- camel/trunk/components/camel-dynamicep/src/test/java/org/apache/camel/camel_dynamicep/DynamicComponentTest.java (added)
+++ camel/trunk/components/camel-dynamicep/src/test/java/org/apache/camel/camel_dynamicep/DynamicComponentTest.java Wed Jun 27 10:20:29 2012
@@ -0,0 +1,48 @@
+/**
+ * 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.camel_dynamicep;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+/**
+ * Shows the list parsing works and the , as well as %2C is accepted as separators.
+ * Also shows that two endpoints can feed the same route.
+ */
+public class DynamicComponentTest extends CamelTestSupport {
+
+ @Test
+ public void testDynamic() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedMinimumMessageCount(2);
+ template.sendBody("direct:test1", "Test");
+ template.sendBody("direct:test2", "Test2");
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ public void configure() {
+ from("dynamicep:file:test,direct:test1%2Cdirect%3Atest2")
+ .to("mock:result");
+ }
+ };
+ }
+}
Added: camel/trunk/components/camel-dynamicep/src/test/resources/dynamicep_manual_test.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-dynamicep/src/test/resources/dynamicep_manual_test.xml?rev=1354406&view=auto
==============================================================================
--- camel/trunk/components/camel-dynamicep/src/test/resources/dynamicep_manual_test.xml (added)
+++ camel/trunk/components/camel-dynamicep/src/test/resources/dynamicep_manual_test.xml Wed Jun 27 10:20:29 2012
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- 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. -->
+
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
+<!-- Manual test that can be deployed into Karaf to check and demo the dynamicep component -->
+
+ <camelContext xmlns="http://camel.apache.org/schema/blueprint" id="simple">
+ <route>
+ <from uri="dynamicep:timer:simple?period=5000,file:/test2"/>
+ <setBody>
+ <simple>Hello World ${in.body}</simple>
+ </setBody>
+ <to uri="stream:out"/>
+ </route>
+ </camelContext>
+
+</blueprint>
Added: camel/trunk/components/camel-dynamicep/src/test/resources/log4j.properties
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-dynamicep/src/test/resources/log4j.properties?rev=1354406&view=auto
==============================================================================
--- camel/trunk/components/camel-dynamicep/src/test/resources/log4j.properties (added)
+++ camel/trunk/components/camel-dynamicep/src/test/resources/log4j.properties Wed Jun 27 10:20:29 2012
@@ -0,0 +1,16 @@
+
+#
+# The logging properties used
+#
+log4j.rootLogger=INFO, out
+
+# uncomment the following line to turn on Camel debugging
+#log4j.logger.org.apache.camel=DEBUG
+
+# CONSOLE appender not used by default
+log4j.appender.out=org.apache.log4j.ConsoleAppender
+log4j.appender.out.layout=org.apache.log4j.PatternLayout
+log4j.appender.out.layout.ConversionPattern=[%30.30t] %-30.30c{1} %-5p %m%n
+#log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
+
+log4j.throwableRenderer=org.apache.log4j.EnhancedThrowableRenderer
\ No newline at end of file
Modified: camel/trunk/components/pom.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/pom.xml?rev=1354406&r1=1354405&r2=1354406&view=diff
==============================================================================
--- camel/trunk/components/pom.xml (original)
+++ camel/trunk/components/pom.xml Wed Jun 27 10:20:29 2012
@@ -71,6 +71,7 @@
<module>camel-csv</module>
<module>camel-dns</module>
<module>camel-dozer</module>
+ <module>camel-dynamicep</module>
<module>camel-eclipse</module>
<module>camel-ejb</module>
<module>camel-eventadmin</module>