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
The following commit(s) were added to refs/heads/master by this push:
new acb2da1 CAMEL-15381: Avoid use of reflection in CronComponent
acb2da1 is described below
commit acb2da1afc8cb1fa44b4ed48951c118228a278d6
Author: Claus Ibsen <[email protected]>
AuthorDate: Fri Aug 7 08:39:08 2020 +0200
CAMEL-15381: Avoid use of reflection in CronComponent
---
.../org/apache/camel/component/cron/CronComponent.java | 16 ++++++++--------
.../org/apache/camel/component/cron/CronEndpoint.java | 14 ++++++++++++--
.../apache/camel/component/cron/CronPatternsTest.java | 12 ++++++++++++
3 files changed, 32 insertions(+), 10 deletions(-)
diff --git
a/components/camel-cron/src/main/java/org/apache/camel/component/cron/CronComponent.java
b/components/camel-cron/src/main/java/org/apache/camel/component/cron/CronComponent.java
index c48356c..80933001 100644
---
a/components/camel-cron/src/main/java/org/apache/camel/component/cron/CronComponent.java
+++
b/components/camel-cron/src/main/java/org/apache/camel/component/cron/CronComponent.java
@@ -45,18 +45,18 @@ public class CronComponent extends DefaultComponent {
public Endpoint createEndpoint(String uri, String remaining, Map<String,
Object> properties) throws Exception {
CamelCronConfiguration configuration = new CamelCronConfiguration();
configuration.setName(remaining);
- setProperties(configuration, properties);
+
+ CronEndpoint answer = new CronEndpoint(uri, this, configuration);
+ setProperties(answer, properties);
+
+ // validate configuration
validate(configuration);
+ // create delegate and set on endpoint
Endpoint delegate = this.service.createEndpoint(configuration);
- CronEndpoint cronEndpoint = new CronEndpoint(uri, this, delegate,
configuration);
-
- if (properties.size() > 0) {
- // Additional endpoint properties present
- setProperties(cronEndpoint, properties);
- }
+ answer.setDelegate(delegate);
- return cronEndpoint;
+ return answer;
}
@Override
diff --git
a/components/camel-cron/src/main/java/org/apache/camel/component/cron/CronEndpoint.java
b/components/camel-cron/src/main/java/org/apache/camel/component/cron/CronEndpoint.java
index 9777175..a809a86 100644
---
a/components/camel-cron/src/main/java/org/apache/camel/component/cron/CronEndpoint.java
+++
b/components/camel-cron/src/main/java/org/apache/camel/component/cron/CronEndpoint.java
@@ -29,6 +29,7 @@ import org.apache.camel.spi.ExceptionHandler;
import org.apache.camel.spi.UriEndpoint;
import org.apache.camel.spi.UriParam;
import org.apache.camel.support.DefaultEndpoint;
+import org.apache.camel.util.ObjectHelper;
/**
* A generic interface for triggering events at times specified through the
Unix cron syntax.
@@ -41,12 +42,15 @@ public class CronEndpoint extends DefaultEndpoint
implements DelegateEndpoint {
@UriParam
private CamelCronConfiguration configuration;
- public CronEndpoint(String endpointUri, Component component, Endpoint
delegate, CamelCronConfiguration configuration) {
+ public CronEndpoint(String endpointUri, CronComponent component,
CamelCronConfiguration configuration) {
super(endpointUri, component);
- this.delegate = delegate;
this.configuration = configuration;
}
+ public void setDelegate(Endpoint delegate) {
+ this.delegate = delegate;
+ }
+
@Override
public Endpoint getEndpoint() {
return delegate;
@@ -108,4 +112,10 @@ public class CronEndpoint extends DefaultEndpoint
implements DelegateEndpoint {
}
}
+ @Override
+ protected void doStart() throws Exception {
+ super.doStart();
+
+ ObjectHelper.notNull(delegate, "delegate endpoint");
+ }
}
diff --git
a/components/camel-cron/src/test/java/org/apache/camel/component/cron/CronPatternsTest.java
b/components/camel-cron/src/test/java/org/apache/camel/component/cron/CronPatternsTest.java
index cbfa53c..451258f 100644
---
a/components/camel-cron/src/test/java/org/apache/camel/component/cron/CronPatternsTest.java
+++
b/components/camel-cron/src/test/java/org/apache/camel/component/cron/CronPatternsTest.java
@@ -16,9 +16,12 @@
*/
package org.apache.camel.component.cron;
+import org.apache.camel.ExtendedCamelContext;
import org.apache.camel.FailedToCreateRouteException;
import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.spi.BeanIntrospection;
import org.apache.camel.test.junit5.CamelTestSupport;
+import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -55,6 +58,9 @@ public class CronPatternsTest extends CamelTestSupport {
@Test
void testPlusInURI() throws Exception {
+ BeanIntrospection bi =
context.adapt(ExtendedCamelContext.class).getBeanIntrospection();
+ bi.setExtendedStatistics(true);
+
context.addRoutes(new RouteBuilder() {
@Override
public void configure() {
@@ -63,6 +69,12 @@ public class CronPatternsTest extends CamelTestSupport {
}
});
context.start();
+
+ Thread.sleep(5);
+
+ context.stop();
+
+ Assertions.assertEquals(0, bi.getInvokedCounter());
}
@Test