You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2015/03/03 10:45:54 UTC
[1/2] camel git commit: CAMEL-7644: Make using Main easier to get the
CamelContext before its started, which we need for Scala users.
Repository: camel
Updated Branches:
refs/heads/master 01f08a626 -> 87c9a9da4
CAMEL-7644: Make using Main easier to get the CamelContext before its started, which we need for Scala users.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/c0db627b
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/c0db627b
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/c0db627b
Branch: refs/heads/master
Commit: c0db627b8fc360848259875647397242407fddad
Parents: 01f08a6
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Mar 3 10:40:12 2015 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Mar 3 10:40:12 2015 +0100
----------------------------------------------------------------------
.../src/main/java/org/apache/camel/main/Main.java | 16 ++++++++++++++--
.../java/org/apache/camel/main/MainSupport.java | 1 -
2 files changed, 14 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/c0db627b/camel-core/src/main/java/org/apache/camel/main/Main.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/main/Main.java b/camel-core/src/main/java/org/apache/camel/main/Main.java
index e674c18..a7871cd 100644
--- a/camel-core/src/main/java/org/apache/camel/main/Main.java
+++ b/camel-core/src/main/java/org/apache/camel/main/Main.java
@@ -18,7 +18,6 @@ package org.apache.camel.main;
import java.util.HashMap;
import java.util.Map;
-
import javax.xml.bind.JAXBException;
import org.apache.camel.CamelContext;
@@ -99,7 +98,20 @@ public class Main extends MainSupport {
*/
public <T> Map<String, T> lookupByType(Class<T> type) {
return registry.findByTypeWithName(type);
- }
+ }
+
+ /**
+ * Gets or creates the {@link org.apache.camel.CamelContext} this main class is using.
+ */
+ public CamelContext getOrCreateCamelContext() {
+ // force init
+ Map<String, CamelContext> map = getCamelContextMap();
+ if (map.size() >= 1) {
+ return map.values().iterator().next();
+ } else {
+ throw new IllegalStateException("Error creating CamelContext");
+ }
+ }
// Implementation methods
// -------------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/c0db627b/camel-core/src/main/java/org/apache/camel/main/MainSupport.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/main/MainSupport.java b/camel-core/src/main/java/org/apache/camel/main/MainSupport.java
index 3e0cb95..4fb30fe 100644
--- a/camel-core/src/main/java/org/apache/camel/main/MainSupport.java
+++ b/camel-core/src/main/java/org/apache/camel/main/MainSupport.java
@@ -27,7 +27,6 @@ import java.util.Set;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
-
import javax.xml.bind.JAXBException;
import org.apache.camel.CamelContext;
[2/2] camel git commit: CAMEL-7644: Adjust maven archetype for scala
to work and use ScalaRouteBuilder
Posted by da...@apache.org.
CAMEL-7644: Adjust maven archetype for scala to work and use ScalaRouteBuilder
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/87c9a9da
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/87c9a9da
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/87c9a9da
Branch: refs/heads/master
Commit: 87c9a9da4ec409c82d710ebd806a08f24579e8c2
Parents: c0db627
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Mar 3 10:47:07 2015 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Mar 3 10:47:07 2015 +0100
----------------------------------------------------------------------
.../META-INF/maven/archetype-metadata.xml | 3 +++
.../src/main/resources/archetype-resources/pom.xml | 5 +++++
.../archetype-resources/src/main/scala/MyRouteBuilder.scala | 8 ++++----
.../archetype-resources/src/main/scala/MyRouteMain.scala | 9 ++++++---
4 files changed, 18 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/87c9a9da/tooling/archetypes/camel-archetype-scala/src/main/resources-filtered/META-INF/maven/archetype-metadata.xml
----------------------------------------------------------------------
diff --git a/tooling/archetypes/camel-archetype-scala/src/main/resources-filtered/META-INF/maven/archetype-metadata.xml b/tooling/archetypes/camel-archetype-scala/src/main/resources-filtered/META-INF/maven/archetype-metadata.xml
index 6c15da2..7df63dc 100644
--- a/tooling/archetypes/camel-archetype-scala/src/main/resources-filtered/META-INF/maven/archetype-metadata.xml
+++ b/tooling/archetypes/camel-archetype-scala/src/main/resources-filtered/META-INF/maven/archetype-metadata.xml
@@ -42,6 +42,9 @@
<requiredProperty key="scala-version">
<defaultValue>${scala-version}</defaultValue>
</requiredProperty>
+ <requiredProperty key="scalaxml-version">
+ <defaultValue>${scalaxml-version}</defaultValue>
+ </requiredProperty>
<requiredProperty key="scala-maven-plugin-version">
<defaultValue>${scala-maven-plugin-version}</defaultValue>
</requiredProperty>
http://git-wip-us.apache.org/repos/asf/camel/blob/87c9a9da/tooling/archetypes/camel-archetype-scala/src/main/resources/archetype-resources/pom.xml
----------------------------------------------------------------------
diff --git a/tooling/archetypes/camel-archetype-scala/src/main/resources/archetype-resources/pom.xml b/tooling/archetypes/camel-archetype-scala/src/main/resources/archetype-resources/pom.xml
index efed7cd..4d1bff6 100644
--- a/tooling/archetypes/camel-archetype-scala/src/main/resources/archetype-resources/pom.xml
+++ b/tooling/archetypes/camel-archetype-scala/src/main/resources/archetype-resources/pom.xml
@@ -50,6 +50,11 @@
<artifactId>scala-library</artifactId>
<version>${scala-version}</version>
</dependency>
+ <dependency>
+ <groupId>org.scala-lang.modules</groupId>
+ <artifactId>scala-xml_2.11</artifactId>
+ <version>${scalaxml-version}</version>
+ </dependency>
<!-- logging -->
<dependency>
http://git-wip-us.apache.org/repos/asf/camel/blob/87c9a9da/tooling/archetypes/camel-archetype-scala/src/main/resources/archetype-resources/src/main/scala/MyRouteBuilder.scala
----------------------------------------------------------------------
diff --git a/tooling/archetypes/camel-archetype-scala/src/main/resources/archetype-resources/src/main/scala/MyRouteBuilder.scala b/tooling/archetypes/camel-archetype-scala/src/main/resources/archetype-resources/src/main/scala/MyRouteBuilder.scala
index a438cc1..885d5d0 100644
--- a/tooling/archetypes/camel-archetype-scala/src/main/resources/archetype-resources/src/main/scala/MyRouteBuilder.scala
+++ b/tooling/archetypes/camel-archetype-scala/src/main/resources/archetype-resources/src/main/scala/MyRouteBuilder.scala
@@ -16,13 +16,13 @@
## ------------------------------------------------------------------------
package ${package}
-import org.apache.camel.Exchange
-import org.apache.camel.scala.dsl.builder.RouteBuilder
+import org.apache.camel.{CamelContext, Exchange}
+import org.apache.camel.scala.dsl.builder.ScalaRouteBuilder
/**
* A Camel Router using the Scala DSL
*/
-class MyRouteBuilder extends RouteBuilder {
+class MyRouteBuilder(override val context : CamelContext) extends ScalaRouteBuilder(context) {
// an example of a Processor method
val myProcessorMethod = (exchange: Exchange) => {
@@ -34,4 +34,4 @@ class MyRouteBuilder extends RouteBuilder {
process(myProcessorMethod)
to("log:block")
}
-}
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/87c9a9da/tooling/archetypes/camel-archetype-scala/src/main/resources/archetype-resources/src/main/scala/MyRouteMain.scala
----------------------------------------------------------------------
diff --git a/tooling/archetypes/camel-archetype-scala/src/main/resources/archetype-resources/src/main/scala/MyRouteMain.scala b/tooling/archetypes/camel-archetype-scala/src/main/resources/archetype-resources/src/main/scala/MyRouteMain.scala
index 0e60d07..46c78c3 100644
--- a/tooling/archetypes/camel-archetype-scala/src/main/resources/archetype-resources/src/main/scala/MyRouteMain.scala
+++ b/tooling/archetypes/camel-archetype-scala/src/main/resources/archetype-resources/src/main/scala/MyRouteMain.scala
@@ -27,10 +27,13 @@ object MyRouteMain extends RouteBuilderSupport {
def main(args: Array[String]) {
val main = new Main()
// enable hangup support so you need to use ctrl + c to stop the running app
- main.enableHangupSupport();
- main.addRouteBuilder(new MyRouteBuilder())
+ main.enableHangupSupport()
+ // create the CamelContext
+ val context = main.getOrCreateCamelContext()
+ // add our route using the created CamelContext
+ main.addRouteBuilder(new MyRouteBuilder(context))
// must use run to start the main application
- main.run();
+ main.run()
}
}