You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2020/01/21 07:12:11 UTC
[camel-spring-boot] branch master updated: CAMEL-14417 [camel-jslt]
Create spring-boot starter for camel-jslt
This is an automated email from the ASF dual-hosted git repository.
acosentino pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-spring-boot.git
The following commit(s) were added to refs/heads/master by this push:
new 6408c4b CAMEL-14417 [camel-jslt] Create spring-boot starter for camel-jslt
new 294a014 Merge pull request #1 from JiriOndrusek/CAMEL-14417_camel-jstl-starter
6408c4b is described below
commit 6408c4b1921ce6d9ac27aa038a4dfb39dd3e224e
Author: JiriOndrusek <jo...@redhat.com>
AuthorDate: Fri Jan 17 15:28:03 2020 +0100
CAMEL-14417 [camel-jslt] Create spring-boot starter for camel-jslt
---
.../camel/springboot/catalog/components.properties | 1 +
.../camel/springboot/catalog/components/jslt.json | 35 ++++++
.../camel/itest/springboot/CamelJsltTest.java | 48 ++++++++
components-starter/camel-jslt-starter/pom.xml | 53 +++++++++
.../springboot/JsltComponentAutoConfiguration.java | 128 +++++++++++++++++++++
.../springboot/JsltComponentConfiguration.java | 86 ++++++++++++++
components-starter/pom.xml | 1 +
tooling/camel-spring-boot-dependencies/pom.xml | 5 +
8 files changed, 357 insertions(+)
diff --git a/camel-catalog-provider-springboot/src/main/resources/org/apache/camel/springboot/catalog/components.properties b/camel-catalog-provider-springboot/src/main/resources/org/apache/camel/springboot/catalog/components.properties
index 2b55883..74f764c 100644
--- a/camel-catalog-provider-springboot/src/main/resources/org/apache/camel/springboot/catalog/components.properties
+++ b/camel-catalog-provider-springboot/src/main/resources/org/apache/camel/springboot/catalog/components.properties
@@ -168,6 +168,7 @@ jmx
jolt
jooq
jpa
+jslt
json-validator
jt400
kafka
diff --git a/camel-catalog-provider-springboot/src/main/resources/org/apache/camel/springboot/catalog/components/jslt.json b/camel-catalog-provider-springboot/src/main/resources/org/apache/camel/springboot/catalog/components/jslt.json
new file mode 100644
index 0000000..3320f58
--- /dev/null
+++ b/camel-catalog-provider-springboot/src/main/resources/org/apache/camel/springboot/catalog/components/jslt.json
@@ -0,0 +1,35 @@
+{
+ "component": {
+ "kind": "component",
+ "scheme": "jslt",
+ "syntax": "jslt:resourceUri",
+ "title": "JSLT",
+ "description": "The jslt component allows you to process a JSON messages using an JSLT transformations.",
+ "label": "transformation",
+ "deprecated": false,
+ "deprecationNote": "",
+ "async": false,
+ "consumerOnly": false,
+ "producerOnly": true,
+ "lenientProperties": false,
+ "javaType": "org.apache.camel.component.jslt.JsltComponent",
+ "firstVersion": "3.1.0",
+ "groupId": "org.apache.camel.springboot",
+ "artifactId": "camel-jslt-starter",
+ "version": "3.1.0-SNAPSHOT"
+ },
+ "componentProperties": {
+ "functions": { "kind": "property", "displayName": "Functions", "group": "advanced", "label": "advanced", "required": false, "type": "array", "javaType": "java.util.Collection<com.schibsted.spt.data.jslt.Function>", "deprecated": false, "secret": false, "description": "JSLT can be extended by plugging in functions written in Java." },
+ "basicPropertyBinding": { "kind": "property", "displayName": "Basic Property Binding", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "secret": false, "defaultValue": false, "description": "Whether the component should use basic property binding (Camel 2.x) or the newer property binding with additional capabilities" },
+ "lazyStartProducer": { "kind": "property", "displayName": "Lazy Start Producer", "group": "producer", "label": "producer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "secret": false, "defaultValue": false, "description": "Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the r [...]
+ },
+ "properties": {
+ "resourceUri": { "kind": "path", "displayName": "Resource Uri", "group": "producer", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "secret": false, "description": "Path to the resource. You can prefix with: classpath, file, http, ref, or bean. classpath, file and http loads the resource using these protocols (classpath is default). ref will lookup the resource in the registry. bean will call a method on a bean to be used as the resource. For [...]
+ "prettyPrint": { "kind": "parameter", "displayName": "Pretty Print", "group": "common", "label": "common", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "secret": false, "defaultValue": false, "description": "If true, JSON in output message is pretty printed." },
+ "contentCache": { "kind": "parameter", "displayName": "Content Cache", "group": "producer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "secret": false, "defaultValue": false, "description": "Sets whether to use resource content cache or not" },
+ "lazyStartProducer": { "kind": "parameter", "displayName": "Lazy Start Producer", "group": "producer", "label": "producer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "secret": false, "defaultValue": false, "description": "Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the [...]
+ "basicPropertyBinding": { "kind": "parameter", "displayName": "Basic Property Binding", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "secret": false, "defaultValue": false, "description": "Whether the endpoint should use basic property binding (Camel 2.x) or the newer property binding with additional capabilities" },
+ "synchronous": { "kind": "parameter", "displayName": "Synchronous", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "secret": false, "defaultValue": false, "description": "Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported)." }
+ }
+}
+
diff --git a/camel-itest-spring-boot/src/test/java/org/apache/camel/itest/springboot/CamelJsltTest.java b/camel-itest-spring-boot/src/test/java/org/apache/camel/itest/springboot/CamelJsltTest.java
new file mode 100644
index 0000000..bb9c801
--- /dev/null
+++ b/camel-itest-spring-boot/src/test/java/org/apache/camel/itest/springboot/CamelJsltTest.java
@@ -0,0 +1,48 @@
+/*
+ * 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.itest.springboot;
+
+import org.apache.camel.itest.springboot.util.ArquillianPackager;
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.shrinkwrap.api.Archive;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+
+@RunWith(Arquillian.class)
+public class CamelJsltTest extends AbstractSpringBootTestSupport {
+
+ @Deployment
+ public static Archive<?> createSpringBootPackage() throws Exception {
+ return ArquillianPackager.springBootPackage(createTestConfig());
+ }
+
+ public static ITestConfig createTestConfig() {
+ return new ITestConfigBuilder()
+ .module(inferModuleName(CamelJsltTest.class))
+ .build();
+ }
+
+ @Test
+ public void componentTests() throws Exception {
+ this.runComponentTest(config);
+ this.runModuleUnitTestsIfEnabled(config);
+ }
+
+
+}
diff --git a/components-starter/camel-jslt-starter/pom.xml b/components-starter/camel-jslt-starter/pom.xml
new file mode 100644
index 0000000..4d17a84
--- /dev/null
+++ b/components-starter/camel-jslt-starter/pom.xml
@@ -0,0 +1,53 @@
+<?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.springboot</groupId>
+ <artifactId>components-starter</artifactId>
+ <version>3.1.0-SNAPSHOT</version>
+ </parent>
+ <artifactId>camel-jslt-starter</artifactId>
+ <packaging>jar</packaging>
+ <!-- <name>Camel Spring Boot :: Starters :: Dozer</name>-->
+ <!-- <description>Spring-Boot Starter for Camel Support for the Dozer type conversion framework</description>-->
+ <dependencies>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter</artifactId>
+ <version>${spring-boot-version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-jslt</artifactId>
+ <version>${camel-version}</version>
+ </dependency>
+ <!--START OF GENERATED CODE-->
+ <dependency>
+ <groupId>org.apache.camel.springboot</groupId>
+ <artifactId>camel-core-starter</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel.springboot</groupId>
+ <artifactId>camel-spring-boot-starter</artifactId>
+ </dependency>
+ <!--END OF GENERATED CODE-->
+ </dependencies>
+</project>
diff --git a/components-starter/camel-jslt-starter/src/main/java/org/apache/camel/component/jslt/springboot/JsltComponentAutoConfiguration.java b/components-starter/camel-jslt-starter/src/main/java/org/apache/camel/component/jslt/springboot/JsltComponentAutoConfiguration.java
new file mode 100644
index 0000000..b10f8d1
--- /dev/null
+++ b/components-starter/camel-jslt-starter/src/main/java/org/apache/camel/component/jslt/springboot/JsltComponentAutoConfiguration.java
@@ -0,0 +1,128 @@
+/*
+ * 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.component.jslt.springboot;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import javax.annotation.Generated;
+import org.apache.camel.CamelContext;
+import org.apache.camel.component.jslt.JsltComponent;
+import org.apache.camel.spi.ComponentCustomizer;
+import org.apache.camel.spi.HasId;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+import org.apache.camel.spring.boot.ComponentConfigurationProperties;
+import org.apache.camel.spring.boot.util.CamelPropertiesHelper;
+import org.apache.camel.spring.boot.util.ConditionalOnCamelContextAndAutoConfigurationBeans;
+import org.apache.camel.spring.boot.util.GroupCondition;
+import org.apache.camel.spring.boot.util.HierarchicalPropertiesEvaluator;
+import org.apache.camel.support.IntrospectionSupport;
+import org.apache.camel.util.ObjectHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.AutoConfigureAfter;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Conditional;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Lazy;
+
+/**
+ * Generated by camel-package-maven-plugin - do not edit this file!
+ */
+@Generated("org.apache.camel.springboot.maven.SpringBootAutoConfigurationMojo")
+@Configuration
+@Conditional({ConditionalOnCamelContextAndAutoConfigurationBeans.class,
+ JsltComponentAutoConfiguration.GroupConditions.class})
+@AutoConfigureAfter(CamelAutoConfiguration.class)
+@EnableConfigurationProperties({ComponentConfigurationProperties.class,
+ JsltComponentConfiguration.class})
+public class JsltComponentAutoConfiguration {
+
+ private static final Logger LOGGER = LoggerFactory
+ .getLogger(JsltComponentAutoConfiguration.class);
+ @Autowired
+ private ApplicationContext applicationContext;
+ @Autowired
+ private CamelContext camelContext;
+ @Autowired
+ private JsltComponentConfiguration configuration;
+ @Autowired(required = false)
+ private List<ComponentCustomizer<JsltComponent>> customizers;
+
+ static class GroupConditions extends GroupCondition {
+ public GroupConditions() {
+ super("camel.component", "camel.component.jslt");
+ }
+ }
+
+ @Lazy
+ @Bean(name = "jslt-component")
+ @ConditionalOnMissingBean(JsltComponent.class)
+ public JsltComponent configureJsltComponent() throws Exception {
+ JsltComponent component = new JsltComponent();
+ component.setCamelContext(camelContext);
+ Map<String, Object> parameters = new HashMap<>();
+ IntrospectionSupport.getProperties(configuration, parameters, null,
+ false);
+ for (Map.Entry<String, Object> entry : parameters.entrySet()) {
+ Object value = entry.getValue();
+ Class<?> paramClass = value.getClass();
+ if (paramClass.getName().endsWith("NestedConfiguration")) {
+ Class nestedClass = null;
+ try {
+ nestedClass = (Class) paramClass.getDeclaredField(
+ "CAMEL_NESTED_CLASS").get(null);
+ HashMap<String, Object> nestedParameters = new HashMap<>();
+ IntrospectionSupport.getProperties(value, nestedParameters,
+ null, false);
+ Object nestedProperty = nestedClass.newInstance();
+ CamelPropertiesHelper.setCamelProperties(camelContext,
+ nestedProperty, nestedParameters, false);
+ entry.setValue(nestedProperty);
+ } catch (NoSuchFieldException e) {
+ }
+ }
+ }
+ CamelPropertiesHelper.setCamelProperties(camelContext, component,
+ parameters, false);
+ if (ObjectHelper.isNotEmpty(customizers)) {
+ for (ComponentCustomizer<JsltComponent> customizer : customizers) {
+ boolean useCustomizer = (customizer instanceof HasId)
+ ? HierarchicalPropertiesEvaluator.evaluate(
+ applicationContext.getEnvironment(),
+ "camel.component.customizer",
+ "camel.component.jslt.customizer",
+ ((HasId) customizer).getId())
+ : HierarchicalPropertiesEvaluator.evaluate(
+ applicationContext.getEnvironment(),
+ "camel.component.customizer",
+ "camel.component.jslt.customizer");
+ if (useCustomizer) {
+ LOGGER.debug("Configure component {}, with customizer {}",
+ component, customizer);
+ customizer.customize(component);
+ }
+ }
+ }
+ return component;
+ }
+}
\ No newline at end of file
diff --git a/components-starter/camel-jslt-starter/src/main/java/org/apache/camel/component/jslt/springboot/JsltComponentConfiguration.java b/components-starter/camel-jslt-starter/src/main/java/org/apache/camel/component/jslt/springboot/JsltComponentConfiguration.java
new file mode 100644
index 0000000..69dbcea
--- /dev/null
+++ b/components-starter/camel-jslt-starter/src/main/java/org/apache/camel/component/jslt/springboot/JsltComponentConfiguration.java
@@ -0,0 +1,86 @@
+/*
+ * 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.component.jslt.springboot;
+
+import java.util.Collection;
+import javax.annotation.Generated;
+import com.schibsted.spt.data.jslt.Function;
+import org.apache.camel.spring.boot.ComponentConfigurationPropertiesCommon;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+
+/**
+ * The jslt component allows you to process a JSON messages using an JSLT
+ * transformations.
+ *
+ * Generated by camel-package-maven-plugin - do not edit this file!
+ */
+@Generated("org.apache.camel.springboot.maven.SpringBootAutoConfigurationMojo")
+@ConfigurationProperties(prefix = "camel.component.jslt")
+public class JsltComponentConfiguration
+ extends
+ ComponentConfigurationPropertiesCommon {
+
+ /**
+ * Whether to enable auto configuration of the jslt component. This is
+ * enabled by default.
+ */
+ private Boolean enabled;
+ /**
+ * JSLT can be extended by plugging in functions written in Java.
+ */
+ private Collection<Function> functions;
+ /**
+ * Whether the component should use basic property binding (Camel 2.x) or
+ * the newer property binding with additional capabilities
+ */
+ private Boolean basicPropertyBinding = false;
+ /**
+ * Whether the producer should be started lazy (on the first message). By
+ * starting lazy you can use this to allow CamelContext and routes to
+ * startup in situations where a producer may otherwise fail during starting
+ * and cause the route to fail being started. By deferring this startup to
+ * be lazy then the startup failure can be handled during routing messages
+ * via Camel's routing error handlers. Beware that when the first message is
+ * processed then creating and starting the producer may take a little time
+ * and prolong the total processing time of the processing.
+ */
+ private Boolean lazyStartProducer = false;
+
+ public Collection<Function> getFunctions() {
+ return functions;
+ }
+
+ public void setFunctions(Collection<Function> functions) {
+ this.functions = functions;
+ }
+
+ public Boolean getBasicPropertyBinding() {
+ return basicPropertyBinding;
+ }
+
+ public void setBasicPropertyBinding(Boolean basicPropertyBinding) {
+ this.basicPropertyBinding = basicPropertyBinding;
+ }
+
+ public Boolean getLazyStartProducer() {
+ return lazyStartProducer;
+ }
+
+ public void setLazyStartProducer(Boolean lazyStartProducer) {
+ this.lazyStartProducer = lazyStartProducer;
+ }
+}
\ No newline at end of file
diff --git a/components-starter/pom.xml b/components-starter/pom.xml
index dfa3c24..7d11699 100644
--- a/components-starter/pom.xml
+++ b/components-starter/pom.xml
@@ -257,6 +257,7 @@
<module>camel-jooq-starter</module>
<module>camel-jpa-starter</module>
<module>camel-jsch-starter</module>
+ <module>camel-jslt-starter</module>
<module>camel-json-validator-starter</module>
<module>camel-jsonapi-starter</module>
<module>camel-jsonpath-starter</module>
diff --git a/tooling/camel-spring-boot-dependencies/pom.xml b/tooling/camel-spring-boot-dependencies/pom.xml
index dc991b4..0de6115 100644
--- a/tooling/camel-spring-boot-dependencies/pom.xml
+++ b/tooling/camel-spring-boot-dependencies/pom.xml
@@ -1038,6 +1038,11 @@
</dependency>
<dependency>
<groupId>org.apache.camel.springboot</groupId>
+ <artifactId>camel-jslt-starter</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-json-validator-starter</artifactId>
<version>${project.version}</version>
</dependency>