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 2019/12/11 07:44:26 UTC
[camel] 02/03: CAMEL-14288: Endpoint configurer should deal better
with list types
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch camel-3.0.x
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 25a24db2136757d2ea29aac8346de15e36504913
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Wed Dec 11 06:21:53 2019 +0100
CAMEL-14288: Endpoint configurer should deal better with list types
---
.../org/apache/camel/support/EndpointHelper.java | 3 ++-
.../component/PropertyConfigurerSupport.java | 28 ++++++++++++++++------
2 files changed, 23 insertions(+), 8 deletions(-)
diff --git a/core/camel-support/src/main/java/org/apache/camel/support/EndpointHelper.java b/core/camel-support/src/main/java/org/apache/camel/support/EndpointHelper.java
index fd0a829..675cd85 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/EndpointHelper.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/EndpointHelper.java
@@ -245,7 +245,8 @@ public final class EndpointHelper {
* <code>mandatory</code> is <code>true</code>.
*/
public static <T> T resolveReferenceParameter(CamelContext context, String value, Class<T> type, boolean mandatory) {
- String valueNoHash = StringHelper.replaceAll(value, "#", "");
+ String valueNoHash = StringHelper.replaceAll(value, "#bean:", "");
+ valueNoHash = StringHelper.replaceAll(valueNoHash, "#", "");
if (mandatory) {
return CamelContextHelper.mandatoryLookupAndConvert(context, valueNoHash, type);
} else {
diff --git a/core/camel-support/src/main/java/org/apache/camel/support/component/PropertyConfigurerSupport.java b/core/camel-support/src/main/java/org/apache/camel/support/component/PropertyConfigurerSupport.java
index 4cdc655..349ea15 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/component/PropertyConfigurerSupport.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/component/PropertyConfigurerSupport.java
@@ -16,8 +16,12 @@
*/
package org.apache.camel.support.component;
+import java.util.Arrays;
+import java.util.List;
+
import org.apache.camel.CamelContext;
import org.apache.camel.NoSuchBeanException;
+import org.apache.camel.support.EndpointHelper;
/**
* Base class used by the camel-apt compiler plugin when it generates source code for fast
@@ -37,17 +41,27 @@ public abstract class PropertyConfigurerSupport {
// if the type is not string based and the value is a bean reference, then we need to lookup
// the bean from the registry
if (value instanceof String && String.class != type) {
- // is it a reference parameter
+ Object obj = null;
+
String text = value.toString();
- if (text.startsWith("#")) {
- String ref = text.startsWith("#bean:") ? text.substring(6) : text.substring(1);
- Object obj = camelContext.getRegistry().lookupByName(ref);
- if (obj != null) {
- value = obj;
+ if (EndpointHelper.isReferenceParameter(text)) {
+ // special for a list where we refer to beans which can be either a list or a single element
+ // so use Object.class as type
+ if (type == List.class) {
+ obj = EndpointHelper.resolveReferenceListParameter(camelContext, text, Object.class);
} else {
+ obj = EndpointHelper.resolveReferenceParameter(camelContext, text, type);
+ }
+ if (obj == null) {
// no bean found so throw an exception
- throw new NoSuchBeanException(ref, type.getName());
+ throw new NoSuchBeanException(text, type.getName());
}
+ } else if (type == List.class) {
+ // its a list but we have a string, where we support splitting via comma
+ obj = Arrays.asList(text.split(","));
+ }
+ if (obj != null) {
+ value = obj;
}
}