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 47b9d4658d27ee9207e33a207824aba351f50e5e
Author: Claus Ibsen <claus.ib...@gmail.com>
AuthorDate: Wed Jun 26 22:44:21 2019 +0200

    CAMEL-13688: Camel main - Setting boolean option should have strict 
conversition
---
 .../camel/component/file/FileKeepLastModifiedTest.java  |  4 ++--
 .../main/java/org/apache/camel/main/MainSupport.java    | 17 +++++++++++++----
 .../org/apache/camel/support/IntrospectionSupport.java  |  8 ++++++++
 3 files changed, 23 insertions(+), 6 deletions(-)

diff --git 
a/core/camel-core/src/test/java/org/apache/camel/component/file/FileKeepLastModifiedTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/component/file/FileKeepLastModifiedTest.java
index a5ffd83..df51d01 100644
--- 
a/core/camel-core/src/test/java/org/apache/camel/component/file/FileKeepLastModifiedTest.java
+++ 
b/core/camel-core/src/test/java/org/apache/camel/component/file/FileKeepLastModifiedTest.java
@@ -38,7 +38,7 @@ public class FileKeepLastModifiedTest extends 
ContextTestSupport {
         context.addRoutes(new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-                
from("file://target/data/keep?noop=true?initialDelay=0&delay=10")
+                
from("file://target/data/keep?noop=true&initialDelay=0&delay=10")
                     .delay(10)
                     .to("file://target/data/keep/out?keepLastModified=true", 
"mock:result");
             }
@@ -64,7 +64,7 @@ public class FileKeepLastModifiedTest extends 
ContextTestSupport {
         context.addRoutes(new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-                
from("file://target/data/keep?noop=true?initialDelay=0&delay=10")
+                
from("file://target/data/keep?noop=true&initialDelay=0&delay=10")
                     .delay(10)
                     .to("file://target/data/keep/out?keepLastModified=false", 
"mock:result");
             }
diff --git 
a/core/camel-main/src/main/java/org/apache/camel/main/MainSupport.java 
b/core/camel-main/src/main/java/org/apache/camel/main/MainSupport.java
index b0879e5..1bc0c97 100644
--- a/core/camel-main/src/main/java/org/apache/camel/main/MainSupport.java
+++ b/core/camel-main/src/main/java/org/apache/camel/main/MainSupport.java
@@ -1195,12 +1195,21 @@ public abstract class MainSupport extends 
ServiceSupport {
             LOG.debug("Setting property {} on {} with value {}", name, target, 
stringValue);
             if (failIfNotSet) {
                 PropertyBindingSupport.bindMandatoryProperty(context, target, 
name, stringValue, ignoreCase);
+                it.remove();
                 rc = true;
             } else {
-                boolean hit = PropertyBindingSupport.bindProperty(context, 
target, name, stringValue, ignoreCase);
-                if (hit) {
-                    it.remove();
-                    rc = true;
+                try {
+                    boolean hit = PropertyBindingSupport.bindProperty(context, 
target, name, stringValue, ignoreCase);
+                    if (hit) {
+                        it.remove();
+                        rc = true;
+                    }
+                } catch (Exception e) {
+                    if (failIfNotSet) {
+                        throw e;
+                    } else {
+                        LOG.debug(e.getMessage() + ". This exception is 
ignored.", e);
+                    }
                 }
             }
         }
diff --git 
a/core/camel-support/src/main/java/org/apache/camel/support/IntrospectionSupport.java
 
b/core/camel-support/src/main/java/org/apache/camel/support/IntrospectionSupport.java
index 21c5d9a..9883396 100644
--- 
a/core/camel-support/src/main/java/org/apache/camel/support/IntrospectionSupport.java
+++ 
b/core/camel-support/src/main/java/org/apache/camel/support/IntrospectionSupport.java
@@ -711,6 +711,14 @@ public final class IntrospectionSupport {
                         return true;
                     } else {
                         // We need to convert it
+                        // special for boolean values with string values as we 
only want to accept "true" or "false"
+                        if (parameterType == Boolean.class || parameterType == 
boolean.class && ref instanceof String) {
+                            String val = (String) ref;
+                            if (!val.equalsIgnoreCase("true") && 
!val.equalsIgnoreCase("false")) {
+                                throw new IllegalArgumentException("Cannot 
convert the String value: " + ref + " to type: " + parameterType
+                                        + " as the value is not true or 
false");
+                            }
+                        }
                         Object convertedValue = typeConverter != null ? 
typeConverter.mandatoryConvertTo(parameterType, ref) : ref;
                         // we may want to set options on classes that has 
package view visibility, so override the accessible
                         setter.setAccessible(true);

Reply via email to