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 <claus.ib...@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 davscl...@apache.org.