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 2017/01/03 14:04:30 UTC
camel git commit: Added a little scala example
Repository: camel
Updated Branches:
refs/heads/master bb3ab8bd0 -> af605fbce
Added a little scala example
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/af605fbc
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/af605fbc
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/af605fbc
Branch: refs/heads/master
Commit: af605fbce94e90c3e295ff37bf768342c2328615
Parents: bb3ab8b
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Jan 3 11:26:20 2017 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Jan 3 11:26:20 2017 +0100
----------------------------------------------------------------------
examples/README.md | 3 +-
examples/camel-example-scala/ReadMe.md | 15 ++
examples/camel-example-scala/pom.xml | 153 +++++++++++++++++++
.../src/main/resources/log4j2.properties | 9 ++
.../apache/camel/example/MyRouteBuilder.scala | 37 +++++
.../org/apache/camel/example/MyRouteMain.scala | 37 +++++
examples/pom.xml | 1 +
7 files changed, 254 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/af605fbc/examples/README.md
----------------------------------------------------------------------
diff --git a/examples/README.md b/examples/README.md
index c48ab55..5fe7b10 100644
--- a/examples/README.md
+++ b/examples/README.md
@@ -45,7 +45,8 @@ All examples have been sort by type/category
##### Other Languages
-* [camel-example-groovy](camel-example-groovt/ReadMe.md)
+* [camel-example-groovy](camel-example-groovy/ReadMe.md)
+* [camel-example-scala](camel-example-scala/ReadMe.md)
##### CDI
http://git-wip-us.apache.org/repos/asf/camel/blob/af605fbc/examples/camel-example-scala/ReadMe.md
----------------------------------------------------------------------
diff --git a/examples/camel-example-scala/ReadMe.md b/examples/camel-example-scala/ReadMe.md
new file mode 100644
index 0000000..5806db3
--- /dev/null
+++ b/examples/camel-example-scala/ReadMe.md
@@ -0,0 +1,15 @@
+Camel Router with Scala DSL Project
+===================================
+
+To build this project use
+
+ mvn install
+
+To run this project
+
+ mvn exec:java
+
+For more help see the Apache Camel documentation
+
+ http://camel.apache.org/
+
http://git-wip-us.apache.org/repos/asf/camel/blob/af605fbc/examples/camel-example-scala/pom.xml
----------------------------------------------------------------------
diff --git a/examples/camel-example-scala/pom.xml b/examples/camel-example-scala/pom.xml
new file mode 100644
index 0000000..2e23b7d
--- /dev/null
+++ b/examples/camel-example-scala/pom.xml
@@ -0,0 +1,153 @@
+<?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>examples</artifactId>
+ <version>2.19.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>camel-example-scala</artifactId>
+ <packaging>jar</packaging>
+ <name>Camel :: Example :: Scala</name>
+ <description>A Camel route using Scala</description>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-scala</artifactId>
+ </dependency>
+
+ <!-- scala -->
+ <dependency>
+ <groupId>org.scala-lang</groupId>
+ <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>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-slf4j-impl</artifactId>
+ </dependency>
+
+ </dependencies>
+
+ <build>
+ <defaultGoal>install</defaultGoal>
+ <sourceDirectory>src/main/scala</sourceDirectory>
+
+ <plugins>
+
+ <!-- the Maven compiler plugin will compile Java source files -->
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>${maven-compiler-plugin-version}</version>
+ <configuration>
+ <source>1.8</source>
+ <target>1.8</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-resources-plugin</artifactId>
+ <version>${maven-resources-plugin-version}</version>
+ <configuration>
+ <encoding>UTF-8</encoding>
+ </configuration>
+ </plugin>
+
+ <!-- the Maven Scala plugin will compile Scala source files -->
+ <plugin>
+ <groupId>net.alchim31.maven</groupId>
+ <artifactId>scala-maven-plugin</artifactId>
+ <version>${scala-maven-plugin-version}</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>compile</goal>
+ <goal>testCompile</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+
+ <!-- configure the eclipse plugin to generate eclipse project descriptors for a Scala project -->
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-eclipse-plugin</artifactId>
+ <version>${maven-eclipse-plugin-version}</version>
+ <configuration>
+ <projectnatures>
+ <projectnature>org.scala-ide.sdt.core.scalanature</projectnature>
+ <projectnature>org.eclipse.jdt.core.javanature</projectnature>
+ </projectnatures>
+ <buildcommands>
+ <buildcommand>org.scala-ide.sdt.core.scalabuilder</buildcommand>
+ </buildcommands>
+ <classpathContainers>
+ <classpathContainer>org.scala-ide.sdt.launching.SCALA_CONTAINER</classpathContainer>
+ <classpathContainer>org.eclipse.jdt.launching.JRE_CONTAINER</classpathContainer>
+ </classpathContainers>
+ <excludes>
+ <exclude>org.scala-lang:scala-library</exclude>
+ <exclude>org.scala-lang:scala-compiler</exclude>
+ </excludes>
+ <sourceIncludes>
+ <sourceInclude>**/*.scala</sourceInclude>
+ <sourceInclude>**/*.java</sourceInclude>
+ </sourceIncludes>
+ </configuration>
+ </plugin>
+
+ <!-- allows the route to be run via 'mvn exec:java' -->
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>exec-maven-plugin</artifactId>
+ <version>${exec-maven-plugin-version}</version>
+ <configuration>
+ <mainClass>org.apache.camel.MyRouteMain</mainClass>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
http://git-wip-us.apache.org/repos/asf/camel/blob/af605fbc/examples/camel-example-scala/src/main/resources/log4j2.properties
----------------------------------------------------------------------
diff --git a/examples/camel-example-scala/src/main/resources/log4j2.properties b/examples/camel-example-scala/src/main/resources/log4j2.properties
new file mode 100644
index 0000000..d941e1b
--- /dev/null
+++ b/examples/camel-example-scala/src/main/resources/log4j2.properties
@@ -0,0 +1,9 @@
+
+appender.out.type = Console
+appender.out.name = out
+appender.out.layout.type = PatternLayout
+appender.out.layout.pattern = [%30.30t] %-30.30c{1} %-5p %m%n
+logger.springframework.name = org.springframework
+logger.springframework.level = WARN
+rootLogger.level = INFO
+rootLogger.appenderRef.out.ref = out
http://git-wip-us.apache.org/repos/asf/camel/blob/af605fbc/examples/camel-example-scala/src/main/scala/org/apache/camel/example/MyRouteBuilder.scala
----------------------------------------------------------------------
diff --git a/examples/camel-example-scala/src/main/scala/org/apache/camel/example/MyRouteBuilder.scala b/examples/camel-example-scala/src/main/scala/org/apache/camel/example/MyRouteBuilder.scala
new file mode 100644
index 0000000..a55fae4
--- /dev/null
+++ b/examples/camel-example-scala/src/main/scala/org/apache/camel/example/MyRouteBuilder.scala
@@ -0,0 +1,37 @@
+/**
+ * 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.example
+
+import org.apache.camel.scala.dsl.builder.ScalaRouteBuilder
+import org.apache.camel.{CamelContext, Exchange}
+
+/**
+ * A Camel Router using the Scala DSL
+ */
+class MyRouteBuilder(override val context : CamelContext) extends ScalaRouteBuilder(context) {
+
+ // an example of a Processor method
+ val myProcessorMethod: (Exchange) => Unit = (exchange: Exchange) => {
+ exchange.getIn.setBody("block test")
+ }
+
+ // a route using Scala blocks
+ "timer://foo?period=5s" ==> {
+ process(myProcessorMethod)
+ to("log:block")
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/af605fbc/examples/camel-example-scala/src/main/scala/org/apache/camel/example/MyRouteMain.scala
----------------------------------------------------------------------
diff --git a/examples/camel-example-scala/src/main/scala/org/apache/camel/example/MyRouteMain.scala b/examples/camel-example-scala/src/main/scala/org/apache/camel/example/MyRouteMain.scala
new file mode 100644
index 0000000..891a94f
--- /dev/null
+++ b/examples/camel-example-scala/src/main/scala/org/apache/camel/example/MyRouteMain.scala
@@ -0,0 +1,37 @@
+/**
+ * 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.example
+
+import org.apache.camel.main.Main
+import org.apache.camel.scala.dsl.builder.RouteBuilderSupport
+
+/**
+ * A Main to run Camel with MyRouteBuilder
+ */
+object MyRouteMain extends RouteBuilderSupport {
+
+ def main(args: Array[String]) {
+ val main = new Main()
+ // 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()
+ }
+}
+
http://git-wip-us.apache.org/repos/asf/camel/blob/af605fbc/examples/pom.xml
----------------------------------------------------------------------
diff --git a/examples/pom.xml b/examples/pom.xml
index b529b2b..01b1d82 100644
--- a/examples/pom.xml
+++ b/examples/pom.xml
@@ -73,6 +73,7 @@
<module>camel-example-reportincident-wssecurity</module>
<module>camel-example-restlet-jdbc</module>
<module>camel-example-route-throttling</module>
+ <module>camel-example-scala</module>
<module>camel-example-servlet-rest-blueprint</module>
<module>camel-example-servlet-tomcat</module>
<module>camel-example-servlet-tomcat-no-spring</module>