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 061a12e9031e3e212771323ae246ca0cec11e144
Author: Claus Ibsen <[email protected]>
AuthorDate: Wed May 27 10:05:07 2020 +0200

    CAMEL-14878: Endpoint configurer should support again support the 2.x 
syntax for timeout values with eg 5s for 5000 as millis.
---
 .../component/timer/TimerDelaySecondsTest.java     |  2 --
 .../component/PropertyConfigurerSupport.java       | 25 ++++++++++++++++++----
 2 files changed, 21 insertions(+), 6 deletions(-)

diff --git 
a/core/camel-core/src/test/java/org/apache/camel/component/timer/TimerDelaySecondsTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/component/timer/TimerDelaySecondsTest.java
index f157db8..dd777c8 100644
--- 
a/core/camel-core/src/test/java/org/apache/camel/component/timer/TimerDelaySecondsTest.java
+++ 
b/core/camel-core/src/test/java/org/apache/camel/component/timer/TimerDelaySecondsTest.java
@@ -22,8 +22,6 @@ import org.apache.camel.component.mock.MockEndpoint;
 import org.junit.Ignore;
 import org.junit.Test;
 
-// TODO: https://issues.apache.org/jira/browse/CAMEL-14878
-@Ignore
 public class TimerDelaySecondsTest extends ContextTestSupport {
 
     @Test
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 a2b3ef0..bc10076 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
@@ -21,6 +21,7 @@ import java.util.List;
 import org.apache.camel.CamelContext;
 import org.apache.camel.NoSuchBeanException;
 import org.apache.camel.support.EndpointHelper;
+import org.apache.camel.util.TimeUtils;
 
 /**
  * Base class used by Camel Package Maven Plugin when it generates source code 
for fast
@@ -40,10 +41,10 @@ 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) {
-            Object obj = null;
-
             String text = value.toString();
+
             if (EndpointHelper.isReferenceParameter(text)) {
+                Object obj;
                 // 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) {
@@ -55,9 +56,25 @@ public abstract class PropertyConfigurerSupport {
                     // no bean found so throw an exception
                     throw new NoSuchBeanException(text, type.getName());
                 }
-            }
-            if (obj != null) {
                 value = obj;
+            } else if (type == long.class || type == Long.class || type == 
int.class || type == Integer.class) {
+                Object obj = null;
+                // string to long/int then it may be a duration where we can 
convert the value to milli seconds
+                // it may be a time pattern, such as 5s for 5 seconds = 5000
+                try {
+                    long num = TimeUtils.toMilliSeconds(text);
+                    if (type == int.class || type == Integer.class) {
+                        // need to cast to int
+                        obj = (int) num;
+                    } else {
+                        obj = num;
+                    }
+                } catch (IllegalArgumentException e) {
+                    // ignore
+                }
+                if (obj != null) {
+                    value = obj;
+                }
             }
         }
 

Reply via email to