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/03/05 06:24:57 UTC

[camel] branch bind created (now f4f3b69)

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a change to branch bind
in repository https://gitbox.apache.org/repos/asf/camel.git.


      at f4f3b69  CAMEL-13283: Add example

This branch includes the following new commits:

     new 8412ba2  CAMEL-13283: Add @BindRegistry annotation to allow to bind beans/classes to registry.
     new 544d6f4  Upgrade eclipse paho
     new d8bc6ff  CAMEL-13283: Add @BindRegistry annotation to allow to bind beans/classes to registry.
     new fb8315f  Upgrade mina2
     new fafcfbc  CAMEL-13283: Add @BindRegistry annotation to allow to bind beans/classes to registry.
     new e234666   CAMEL-13283: Add example
     new f4f3b69  CAMEL-13283: Add example

The 7 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[camel] 07/07: CAMEL-13283: Add example

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch bind
in repository https://gitbox.apache.org/repos/asf/camel.git

commit f4f3b69087c1692b5cb62a4407a52e37700fe3c4
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Tue Mar 5 07:23:14 2019 +0100

    CAMEL-13283: Add example
---
 .../camel/impl/CamelPostProcessorHelper.java       |  4 ++
 .../src/main/java/org/apache/camel/main/Main.java  |  4 ++
 .../java/org/apache/camel/main/MainSupport.java    | 41 +++++++++++++--
 .../java/org/apache/camel/main/MainIoCTest.java    | 17 ++++++-
 examples/camel-example-main/pom.xml                |  4 ++
 .../org/apache/camel/example/MyApplication.java    | 59 ++++------------------
 .../main/java/org/apache/camel/example/MyBean.java | 30 +++++++++++
 .../org/apache/camel/example/MyConfiguration.java  | 40 +++++++++++++++
 .../org/apache/camel/example/MyRouteBuilder.java   | 29 +++++++++++
 .../src/main/resources/application.properties      | 21 ++++++++
 10 files changed, 195 insertions(+), 54 deletions(-)

diff --git a/core/camel-core/src/main/java/org/apache/camel/impl/CamelPostProcessorHelper.java b/core/camel-core/src/main/java/org/apache/camel/impl/CamelPostProcessorHelper.java
index 2845ac8..7ca5f9d 100644
--- a/core/camel-core/src/main/java/org/apache/camel/impl/CamelPostProcessorHelper.java
+++ b/core/camel-core/src/main/java/org/apache/camel/impl/CamelPostProcessorHelper.java
@@ -294,6 +294,10 @@ public class CamelPostProcessorHelper implements CamelContextAware {
 
     public Object getInjectionBeanValue(Class<?> type, String name) {
         if (ObjectHelper.isEmpty(name)) {
+            // is it camel context itself?
+            if (type.isAssignableFrom(camelContext.getClass())) {
+                return camelContext;
+            }
             Set<?> found = getCamelContext().getRegistry().findByType(type);
             if (found == null || found.isEmpty()) {
                 throw new NoSuchBeanException(name, type.getName());
diff --git a/core/camel-core/src/main/java/org/apache/camel/main/Main.java b/core/camel-core/src/main/java/org/apache/camel/main/Main.java
index e2ea96c..2309fe2 100644
--- a/core/camel-core/src/main/java/org/apache/camel/main/Main.java
+++ b/core/camel-core/src/main/java/org/apache/camel/main/Main.java
@@ -35,6 +35,10 @@ public class Main extends MainSupport {
     public Main() {
     }
 
+    public Main(Class configurationClass) {
+        super(configurationClass);
+    }
+
     public static void main(String... args) throws Exception {
         Main main = new Main();
         instance = main;
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 832e610..4154844 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
@@ -16,6 +16,7 @@
  */
 package org.apache.camel.main;
 
+import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Iterator;
@@ -52,6 +53,9 @@ import org.apache.camel.util.concurrent.ThreadHelper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import static org.apache.camel.support.ObjectHelper.invokeMethod;
+import static org.apache.camel.util.ReflectionHelper.findMethod;
+
 /**
  * Base class for main implementations to allow starting up a JVM with Camel embedded.
  */
@@ -72,6 +76,7 @@ public abstract class MainSupport extends ServiceSupport {
 
     protected CamelContext camelContext;
     protected List<RouteBuilder> routeBuilders = new ArrayList<>();
+    protected Class configurationClass;
     protected String routeBuilderClasses;
     protected String fileWatchDirectory;
     protected boolean fileWatchDirectoryRecursively;
@@ -104,6 +109,11 @@ public abstract class MainSupport extends ServiceSupport {
         }
     }
 
+    protected MainSupport(Class configurationClass) {
+        this();
+        this.configurationClass = configurationClass;
+    }
+
     protected MainSupport() {
         addOption(new Option("h", "help", "Displays the help screen") {
             protected void doProcess(String arg, LinkedList<String> remainingArgs) {
@@ -416,6 +426,22 @@ public abstract class MainSupport extends ServiceSupport {
         return exitCode.get();
     }
 
+    public Class getConfigurationClass() {
+        return configurationClass;
+    }
+
+    /**
+     * Sets optional configuration class which allows to do any initial configuration.
+     * The class can/should have a method named <tt>configure</tt> which is called.
+     */
+    public void setConfigurationClass(Class configurationClass) {
+        this.configurationClass = configurationClass;
+    }
+
+    public String getRouteBuilderClasses() {
+        return routeBuilderClasses;
+    }
+
     public void setRouteBuilderClasses(String builders) {
         this.routeBuilderClasses = builders;
     }
@@ -446,10 +472,6 @@ public abstract class MainSupport extends ServiceSupport {
         this.fileWatchDirectoryRecursively = fileWatchDirectoryRecursively;
     }
 
-    public String getRouteBuilderClasses() {
-        return routeBuilderClasses;
-    }
-
     public ReloadStrategy getReloadStrategy() {
         return reloadStrategy;
     }
@@ -672,6 +694,17 @@ public abstract class MainSupport extends ServiceSupport {
             autoConfigurationFromProperties(camelContext);
         }
 
+        if (configurationClass != null) {
+            // create instance of configuration class as it may do dependency injection and bind to registry
+            Object config = camelContext.getInjector().newInstance(configurationClass);
+            // invoke configure method if exists
+            Method method = findMethod(configurationClass, "configure");
+            if (method != null) {
+                log.info("Calling configure method on configuration class: {}", configurationClass);
+                invokeMethod(method, config);
+            }
+        }
+
         // try to load the route builders from the routeBuilderClasses
         loadRouteBuilders(camelContext);
         for (RouteBuilder routeBuilder : routeBuilders) {
diff --git a/core/camel-core/src/test/java/org/apache/camel/main/MainIoCTest.java b/core/camel-core/src/test/java/org/apache/camel/main/MainIoCTest.java
index 3a7af5d..2d57f1b 100644
--- a/core/camel-core/src/test/java/org/apache/camel/main/MainIoCTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/main/MainIoCTest.java
@@ -16,6 +16,7 @@
  */
 package org.apache.camel.main;
 
+import org.apache.camel.BeanInject;
 import org.apache.camel.CamelContext;
 import org.apache.camel.PropertyInject;
 import org.apache.camel.builder.RouteBuilder;
@@ -29,7 +30,8 @@ public class MainIoCTest extends Assert {
 
     @Test
     public void testMainIoC() throws Exception {
-        Main main = new Main();
+        // use configuration class
+        Main main = new Main(MyConfiguration.class);
         // add as class so we get IoC
         main.addRouteBuilder(MyRouteBuilder.class);
         main.start();
@@ -52,9 +54,22 @@ public class MainIoCTest extends Assert {
         DirectComponent direct = camelContext.getComponent("direct", DirectComponent.class);
         assertEquals(1234, direct.getTimeout());
 
+        // should have called the configure class
+        assertEquals("123", camelContext.getGlobalOptions().get("foo"));
+
         main.stop();
     }
 
+    public static class MyConfiguration {
+
+        @BeanInject
+        private CamelContext camel;
+
+        public void configure() {
+            camel.getGlobalOptions().put("foo", "123");
+        }
+    }
+
     public static class MyRouteBuilder extends RouteBuilder {
 
         // properties is automatic loaded from classpath:application.properties
diff --git a/examples/camel-example-main/pom.xml b/examples/camel-example-main/pom.xml
index f2c9489..31bfa23 100644
--- a/examples/camel-example-main/pom.xml
+++ b/examples/camel-example-main/pom.xml
@@ -43,6 +43,10 @@
       <groupId>org.apache.camel</groupId>
       <artifactId>camel-core</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.apache.camel</groupId>
+      <artifactId>camel-quartz2</artifactId>
+    </dependency>
 
     <!-- logging -->
     <dependency>
diff --git a/examples/camel-example-main/src/main/java/org/apache/camel/example/MyApplication.java b/examples/camel-example-main/src/main/java/org/apache/camel/example/MyApplication.java
index e60df81..1a3617c 100644
--- a/examples/camel-example-main/src/main/java/org/apache/camel/example/MyApplication.java
+++ b/examples/camel-example-main/src/main/java/org/apache/camel/example/MyApplication.java
@@ -16,65 +16,26 @@
  */
 package org.apache.camel.example;
 
-import java.util.Date;
-import java.util.Objects;
-
-import org.apache.camel.Exchange;
-import org.apache.camel.Message;
-import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.main.Main;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
+/**
+ * Main class that boot the Camel application
+ */
 public final class MyApplication {
-    private static final Logger LOGGER = LoggerFactory.getLogger(MyApplication.class);
 
     private MyApplication() {
     }
 
     public static void main(String[] args) throws Exception {
+        // use Camels Main class
         Main main = new Main();
-        main.addRouteBuilder(new MyRouteBuilder());
+        // lets use a configuration class
+        // properties are automatic loaded from application.properties
+        main.setConfigurationClass(MyConfiguration.class);
+        // and add the routes
+        main.addRouteBuilder(MyRouteBuilder.class);
+        // now keep the application running until the JVM is terminated (ctrl + c or sigterm)
         main.run(args);
     }
 
-    private static class MyRouteBuilder extends RouteBuilder {
-        @Override
-        public void configure() throws Exception {
-            from("timer:simple?period=503")
-                .id("simple-route")
-                .transform()
-                    .exchange(this::dateToTime)
-                .process()
-                    .message(this::log)
-                .process()
-                    .body(this::log)
-                .choice()
-                    .when()
-                        .body(Integer.class, b -> (b & 1) == 0)
-                        .log("Received even number")
-                    .when()
-                        .body(Integer.class, (b, h) -> h.containsKey("skip") ? false : (b & 1) == 0)
-                        .log("Received odd number")
-                    .when()
-                        .body(Objects::isNull)
-                        .log("Received null body")
-                    .when()
-                        .body(Integer.class, b -> (b & 1) != 0)
-                        .log("Received odd number")
-                .endChoice();
-        }
-
-        private Long dateToTime(Exchange e) {
-            return e.getProperty(Exchange.TIMER_FIRED_TIME, Date.class).getTime();
-        }
-
-        private void log(Object b) {
-            LOGGER.info("body is: {}", b);
-        }
-
-        private void log(Message m) {
-            LOGGER.info("message is: {}", m);
-        }
-    }
 }
diff --git a/examples/camel-example-main/src/main/java/org/apache/camel/example/MyBean.java b/examples/camel-example-main/src/main/java/org/apache/camel/example/MyBean.java
new file mode 100644
index 0000000..5abc1c7
--- /dev/null
+++ b/examples/camel-example-main/src/main/java/org/apache/camel/example/MyBean.java
@@ -0,0 +1,30 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.example;
+
+public class MyBean {
+
+    private String hi;
+
+    public MyBean(String hi) {
+        this.hi = hi;
+    }
+
+    public String hello() {
+        return hi + " how are you?";
+    }
+}
diff --git a/examples/camel-example-main/src/main/java/org/apache/camel/example/MyConfiguration.java b/examples/camel-example-main/src/main/java/org/apache/camel/example/MyConfiguration.java
new file mode 100644
index 0000000..81289db
--- /dev/null
+++ b/examples/camel-example-main/src/main/java/org/apache/camel/example/MyConfiguration.java
@@ -0,0 +1,40 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.example;
+
+import org.apache.camel.BindToRegistry;
+import org.apache.camel.PropertyInject;
+
+/**
+ * Class to configure the Camel application.
+ */
+public class MyConfiguration {
+
+    @PropertyInject("hi")
+    private String hi;
+
+    @BindToRegistry
+    public MyBean myBean() {
+        // this will create an instance of this bean with the name of the method (eg myBean)
+        return new MyBean(hi);
+    }
+
+    public void configure() {
+        // this method is optional and can be removed if no additional configuration is needed.
+    }
+
+}
diff --git a/examples/camel-example-main/src/main/java/org/apache/camel/example/MyRouteBuilder.java b/examples/camel-example-main/src/main/java/org/apache/camel/example/MyRouteBuilder.java
new file mode 100644
index 0000000..1e38eab
--- /dev/null
+++ b/examples/camel-example-main/src/main/java/org/apache/camel/example/MyRouteBuilder.java
@@ -0,0 +1,29 @@
+/**
+ * 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.example;
+
+import org.apache.camel.builder.RouteBuilder;
+
+public class MyRouteBuilder extends RouteBuilder {
+
+    @Override
+    public void configure() throws Exception {
+        from("quartz2:foo?cron={{myCron}}")
+            .bean("myBean")
+            .log("${body}");
+    }
+}
diff --git a/examples/camel-example-main/src/main/resources/application.properties b/examples/camel-example-main/src/main/resources/application.properties
new file mode 100644
index 0000000..febdbea
--- /dev/null
+++ b/examples/camel-example-main/src/main/resources/application.properties
@@ -0,0 +1,21 @@
+## ---------------------------------------------------------------------------
+## 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.
+## ---------------------------------------------------------------------------
+// TODO: add some configuration here
+
+camel.component.quartz2.startDelayedSeconds = 3
+hi = Hello
+myCron = 0/2+*+*+*+*+?
\ No newline at end of file


[camel] 03/07: CAMEL-13283: Add @BindRegistry annotation to allow to bind beans/classes to registry.

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch bind
in repository https://gitbox.apache.org/repos/asf/camel.git

commit d8bc6ff097b85087e7b82afe83b96f92ac83d918
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Tue Mar 5 05:19:14 2019 +0100

    CAMEL-13283: Add @BindRegistry annotation to allow to bind beans/classes to registry.
---
 .../apache/camel/{BindRegistry.java => BindToRegistry.java}    |  2 +-
 .../src/main/java/org/apache/camel/builder/RouteBuilder.java   | 10 ++++++++++
 .../org/apache/camel/impl/DefaultCamelBeanPostProcessor.java   |  6 +++---
 .../apache/camel/impl/DefaultCamelBeanPostProcessorTest.java   |  6 +++---
 .../org/apache/camel/processor/CBRHeaderPredicateTest.java     | 10 ++--------
 5 files changed, 19 insertions(+), 15 deletions(-)

diff --git a/core/camel-api/src/main/java/org/apache/camel/BindRegistry.java b/core/camel-api/src/main/java/org/apache/camel/BindToRegistry.java
similarity index 97%
rename from core/camel-api/src/main/java/org/apache/camel/BindRegistry.java
rename to core/camel-api/src/main/java/org/apache/camel/BindToRegistry.java
index b2aebca..d5a446c 100644
--- a/core/camel-api/src/main/java/org/apache/camel/BindRegistry.java
+++ b/core/camel-api/src/main/java/org/apache/camel/BindToRegistry.java
@@ -31,7 +31,7 @@ import java.lang.annotation.Target;
 @Retention(RetentionPolicy.RUNTIME)
 @Documented
 @Target({ElementType.TYPE, ElementType.FIELD, ElementType.METHOD})
-public @interface BindRegistry {
+public @interface BindToRegistry {
     String name() default "";
     String context() default "";
 }
diff --git a/core/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java b/core/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java
index 6cac0ce..d3c8b34 100644
--- a/core/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java
+++ b/core/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java
@@ -81,6 +81,16 @@ public abstract class RouteBuilder extends BuilderSupport implements RoutesBuild
     public abstract void configure() throws Exception;
 
     /**
+     * Binds the bean to the repository (if possible).
+     *
+     * @param id   the id of the bean
+     * @param bean the bean
+     */
+    public void bindToRegistry(String id, Object bean) {
+        getContext().getRegistry().bind(id, bean);
+    }
+
+    /**
      * Configures the REST services
      *
      * @return the builder
diff --git a/core/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelBeanPostProcessor.java b/core/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelBeanPostProcessor.java
index e7dc03f..6dfc82d 100644
--- a/core/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelBeanPostProcessor.java
+++ b/core/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelBeanPostProcessor.java
@@ -20,7 +20,7 @@ import java.lang.reflect.Field;
 import java.lang.reflect.Method;
 
 import org.apache.camel.BeanInject;
-import org.apache.camel.BindRegistry;
+import org.apache.camel.BindToRegistry;
 import org.apache.camel.CamelContext;
 import org.apache.camel.CamelContextAware;
 import org.apache.camel.DeferredContextBinding;
@@ -88,7 +88,7 @@ public class DefaultCamelBeanPostProcessor {
         injectMethods(bean, beanName);
 
         // the bean may also need to be registered into the registry
-        BindRegistry bind = bean.getClass().getAnnotation(BindRegistry.class);
+        BindToRegistry bind = bean.getClass().getAnnotation(BindToRegistry.class);
         if (bind != null) {
             String name = bind.name();
             if (isEmpty(name)) {
@@ -203,7 +203,7 @@ public class DefaultCamelBeanPostProcessor {
                     injectField(field, produce.uri(), produce.ref(), produce.property(), bean, beanName, produce.binding());
                 }
 
-                BindRegistry bind = field.getAnnotation(BindRegistry.class);
+                BindToRegistry bind = field.getAnnotation(BindToRegistry.class);
                 if (bind != null && getPostProcessorHelper().matchContext(bind.context())) {
                     bindRegistry(field, bind.name(), bean, beanName);
                 }
diff --git a/core/camel-core/src/test/java/org/apache/camel/impl/DefaultCamelBeanPostProcessorTest.java b/core/camel-core/src/test/java/org/apache/camel/impl/DefaultCamelBeanPostProcessorTest.java
index f6b7ef8..8814848 100644
--- a/core/camel-core/src/test/java/org/apache/camel/impl/DefaultCamelBeanPostProcessorTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/impl/DefaultCamelBeanPostProcessorTest.java
@@ -16,7 +16,7 @@
  */
 package org.apache.camel.impl;
 
-import org.apache.camel.BindRegistry;
+import org.apache.camel.BindToRegistry;
 import org.apache.camel.Consume;
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.Produce;
@@ -57,14 +57,14 @@ public class DefaultCamelBeanPostProcessorTest extends ContextTestSupport {
         postProcessor = new DefaultCamelBeanPostProcessor(context);
     }
 
-    @BindRegistry
+    @BindToRegistry
     public class FooService {
 
         private String fooEndpoint;
         private String barEndpoint;
         @Produce
         private ProducerTemplate bar;
-        @BindRegistry(name = "myCoolBean")
+        @BindToRegistry(name = "myCoolBean")
         private MySerialBean myBean = new MySerialBean();
 
         public String getFooEndpoint() {
diff --git a/core/camel-core/src/test/java/org/apache/camel/processor/CBRHeaderPredicateTest.java b/core/camel-core/src/test/java/org/apache/camel/processor/CBRHeaderPredicateTest.java
index f97ec2c..a253cfe 100644
--- a/core/camel-core/src/test/java/org/apache/camel/processor/CBRHeaderPredicateTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/processor/CBRHeaderPredicateTest.java
@@ -21,18 +21,10 @@ import org.apache.camel.Exchange;
 import org.apache.camel.Message;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
-import org.apache.camel.impl.JndiRegistry;
 import org.junit.Test;
 
 public class CBRHeaderPredicateTest extends ContextTestSupport {
 
-    @Override
-    protected JndiRegistry createRegistry() throws Exception {
-        JndiRegistry jndi = super.createRegistry();
-        jndi.bind("cbrBean", new MyCBRBean());
-        return jndi;
-    }
-
     @Test
     public void testCBR() throws Exception {
         MockEndpoint foo = getMockEndpoint("mock:foo");
@@ -52,6 +44,8 @@ public class CBRHeaderPredicateTest extends ContextTestSupport {
         return new RouteBuilder() {
             @Override
             public void configure() throws Exception {
+                bindToRegistry("cbrBean", new MyCBRBean());
+
                 from("direct:start")
                     .choice()
                         .when().method("cbrBean", "checkHeader")


[camel] 04/07: Upgrade mina2

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch bind
in repository https://gitbox.apache.org/repos/asf/camel.git

commit fb8315fb0bea9799b199ef73b18ba9204804bfc8
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Tue Mar 5 05:25:01 2019 +0100

    Upgrade mina2
---
 parent/pom.xml | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/parent/pom.xml b/parent/pom.xml
index c191fdf..ada24f4 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -486,9 +486,7 @@
     <metrics-version>3.2.6</metrics-version>
     <micrometer-version>1.1.3</micrometer-version>
     <milo-version>0.2.4</milo-version>
-    <mina-bundle-version>1.1.7_6</mina-bundle-version>
-    <mina-version>1.1.7</mina-version>
-    <mina2-version>2.0.17</mina2-version>
+    <mina2-version>2.0.20</mina2-version>
     <minidns-version>0.3.3</minidns-version>
     <minimal-json-version>0.9.4</minimal-json-version>
     <mock-javamail-version>1.9</mock-javamail-version>


[camel] 01/07: CAMEL-13283: Add @BindRegistry annotation to allow to bind beans/classes to registry.

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch bind
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 8412ba2b4f64b2ae8f280f190b0cc146083c4f4a
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Mon Mar 4 10:01:11 2019 +0100

    CAMEL-13283: Add @BindRegistry annotation to allow to bind beans/classes to registry.
---
 .../main/java/org/apache/camel/BindRegistry.java   | 37 ++++++++++++++++++++++
 .../camel/impl/DefaultCamelBeanPostProcessor.java  | 28 ++++++++++++++++
 .../impl/DefaultCamelBeanPostProcessorTest.java    | 13 ++++++++
 .../org/apache/camel/util/ReflectionHelper.java    | 18 +++++++++++
 4 files changed, 96 insertions(+)

diff --git a/core/camel-api/src/main/java/org/apache/camel/BindRegistry.java b/core/camel-api/src/main/java/org/apache/camel/BindRegistry.java
new file mode 100644
index 0000000..b2aebca
--- /dev/null
+++ b/core/camel-api/src/main/java/org/apache/camel/BindRegistry.java
@@ -0,0 +1,37 @@
+/**
+ * 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;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Used for binding a bean to the registry
+ *
+ * If no name is specified then the bean will have its name auto computed based on the
+ * field name, or method name where the annotation is configured.
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Documented
+@Target({ElementType.TYPE, ElementType.FIELD, ElementType.METHOD})
+public @interface BindRegistry {
+    String name() default "";
+    String context() default "";
+}
diff --git a/core/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelBeanPostProcessor.java b/core/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelBeanPostProcessor.java
index 8b77e86..e7dc03f 100644
--- a/core/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelBeanPostProcessor.java
+++ b/core/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelBeanPostProcessor.java
@@ -20,6 +20,7 @@ import java.lang.reflect.Field;
 import java.lang.reflect.Method;
 
 import org.apache.camel.BeanInject;
+import org.apache.camel.BindRegistry;
 import org.apache.camel.CamelContext;
 import org.apache.camel.CamelContextAware;
 import org.apache.camel.DeferredContextBinding;
@@ -32,6 +33,8 @@ import org.apache.camel.util.ReflectionHelper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import static org.apache.camel.util.ObjectHelper.isEmpty;
+
 /**
  * A bean post processor which implements the <a href="http://camel.apache.org/bean-integration.html">Bean Integration</a>
  * features in Camel. Features such as the <a href="http://camel.apache.org/bean-injection.html">Bean Injection</a> of objects like
@@ -84,6 +87,16 @@ public class DefaultCamelBeanPostProcessor {
         injectFields(bean, beanName);
         injectMethods(bean, beanName);
 
+        // the bean may also need to be registered into the registry
+        BindRegistry bind = bean.getClass().getAnnotation(BindRegistry.class);
+        if (bind != null) {
+            String name = bind.name();
+            if (isEmpty(name)) {
+                name = bean.getClass().getSimpleName();
+            }
+            camelContext.getRegistry().bind(name, bean);
+        }
+
         if (bean instanceof CamelContextAware && canSetCamelContext(bean, beanName)) {
             CamelContextAware contextAware = (CamelContextAware)bean;
             DeferredContextBinding deferredBinding = bean.getClass().getAnnotation(DeferredContextBinding.class);
@@ -189,10 +202,25 @@ public class DefaultCamelBeanPostProcessor {
                 if (produce != null && getPostProcessorHelper().matchContext(produce.context())) {
                     injectField(field, produce.uri(), produce.ref(), produce.property(), bean, beanName, produce.binding());
                 }
+
+                BindRegistry bind = field.getAnnotation(BindRegistry.class);
+                if (bind != null && getPostProcessorHelper().matchContext(bind.context())) {
+                    bindRegistry(field, bind.name(), bean, beanName);
+                }
             }
         });
     }
 
+    private void bindRegistry(Field field, String name, Object bean, String beanName) {
+        if (isEmpty(name)) {
+            name = field.getName();
+        }
+        Object value = ReflectionHelper.getField(field, bean);
+        if (value != null) {
+            camelContext.getRegistry().bind(name, value);
+        }
+    }
+
     public void injectField(Field field, String endpointUri, String endpointRef, String endpointProperty,
                                Object bean, String beanName) {
         injectField(field, endpointUri, endpointRef, endpointProperty, bean, beanName, true);
diff --git a/core/camel-core/src/test/java/org/apache/camel/impl/DefaultCamelBeanPostProcessorTest.java b/core/camel-core/src/test/java/org/apache/camel/impl/DefaultCamelBeanPostProcessorTest.java
index 006be1a..f6b7ef8 100644
--- a/core/camel-core/src/test/java/org/apache/camel/impl/DefaultCamelBeanPostProcessorTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/impl/DefaultCamelBeanPostProcessorTest.java
@@ -15,6 +15,8 @@
  * limitations under the License.
  */
 package org.apache.camel.impl;
+
+import org.apache.camel.BindRegistry;
 import org.apache.camel.Consume;
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.Produce;
@@ -38,6 +40,14 @@ public class DefaultCamelBeanPostProcessorTest extends ContextTestSupport {
         getMockEndpoint("mock:result").expectedMessageCount(1);
         template.sendBody("seda:input", "Hello World");
         assertMockEndpointsSatisfied();
+
+        // should register the beans in the registry via @BindRegistry
+        Object bean = context.getRegistry().lookupByName("myCoolBean");
+        assertNotNull(bean);
+        assertIsInstanceOf(MySerialBean.class, bean);
+        bean = context.getRegistry().lookupByName("FooService");
+        assertNotNull(bean);
+        assertIsInstanceOf(FooService.class, bean);
     }
 
     @Override
@@ -47,12 +57,15 @@ public class DefaultCamelBeanPostProcessorTest extends ContextTestSupport {
         postProcessor = new DefaultCamelBeanPostProcessor(context);
     }
 
+    @BindRegistry
     public class FooService {
 
         private String fooEndpoint;
         private String barEndpoint;
         @Produce
         private ProducerTemplate bar;
+        @BindRegistry(name = "myCoolBean")
+        private MySerialBean myBean = new MySerialBean();
 
         public String getFooEndpoint() {
             return fooEndpoint;
diff --git a/core/camel-util/src/main/java/org/apache/camel/util/ReflectionHelper.java b/core/camel-util/src/main/java/org/apache/camel/util/ReflectionHelper.java
index 0a4b8cf..e36aa98 100644
--- a/core/camel-util/src/main/java/org/apache/camel/util/ReflectionHelper.java
+++ b/core/camel-util/src/main/java/org/apache/camel/util/ReflectionHelper.java
@@ -157,4 +157,22 @@ public final class ReflectionHelper {
         }
     }
 
+    public static Object getField(Field f, Object instance) {
+        try {
+            boolean oldAccessible = f.isAccessible();
+            boolean shouldSetAccessible = !Modifier.isPublic(f.getModifiers()) && !oldAccessible;
+            if (shouldSetAccessible) {
+                f.setAccessible(true);
+            }
+            Object answer = f.get(instance);
+            if (shouldSetAccessible) {
+                f.setAccessible(oldAccessible);
+            }
+            return answer;
+        } catch (Exception ex) {
+            // ignore
+        }
+        return null;
+    }
+
 }


[camel] 05/07: CAMEL-13283: Add @BindRegistry annotation to allow to bind beans/classes to registry.

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch bind
in repository https://gitbox.apache.org/repos/asf/camel.git

commit fafcfbcd8eb65094acd070456d5efab59d041de6
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Tue Mar 5 05:46:27 2019 +0100

    CAMEL-13283: Add @BindRegistry annotation to allow to bind beans/classes to registry.
---
 .../camel/impl/DefaultCamelBeanPostProcessor.java  | 65 +++++++++++++++-------
 .../impl/DefaultCamelBeanPostProcessorTest.java    |  8 +++
 2 files changed, 52 insertions(+), 21 deletions(-)

diff --git a/core/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelBeanPostProcessor.java b/core/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelBeanPostProcessor.java
index 6dfc82d..98ba439 100644
--- a/core/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelBeanPostProcessor.java
+++ b/core/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelBeanPostProcessor.java
@@ -28,11 +28,11 @@ import org.apache.camel.EndpointInject;
 import org.apache.camel.Produce;
 import org.apache.camel.PropertyInject;
 import org.apache.camel.support.DefaultEndpoint;
-import org.apache.camel.support.ObjectHelper;
 import org.apache.camel.util.ReflectionHelper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import static org.apache.camel.support.ObjectHelper.invokeMethod;
 import static org.apache.camel.util.ObjectHelper.isEmpty;
 
 /**
@@ -205,22 +205,12 @@ public class DefaultCamelBeanPostProcessor {
 
                 BindToRegistry bind = field.getAnnotation(BindToRegistry.class);
                 if (bind != null && getPostProcessorHelper().matchContext(bind.context())) {
-                    bindRegistry(field, bind.name(), bean, beanName);
+                    bindToRegistry(field, bind.name(), bean, beanName);
                 }
             }
         });
     }
 
-    private void bindRegistry(Field field, String name, Object bean, String beanName) {
-        if (isEmpty(name)) {
-            name = field.getName();
-        }
-        Object value = ReflectionHelper.getField(field, bean);
-        if (value != null) {
-            camelContext.getRegistry().bind(name, value);
-        }
-    }
-
     public void injectField(Field field, String endpointUri, String endpointRef, String endpointProperty,
                                Object bean, String beanName) {
         injectField(field, endpointUri, endpointRef, endpointProperty, bean, beanName, true);
@@ -273,6 +263,11 @@ public class DefaultCamelBeanPostProcessor {
         if (produce != null && getPostProcessorHelper().matchContext(produce.context())) {
             setterInjection(method, bean, beanName, produce.uri(), produce.ref(), produce.property());
         }
+
+        BindToRegistry bind = method.getAnnotation(BindToRegistry.class);
+        if (bind != null && getPostProcessorHelper().matchContext(bind.context())) {
+            bindToRegistry(method, bind.name(), bean, beanName);
+        }
     }
 
     public void setterInjection(Method method, Object bean, String beanName, String endpointUri, String endpointRef, String endpointProperty) {
@@ -284,7 +279,7 @@ public class DefaultCamelBeanPostProcessor {
                 String propertyName = org.apache.camel.util.ObjectHelper.getPropertyName(method);
                 Object value = getPostProcessorHelper().getInjectionValue(parameterTypes[0], endpointUri, endpointRef, endpointProperty,
                         propertyName, bean, beanName);
-                ObjectHelper.invokeMethod(method, bean, value);
+                invokeMethod(method, bean, value);
             }
         }
     }
@@ -298,20 +293,48 @@ public class DefaultCamelBeanPostProcessor {
             } else {
                 String propertyName = org.apache.camel.util.ObjectHelper.getPropertyName(method);
                 Object value = getPostProcessorHelper().getInjectionPropertyValue(parameterTypes[0], propertyValue, propertyDefaultValue, propertyName, bean, beanName);
-                ObjectHelper.invokeMethod(method, bean, value);
+                invokeMethod(method, bean, value);
             }
         }
     }
 
     public void setterBeanInjection(Method method, String name, Object bean, String beanName) {
         Class<?>[] parameterTypes = method.getParameterTypes();
-        if (parameterTypes != null) {
-            if (parameterTypes.length != 1) {
-                LOG.warn("Ignoring badly annotated method for injection due to incorrect number of parameters: {}", method);
-            } else {
-                Object value = getPostProcessorHelper().getInjectionBeanValue(parameterTypes[0], name);
-                ObjectHelper.invokeMethod(method, bean, value);
-            }
+        if (parameterTypes.length != 1) {
+            LOG.warn("Ignoring badly annotated method for injection due to incorrect number of parameters: {}", method);
+        } else {
+            Object value = getPostProcessorHelper().getInjectionBeanValue(parameterTypes[0], name);
+            invokeMethod(method, bean, value);
+        }
+    }
+
+    private void bindToRegistry(Field field, String name, Object bean, String beanName) {
+        if (isEmpty(name)) {
+            name = field.getName();
+        }
+        Object value = ReflectionHelper.getField(field, bean);
+        if (value != null) {
+            camelContext.getRegistry().bind(name, value);
+        }
+    }
+
+    private void bindToRegistry(Method method, String name, Object bean, String beanName) {
+        if (isEmpty(name)) {
+            name = method.getName();
+        }
+        Class<?> returnType = method.getReturnType();
+        if (returnType == null || returnType == Void.TYPE) {
+            throw new IllegalArgumentException("@BindToRegistry on class: " + method.getDeclaringClass()
+                + " method: " + method.getName() + " with void return type is not allowed");
+        }
+        // TODO: Add support for some bean parameter bindings, like CamelContext,Registry and auto-lookup of by type in registry
+        if (method.getParameterCount() != 0) {
+            throw new IllegalArgumentException("@BindToRegistry on class: " + method.getDeclaringClass()
+                + " method: " + method.getName() + " with method parameters is not allowed");
+        }
+        Object value = invokeMethod(method, bean);
+        if (value != null) {
+            camelContext.getRegistry().bind(name, value);
         }
     }
 
diff --git a/core/camel-core/src/test/java/org/apache/camel/impl/DefaultCamelBeanPostProcessorTest.java b/core/camel-core/src/test/java/org/apache/camel/impl/DefaultCamelBeanPostProcessorTest.java
index 8814848..2934360 100644
--- a/core/camel-core/src/test/java/org/apache/camel/impl/DefaultCamelBeanPostProcessorTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/impl/DefaultCamelBeanPostProcessorTest.java
@@ -48,6 +48,9 @@ public class DefaultCamelBeanPostProcessorTest extends ContextTestSupport {
         bean = context.getRegistry().lookupByName("FooService");
         assertNotNull(bean);
         assertIsInstanceOf(FooService.class, bean);
+        bean = context.getRegistry().lookupByName("doSomething");
+        assertNotNull(bean);
+        assertIsInstanceOf(FooBar.class, bean);
     }
 
     @Override
@@ -67,6 +70,11 @@ public class DefaultCamelBeanPostProcessorTest extends ContextTestSupport {
         @BindToRegistry(name = "myCoolBean")
         private MySerialBean myBean = new MySerialBean();
 
+        @BindToRegistry
+        public FooBar doSomething(String s) {
+            return new FooBar();
+        }
+
         public String getFooEndpoint() {
             return fooEndpoint;
         }


[camel] 06/07: CAMEL-13283: Add example

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch bind
in repository https://gitbox.apache.org/repos/asf/camel.git

commit e23466692d005a456fc12f81a62e8a3e9d4fa371
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Tue Mar 5 05:51:21 2019 +0100

     CAMEL-13283: Add example
---
 examples/camel-example-main/pom.xml                | 85 ++++++++++++++++++++++
 examples/camel-example-main/readme.adoc            | 13 ++++
 .../org/apache/camel/example/MyApplication.java    | 80 ++++++++++++++++++++
 .../src/main/resources/log4j2.properties           | 23 ++++++
 examples/pom.xml                                   |  1 +
 5 files changed, 202 insertions(+)

diff --git a/examples/camel-example-main/pom.xml b/examples/camel-example-main/pom.xml
new file mode 100644
index 0000000..f2c9489
--- /dev/null
+++ b/examples/camel-example-main/pom.xml
@@ -0,0 +1,85 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    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.
+
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+  <modelVersion>4.0.0</modelVersion>
+
+  <parent>
+    <groupId>org.apache.camel.example</groupId>
+    <artifactId>examples</artifactId>
+    <version>3.0.0-SNAPSHOT</version>
+  </parent>
+
+  <artifactId>camel-example-main</artifactId>
+  <packaging>jar</packaging>
+  <name>Camel :: Example :: Main</name>
+  <description>An example for showing standalone Camel</description>
+
+  <properties>
+    <category>Beginner</category>
+  </properties>
+
+  <dependencies>
+
+    <dependency>
+      <groupId>org.apache.camel</groupId>
+      <artifactId>camel-core</artifactId>
+    </dependency>
+
+    <!-- logging -->
+    <dependency>
+      <groupId>org.apache.logging.log4j</groupId>
+      <artifactId>log4j-api</artifactId>
+      <scope>runtime</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.logging.log4j</groupId>
+      <artifactId>log4j-core</artifactId>
+      <scope>runtime</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.logging.log4j</groupId>
+      <artifactId>log4j-slf4j-impl</artifactId>
+      <scope>runtime</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.logging.log4j</groupId>
+      <artifactId>log4j-jul</artifactId>
+      <scope>runtime</scope>
+    </dependency>
+
+  </dependencies>
+
+  <build>
+    <plugins>
+      <!-- Allows the example to be run via 'mvn camel:run' -->
+      <plugin>
+        <groupId>org.apache.camel</groupId>
+        <artifactId>camel-maven-plugin</artifactId>
+        <version>${project.version}</version>
+        <configuration>
+          <mainClass>org.apache.camel.example.MyApplication</mainClass>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+
+</project>
diff --git a/examples/camel-example-main/readme.adoc b/examples/camel-example-main/readme.adoc
new file mode 100644
index 0000000..18aef79
--- /dev/null
+++ b/examples/camel-example-main/readme.adoc
@@ -0,0 +1,13 @@
+# Camel Example Main
+
+This example shows how to run Camel standalone via the built-in Main class.
+
+## How to run
+
+You can run this example using
+
+    mvn camel:run   
+
+## More information
+
+You can find more information about Apache Camel at the website: http://camel.apache.org/
diff --git a/examples/camel-example-main/src/main/java/org/apache/camel/example/MyApplication.java b/examples/camel-example-main/src/main/java/org/apache/camel/example/MyApplication.java
new file mode 100644
index 0000000..e60df81
--- /dev/null
+++ b/examples/camel-example-main/src/main/java/org/apache/camel/example/MyApplication.java
@@ -0,0 +1,80 @@
+/**
+ * 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.example;
+
+import java.util.Date;
+import java.util.Objects;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.main.Main;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public final class MyApplication {
+    private static final Logger LOGGER = LoggerFactory.getLogger(MyApplication.class);
+
+    private MyApplication() {
+    }
+
+    public static void main(String[] args) throws Exception {
+        Main main = new Main();
+        main.addRouteBuilder(new MyRouteBuilder());
+        main.run(args);
+    }
+
+    private static class MyRouteBuilder extends RouteBuilder {
+        @Override
+        public void configure() throws Exception {
+            from("timer:simple?period=503")
+                .id("simple-route")
+                .transform()
+                    .exchange(this::dateToTime)
+                .process()
+                    .message(this::log)
+                .process()
+                    .body(this::log)
+                .choice()
+                    .when()
+                        .body(Integer.class, b -> (b & 1) == 0)
+                        .log("Received even number")
+                    .when()
+                        .body(Integer.class, (b, h) -> h.containsKey("skip") ? false : (b & 1) == 0)
+                        .log("Received odd number")
+                    .when()
+                        .body(Objects::isNull)
+                        .log("Received null body")
+                    .when()
+                        .body(Integer.class, b -> (b & 1) != 0)
+                        .log("Received odd number")
+                .endChoice();
+        }
+
+        private Long dateToTime(Exchange e) {
+            return e.getProperty(Exchange.TIMER_FIRED_TIME, Date.class).getTime();
+        }
+
+        private void log(Object b) {
+            LOGGER.info("body is: {}", b);
+        }
+
+        private void log(Message m) {
+            LOGGER.info("message is: {}", m);
+        }
+    }
+}
diff --git a/examples/camel-example-main/src/main/resources/log4j2.properties b/examples/camel-example-main/src/main/resources/log4j2.properties
new file mode 100644
index 0000000..d406a9f
--- /dev/null
+++ b/examples/camel-example-main/src/main/resources/log4j2.properties
@@ -0,0 +1,23 @@
+## ---------------------------------------------------------------------------
+## 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.
+## ---------------------------------------------------------------------------
+
+appender.out.type = Console
+appender.out.name = out
+appender.out.layout.type = PatternLayout
+appender.out.layout.pattern = %d [%-15.15t] %-5p %-30.30c{1} - %m%n
+rootLogger.level = INFO
+rootLogger.appenderRef.out.ref = out
diff --git a/examples/pom.xml b/examples/pom.xml
index ab39b58..a5c5d8b 100644
--- a/examples/pom.xml
+++ b/examples/pom.xml
@@ -77,6 +77,7 @@
     <module>camel-example-loadbalancing</module>
     <module>camel-example-loan-broker-cxf</module>
     <module>camel-example-loan-broker-jms</module>
+    <module>camel-example-main</module>
     <module>camel-example-management</module>
     <module>camel-example-micrometer</module>	
     <module>camel-example-mybatis</module>


[camel] 02/07: Upgrade eclipse paho

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch bind
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 544d6f4ebef8afcc68886988173e6bd29e25aa08
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Tue Mar 5 05:14:24 2019 +0100

    Upgrade eclipse paho
---
 parent/pom.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/parent/pom.xml b/parent/pom.xml
index d4ace48..c191fdf 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -544,7 +544,7 @@
     <os-maven-plugin-version>1.6.0</os-maven-plugin-version>
     <oscache-bundle-version>2.4_5</oscache-bundle-version>
     <osgi-version>6.0.0</osgi-version>
-    <paho-version>1.2.0</paho-version>
+    <paho-version>1.2.1</paho-version>
     <paranamer-bundle-version>2.8_1</paranamer-bundle-version>
     <pax-cdi-version>1.0.0</pax-cdi-version>
     <pax-exam-version>4.13.0</pax-exam-version>