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

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


The following commit(s) were added to refs/heads/main by this push:
     new 34d6060b refactor: move MyRouteBuilder to standalone class in 
java-lambda example (#158)
34d6060b is described below

commit 34d6060b4920691ba87b23866d3ef271e5f6f9a8
Author: Jomin <[email protected]>
AuthorDate: Mon Mar 2 14:12:56 2026 +0000

    refactor: move MyRouteBuilder to standalone class in java-lambda example 
(#158)
    
    * refactor: move MyRouteBuilder to standalone class in java-lambda example
    
    Fixes IllegalAccessException during 'mvn camel:run' by ensuring the
    RouteBuilder is public and accessible for reflection.
    
    * docs: add license header and fix indentation
    
    ---------
    
    Co-authored-by: jomin mathew <>
---
 .../apache/camel/example/java8/MyApplication.java  | 47 ----------------
 .../apache/camel/example/java8/MyRouteBuilder.java | 65 ++++++++++++++++++++++
 .../org/apache/camel/example/java8/Java8Test.java  |  2 +-
 3 files changed, 66 insertions(+), 48 deletions(-)

diff --git 
a/java-lambda/src/main/java/org/apache/camel/example/java8/MyApplication.java 
b/java-lambda/src/main/java/org/apache/camel/example/java8/MyApplication.java
index f10b8955..ebe906f2 100644
--- 
a/java-lambda/src/main/java/org/apache/camel/example/java8/MyApplication.java
+++ 
b/java-lambda/src/main/java/org/apache/camel/example/java8/MyApplication.java
@@ -16,18 +16,9 @@
  */
 package org.apache.camel.example.java8;
 
-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() {
     }
@@ -36,42 +27,4 @@ public final class MyApplication {
         Main main = new Main(MyApplication.class);
         main.run(args);
     }
-
-    static class MyRouteBuilder extends RouteBuilder {
-
-        @Override
-        public void configure() throws Exception {
-            from("timer:simple?includeMetadata=true&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 -> (b & 1) != 0)
-                        .log("Received odd number")
-                    .when()
-                        .body(Objects::isNull)
-                        .log("Received null body")
-                .end();
-        }
-
-        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/java-lambda/src/main/java/org/apache/camel/example/java8/MyRouteBuilder.java 
b/java-lambda/src/main/java/org/apache/camel/example/java8/MyRouteBuilder.java
new file mode 100644
index 00000000..ac25f0e1
--- /dev/null
+++ 
b/java-lambda/src/main/java/org/apache/camel/example/java8/MyRouteBuilder.java
@@ -0,0 +1,65 @@
+/*
+ * 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.java8;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.builder.RouteBuilder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Date;
+import java.util.Objects;
+
+public class MyRouteBuilder extends RouteBuilder {
+    private static final Logger LOGGER = 
LoggerFactory.getLogger(MyApplication.class);
+
+    @Override
+    public void configure() throws Exception {
+        from("timer:simple?includeMetadata=true&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 -> (b & 1) != 0)
+                    .log("Received odd number")
+                .when()
+                    .body(Objects::isNull)
+                    .log("Received null body")
+            .end();
+    }
+
+    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/java-lambda/src/test/java/org/apache/camel/example/java8/Java8Test.java 
b/java-lambda/src/test/java/org/apache/camel/example/java8/Java8Test.java
index 57eb3ba8..8ee16592 100644
--- a/java-lambda/src/test/java/org/apache/camel/example/java8/Java8Test.java
+++ b/java-lambda/src/test/java/org/apache/camel/example/java8/Java8Test.java
@@ -41,6 +41,6 @@ class Java8Test extends CamelMainTestSupport {
 
     @Override
     protected void configure(MainConfigurationProperties configuration) {
-        configuration.addRoutesBuilder(new MyApplication.MyRouteBuilder());
+        configuration.addRoutesBuilder(new MyRouteBuilder());
     }
 }

Reply via email to