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 2018/03/09 17:46:29 UTC

[camel] branch master updated (9110a7e -> 8fda60b)

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git.


    from 9110a7e  Polished
     new 9e16d99  Polished camel-archetype-spring-boot to generate a project similar to examples/camel-example-spring-boot
     new 8fda60b  CAMEL-12341: Add dump method to camel-spring-boot actuator to dump route in XML format if not in read-only mode (not by default). Polsihed maven archetype

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../META-INF/maven/archetype-metadata.xml          |  8 +----
 .../main/resources/archetype-resources/ReadMe.txt  | 34 ----------------------
 .../resources/archetype-resources}/readme.adoc     |  3 ++
 .../{MySpringBootRouter.java => MySpringBean.java} | 26 ++++++++---------
 .../src/main/java/MySpringBootRouter.java          | 19 +++++++-----
 .../{application.yml => application.properties}    | 23 ++++++++++++++-
 .../camel/spring/boot/CamelAutoConfiguration.java  |  2 +-
 .../spring/boot/CamelConfigurationProperties.java  | 26 ++++++++++++++---
 .../boot/actuate/endpoint/CamelRoutesEndpoint.java | 11 +++++++
 .../actuate/endpoint/CamelRoutesMvcEndpoint.java   | 25 ++++++++++++++++
 .../endpoint/CamelRoutesMvcEndpointTest.java       |  8 +++++
 .../packaging/SpringBootAutoConfigurationMojo.java |  1 +
 12 files changed, 118 insertions(+), 68 deletions(-)
 delete mode 100644 archetypes/camel-archetype-spring-boot/src/main/resources/archetype-resources/ReadMe.txt
 copy {examples/camel-example-spring-boot => archetypes/camel-archetype-spring-boot/src/main/resources/archetype-resources}/readme.adoc (99%)
 copy archetypes/camel-archetype-spring-boot/src/main/resources/archetype-resources/src/main/java/{MySpringBootRouter.java => MySpringBean.java} (69%)
 rename archetypes/camel-archetype-spring-boot/src/main/resources/archetype-resources/src/main/resources/{application.yml => application.properties} (60%)

-- 
To stop receiving notification emails like this one, please contact
davsclaus@apache.org.

[camel] 01/02: Polished camel-archetype-spring-boot to generate a project similar to examples/camel-example-spring-boot

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 9e16d993e3891ce948630338072b3ddc229cc673
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Fri Mar 9 18:26:26 2018 +0100

    Polished camel-archetype-spring-boot to generate a project similar to examples/camel-example-spring-boot
---
 .../META-INF/maven/archetype-metadata.xml          |  8 +---
 .../main/resources/archetype-resources/ReadMe.txt  | 34 -----------------
 .../main/resources/archetype-resources/readme.adoc | 44 ++++++++++++++++++++++
 .../{MySpringBootRouter.java => MySpringBean.java} | 26 ++++++-------
 .../src/main/java/MySpringBootRouter.java          | 19 ++++++----
 .../{application.yml => application.properties}    | 19 +++++++++-
 .../camel/spring/boot/CamelAutoConfiguration.java  |  2 +-
 .../spring/boot/CamelConfigurationProperties.java  | 26 +++++++++++--
 .../packaging/SpringBootAutoConfigurationMojo.java |  1 +
 9 files changed, 111 insertions(+), 68 deletions(-)

diff --git a/archetypes/camel-archetype-spring-boot/src/main/resources-filtered/META-INF/maven/archetype-metadata.xml b/archetypes/camel-archetype-spring-boot/src/main/resources-filtered/META-INF/maven/archetype-metadata.xml
index fb533a3..fe2e747 100644
--- a/archetypes/camel-archetype-spring-boot/src/main/resources-filtered/META-INF/maven/archetype-metadata.xml
+++ b/archetypes/camel-archetype-spring-boot/src/main/resources-filtered/META-INF/maven/archetype-metadata.xml
@@ -69,13 +69,7 @@
       </includes>
     </fileSet>
     <fileSet filtered="true" encoding="UTF-8">
-      <directory>src/data</directory>
-      <includes>
-        <include>**/*.xml</include>
-      </includes>
-    </fileSet>
-    <fileSet filtered="true" encoding="UTF-8">
-      <directory></directory>
+      <directory>.</directory>
       <includes>
         <include>ReadMe.txt</include>
       </includes>
diff --git a/archetypes/camel-archetype-spring-boot/src/main/resources/archetype-resources/ReadMe.txt b/archetypes/camel-archetype-spring-boot/src/main/resources/archetype-resources/ReadMe.txt
deleted file mode 100644
index db2f325..0000000
--- a/archetypes/camel-archetype-spring-boot/src/main/resources/archetype-resources/ReadMe.txt
+++ /dev/null
@@ -1,34 +0,0 @@
-Spring Boot Example
-===================
-
-This example shows how to work with the simple Camel application based on the Spring Boot.
-
-The example generates messages using timer trigger, writes them to the standard output
-and the mock endpoint (for testing purposes).
-
-This example exposes Jolokia API and Spring Boot actuators endpoints (like metrics) via
-the webmvc endpoint. We consider this as the best practice - Spring Boot applications
-with these API exposed can be easily monitored and managed by 3rd parties tools.
-
-This example packages your application as a JAR, but you can also package as a WAR and
-deploy to servlet containers like Tomcat.
-
-You will need to compile this example first:
-
-    mvn install
-
-To run the example type
-
-    mvn spring-boot:run
-
-You can also execute the JAR directly:
-
-    java -jar target/${artifactId}-${version}.jar
-
-You will see the message printed to the console every second.
-To stop the example hit ctrl + c
-
-For more help see the Apache Camel documentation
-
-    http://camel.apache.org/
-
diff --git a/archetypes/camel-archetype-spring-boot/src/main/resources/archetype-resources/readme.adoc b/archetypes/camel-archetype-spring-boot/src/main/resources/archetype-resources/readme.adoc
new file mode 100644
index 0000000..04347d3
--- /dev/null
+++ b/archetypes/camel-archetype-spring-boot/src/main/resources/archetype-resources/readme.adoc
@@ -0,0 +1,44 @@
+# Camel Example Spring Boot
+
+This example shows how to work with a simple Apache Camel application using Spring Boot.
+
+The example generates messages using timer trigger, writes them to standard output.
+
+## Camel routes
+
+The Camel route is located in the `SampleCamelRouter` class. In this class the route
+starts from a timer, that triggers every 2nd second and calls a Spring Bean `SampleBean`
+which returns a message, that is routed to a stream endpoint which writes to standard output.
+
+## Using Camel components
+
+Apache Camel provides 200+ components which you can use to integrate and route messages between many systems
+and data formats. To use any of these Camel components, add the component as a dependency to your project.
+
+## How to run
+
+You can run this example using
+
+    mvn spring-boot:run
+
+## To get info about the routes
+
+To show a summary of all the routes
+
+----
+curl -XGET -s http://localhost:8080/camel/routes
+----
+
+To show detailed information for a specific route
+
+----
+curl -XGET -s http://localhost:8080/camel/routes/{id}/info
+----
+
+
+## More information
+
+You can find more information about Apache Camel at the website: http://camel.apache.org/
+
+
+
diff --git a/archetypes/camel-archetype-spring-boot/src/main/resources/archetype-resources/src/main/java/MySpringBootRouter.java b/archetypes/camel-archetype-spring-boot/src/main/resources/archetype-resources/src/main/java/MySpringBean.java
similarity index 69%
copy from archetypes/camel-archetype-spring-boot/src/main/resources/archetype-resources/src/main/java/MySpringBootRouter.java
copy to archetypes/camel-archetype-spring-boot/src/main/resources/archetype-resources/src/main/java/MySpringBean.java
index 3b65b69..14d87d7 100644
--- a/archetypes/camel-archetype-spring-boot/src/main/resources/archetype-resources/src/main/java/MySpringBootRouter.java
+++ b/archetypes/camel-archetype-spring-boot/src/main/resources/archetype-resources/src/main/java/MySpringBean.java
@@ -16,23 +16,23 @@
 ## ------------------------------------------------------------------------
 package ${package};
 
-import org.apache.camel.builder.RouteBuilder;
-import org.springframework.context.annotation.Bean;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Component;
 
-@Component
-public class MySpringBootRouter extends RouteBuilder {
+/**
+ * A bean that returns a message when you call the {@link #saySomething()} method.
+ * <p/>
+ * Uses <tt>@Component("myBean")</tt> to register this bean with the name <tt>myBean</tt>
+ * that we use in the Camel route to lookup this bean.
+ */
+@Component("myBean")
+public class MySpringBean {
 
-    @Override
-    public void configure() {
-        from("timer:trigger")
-                .transform().simple("ref:myBean")
-                .to("log:out");
-    }
+    @Value("${greeting}")
+    private String say;
 
-    @Bean
-    String myBean() {
-        return "I'm Spring bean!";
+    public String saySomething() {
+        return say;
     }
 
 }
diff --git a/archetypes/camel-archetype-spring-boot/src/main/resources/archetype-resources/src/main/java/MySpringBootRouter.java b/archetypes/camel-archetype-spring-boot/src/main/resources/archetype-resources/src/main/java/MySpringBootRouter.java
index 3b65b69..dc5c216 100644
--- a/archetypes/camel-archetype-spring-boot/src/main/resources/archetype-resources/src/main/java/MySpringBootRouter.java
+++ b/archetypes/camel-archetype-spring-boot/src/main/resources/archetype-resources/src/main/java/MySpringBootRouter.java
@@ -20,19 +20,22 @@ import org.apache.camel.builder.RouteBuilder;
 import org.springframework.context.annotation.Bean;
 import org.springframework.stereotype.Component;
 
+/**
+ * A simple Camel route that triggers from a timer and calls a bean and prints to system out.
+ * <p/>
+ * Use <tt>@Component</tt> to make Camel auto detect this route when starting.
+ */
 @Component
 public class MySpringBootRouter extends RouteBuilder {
 
     @Override
     public void configure() {
-        from("timer:trigger")
-                .transform().simple("ref:myBean")
-                .to("log:out");
-    }
-
-    @Bean
-    String myBean() {
-        return "I'm Spring bean!";
+        from("timer:hello?period={{timer.period}}").routeId("hello")
+            .transform().method("myBean", "saySomething")
+            .filter(simple("${body} contains 'foo'"))
+                .to("log:foo")
+            .end()
+            .log("${body}");
     }
 
 }
diff --git a/archetypes/camel-archetype-spring-boot/src/main/resources/archetype-resources/src/main/resources/application.yml b/archetypes/camel-archetype-spring-boot/src/main/resources/archetype-resources/src/main/resources/application.properties
similarity index 66%
rename from archetypes/camel-archetype-spring-boot/src/main/resources/archetype-resources/src/main/resources/application.yml
rename to archetypes/camel-archetype-spring-boot/src/main/resources/archetype-resources/src/main/resources/application.properties
index 9d727e8..cde1260 100644
--- a/archetypes/camel-archetype-spring-boot/src/main/resources/archetype-resources/src/main/resources/application.yml
+++ b/archetypes/camel-archetype-spring-boot/src/main/resources/archetype-resources/src/main/resources/application.properties
@@ -16,4 +16,21 @@
 ## ------------------------------------------------------------------------
 
 # the name of Camel
-camel.springboot.name = MyCamel
\ No newline at end of file
+camel.springboot.name = MyCamel
+
+# what to say
+greeting = Hello World
+
+# how often to trigger the timer
+timer.period = 2000
+
+# all access to actuator endpoints without security
+management.security.enabled = false
+# turn on actuator health check
+endpoints.health.enabled = true
+
+# to configure logging levels
+#logging.level.org.springframework = INFO
+#logging.level.org.apache.camel.spring.boot = INFO
+#logging.level.org.apache.camel.impl = DEBUG
+#logging.level.sample.camel = DEBUG
\ No newline at end of file
diff --git a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java
index ef71ac3..9dfcd99 100644
--- a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java
+++ b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java
@@ -181,7 +181,7 @@ public class CamelAutoConfiguration {
         camelContext.setAllowUseOriginalMessage(config.isAllowUseOriginalMessage());
         camelContext.setUseBreadcrumb(config.isUseBreadcrumb());
         camelContext.setUseDataType(config.isUseDataType());
-        camelContext.setUseMDCLogging(config.isUseMDCLogging());
+        camelContext.setUseMDCLogging(config.isUseMdcLogging());
         camelContext.setLoadTypeConverters(config.isLoadTypeConverters());
 
         if (camelContext.getManagementStrategy().getManagementAgent() != null) {
diff --git a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelConfigurationProperties.java b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelConfigurationProperties.java
index 4f3c5a0..d00f597 100644
--- a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelConfigurationProperties.java
+++ b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelConfigurationProperties.java
@@ -446,10 +446,18 @@ public class CamelConfigurationProperties {
     
     /**
      * To turn on MDC logging
+     *
+     * @deprecated use useMdcLogging instead
      */
+    @Deprecated
     private boolean useMDCLogging;
 
     /**
+     * To turn on MDC logging
+     */
+    private boolean useMdcLogging;
+
+    /**
      * Sets the thread name pattern used for creating the full thread name.
      * <p/>
      * The default pattern is: <tt>Camel (#camelId#) thread ##counter# - #name#</tt>
@@ -952,13 +960,23 @@ public class CamelConfigurationProperties {
     public void setIncludeNonSingletons(boolean includeNonSingletons) {
         this.includeNonSingletons = includeNonSingletons;
     }
-    
+
+    @Deprecated
     public boolean isUseMDCLogging() {
-        return useMDCLogging;
+        return isUseMdcLogging();
     }
-    
+
+    @Deprecated
     public void setUseMDCLogging(boolean useMDCLogging) {
-        this.useMDCLogging = useMDCLogging;
+        setUseMdcLogging(useMDCLogging);
+    }
+
+    public boolean isUseMdcLogging() {
+        return useMdcLogging;
+    }
+
+    public void setUseMdcLogging(boolean useMdcLogging) {
+        this.useMdcLogging = useMdcLogging;
     }
 
     public String getThreadNamePattern() {
diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/SpringBootAutoConfigurationMojo.java b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/SpringBootAutoConfigurationMojo.java
index 976010e..a9734f3 100644
--- a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/SpringBootAutoConfigurationMojo.java
+++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/SpringBootAutoConfigurationMojo.java
@@ -420,6 +420,7 @@ public class SpringBootAutoConfigurationMojo extends AbstractMojo {
                 type = "java.util.Map<java.lang.String, java.lang.Object>";
             }
 
+            // to avoid ugly names such as c-o-r-s
             if ("enableCORS".equalsIgnoreCase(name)) {
                 name = "enableCors";
             }

-- 
To stop receiving notification emails like this one, please contact
davsclaus@apache.org.

[camel] 02/02: CAMEL-12341: Add dump method to camel-spring-boot actuator to dump route in XML format if not in read-only mode (not by default). Polsihed maven archetype

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 8fda60ba759ead7bfa0f8d3a1e09dc8c22381e67
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Fri Mar 9 18:46:14 2018 +0100

    CAMEL-12341: Add dump method to camel-spring-boot actuator to dump route in XML format if not in read-only mode (not by default). Polsihed maven archetype
---
 .../src/main/resources/application.properties      |  4 ++++
 .../boot/actuate/endpoint/CamelRoutesEndpoint.java | 11 ++++++++++
 .../actuate/endpoint/CamelRoutesMvcEndpoint.java   | 25 ++++++++++++++++++++++
 .../endpoint/CamelRoutesMvcEndpointTest.java       |  8 +++++++
 4 files changed, 48 insertions(+)

diff --git a/archetypes/camel-archetype-spring-boot/src/main/resources/archetype-resources/src/main/resources/application.properties b/archetypes/camel-archetype-spring-boot/src/main/resources/archetype-resources/src/main/resources/application.properties
index cde1260..2fb8185 100644
--- a/archetypes/camel-archetype-spring-boot/src/main/resources/archetype-resources/src/main/resources/application.properties
+++ b/archetypes/camel-archetype-spring-boot/src/main/resources/archetype-resources/src/main/resources/application.properties
@@ -29,6 +29,10 @@ management.security.enabled = false
 # turn on actuator health check
 endpoints.health.enabled = true
 
+# allow to obtain basic information about camel routes (read only mode)
+endpoints.camelroutes.enabled = true
+endpoints.camelroutes.read-only = true
+
 # to configure logging levels
 #logging.level.org.springframework = INFO
 #logging.level.org.apache.camel.spring.boot = INFO
diff --git a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRoutesEndpoint.java b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRoutesEndpoint.java
index 5a5d314..e96ac6b 100644
--- a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRoutesEndpoint.java
+++ b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRoutesEndpoint.java
@@ -24,6 +24,8 @@ import java.util.stream.Collectors;
 import org.apache.camel.CamelContext;
 import org.apache.camel.Route;
 import org.apache.camel.api.management.mbean.ManagedRouteMBean;
+import org.apache.camel.model.ModelHelper;
+import org.apache.camel.model.RouteDefinition;
 import org.apache.camel.spring.boot.model.RouteDetailsInfo;
 import org.apache.camel.spring.boot.model.RouteInfo;
 import org.springframework.boot.actuate.endpoint.Endpoint;
@@ -69,6 +71,15 @@ public class CamelRoutesEndpoint extends AbstractCamelEndpoint<List<RouteInfo>>
         return null;
     }
 
+    public String getRouteDump(String id) throws Exception {
+        RouteDefinition route = getCamelContext().getRouteDefinition(id);
+        if (route != null) {
+            return ModelHelper.dumpModelAsXml(getCamelContext(), route);
+        }
+
+        return null;
+    }
+
     public void startRoute(String id) throws Exception {
         getCamelContext().getRouteController().startRoute(id);
     }
diff --git a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRoutesMvcEndpoint.java b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRoutesMvcEndpoint.java
index 5e852be..722cd75 100644
--- a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRoutesMvcEndpoint.java
+++ b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRoutesMvcEndpoint.java
@@ -48,6 +48,31 @@ public class CamelRoutesMvcEndpoint extends AbstractCamelMvcEndpoint<CamelRoutes
 
     @ResponseBody
     @GetMapping(
+        value = "/{id}/dump",
+        produces = {
+            MediaType.APPLICATION_XML_VALUE,
+            MediaType.APPLICATION_XML_VALUE
+        }
+    )
+    public Object dump(
+        @PathVariable String id) {
+
+        return doIfEnabledAndNotReadOnly(() -> {
+            try {
+                Object result = delegate().getRouteDump(id);
+                if (result == null) {
+                    throw new NoSuchRouteException("No such route " + id);
+                }
+
+                return result;
+            } catch (Exception e) {
+                throw new GenericException("Error dumping route " + id, e);
+            }
+        });
+    }
+
+    @ResponseBody
+    @GetMapping(
             value = "/{id}/detail",
             produces = {
                     ActuatorMediaTypes.APPLICATION_ACTUATOR_V1_JSON_VALUE,
diff --git a/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRoutesMvcEndpointTest.java b/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRoutesMvcEndpointTest.java
index ff9187b..8eb41a3 100644
--- a/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRoutesMvcEndpointTest.java
+++ b/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/actuate/endpoint/CamelRoutesMvcEndpointTest.java
@@ -78,4 +78,12 @@ public class CamelRoutesMvcEndpointTest extends Assert {
         assertEquals(200, ent.getStatusCodeValue());
     }
 
+    @Test
+    public void testMvcRouteDump() throws Exception {
+        Object result = endpoint.dump("foo-route");
+
+        assertTrue(result instanceof String);
+        assertTrue(result.toString().contains("<from uri=\"timer:foo\"/>"));
+    }
+
 }

-- 
To stop receiving notification emails like this one, please contact
davsclaus@apache.org.