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/05/12 06:54:58 UTC
[camel] 02/02: CAMEL-13500: Camel Main can now configure component
options with nested values like you can do with Spring Boot etc.
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
commit faeeb51fab3a29b8fcdc2698feaa27afd1009481
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Sun May 12 08:54:30 2019 +0200
CAMEL-13500: Camel Main can now configure component options with nested values like you can do with Spring Boot etc.
---
.../java/org/apache/camel/main/MainSupport.java | 26 ++++++++++++++++++++--
1 file changed, 24 insertions(+), 2 deletions(-)
diff --git a/core/camel-core/src/main/java/org/apache/camel/main/MainSupport.java b/core/camel-core/src/main/java/org/apache/camel/main/MainSupport.java
index 9f5ced9..c7f8b0c 100644
--- a/core/camel-core/src/main/java/org/apache/camel/main/MainSupport.java
+++ b/core/camel-core/src/main/java/org/apache/camel/main/MainSupport.java
@@ -34,6 +34,8 @@ import java.util.concurrent.atomic.AtomicInteger;
import org.apache.camel.CamelContext;
import org.apache.camel.Component;
+import org.apache.camel.Exchange;
+import org.apache.camel.Expression;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.FileWatcherReloadStrategy;
@@ -45,6 +47,7 @@ import org.apache.camel.spi.EventNotifier;
import org.apache.camel.spi.Language;
import org.apache.camel.spi.PropertiesComponent;
import org.apache.camel.spi.ReloadStrategy;
+import org.apache.camel.support.DefaultExchange;
import org.apache.camel.support.EndpointHelper;
import org.apache.camel.support.IntrospectionSupport;
import org.apache.camel.support.LifecycleStrategySupport;
@@ -960,15 +963,34 @@ public abstract class MainSupport extends ServiceSupport {
Map.Entry<String, Object> entry = (Map.Entry) it.next();
String name = entry.getKey();
Object value = entry.getValue();
+
+ // if the name has dot's then its an OGNL expressions (so lets use simple language to walk down this ognl path)
+ boolean ognl = name.contains(".");
+ if (ognl) {
+ Language method = context.resolveLanguage("simple");
+ String path = name.substring(0, name.lastIndexOf('.'));
+ Expression exp = method.createExpression("${body." + path + "}");
+ Exchange dummy = new DefaultExchange(context);
+ dummy.getMessage().setBody(target);
+ Object newTarget = exp.evaluate(dummy, Object.class);
+ if (newTarget != null) {
+ target = newTarget;
+ name = name.substring(name.lastIndexOf('.') + 1);
+ }
+ }
+
+
String stringValue = value != null ? value.toString() : null;
boolean hit = false;
+
+ LOG.debug("Setting property {} on {} with value {}", name, target, stringValue);
if (EndpointHelper.isReferenceParameter(stringValue)) {
- hit = IntrospectionSupport.setProperty(context, context.getTypeConverter(), target, name, (Object) null, stringValue, true);
+ hit = IntrospectionSupport.setProperty(context, context.getTypeConverter(), target, name, null, stringValue, true);
} else if (value != null) {
try {
hit = IntrospectionSupport.setProperty(context, context.getTypeConverter(), target, name, value);
} catch (IllegalArgumentException var12) {
- hit = IntrospectionSupport.setProperty(context, context.getTypeConverter(), target, name, (Object) null, stringValue, true);
+ hit = IntrospectionSupport.setProperty(context, context.getTypeConverter(), target, name, null, stringValue, true);
}
}