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 09:38:55 UTC

camel git commit: Added a little groovy example

Repository: camel
Updated Branches:
  refs/heads/master cea1ccf51 -> bb3ab8bd0


Added a little groovy example


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/bb3ab8bd
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/bb3ab8bd
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/bb3ab8bd

Branch: refs/heads/master
Commit: bb3ab8bd090f4d3ae2109d64ae89b251cee1ab36
Parents: cea1ccf
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Jan 3 10:37:20 2017 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Jan 3 10:38:41 2017 +0100

----------------------------------------------------------------------
 examples/README.md                              |   4 +
 examples/camel-example-groovy/ReadMe.md         |  23 +++
 examples/camel-example-groovy/pom.xml           | 139 +++++++++++++++++++
 .../main/java/org/apache/camel/MainApp.groovy   |  44 ++++++
 .../java/org/apache/camel/MyRouteBuilder.groovy |  34 +++++
 .../src/main/resources/log4j2.properties        |   7 +
 examples/pom.xml                                |   7 +-
 7 files changed, 254 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/bb3ab8bd/examples/README.md
----------------------------------------------------------------------
diff --git a/examples/README.md b/examples/README.md
index a7c3615..c48ab55 100644
--- a/examples/README.md
+++ b/examples/README.md
@@ -43,6 +43,10 @@ All examples have been sort by type/category
 * [camel-example-reportincident-wssecurity](camel-example-reportincident-wssecurity/README.md)
 * [camel-example-cafe](camel-example-cafe/README.md)
 
+##### Other Languages
+
+* [camel-example-groovy](camel-example-groovt/ReadMe.md)
+
 ##### CDI
 
 * [camel-example-cdi](camel-example-cdi/README.md)

http://git-wip-us.apache.org/repos/asf/camel/blob/bb3ab8bd/examples/camel-example-groovy/ReadMe.md
----------------------------------------------------------------------
diff --git a/examples/camel-example-groovy/ReadMe.md b/examples/camel-example-groovy/ReadMe.md
new file mode 100644
index 0000000..5c8f4ef
--- /dev/null
+++ b/examples/camel-example-groovy/ReadMe.md
@@ -0,0 +1,23 @@
+Camel Groovy Router Project
+===========================
+
+To build this project use
+
+    mvn install
+
+To run this project from within Maven use
+
+    mvn exec:java
+
+The groovy source code is located in `src/main/java` which makes it
+easier to integrate with Maven as the compiler will compile from this directory.
+
+This also allows you to mix both Java and Groovy source code in this folder.
+
+In this example we have the Camel route in the groovy source code in `MyRouteBuilder.groovy` file.
+
+
+For more help see the Apache Camel documentation
+
+    http://camel.apache.org/
+

http://git-wip-us.apache.org/repos/asf/camel/blob/bb3ab8bd/examples/camel-example-groovy/pom.xml
----------------------------------------------------------------------
diff --git a/examples/camel-example-groovy/pom.xml b/examples/camel-example-groovy/pom.xml
new file mode 100644
index 0000000..07dd07d
--- /dev/null
+++ b/examples/camel-example-groovy/pom.xml
@@ -0,0 +1,139 @@
+<?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-groovy</artifactId>
+  <packaging>jar</packaging>
+  <name>Camel :: Example :: Groovy</name>
+  <description>A Camel route using Groovy</description>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.camel</groupId>
+      <artifactId>camel-core</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.camel</groupId>
+      <artifactId>camel-groovy</artifactId>
+    </dependency>
+
+    <!-- used for jetty -->
+    <dependency>
+      <groupId>org.apache.camel</groupId>
+      <artifactId>camel-jetty</artifactId>
+    </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>
+
+    <plugins>
+
+      <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>
+
+      <plugin>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <version>${maven-compiler-plugin-version}</version>
+        <configuration>
+          <source>1.8</source>
+          <target>1.8</target>
+          <compilerId>groovy-eclipse-compiler</compilerId>
+          <!-- set verbose to be true if you want lots of uninteresting messages -->
+          <!-- <verbose>true</verbose> -->
+        </configuration>
+        <dependencies>
+          <dependency>
+            <groupId>org.codehaus.groovy</groupId>
+            <artifactId>groovy-eclipse-compiler</artifactId>
+            <version>2.9.2-01</version>
+            <exclusions>
+              <exclusion>
+                <groupId>org.codehaus.groovy</groupId>
+                <artifactId>groovy-eclipse-batch</artifactId>
+              </exclusion>
+            </exclusions>
+          </dependency>
+          <dependency>
+            <groupId>org.codehaus.groovy</groupId>
+            <artifactId>groovy-eclipse-batch</artifactId>
+            <version>2.4.3-01</version>
+          </dependency>
+        </dependencies>
+      </plugin>
+
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-eclipse-plugin</artifactId>
+        <version>${maven-eclipse-plugin-version}</version>
+        <configuration>
+          <additionalProjectnatures>
+            <projectnature>org.eclipse.jdt.groovy.core.groovyNature</projectnature>
+          </additionalProjectnatures>
+          <classpathContainers>
+            <classpathContainer>org.eclipse.jdt.launching.JRE_CONTAINER</classpathContainer>
+            <classpathContainer>GROOVY_DSL_SUPPORT</classpathContainer>
+          </classpathContainers>
+        </configuration>
+      </plugin>
+
+      <!-- Allows the example to be run via 'mvn compile exec:java' -->
+      <plugin>
+        <groupId>org.codehaus.mojo</groupId>
+        <artifactId>exec-maven-plugin</artifactId>
+        <version>${exec-maven-plugin-version}</version>
+        <configuration>
+          <mainClass>org.apache.camel.MainApp</mainClass>
+          <includePluginDependencies>false</includePluginDependencies>
+        </configuration>
+      </plugin>
+
+    </plugins>
+  </build>
+
+</project>

http://git-wip-us.apache.org/repos/asf/camel/blob/bb3ab8bd/examples/camel-example-groovy/src/main/java/org/apache/camel/MainApp.groovy
----------------------------------------------------------------------
diff --git a/examples/camel-example-groovy/src/main/java/org/apache/camel/MainApp.groovy b/examples/camel-example-groovy/src/main/java/org/apache/camel/MainApp.groovy
new file mode 100644
index 0000000..a3eaa04
--- /dev/null
+++ b/examples/camel-example-groovy/src/main/java/org/apache/camel/MainApp.groovy
@@ -0,0 +1,44 @@
+/**
+ * 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
+
+import org.apache.camel.main.Main
+
+/**
+ * A Camel Application
+ */
+class MainApp {
+
+    /**
+     * A main() so we can easily run these routing rules in our IDE
+     */
+    static void main(String... args) throws Exception {
+
+        println "\n\n\n\n"
+        println "==============================================="
+        println "Open your web browser on http://localhost:8080"
+        println "Press ctrl+c to stop this example"
+        println "==============================================="
+        println "\n\n\n\n"
+
+        Main main = new Main()
+        main.addRouteBuilder(new MyRouteBuilder())
+        main.run(args)
+    }
+
+}
+

http://git-wip-us.apache.org/repos/asf/camel/blob/bb3ab8bd/examples/camel-example-groovy/src/main/java/org/apache/camel/MyRouteBuilder.groovy
----------------------------------------------------------------------
diff --git a/examples/camel-example-groovy/src/main/java/org/apache/camel/MyRouteBuilder.groovy b/examples/camel-example-groovy/src/main/java/org/apache/camel/MyRouteBuilder.groovy
new file mode 100644
index 0000000..3956e33
--- /dev/null
+++ b/examples/camel-example-groovy/src/main/java/org/apache/camel/MyRouteBuilder.groovy
@@ -0,0 +1,34 @@
+/**
+ * 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
+
+import org.apache.camel.builder.RouteBuilder
+
+/**
+ * A Camel Groovy DSL Router
+ */
+class MyRouteBuilder extends RouteBuilder {
+
+    /**
+     * Let's configure the Camel routing rules using Groovy code...
+     */
+    void configure() {
+        from("jetty:http://0.0.0.0:8080")
+          .transform { 'Today is ' + new Date() }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/bb3ab8bd/examples/camel-example-groovy/src/main/resources/log4j2.properties
----------------------------------------------------------------------
diff --git a/examples/camel-example-groovy/src/main/resources/log4j2.properties b/examples/camel-example-groovy/src/main/resources/log4j2.properties
new file mode 100644
index 0000000..328db35
--- /dev/null
+++ b/examples/camel-example-groovy/src/main/resources/log4j2.properties
@@ -0,0 +1,7 @@
+
+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
+rootLogger.level = INFO
+rootLogger.appenderRef.out.ref = out

http://git-wip-us.apache.org/repos/asf/camel/blob/bb3ab8bd/examples/pom.xml
----------------------------------------------------------------------
diff --git a/examples/pom.xml b/examples/pom.xml
index cda2ed9..b529b2b 100644
--- a/examples/pom.xml
+++ b/examples/pom.xml
@@ -14,9 +14,7 @@
     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">
+--><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>
 
@@ -56,6 +54,7 @@
     <module>camel-example-etl</module>
     <module>camel-example-ftp</module>
     <module>camel-example-guice-jms</module>
+    <module>camel-example-groovy</module>
     <module>camel-example-hystrix</module>
     <module>camel-example-java8</module>
     <module>camel-example-java8-rx</module>
@@ -232,4 +231,4 @@
     </profile>
   </profiles>
 
-</project>
+</project>
\ No newline at end of file