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 2016/06/07 12:50:30 UTC
[2/8] camel git commit: Experiment with generating spring-boot auto
configuration for the Camel components.
Experiment with generating spring-boot auto configuration for the Camel components.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/4548609a
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/4548609a
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/4548609a
Branch: refs/heads/boot-generate
Commit: 4548609ae0f9a8cd7a04dd3a1924a08f14d22787
Parents: a9b40df
Author: Claus Ibsen <da...@apache.org>
Authored: Mon Jun 6 17:51:44 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Mon Jun 6 17:51:44 2016 +0200
----------------------------------------------------------------------
.../camel/component/ahc/AhcComponent.java | 6 +-
.../camel/component/stomp/StompComponent.java | 34 +++++++++-
components/pom.xml | 21 ++----
examples/camel-example-spring-boot/pom.xml | 5 ++
.../example/spring/boot/MySpringBootRouter.java | 11 ++++
.../src/main/resources/application.yml | 7 ++
tooling/apt-spring-boot/pom.xml | 68 ++++++++++++++++++++
.../ComponentAnnotationProcessor.java | 34 ++++++++++
.../javax.annotation.processing.Processor | 17 +++++
tooling/pom.xml | 1 +
.../java/org/apache/camel/spi/UriComponent.java | 35 ++++++++++
11 files changed, 219 insertions(+), 20 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/4548609a/components/camel-ahc/src/main/java/org/apache/camel/component/ahc/AhcComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-ahc/src/main/java/org/apache/camel/component/ahc/AhcComponent.java b/components/camel-ahc/src/main/java/org/apache/camel/component/ahc/AhcComponent.java
index 88dd7e7..9c0854a 100644
--- a/components/camel-ahc/src/main/java/org/apache/camel/component/ahc/AhcComponent.java
+++ b/components/camel-ahc/src/main/java/org/apache/camel/component/ahc/AhcComponent.java
@@ -21,23 +21,21 @@ import java.util.Map;
import com.ning.http.client.AsyncHttpClient;
import com.ning.http.client.AsyncHttpClientConfig;
-
import com.ning.http.client.Realm;
import org.apache.camel.Endpoint;
import org.apache.camel.impl.HeaderFilterStrategyComponent;
+import org.apache.camel.spi.UriComponent;
import org.apache.camel.util.IntrospectionSupport;
import org.apache.camel.util.URISupport;
import org.apache.camel.util.UnsafeUriCharactersEncoder;
import org.apache.camel.util.jsse.SSLContextParameters;
-
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.boot.context.properties.ConfigurationProperties;
/**
* To call external HTTP services using <a href="http://github.com/sonatype/async-http-client">Async Http Client</a>
*/
-@ConfigurationProperties(prefix = "camel.ahc", merge = false)
+@UriComponent(prefix = "camel.component.ahc")
public class AhcComponent extends HeaderFilterStrategyComponent {
private static final Logger LOG = LoggerFactory.getLogger(AhcComponent.class);
http://git-wip-us.apache.org/repos/asf/camel/blob/4548609a/components/camel-stomp/src/main/java/org/apache/camel/component/stomp/StompComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-stomp/src/main/java/org/apache/camel/component/stomp/StompComponent.java b/components/camel-stomp/src/main/java/org/apache/camel/component/stomp/StompComponent.java
index 8a87a87..cda343e 100644
--- a/components/camel-stomp/src/main/java/org/apache/camel/component/stomp/StompComponent.java
+++ b/components/camel-stomp/src/main/java/org/apache/camel/component/stomp/StompComponent.java
@@ -20,10 +20,35 @@ import java.util.Map;
import org.apache.camel.Endpoint;
import org.apache.camel.impl.UriEndpointComponent;
+import org.apache.camel.spi.UriComponent;
+@UriComponent(prefix = "camel.stomp")
public class StompComponent extends UriEndpointComponent {
- private StompConfiguration configuration = new StompConfiguration();
+ /**
+ * To use the shared stomp configuration
+ */
+ private StompConfiguration configuration;
+
+ /**
+ * The URI of the Stomp broker to connect to
+ */
+ private String brokerUrl;
+
+ /**
+ * The username
+ */
+ private String login;
+
+ /**
+ * The password
+ */
+ private String passcode;
+
+ /**
+ * The virtual host
+ */
+ private String host;
public StompComponent() {
super(StompEndpoint.class);
@@ -43,6 +68,13 @@ public class StompComponent extends UriEndpointComponent {
return endpoint;
}
+ @Override
+ protected void doStart() throws Exception {
+ super.doStart();
+
+ configuration.setBrokerURL(brokerUrl);
+ }
+
public StompConfiguration getConfiguration() {
return configuration;
}
http://git-wip-us.apache.org/repos/asf/camel/blob/4548609a/components/pom.xml
----------------------------------------------------------------------
diff --git a/components/pom.xml b/components/pom.xml
index 7081b1f..c559328 100644
--- a/components/pom.xml
+++ b/components/pom.xml
@@ -317,30 +317,21 @@
</activation>
<dependencies>
- <!-- enable the APT processor -->
+ <!-- enable the APT processors -->
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>apt</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
-
- <!-- enable spring-boot APT processor -->
<dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-configuration-processor</artifactId>
- <version>${spring-boot-version}</version>
- <optional>true</optional>
- </dependency>
-
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot</artifactId>
- <version>${spring-boot-version}</version>
- <optional>true</optional>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>apt-spring-boot</artifactId>
+ <version>${project.version}</version>
+ <scope>provided</scope>
</dependency>
-
</dependencies>
</profile>
</profiles>
+
</project>
http://git-wip-us.apache.org/repos/asf/camel/blob/4548609a/examples/camel-example-spring-boot/pom.xml
----------------------------------------------------------------------
diff --git a/examples/camel-example-spring-boot/pom.xml b/examples/camel-example-spring-boot/pom.xml
index 9be898c..c15e023 100755
--- a/examples/camel-example-spring-boot/pom.xml
+++ b/examples/camel-example-spring-boot/pom.xml
@@ -77,6 +77,11 @@
<artifactId>camel-commands-spring-boot</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-ahc</artifactId>
+ </dependency>
+
<!-- testing -->
<dependency>
<groupId>org.springframework.boot</groupId>
http://git-wip-us.apache.org/repos/asf/camel/blob/4548609a/examples/camel-example-spring-boot/src/main/java/org/apache/camel/example/spring/boot/MySpringBootRouter.java
----------------------------------------------------------------------
diff --git a/examples/camel-example-spring-boot/src/main/java/org/apache/camel/example/spring/boot/MySpringBootRouter.java b/examples/camel-example-spring-boot/src/main/java/org/apache/camel/example/spring/boot/MySpringBootRouter.java
index a581c07..16335bc 100644
--- a/examples/camel-example-spring-boot/src/main/java/org/apache/camel/example/spring/boot/MySpringBootRouter.java
+++ b/examples/camel-example-spring-boot/src/main/java/org/apache/camel/example/spring/boot/MySpringBootRouter.java
@@ -16,20 +16,31 @@
*/
package org.apache.camel.example.spring.boot;
+import org.apache.camel.component.ahc.AhcComponent;
import org.apache.camel.spring.boot.FatJarRouter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.endpoint.HealthEndpoint;
import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
@SpringBootApplication
+@EnableConfigurationProperties(AhcComponent.class)
public class MySpringBootRouter extends FatJarRouter {
@Autowired
private HealthEndpoint health;
+ @Autowired
+ private AhcComponent ahc;
+
@Override
public void configure() {
+ log.warn("AhcComponent isAllowJavaSerializedObject = " + ahc.isAllowJavaSerializedObject());
+ log.warn("AhcComponent isAllowJavaSerializedObject = " + ahc.isAllowJavaSerializedObject());
+ log.warn("AhcComponent isAllowJavaSerializedObject = " + ahc.isAllowJavaSerializedObject());
+
+
from("timer:trigger")
.transform().simple("ref:myBean")
.to("log:out");
http://git-wip-us.apache.org/repos/asf/camel/blob/4548609a/examples/camel-example-spring-boot/src/main/resources/application.yml
----------------------------------------------------------------------
diff --git a/examples/camel-example-spring-boot/src/main/resources/application.yml b/examples/camel-example-spring-boot/src/main/resources/application.yml
index 59fc3f5..3527cc1 100644
--- a/examples/camel-example-spring-boot/src/main/resources/application.yml
+++ b/examples/camel-example-spring-boot/src/main/resources/application.yml
@@ -17,3 +17,10 @@
spring.main.sources: org.apache.camel.example.spring.boot.MySpringBootRouter
shell.auth.simple.user.password: password
+
+camel:
+ springboot:
+ allow-use-original-message: false
+ component:
+ ahc:
+ allow-java-serialized-object: true
http://git-wip-us.apache.org/repos/asf/camel/blob/4548609a/tooling/apt-spring-boot/pom.xml
----------------------------------------------------------------------
diff --git a/tooling/apt-spring-boot/pom.xml b/tooling/apt-spring-boot/pom.xml
new file mode 100644
index 0000000..bc92167
--- /dev/null
+++ b/tooling/apt-spring-boot/pom.xml
@@ -0,0 +1,68 @@
+<?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>tooling</artifactId>
+ <version>2.18-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>apt-spring-boot</artifactId>
+ <name>Camel :: Annotation Processor for Spring Boot</name>
+ <description>Processes Camel components to generate Spring Boot auto configuration files</description>
+
+ <properties>
+ </properties>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>spi-annotations</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <!-- re-use spring-boot APT -->
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-configuration-processor</artifactId>
+ <version>${spring-boot-version}</version>
+ </dependency>
+
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>${jdk.version}</source>
+ <target>${jdk.version}</target>
+ <!-- Disable annotation processing for ourselves. -->
+ <proc>none</proc>
+ <verbose>false</verbose>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
http://git-wip-us.apache.org/repos/asf/camel/blob/4548609a/tooling/apt-spring-boot/src/main/java/org/apache/camel/tools/apt/springboot/ComponentAnnotationProcessor.java
----------------------------------------------------------------------
diff --git a/tooling/apt-spring-boot/src/main/java/org/apache/camel/tools/apt/springboot/ComponentAnnotationProcessor.java b/tooling/apt-spring-boot/src/main/java/org/apache/camel/tools/apt/springboot/ComponentAnnotationProcessor.java
new file mode 100644
index 0000000..627b573
--- /dev/null
+++ b/tooling/apt-spring-boot/src/main/java/org/apache/camel/tools/apt/springboot/ComponentAnnotationProcessor.java
@@ -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.tools.apt.springboot;
+
+import javax.annotation.processing.SupportedAnnotationTypes;
+import javax.annotation.processing.SupportedSourceVersion;
+import javax.lang.model.SourceVersion;
+
+import org.apache.camel.spi.UriComponent;
+import org.springframework.boot.configurationprocessor.ConfigurationMetadataAnnotationProcessor;
+
+@SupportedAnnotationTypes({ "*" })
+@SupportedSourceVersion(SourceVersion.RELEASE_8)
+public class ComponentAnnotationProcessor extends ConfigurationMetadataAnnotationProcessor {
+
+ @Override
+ protected String configurationPropertiesAnnotation() {
+ return UriComponent.class.getName();
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/4548609a/tooling/apt-spring-boot/src/main/resources/META-INF/services/javax.annotation.processing.Processor
----------------------------------------------------------------------
diff --git a/tooling/apt-spring-boot/src/main/resources/META-INF/services/javax.annotation.processing.Processor b/tooling/apt-spring-boot/src/main/resources/META-INF/services/javax.annotation.processing.Processor
new file mode 100644
index 0000000..a96c928
--- /dev/null
+++ b/tooling/apt-spring-boot/src/main/resources/META-INF/services/javax.annotation.processing.Processor
@@ -0,0 +1,17 @@
+#
+# 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.
+#
+org.apache.camel.tools.apt.springboot.ComponentAnnotationProcessor
http://git-wip-us.apache.org/repos/asf/camel/blob/4548609a/tooling/pom.xml
----------------------------------------------------------------------
diff --git a/tooling/pom.xml b/tooling/pom.xml
index 0425218..f230af5 100644
--- a/tooling/pom.xml
+++ b/tooling/pom.xml
@@ -39,6 +39,7 @@
<module>parent</module>
<module>spi-annotations</module>
<module>apt</module>
+ <module>apt-spring-boot</module>
<module>maven</module>
<module>archetypes</module>
<module>camel-manual</module>
http://git-wip-us.apache.org/repos/asf/camel/blob/4548609a/tooling/spi-annotations/src/main/java/org/apache/camel/spi/UriComponent.java
----------------------------------------------------------------------
diff --git a/tooling/spi-annotations/src/main/java/org/apache/camel/spi/UriComponent.java b/tooling/spi-annotations/src/main/java/org/apache/camel/spi/UriComponent.java
new file mode 100644
index 0000000..5ed5f05
--- /dev/null
+++ b/tooling/spi-annotations/src/main/java/org/apache/camel/spi/UriComponent.java
@@ -0,0 +1,35 @@
+/**
+ * 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.spi;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Documented
+@Target({ElementType.TYPE})
+public @interface UriComponent {
+
+ /**
+ * Prefix to use when configuring component
+ */
+ String prefix() default "";
+
+}