Author: janstey
Date: Sun Aug 22 15:20:24 2010
New Revision: 987917
URL: http://svn.apache.org/viewvc?rev=987917&view=rev
Log:
CAMEL-3048 - switched component archetype to use simple hello world component
rather than direct
Added:
camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/archetype-resources/src/main/java/HelloWorldComponent.java
- copied, changed from r985551,
camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/archetype-resources/src/main/java/DirectComponent.java
camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/archetype-resources/src/main/java/HelloWorldConsumer.java
- copied, changed from r985551,
camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/archetype-resources/src/main/java/DirectConsumer.java
camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/archetype-resources/src/main/java/HelloWorldEndpoint.java
- copied, changed from r985551,
camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/archetype-resources/src/main/java/DirectEndpoint.java
camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/archetype-resources/src/main/java/HelloWorldProducer.java
- copied, changed from r985551,
camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/archetype-resources/src/main/java/DirectProducer.java
camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/archetype-resources/src/main/resources/META-INF/services/org/apache/camel/component/helloworld
- copied, changed from r985551,
camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/archetype-resources/src/main/resources/META-INF/services/org/apache/camel/component/direct
camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/archetype-resources/src/test/
camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/archetype-resources/src/test/java/
camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/archetype-resources/src/test/java/HelloWorldComponentTest.java
(with props)
Removed:
camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/archetype-resources/src/main/java/DirectComponent.java
camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/archetype-resources/src/main/java/DirectConsumer.java
camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/archetype-resources/src/main/java/DirectEndpoint.java
camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/archetype-resources/src/main/java/DirectProducer.java
camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/archetype-resources/src/main/resources/META-INF/services/org/apache/camel/component/direct
Modified:
camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/META-INF/maven/archetype.xml
camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/archetype-resources/ReadMe.txt
camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/archetype-resources/pom.xml
Modified:
camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/META-INF/maven/archetype.xml
URL:
http://svn.apache.org/viewvc/camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/META-INF/maven/archetype.xml?rev=987917&r1=987916&r2=987917&view=diff
==============================================================================
---
camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/META-INF/maven/archetype.xml
(original)
+++
camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/META-INF/maven/archetype.xml
Sun Aug 22 15:20:24 2010
@@ -20,14 +20,15 @@
<archetype>
<id>camel-component</id>
<sources>
- <source>src/main/java/DirectComponent.java</source>
- <source>src/main/java/DirectConsumer.java</source>
- <source>src/main/java/DirectEndpoint.java</source>
- <source>src/main/java/DirectProducer.java</source>
+ <source>src/main/java/HelloWorldComponent.java</source>
+ <source>src/main/java/HelloWorldConsumer.java</source>
+ <source>src/main/java/HelloWorldEndpoint.java</source>
+ <source>src/main/java/HelloWorldProducer.java</source>
+ <source>src/test/java/HelloWorldComponentTest.java</source>
</sources>
<resources>
<resource>ReadMe.txt</resource>
-
<resource>src/main/resources/META-INF/services/org/apache/camel/component/direct</resource>
+
<resource>src/main/resources/META-INF/services/org/apache/camel/component/helloworld</resource>
<resource>src/main/resources/log4j.properties</resource>
</resources>
</archetype>
Modified:
camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/archetype-resources/ReadMe.txt
URL:
http://svn.apache.org/viewvc/camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/archetype-resources/ReadMe.txt?rev=987917&r1=987916&r2=987917&view=diff
==============================================================================
---
camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/archetype-resources/ReadMe.txt
(original)
+++
camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/archetype-resources/ReadMe.txt
Sun Aug 22 15:20:24 2010
@@ -1,7 +1,9 @@
Camel Component Project
====================
This Project is a template of the Camel component.
-When you create the component project , you need to move the
META-INF/services/org/apache/camel/component/direct file to
META-INF/services/org/apache/camel/component/FOO where FOO is the URI scheme
for your component and any related endpoints created on the fly.
+When you create the component project, you need to move the
META-INF/services/org/apache/camel/component/helloworld
+file to META-INF/services/org/apache/camel/component/foo where "foo" is the
URI scheme for your component and any
+ related endpoints created on the fly.
For more help see the Apache Camel documentation
Modified:
camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/archetype-resources/pom.xml
URL:
http://svn.apache.org/viewvc/camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/archetype-resources/pom.xml?rev=987917&r1=987916&r2=987917&view=diff
==============================================================================
---
camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/archetype-resources/pom.xml
(original)
+++
camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/archetype-resources/pom.xml
Sun Aug 22 15:20:24 2010
@@ -39,7 +39,21 @@
<artifactId>camel-core</artifactId>
<version>${camel-version}</version>
</dependency>
-
+
+ <!-- for testing -->
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.8.1</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-core</artifactId>
+ <version>${camel-version}</version>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
Copied:
camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/archetype-resources/src/main/java/HelloWorldComponent.java
(from r985551,
camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/archetype-resources/src/main/java/DirectComponent.java)
URL:
http://svn.apache.org/viewvc/camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/archetype-resources/src/main/java/HelloWorldComponent.java?p2=camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/archetype-resources/src/main/java/HelloWorldComponent.java&p1=camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/archetype-resources/src/main/java/DirectComponent.java&r1=985551&r2=987917&rev=987917&view=diff
==============================================================================
---
camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/archetype-resources/src/main/java/DirectComponent.java
(original)
+++
camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/archetype-resources/src/main/java/HelloWorldComponent.java
Sun Aug 22 15:20:24 2010
@@ -22,15 +22,12 @@ import org.apache.camel.Endpoint;
import org.apache.camel.impl.DefaultComponent;
/**
- * Represents the component that manages {...@link DirectEndpoint}. It holds
the
- * list of named direct endpoints.
- *
- * @version $Revision$
+ * Represents the component that manages {...@link HelloWorldEndpoint}.
*/
-public class DirectComponent extends DefaultComponent {
+public class HelloWorldComponent extends DefaultComponent {
protected Endpoint createEndpoint(String uri, String remaining,
Map<String, Object> parameters) throws Exception {
- Endpoint endpoint = new DirectEndpoint(uri, this);
+ Endpoint endpoint = new HelloWorldEndpoint(uri, this);
setProperties(endpoint, parameters);
return endpoint;
}
Copied:
camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/archetype-resources/src/main/java/HelloWorldConsumer.java
(from r985551,
camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/archetype-resources/src/main/java/DirectConsumer.java)
URL:
http://svn.apache.org/viewvc/camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/archetype-resources/src/main/java/HelloWorldConsumer.java?p2=camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/archetype-resources/src/main/java/HelloWorldConsumer.java&p1=camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/archetype-resources/src/main/java/DirectConsumer.java&r1=985551&r2=987917&rev=987917&view=diff
==============================================================================
---
camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/archetype-resources/src/main/java/DirectConsumer.java
(original)
+++
camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/archetype-resources/src/main/java/HelloWorldConsumer.java
Sun Aug 22 15:20:24 2010
@@ -16,53 +16,41 @@
*/
package ${packageName};
-import org.apache.camel.Endpoint;
+import java.util.Date;
+
+import org.apache.camel.Exchange;
import org.apache.camel.Processor;
-import org.apache.camel.ShutdownRunningTask;
-import org.apache.camel.impl.DefaultConsumer;
-import org.apache.camel.spi.ShutdownAware;
+import org.apache.camel.impl.ScheduledPollConsumer;
/**
- * The direct consumer.
- *
- * @version $Revision$
+ * The HelloWorld consumer.
*/
-public class DirectConsumer extends DefaultConsumer implements ShutdownAware {
-
- private DirectEndpoint endpoint;
+public class HelloWorldConsumer extends ScheduledPollConsumer {
+ private final HelloWorldEndpoint endpoint;
- public DirectConsumer(Endpoint endpoint, Processor processor) {
+ public HelloWorldConsumer(HelloWorldEndpoint endpoint, Processor
processor) {
super(endpoint, processor);
- this.endpoint = (DirectEndpoint) endpoint;
+ this.endpoint = endpoint;
}
@Override
- public void start() throws Exception {
- // only add as consumer if not already registered
- if (!endpoint.getConsumers().contains(this)) {
- if (!endpoint.getConsumers().isEmpty()) {
- throw new IllegalStateException("Endpoint " +
endpoint.getEndpointUri() + " only allows 1 active consumer but you attempted
to start a 2nd consumer.");
+ // poll method will fire every 500 ms by default
+ protected void poll() throws Exception {
+ Exchange exchange = endpoint.createExchange();
+
+ // create a message body
+ Date now = new Date();
+ exchange.getIn().setBody("Hello World! The time is " + now);
+
+ try {
+ // send message to next processor in the route
+ getProcessor().process(exchange);
+ } finally {
+ // log exception if an exception occurred and was not handled
+ if (exchange.getException() != null) {
+ getExceptionHandler().handleException("Error processing
exchange", exchange, exchange.getException());
}
- endpoint.getConsumers().add(this);
- }
- super.start();
- }
-
- @Override
- public void stop() throws Exception {
- super.stop();
- endpoint.getConsumers().remove(this);
- }
-
- public boolean deferShutdown(ShutdownRunningTask shutdownRunningTask) {
- // deny stopping on shutdown as we want direct consumers to run in
case some other queues
- // depend on this consumer to run, so it can complete its exchanges
- return true;
+ }
}
- public int getPendingExchangesSize() {
- // return 0 as we do not have an internal memory queue with a variable
size
- // of inflight messages.
- return 0;
- }
}
Copied:
camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/archetype-resources/src/main/java/HelloWorldEndpoint.java
(from r985551,
camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/archetype-resources/src/main/java/DirectEndpoint.java)
URL:
http://svn.apache.org/viewvc/camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/archetype-resources/src/main/java/HelloWorldEndpoint.java?p2=camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/archetype-resources/src/main/java/HelloWorldEndpoint.java&p1=camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/archetype-resources/src/main/java/DirectEndpoint.java&r1=985551&r2=987917&rev=987917&view=diff
==============================================================================
---
camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/archetype-resources/src/main/java/DirectEndpoint.java
(original)
+++
camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/archetype-resources/src/main/java/HelloWorldEndpoint.java
Sun Aug 22 15:20:24 2010
@@ -26,38 +26,29 @@ import org.apache.camel.impl.DefaultCons
import org.apache.camel.impl.DefaultEndpoint;
/**
- * Represents a direct endpoint that synchronously invokes the consumers of the
- * endpoint when a producer sends a message to it.
- *
- * @version $Revision$
+ * Represents a HelloWorld endpoint.
*/
-public class DirectEndpoint extends DefaultEndpoint {
- private final CopyOnWriteArrayList<DefaultConsumer> consumers = new
CopyOnWriteArrayList<DefaultConsumer>();
-
- public DirectEndpoint() {
+public class HelloWorldEndpoint extends DefaultEndpoint {
+ public HelloWorldEndpoint() {
}
- public DirectEndpoint(String uri, DirectComponent component) {
+ public HelloWorldEndpoint(String uri, HelloWorldComponent component) {
super(uri, component);
}
- public DirectEndpoint(String endpointUri) {
+ public HelloWorldEndpoint(String endpointUri) {
super(endpointUri);
}
public Producer createProducer() throws Exception {
- return new DirectProducer(this);
+ return new HelloWorldProducer(this);
}
public Consumer createConsumer(Processor processor) throws Exception {
- return new DirectConsumer(this, processor);
+ return new HelloWorldConsumer(this, processor);
}
public boolean isSingleton() {
return true;
}
-
- public List<DefaultConsumer> getConsumers() {
- return consumers;
- }
}
Copied:
camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/archetype-resources/src/main/java/HelloWorldProducer.java
(from r985551,
camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/archetype-resources/src/main/java/DirectProducer.java)
URL:
http://svn.apache.org/viewvc/camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/archetype-resources/src/main/java/HelloWorldProducer.java?p2=camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/archetype-resources/src/main/java/HelloWorldProducer.java&p1=camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/archetype-resources/src/main/java/DirectProducer.java&r1=985551&r2=987917&rev=987917&view=diff
==============================================================================
---
camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/archetype-resources/src/main/java/DirectProducer.java
(original)
+++
camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/archetype-resources/src/main/java/HelloWorldProducer.java
Sun Aug 22 15:20:24 2010
@@ -23,27 +23,19 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
- * The direct producer.
- *
- * @version $Revision$
+ * The HelloWorld producer.
*/
-public class DirectProducer extends DefaultProducer {
- private static final transient Log LOG =
LogFactory.getLog(DirectProducer.class);
- private DirectEndpoint endpoint;
+public class HelloWorldProducer extends DefaultProducer {
+ private static final transient Log LOG =
LogFactory.getLog(HelloWorldProducer.class);
+ private HelloWorldEndpoint endpoint;
- public DirectProducer(DirectEndpoint endpoint) {
+ public HelloWorldProducer(HelloWorldEndpoint endpoint) {
super(endpoint);
this.endpoint = endpoint;
}
public void process(Exchange exchange) throws Exception {
- if (endpoint.getConsumers().isEmpty()) {
- LOG.warn("No consumers available on endpoint: " + endpoint + " to
process: " + exchange);
- } else {
- for (DefaultConsumer consumer : endpoint.getConsumers()) {
- consumer.getProcessor().process(exchange);
- }
- }
+ System.out.println(exchange.getIn().getBody());
}
}
Copied:
camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/archetype-resources/src/main/resources/META-INF/services/org/apache/camel/component/helloworld
(from r985551,
camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/archetype-resources/src/main/resources/META-INF/services/org/apache/camel/component/direct)
URL:
http://svn.apache.org/viewvc/camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/archetype-resources/src/main/resources/META-INF/services/org/apache/camel/component/helloworld?p2=camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/archetype-resources/src/main/resources/META-INF/services/org/apache/camel/component/helloworld&p1=camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/archetype-resources/src/main/resources/META-INF/services/org/apache/camel/component/direct&r1=985551&r2=987917&rev=987917&view=diff
==============================================================================
---
camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/archetype-resources/src/main/resources/META-INF/services/org/apache/camel/component/direct
(original)
+++
camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/archetype-resources/src/main/resources/META-INF/services/org/apache/camel/component/helloworld
Sun Aug 22 15:20:24 2010
@@ -15,4 +15,4 @@
# limitations under the License.
#
-class=${packageName}.DirectComponent
+class=${packageName}.HelloWorldComponent
Added:
camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/archetype-resources/src/test/java/HelloWorldComponentTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/archetype-resources/src/test/java/HelloWorldComponentTest.java?rev=987917&view=auto
==============================================================================
---
camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/archetype-resources/src/test/java/HelloWorldComponentTest.java
(added)
+++
camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/archetype-resources/src/test/java/HelloWorldComponentTest.java
Sun Aug 22 15:20:24 2010
@@ -0,0 +1,42 @@
+/**
+ * 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 ${packageName};
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+
+public class HelloWorldComponentTest extends ContextTestSupport {
+
+ public void testHelloWorld() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedMinimumMessageCount(1);
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ public void configure() {
+ from("helloworld://foo") // will send a message every 500ms
+ .to("helloworld://bar") // prints message to stdout
+ .to("mock:result"); // to actually test that a message
arrives
+ }
+ };
+ }
+}
Propchange:
camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/archetype-resources/src/test/java/HelloWorldComponentTest.java
------------------------------------------------------------------------------
svn:eol-style = native