Repository: camel
Updated Branches:
  refs/heads/master 18573971a -> 745aa5ce4


CAMEL-7540 Quartz Endpoint with a SimpleTrigger supports referencing a bean in 
URI


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/a3876eb8
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/a3876eb8
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/a3876eb8

Branch: refs/heads/master
Commit: a3876eb8fcfc1d794ea6994429a62d9842ac1a28
Parents: 1857397
Author: Willem Jiang <[email protected]>
Authored: Fri Jun 27 16:39:50 2014 +0800
Committer: Willem Jiang <[email protected]>
Committed: Fri Jun 27 16:39:50 2014 +0800

----------------------------------------------------------------------
 .../org/apache/camel/util/EndpointHelper.java   | 10 +++++
 .../camel/component/quartz/QuartzComponent.java | 10 +++--
 .../QuartzStartDelayedWithReferenceTest.java    | 46 ++++++++++++++++++++
 3 files changed, 63 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/a3876eb8/camel-core/src/main/java/org/apache/camel/util/EndpointHelper.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/EndpointHelper.java 
b/camel-core/src/main/java/org/apache/camel/util/EndpointHelper.java
index 1151cdf..4d7d1af 100644
--- a/camel-core/src/main/java/org/apache/camel/util/EndpointHelper.java
+++ b/camel-core/src/main/java/org/apache/camel/util/EndpointHelper.java
@@ -360,6 +360,16 @@ public final class EndpointHelper {
             return result;
         }
     }
+    
+    public static <T> T resloveStringParameter(CamelContext context, String 
value, Class<T> type) {
+        T result = null;
+        if (EndpointHelper.isReferenceParameter(value)) {
+            result = EndpointHelper.resolveReferenceParameter(context, value, 
type);
+        } else {
+            result = context.getTypeConverter().convertTo(type, value);
+        }
+        return result;
+    }
 
     /**
      * Gets the route id for the given endpoint in which there is a consumer 
listening.

http://git-wip-us.apache.org/repos/asf/camel/blob/a3876eb8/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/QuartzComponent.java
----------------------------------------------------------------------
diff --git 
a/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/QuartzComponent.java
 
b/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/QuartzComponent.java
index a9e83fb..a0eb2b3 100644
--- 
a/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/QuartzComponent.java
+++ 
b/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/QuartzComponent.java
@@ -30,6 +30,7 @@ import java.util.concurrent.atomic.AtomicInteger;
 import org.apache.camel.CamelContext;
 import org.apache.camel.StartupListener;
 import org.apache.camel.impl.DefaultComponent;
+import org.apache.camel.util.EndpointHelper;
 import org.apache.camel.util.IOHelper;
 import org.apache.camel.util.IntrospectionSupport;
 import org.apache.camel.util.ObjectHelper;
@@ -153,7 +154,8 @@ public class QuartzComponent extends DefaultComponent 
implements StartupListener
             if (fireNow) {
                 String intervalString = (String) 
triggerParameters.get("repeatInterval");
                 if (intervalString != null) {
-                    long interval = Long.valueOf(intervalString);
+                    long interval = 
EndpointHelper.resloveStringParameter(getCamelContext(), intervalString, 
Long.class);
+                    
                     trigger.setStartTime(new Date(System.currentTimeMillis() - 
interval));
                 }
             }
@@ -168,12 +170,14 @@ public class QuartzComponent extends DefaultComponent 
implements StartupListener
             
answer.getJobDetail().getJobDataMap().put(QuartzConstants.QUARTZ_TRIGGER_CRON_EXPRESSION,
 cron);
         } else {
             
answer.getJobDetail().getJobDataMap().put(QuartzConstants.QUARTZ_TRIGGER_TYPE, 
"simple");
-            Long interval = 
getCamelContext().getTypeConverter().convertTo(Long.class, 
triggerParameters.get("repeatInterval"));
+            Long interval = 
EndpointHelper.resloveStringParameter(getCamelContext(), 
(String)triggerParameters.get("repeatInterval"), Long.class);
             if (interval != null) {
+                triggerParameters.put("repeatInterval", interval);
                 
answer.getJobDetail().getJobDataMap().put(QuartzConstants.QUARTZ_TRIGGER_SIMPLE_REPEAT_INTERVAL,
 interval);
             }
-            Integer counter = 
getCamelContext().getTypeConverter().convertTo(Integer.class, 
triggerParameters.get("repeatCount"));
+            Integer counter = 
EndpointHelper.resloveStringParameter(getCamelContext(), 
(String)triggerParameters.get("repeatCount"), Integer.class);
             if (counter != null) {
+                triggerParameters.put("repeatCount", counter);
                 
answer.getJobDetail().getJobDataMap().put(QuartzConstants.QUARTZ_TRIGGER_SIMPLE_REPEAT_COUNTER,
 counter);
             }
         }

http://git-wip-us.apache.org/repos/asf/camel/blob/a3876eb8/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzStartDelayedWithReferenceTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzStartDelayedWithReferenceTest.java
 
b/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzStartDelayedWithReferenceTest.java
new file mode 100644
index 0000000..46da54d
--- /dev/null
+++ 
b/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzStartDelayedWithReferenceTest.java
@@ -0,0 +1,46 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.quartz;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.impl.JndiRegistry;
+
+public class QuartzStartDelayedWithReferenceTest extends 
QuartzStartDelayedTest {
+    
+    // just bind the reference value here
+    protected JndiRegistry createRegistry() throws Exception {
+        JndiRegistry registry = super.createRegistry();
+        registry.bind("interval", new Long(2));
+        registry.bind("count", new Integer(1));
+        return registry;
+    }
+    
+    
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                QuartzComponent quartz = context.getComponent("quartz", 
QuartzComponent.class);
+                quartz.setStartDelayedSeconds(2);
+
+                
from("quartz://myGroup/myTimerName?trigger.repeatInterval=#interval&trigger.repeatCount=#count").routeId("myRoute").to("mock:result");
+            }
+        };
+    }
+
+}

Reply via email to