This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-spring-boot.git
The following commit(s) were added to refs/heads/main by this push:
new 0c302def2a0 CAMEL-21398: Smooks autowire SmooksFactory.
0c302def2a0 is described below
commit 0c302def2a0631b4b701d3adb9bd2d23b8667e27
Author: Claus Ibsen <[email protected]>
AuthorDate: Wed Oct 30 10:14:12 2024 +0100
CAMEL-21398: Smooks autowire SmooksFactory.
---
.../springboot/catalog/components/smooks.json | 3 +-
.../camel-smooks-starter/src/main/docs/smooks.json | 6 +++
.../SmooksComponentAutoConfiguration.java | 2 +-
.../springboot/SmooksComponentConfiguration.java | 14 +++++
.../springboot/SmooksComponentConverter.java | 63 ++++++++++++++++++++++
...rk.boot.autoconfigure.AutoConfiguration.imports | 1 +
6 files changed, 87 insertions(+), 2 deletions(-)
diff --git
a/catalog/camel-catalog-provider-springboot/src/main/resources/org/apache/camel/springboot/catalog/components/smooks.json
b/catalog/camel-catalog-provider-springboot/src/main/resources/org/apache/camel/springboot/catalog/components/smooks.json
index 6a734c38b99..ede3e9db2d1 100644
---
a/catalog/camel-catalog-provider-springboot/src/main/resources/org/apache/camel/springboot/catalog/components/smooks.json
+++
b/catalog/camel-catalog-provider-springboot/src/main/resources/org/apache/camel/springboot/catalog/components/smooks.json
@@ -25,7 +25,8 @@
},
"componentProperties": {
"lazyStartProducer": { "index": 0, "kind": "property", "displayName":
"Lazy Start Producer", "group": "producer", "label": "producer", "required":
false, "type": "boolean", "javaType": "boolean", "deprecated": false,
"autowired": 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 [...]
- "autowiredEnabled": { "index": 1, "kind": "property", "displayName":
"Autowired Enabled", "group": "advanced", "label": "advanced", "required":
false, "type": "boolean", "javaType": "boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": true, "description":
"Whether autowiring is enabled. This is used for automatic autowiring options
(the option must be marked as autowired) by looking up in the registry to find
if there is a single instance of matching t [...]
+ "autowiredEnabled": { "index": 1, "kind": "property", "displayName":
"Autowired Enabled", "group": "advanced", "label": "advanced", "required":
false, "type": "boolean", "javaType": "boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": true, "description":
"Whether autowiring is enabled. This is used for automatic autowiring options
(the option must be marked as autowired) by looking up in the registry to find
if there is a single instance of matching t [...]
+ "smooksFactory": { "index": 2, "kind": "property", "displayName": "Smooks
Factory", "group": "advanced", "label": "advanced", "required": false, "type":
"object", "javaType": "org.smooks.SmooksFactory", "deprecated": false,
"autowired": true, "secret": false, "description": "To use a custom factory for
creating Smooks." }
},
"properties": {
"smooksConfig": { "index": 0, "kind": "path", "displayName": "Smooks
Config", "group": "producer", "label": "", "required": true, "type": "string",
"javaType": "java.lang.String", "deprecated": false, "deprecationNote": "",
"autowired": false, "secret": false, "supportFileReference": true,
"description": "Path to the Smooks configuration file" },
diff --git a/components-starter/camel-smooks-starter/src/main/docs/smooks.json
b/components-starter/camel-smooks-starter/src/main/docs/smooks.json
index a4d751784a6..8bd1b25a3c7 100644
--- a/components-starter/camel-smooks-starter/src/main/docs/smooks.json
+++ b/components-starter/camel-smooks-starter/src/main/docs/smooks.json
@@ -49,6 +49,12 @@
"sourceType":
"org.apache.camel.component.smooks.springboot.SmooksComponentConfiguration",
"defaultValue": false
},
+ {
+ "name": "camel.component.smooks.smooks-factory",
+ "type": "org.smooks.SmooksFactory",
+ "description": "To use a custom factory for creating Smooks. The option
is a org.smooks.SmooksFactory type.",
+ "sourceType":
"org.apache.camel.component.smooks.springboot.SmooksComponentConfiguration"
+ },
{
"name": "camel.dataformat.smooks.customizer.enabled",
"type": "java.lang.Boolean",
diff --git
a/components-starter/camel-smooks-starter/src/main/java/org/apache/camel/component/smooks/springboot/SmooksComponentAutoConfiguration.java
b/components-starter/camel-smooks-starter/src/main/java/org/apache/camel/component/smooks/springboot/SmooksComponentAutoConfiguration.java
index 45e1253bac3..dc5976ae22c 100644
---
a/components-starter/camel-smooks-starter/src/main/java/org/apache/camel/component/smooks/springboot/SmooksComponentAutoConfiguration.java
+++
b/components-starter/camel-smooks-starter/src/main/java/org/apache/camel/component/smooks/springboot/SmooksComponentAutoConfiguration.java
@@ -42,7 +42,7 @@ import org.springframework.context.annotation.Lazy;
@Conditional(ConditionalOnCamelContextAndAutoConfigurationBeans.class)
@EnableConfigurationProperties({ComponentConfigurationProperties.class,SmooksComponentConfiguration.class})
@ConditionalOnHierarchicalProperties({"camel.component",
"camel.component.smooks"})
-@AutoConfigureAfter(CamelAutoConfiguration.class)
+@AutoConfigureAfter({CamelAutoConfiguration.class,
SmooksComponentConverter.class})
public class SmooksComponentAutoConfiguration {
@Autowired
diff --git
a/components-starter/camel-smooks-starter/src/main/java/org/apache/camel/component/smooks/springboot/SmooksComponentConfiguration.java
b/components-starter/camel-smooks-starter/src/main/java/org/apache/camel/component/smooks/springboot/SmooksComponentConfiguration.java
index 2e80eb8dacf..70ace14a52f 100644
---
a/components-starter/camel-smooks-starter/src/main/java/org/apache/camel/component/smooks/springboot/SmooksComponentConfiguration.java
+++
b/components-starter/camel-smooks-starter/src/main/java/org/apache/camel/component/smooks/springboot/SmooksComponentConfiguration.java
@@ -17,6 +17,7 @@
package org.apache.camel.component.smooks.springboot;
import org.apache.camel.spring.boot.ComponentConfigurationPropertiesCommon;
+import org.smooks.SmooksFactory;
import org.springframework.boot.context.properties.ConfigurationProperties;
/**
@@ -55,6 +56,11 @@ public class SmooksComponentConfiguration
* etc.
*/
private Boolean autowiredEnabled = true;
+ /**
+ * To use a custom factory for creating Smooks. The option is a
+ * org.smooks.SmooksFactory type.
+ */
+ private SmooksFactory smooksFactory;
public Boolean getLazyStartProducer() {
return lazyStartProducer;
@@ -71,4 +77,12 @@ public class SmooksComponentConfiguration
public void setAutowiredEnabled(Boolean autowiredEnabled) {
this.autowiredEnabled = autowiredEnabled;
}
+
+ public SmooksFactory getSmooksFactory() {
+ return smooksFactory;
+ }
+
+ public void setSmooksFactory(SmooksFactory smooksFactory) {
+ this.smooksFactory = smooksFactory;
+ }
}
\ No newline at end of file
diff --git
a/components-starter/camel-smooks-starter/src/main/java/org/apache/camel/component/smooks/springboot/SmooksComponentConverter.java
b/components-starter/camel-smooks-starter/src/main/java/org/apache/camel/component/smooks/springboot/SmooksComponentConverter.java
new file mode 100644
index 00000000000..f7076332bd7
--- /dev/null
+++
b/components-starter/camel-smooks-starter/src/main/java/org/apache/camel/component/smooks/springboot/SmooksComponentConverter.java
@@ -0,0 +1,63 @@
+/*
+ * 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.smooks.springboot;
+
+import java.util.LinkedHashSet;
+import java.util.Set;
+import org.springframework.beans.factory.annotation.Autowired;
+import
org.springframework.boot.context.properties.ConfigurationPropertiesBinding;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.core.convert.TypeDescriptor;
+import org.springframework.core.convert.converter.GenericConverter;
+import org.springframework.stereotype.Component;
+
+/**
+ * Generated by camel-package-maven-plugin - do not edit this file!
+ */
+@Configuration(proxyBeanMethods = false)
+@ConfigurationPropertiesBinding
+@Component
+public class SmooksComponentConverter implements GenericConverter {
+
+ @Autowired
+ private ApplicationContext applicationContext;
+
+ public Set<ConvertiblePair> getConvertibleTypes() {
+ Set<ConvertiblePair> answer = new LinkedHashSet<>();
+ answer.add(new ConvertiblePair(String.class,
org.smooks.SmooksFactory.class));
+ return answer;
+ }
+
+ public Object convert(
+ Object source,
+ TypeDescriptor sourceType,
+ TypeDescriptor targetType) {
+ if (source == null) {
+ return null;
+ }
+ String ref = source.toString();
+ if (!ref.startsWith("#")) {
+ return null;
+ }
+ ref = ref.startsWith("#bean:") ? ref.substring(6) : ref.substring(1);
+ switch (targetType.getName()) {
+ case "org.smooks.SmooksFactory": return
applicationContext.getBean(ref, org.smooks.SmooksFactory.class);
+ }
+ return null;
+ }
+}
\ No newline at end of file
diff --git
a/components-starter/camel-smooks-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
b/components-starter/camel-smooks-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
index 20409bfae6b..5519d9d8dd7 100644
---
a/components-starter/camel-smooks-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
+++
b/components-starter/camel-smooks-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
@@ -17,3 +17,4 @@
org.apache.camel.component.smooks.springboot.SmooksComponentAutoConfiguration
org.apache.camel.dataformat.smooks.springboot.SmooksDataFormatAutoConfiguration
+org.apache.camel.component.smooks.springboot.SmooksComponentConverter