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 2023/05/26 13:15:58 UTC
[camel] branch main updated (838ab6be455 -> 02e56ce29e0)
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a change to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
from 838ab6be455 Sync deps
new f3da80a32d2 CAMEL-19393: camel-kafka - Should keep the configuration value types as-is as Kafka converts this automatic.
new dcdd2343115 CAMEL-19393: Allow to specify if a value should be converter to a specific type when using property binding. This is needed with camel-kafka and other vendor integrations such as MS Azure.
new 02e56ce29e0 CAMEL-19393: Allow to specify if a value should be converter to a specific type when using property binding. This is needed with camel-kafka and other vendor integrations such as MS Azure.
The 3 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:
.../camel/component/kafka/KafkaConfiguration.java | 12 +++++------
.../camel/support/PropertyBindingSupportTest.java | 24 ++++++++++++++++++++++
.../camel/support/PropertyBindingSupport.java | 16 +++++++++++++--
.../modules/ROOT/pages/property-binding.adoc | 6 ++++--
4 files changed, 47 insertions(+), 11 deletions(-)
[camel] 03/03: CAMEL-19393: Allow to specify if a value should be converter to a specific type when using property binding. This is needed with camel-kafka and other vendor integrations such as MS Azure.
Posted by da...@apache.org.
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.git
commit 02e56ce29e0cdc6c4cb328f33ab9d9f7f9e56d09
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Fri May 26 15:14:58 2023 +0200
CAMEL-19393: Allow to specify if a value should be converter to a specific type when using property binding. This is needed with camel-kafka and other vendor integrations such as MS Azure.
---
docs/user-manual/modules/ROOT/pages/property-binding.adoc | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/docs/user-manual/modules/ROOT/pages/property-binding.adoc b/docs/user-manual/modules/ROOT/pages/property-binding.adoc
index 586c9ca4b8e..267e87a3fae 100644
--- a/docs/user-manual/modules/ROOT/pages/property-binding.adoc
+++ b/docs/user-manual/modules/ROOT/pages/property-binding.adoc
@@ -28,6 +28,8 @@ The `PropertyBindingSupport` class supports binding String valued properties to
`#class:com.foo.MyClassType#myFactoryMethod('Hello World', 5, true)`.
Or if you need to create the instance via constructor parameters then you can specify the parameters as shown:
`#class:com.foo.MyClass('Hello World', 5, true)`.
+- _valueAs(type):value_ - To declare that the value should be converted to the given type, such as `#valueAs(int):123`
+ which indicates that the value 123 should be converted to an integer.
- _ignore case_ - Whether to ignore case for property keys (will ignore by default)
== Property binding basics
@@ -43,7 +45,7 @@ For example to set brokers on the Kafka component you can do:
camel.component.kafka.brokers = mykafka1,mykafka2
----
-This will essentially be equivavlent to configuring Kafka component in regular Java code via setters:
+This will essentially be equivalent to configuring Kafka component in regular Java code via setters:
[source,java]
----
@@ -190,7 +192,7 @@ PropertyBindingSupport.build().withCamelContext(context).withTarget(foo)
== More details
-Property binding is noteably used when running Camel in standalone mode with Camel Main, or using Camel Spring Boot, Camel K,
+Property binding is notably used when running Camel in standalone mode with Camel Main, or using Camel Spring Boot, Camel K,
Camel Kafka Connector, or Camel Quarkus. All these runtimes have a similar way of configuring via property bindings such
as from `application.properties` files.
[camel] 01/03: CAMEL-19393: camel-kafka - Should keep the configuration value types as-is as Kafka converts this automatic.
Posted by da...@apache.org.
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.git
commit f3da80a32d2f5e53696ebef01ee28ff7f5475e02
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Fri May 26 14:40:54 2023 +0200
CAMEL-19393: camel-kafka - Should keep the configuration value types as-is as Kafka converts this automatic.
---
.../org/apache/camel/component/kafka/KafkaConfiguration.java | 12 +++++-------
1 file changed, 5 insertions(+), 7 deletions(-)
diff --git a/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/KafkaConfiguration.java b/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/KafkaConfiguration.java
index 07a7fee868b..e81007ffad9 100755
--- a/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/KafkaConfiguration.java
+++ b/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/KafkaConfiguration.java
@@ -549,7 +549,6 @@ public class KafkaConfiguration implements Cloneable, HeaderFilterStrategyAware
if (keyManagers != null) {
addPropertyIfNotNull(props, SslConfigs.SSL_KEYMANAGER_ALGORITHM_CONFIG, keyManagers.getAlgorithm());
addPropertyIfNotNull(props, SslConfigs.SSL_KEY_PASSWORD_CONFIG, keyManagers.getKeyPassword());
-
KeyStoreParameters keyStore = keyManagers.getKeyStore();
if (keyStore != null) {
addPropertyIfNotNull(props, SslConfigs.SSL_KEYSTORE_TYPE_CONFIG, keyStore.getType());
@@ -561,7 +560,6 @@ public class KafkaConfiguration implements Cloneable, HeaderFilterStrategyAware
TrustManagersParameters trustManagers = sslContextParameters.getTrustManagers();
if (trustManagers != null) {
addPropertyIfNotNull(props, SslConfigs.SSL_TRUSTMANAGER_ALGORITHM_CONFIG, trustManagers.getAlgorithm());
-
KeyStoreParameters keyStore = trustManagers.getKeyStore();
if (keyStore != null) {
addPropertyIfNotNull(props, SslConfigs.SSL_TRUSTSTORE_TYPE_CONFIG, keyStore.getType());
@@ -584,22 +582,22 @@ public class KafkaConfiguration implements Cloneable, HeaderFilterStrategyAware
private static void addPropertyIfNotFalse(Properties props, String key, boolean value) {
if (value) {
- // Kafka expects all properties as String
+ // value should be as-is
props.put(key, value);
}
}
private static <T> void addPropertyIfNotEmpty(Properties props, String key, T value) {
if (ObjectHelper.isNotEmpty(value)) {
- // Kafka expects all properties as String
- props.put(key, value.toString());
+ // value should be as-is
+ props.put(key, value);
}
}
private static <T> void addPropertyIfNotNull(Properties props, String key, T value) {
if (value != null) {
- // Kafka expects all properties as String
- props.put(key, value.toString());
+ // value should be as-is
+ props.put(key, value);
}
}
[camel] 02/03: CAMEL-19393: Allow to specify if a value should be converter to a specific type when using property binding. This is needed with camel-kafka and other vendor integrations such as MS Azure.
Posted by da...@apache.org.
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.git
commit dcdd2343115c07a9916272ab54cf07877e4e38f5
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Fri May 26 15:12:46 2023 +0200
CAMEL-19393: Allow to specify if a value should be converter to a specific type when using property binding. This is needed with camel-kafka and other vendor integrations such as MS Azure.
---
.../camel/support/PropertyBindingSupportTest.java | 24 ++++++++++++++++++++++
.../camel/support/PropertyBindingSupport.java | 16 +++++++++++++--
2 files changed, 38 insertions(+), 2 deletions(-)
diff --git a/core/camel-core/src/test/java/org/apache/camel/support/PropertyBindingSupportTest.java b/core/camel-core/src/test/java/org/apache/camel/support/PropertyBindingSupportTest.java
index 250c1ec6095..1c7293db519 100644
--- a/core/camel-core/src/test/java/org/apache/camel/support/PropertyBindingSupportTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/support/PropertyBindingSupportTest.java
@@ -581,6 +581,30 @@ public class PropertyBindingSupportTest extends ContextTestSupport {
}
}
+ @Test
+ public void testConvert() throws Exception {
+ Foo foo = new Foo();
+
+ Map<String, Object> prop = new HashMap<>();
+ prop.put("name", "James");
+ prop.put("bar.age", "#valueAs(Integer):33");
+ prop.put("bar.rider", "#valueAs(boolean):true");
+ prop.put("bar.gold-customer", "#valueAs(boolean):true");
+ prop.put("bar.work.id", "#valueAs(int):123");
+ prop.put("bar.work.name", "{{companyName}}");
+
+ PropertyBindingSupport.bindProperties(context, foo, prop);
+
+ assertEquals("James", foo.getName());
+ assertEquals(33, foo.getBar().getAge());
+ assertTrue(foo.getBar().isRider());
+ assertTrue(foo.getBar().isGoldCustomer());
+ assertEquals(123, foo.getBar().getWork().getId());
+ assertEquals("Acme", foo.getBar().getWork().getName());
+
+ assertTrue(prop.isEmpty(), "Should bind all properties");
+ }
+
public static class Foo {
private String name;
private Bar bar = new Bar();
diff --git a/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java b/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java
index 6409e48aeb4..92145fad72a 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java
@@ -72,6 +72,8 @@ import static org.apache.camel.util.StringHelper.startsWithIgnoreCase;
* #class:com.foo.MyClassType#myFactoryMethod('Hello World', 5, true). Or if you need to create the instance via
* constructor parameters then you can specify the parameters as shown: #class:com.foo.MyClass('Hello World', 5,
* true)</li>.
+ * <li>valueAs(type):value</li> - To declare that the value should be converted to the given type, such as
+ * #valueAs(int):123 which indicates that the value 123 should be converted to an integer.
* <li>ignore case - Whether to ignore case for property keys</li>
* </ul>
*
@@ -1247,12 +1249,13 @@ public final class PropertyBindingSupport {
}
// non reference parameters are
- // #bean: #class: #type: #property: #autowired
+ // #bean: #class: #type: #property: #convert: #autowired
if (parameter.equals("#autowired")
|| parameter.startsWith("#bean:")
|| parameter.startsWith("#class:")
|| parameter.startsWith("#type:")
- || parameter.startsWith("#property:")) {
+ || parameter.startsWith("#property:")
+ || parameter.startsWith("#valueAs(:")) {
return false;
}
@@ -1600,6 +1603,15 @@ public final class PropertyBindingSupport {
} else if (strval.startsWith("#bean:")) {
String key = strval.substring(6);
answer = camelContext.getRegistry().lookupByName(key);
+ } else if (strval.startsWith("#valueAs(")) {
+ String text = strval.substring(8);
+ String typeName = StringHelper.between(text, "(", ")");
+ String constant = StringHelper.after(text, ":");
+ if (typeName == null || constant == null) {
+ throw new IllegalArgumentException("Illegal syntax: " + text + " when using function #valueAs(type):value");
+ }
+ Class<?> type = camelContext.getClassResolver().resolveMandatoryClass(typeName);
+ answer = camelContext.getTypeConverter().mandatoryConvertTo(type, constant);
}
return answer;