You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by nf...@apache.org on 2023/04/13 17:50:17 UTC

[camel-quarkus] branch 2.16.x updated (2d0543f8a4 -> fa5fd0cae1)

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

nfilotto pushed a change to branch 2.16.x
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git


    from 2d0543f8a4 Sync versions
     new 42c3c013c4 Ref #4716: java-joor-dsl - Add RegisterForReflection support (#4726)
     new 38e38bf6de Ref #4731: java-joor-dsl - Add support of inner classes (#4732)
     new 3b54f7bf5a Ref #4731: java-joor-dsl - Add support of anonymous classes
     new 45b1b5b6ec Ref #4716: java-joor-dsl - Support RegisterForReflection for the current class
     new 25a814735a Ref #4447: java-joor-dsl - Improve the test coverage
     new fa5fd0cae1 Ref #4749 - java-joor-dsl - Add templated route support to native mode

The 6 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.


Summary of changes:
 .../pages/reference/extensions/java-joor-dsl.adoc  |  8 ++
 .../java/joor/deployment/JavaJoorDslProcessor.java | 90 +++++++++++++++++++++-
 .../runtime/src/main/doc/limitations.adoc          |  3 +
 .../dsl/java/joor/runtime/JavaJoorDslRecorder.java | 14 +++-
 integration-tests/java-joor-dsl/pom.xml            | 51 ++++++++++++
 .../quarkus/dsl/java/joor/JavaJoorDslBean.java}    | 12 ++-
 .../quarkus/dsl/java/joor/JavaJoorDslResource.java | 39 +++++++++-
 .../src/main/resources/application.properties      |  2 +-
 .../src/main/resources/routes/MyBar.java           | 15 ++--
 .../src/main/resources/routes/MyBarEcho.java}      | 17 ++--
 .../src/main/resources/routes/MyBarRoute.java      | 12 +--
 .../src/main/resources/routes/MyRoutes.java        | 29 ++++++-
 .../main/resources/routes/MyRoutesWithBeans.java}  | 29 ++++---
 .../main/resources/routes/MyRoutesWithModel.java   | 27 ++++---
 .../resources/routes/MyRoutesWithNestedClass.java} | 28 ++++---
 .../resources/routes/MyRoutesWithTemplate.java     |  9 ++-
 .../src/main/resources/routes/MyTemplate.java      | 12 ++-
 .../src/main/resources/routes/MyUser.java}         | 18 +++--
 .../quarkus/dsl/java/joor/JavaJoorDslTest.java     | 41 +++++++++-
 19 files changed, 373 insertions(+), 83 deletions(-)
 create mode 100644 extensions/java-joor-dsl/runtime/src/main/doc/limitations.adoc
 copy integration-tests/java-joor-dsl/src/{test/java/org/apache/camel/quarkus/dsl/java/joor/JavaJoorDslIT.java => main/java/org/apache/camel/quarkus/dsl/java/joor/JavaJoorDslBean.java} (74%)
 copy integration-test-groups/foundation/browse/src/test/java/org/apache/camel/quarkus/component/browse/it/BrowseIT.java => integration-tests/java-joor-dsl/src/main/resources/routes/MyBar.java (82%)
 copy integration-tests/{dataformats-json/src/main/java/org/apache/camel/quarkus/component/dataformats/json/model/Views.java => java-joor-dsl/src/main/resources/routes/MyBarEcho.java} (80%)
 copy integration-test-groups/foundation/browse/src/main/java/org/apache/camel/quarkus/component/browse/it/BrowseRoutes.java => integration-tests/java-joor-dsl/src/main/resources/routes/MyBarRoute.java (79%)
 copy integration-tests/{exec/src/main/java/org/apache/camel/quarkus/component/exec/it/ExecRoutes.java => java-joor-dsl/src/main/resources/routes/MyRoutesWithBeans.java} (64%)
 copy extensions/openapi-java/deployment/src/test/java/org/apache/camel/quarkus/component/openapi/java/deployment/RestRoutes.java => integration-tests/java-joor-dsl/src/main/resources/routes/MyRoutesWithModel.java (62%)
 copy integration-tests/{platform-http-proxy/src/main/java/org/apache/camel/quarkus/component/platform/http/proxy/it/Routes.java => java-joor-dsl/src/main/resources/routes/MyRoutesWithNestedClass.java} (59%)
 copy integration-tests-jvm/management/src/main/java/org/apache/camel/quarkus/component/management/it/Routes.java => integration-tests/java-joor-dsl/src/main/resources/routes/MyRoutesWithTemplate.java (78%)
 copy integration-tests-jvm/management/src/main/java/org/apache/camel/quarkus/component/management/it/Routes.java => integration-tests/java-joor-dsl/src/main/resources/routes/MyTemplate.java (72%)
 copy integration-tests/{xstream/src/main/java/org/apache/camel/quarkus/component/xstream/it/PojoA.java => java-joor-dsl/src/main/resources/routes/MyUser.java} (83%)


[camel-quarkus] 06/06: Ref #4749 - java-joor-dsl - Add templated route support to native mode

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

nfilotto pushed a commit to branch 2.16.x
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git

commit fa5fd0cae16ae7ee0254a06c06d85781c1a4873c
Author: Nicolas Filotto <nf...@talend.com>
AuthorDate: Fri Apr 7 15:48:05 2023 +0200

    Ref #4749 - java-joor-dsl - Add templated route support to native mode
---
 .../java/joor/deployment/JavaJoorDslProcessor.java | 10 +++++++-
 .../dsl/java/joor/runtime/JavaJoorDslRecorder.java | 14 ++++++++--
 .../resources/routes/MyRoutesWithTemplate.java     | 27 +++++++++++++++++++
 .../src/main/resources/routes/MyTemplate.java      | 30 ++++++++++++++++++++++
 .../quarkus/dsl/java/joor/JavaJoorDslTest.java     |  4 +--
 5 files changed, 80 insertions(+), 5 deletions(-)

diff --git a/extensions/java-joor-dsl/deployment/src/main/java/org/apache/camel/quarkus/dsl/java/joor/deployment/JavaJoorDslProcessor.java b/extensions/java-joor-dsl/deployment/src/main/java/org/apache/camel/quarkus/dsl/java/joor/deployment/JavaJoorDslProcessor.java
index b52818dc46..c2d2cf3bb0 100644
--- a/extensions/java-joor-dsl/deployment/src/main/java/org/apache/camel/quarkus/dsl/java/joor/deployment/JavaJoorDslProcessor.java
+++ b/extensions/java-joor-dsl/deployment/src/main/java/org/apache/camel/quarkus/dsl/java/joor/deployment/JavaJoorDslProcessor.java
@@ -19,6 +19,7 @@ package org.apache.camel.quarkus.dsl.java.joor.deployment;
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -42,6 +43,7 @@ import io.quarkus.paths.PathCollection;
 import io.quarkus.runtime.RuntimeValue;
 import io.quarkus.runtime.annotations.RegisterForReflection;
 import org.apache.camel.CamelContext;
+import org.apache.camel.RoutesBuilder;
 import org.apache.camel.dsl.java.joor.CompilationUnit;
 import org.apache.camel.dsl.java.joor.MultiCompile;
 import org.apache.camel.quarkus.core.deployment.main.CamelMainHelper;
@@ -208,8 +210,14 @@ public class JavaJoorDslProcessor {
             CamelContextBuildItem context,
             JavaJoorDslRecorder recorder) throws Exception {
         RuntimeValue<CamelContext> camelContext = context.getCamelContext();
+        List<RoutesBuilder> builders = new ArrayList<>(classes.size());
+        // Register routes first
         for (JavaJoorGeneratedClassBuildItem clazz : classes) {
-            recorder.registerRoutesBuilder(camelContext, clazz.getName(), clazz.getLocation());
+            builders.add(recorder.registerRoutes(camelContext, clazz.getName(), clazz.getLocation()));
+        }
+        // Then register templated routes
+        for (RoutesBuilder builder : builders) {
+            recorder.registerTemplatedRoutes(camelContext, builder);
         }
     }
 
diff --git a/extensions/java-joor-dsl/runtime/src/main/java/org/apache/camel/quarkus/dsl/java/joor/runtime/JavaJoorDslRecorder.java b/extensions/java-joor-dsl/runtime/src/main/java/org/apache/camel/quarkus/dsl/java/joor/runtime/JavaJoorDslRecorder.java
index 4a309eceb4..315e6e4cfe 100644
--- a/extensions/java-joor-dsl/runtime/src/main/java/org/apache/camel/quarkus/dsl/java/joor/runtime/JavaJoorDslRecorder.java
+++ b/extensions/java-joor-dsl/runtime/src/main/java/org/apache/camel/quarkus/dsl/java/joor/runtime/JavaJoorDslRecorder.java
@@ -35,7 +35,8 @@ public class JavaJoorDslRecorder {
 
     private static final Logger LOG = LoggerFactory.getLogger(JavaJoorDslRecorder.class);
 
-    public void registerRoutesBuilder(RuntimeValue<CamelContext> context, String className, String location) throws Exception {
+    public RoutesBuilder registerRoutes(RuntimeValue<CamelContext> context, String className, String location)
+            throws Exception {
         Class<?> clazz = Class.forName(className);
         boolean skip = clazz.isInterface() || Modifier.isAbstract(clazz.getModifiers())
                 || Modifier.isPrivate(clazz.getModifiers());
@@ -49,7 +50,9 @@ public class JavaJoorDslRecorder {
                     // inject context and resource
                     CamelContextAware.trySetCamelContext(obj, context.getValue());
                     ResourceAware.trySetResource(obj, ResourceHelper.fromString(location, ""));
-                    context.getValue().addRoutes((RoutesBuilder) obj);
+                    RoutesBuilder builder = (RoutesBuilder) obj;
+                    context.getValue().addRoutes(builder);
+                    return builder;
                 } else {
                     LOG.warn("Ignoring the class {} as it is not of type RoutesBuilder", className);
                 }
@@ -59,5 +62,12 @@ public class JavaJoorDslRecorder {
         } else {
             LOG.warn("Ignoring the class {} as it cannot be instantiated with the default constructor", className);
         }
+        return null;
+    }
+
+    public void registerTemplatedRoutes(RuntimeValue<CamelContext> camelContext, RoutesBuilder builder) throws Exception {
+        if (builder != null) {
+            camelContext.getValue().addTemplatedRoutes(builder);
+        }
     }
 }
diff --git a/integration-tests/java-joor-dsl/src/main/resources/routes/MyRoutesWithTemplate.java b/integration-tests/java-joor-dsl/src/main/resources/routes/MyRoutesWithTemplate.java
new file mode 100644
index 0000000000..4b836f0190
--- /dev/null
+++ b/integration-tests/java-joor-dsl/src/main/resources/routes/MyRoutesWithTemplate.java
@@ -0,0 +1,27 @@
+/*
+ * 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.
+ */
+import org.apache.camel.builder.RouteBuilder;
+
+public class MyRoutesWithTemplate extends RouteBuilder {
+    @Override
+    public void configure() throws Exception {
+        templatedRoute("someTemplate")
+                .routeId("routes-with-template")
+                .parameter("id", "routes-with-template")
+                .parameter("body", "Hi PK");
+    }
+}
diff --git a/integration-tests/java-joor-dsl/src/main/resources/routes/MyTemplate.java b/integration-tests/java-joor-dsl/src/main/resources/routes/MyTemplate.java
new file mode 100644
index 0000000000..0e4fe84f66
--- /dev/null
+++ b/integration-tests/java-joor-dsl/src/main/resources/routes/MyTemplate.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
+ *
+ *      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.
+ */
+import org.apache.camel.builder.RouteBuilder;
+
+public class MyTemplate extends RouteBuilder {
+    @Override
+    public void configure() throws Exception {
+        routeTemplate("someTemplate")
+                .templateParameter("id")
+                .templateParameter("body")
+                .route()
+                .from("direct:{{id}}")
+                .setBody().constant("{{body}}")
+                .setBody().simple("${body.endsWith('PK')}");
+    }
+}
diff --git a/integration-tests/java-joor-dsl/src/test/java/org/apache/camel/quarkus/dsl/java/joor/JavaJoorDslTest.java b/integration-tests/java-joor-dsl/src/test/java/org/apache/camel/quarkus/dsl/java/joor/JavaJoorDslTest.java
index 38998a3cb5..767196aeaf 100644
--- a/integration-tests/java-joor-dsl/src/test/java/org/apache/camel/quarkus/dsl/java/joor/JavaJoorDslTest.java
+++ b/integration-tests/java-joor-dsl/src/test/java/org/apache/camel/quarkus/dsl/java/joor/JavaJoorDslTest.java
@@ -76,13 +76,13 @@ class JavaJoorDslTest {
                 .then()
                 .statusCode(200)
                 .body(CoreMatchers.is(
-                        "inner-classes-route,my-java-route,reflection-route,routes-with-bean,routes-with-inner-bean,routes-with-nested-class,routes-with-rest,routes-with-rest-get"));
+                        "inner-classes-route,my-java-route,reflection-route,routes-with-bean,routes-with-inner-bean,routes-with-nested-class,routes-with-rest,routes-with-rest-get,routes-with-template"));
 
         RestAssured.given()
                 .get("/java-joor-dsl/main/successful/routes")
                 .then()
                 .statusCode(200)
-                .body(CoreMatchers.is("3"));
+                .body(CoreMatchers.is("4"));
     }
 
     @Test


[camel-quarkus] 04/06: Ref #4716: java-joor-dsl - Support RegisterForReflection for the current class

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

nfilotto pushed a commit to branch 2.16.x
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git

commit 45b1b5b6ecfc83b227b6cc41dd5ca9f34ed93830
Author: Nicolas Filotto <nf...@talend.com>
AuthorDate: Mon Apr 3 15:43:09 2023 +0200

    Ref #4716: java-joor-dsl - Support RegisterForReflection for the current class
---
 .../java/joor/deployment/JavaJoorDslProcessor.java | 36 +++++++++++++---------
 1 file changed, 22 insertions(+), 14 deletions(-)

diff --git a/extensions/java-joor-dsl/deployment/src/main/java/org/apache/camel/quarkus/dsl/java/joor/deployment/JavaJoorDslProcessor.java b/extensions/java-joor-dsl/deployment/src/main/java/org/apache/camel/quarkus/dsl/java/joor/deployment/JavaJoorDslProcessor.java
index 4b1d577c26..b52818dc46 100644
--- a/extensions/java-joor-dsl/deployment/src/main/java/org/apache/camel/quarkus/dsl/java/joor/deployment/JavaJoorDslProcessor.java
+++ b/extensions/java-joor-dsl/deployment/src/main/java/org/apache/camel/quarkus/dsl/java/joor/deployment/JavaJoorDslProcessor.java
@@ -109,12 +109,14 @@ public class JavaJoorDslProcessor {
                         .produce(new JavaJoorGeneratedClassBuildItem(className, nameToResource.get(className).getLocation(),
                                 result.getByteCode(className)));
                 Class<?> aClass = result.getClass(className);
+                // Inner classes
                 for (Class<?> clazz : aClass.getDeclaredClasses()) {
                     String name = clazz.getName();
                     generatedClass
                             .produce(new JavaJoorGeneratedClassBuildItem(name, nameToResource.get(className).getLocation(),
                                     result.getByteCode(name)));
                 }
+                // Anonymous classes
                 for (int i = 1;; i++) {
                     String name = String.format("%s$%d", className, i);
                     byte[] content = result.getByteCode(name);
@@ -125,8 +127,7 @@ public class JavaJoorDslProcessor {
                             .produce(new JavaJoorGeneratedClassBuildItem(name, nameToResource.get(className).getLocation(),
                                     content));
                 }
-                registerForReflection(reflectiveClass, lambdaCapturingTypeProducer,
-                        aClass.getAnnotation(RegisterForReflection.class));
+                registerForReflection(reflectiveClass, lambdaCapturingTypeProducer, aClass);
             }
         } finally {
             // Restore the CP
@@ -135,8 +136,8 @@ public class JavaJoorDslProcessor {
     }
 
     private void registerForReflection(BuildProducer<ReflectiveClassBuildItem> reflectiveClass,
-            BuildProducer<LambdaCapturingTypeBuildItem> lambdaCapturingTypeProducer,
-            RegisterForReflection annotation) {
+            BuildProducer<LambdaCapturingTypeBuildItem> lambdaCapturingTypeProducer, Class<?> aClass) {
+        RegisterForReflection annotation = aClass.getAnnotation(RegisterForReflection.class);
         if (annotation == null) {
             return;
         }
@@ -153,17 +154,25 @@ public class JavaJoorDslProcessor {
             LOG.warn(
                     "The element 'registerFullHierarchy' of the annotation 'RegisterForReflection' is not supported by the extension Camel Java jOOR DSL");
         }
-        for (Class<?> type : annotation.targets()) {
-            registerClass(type.getName(), methods, fields, ignoreNested, serialization, reflectiveClass);
+        Class<?>[] targets = annotation.targets();
+        String[] classNames = annotation.classNames();
+        if (targets.length == 0 && classNames.length == 0) {
+            // No target and classname set, the target is then the class itself
+            registerClass(aClass, aClass.getName(), methods, fields, ignoreNested, serialization, reflectiveClass);
+            return;
+        }
+
+        for (Class<?> type : targets) {
+            registerClass(type, type.getName(), methods, fields, ignoreNested, serialization, reflectiveClass);
         }
 
-        for (String className : annotation.classNames()) {
-            registerClass(className, methods, fields, ignoreNested, serialization, reflectiveClass);
+        for (String className : classNames) {
+            registerClass(null, className, methods, fields, ignoreNested, serialization, reflectiveClass);
         }
     }
 
-    private void registerClass(String className, boolean methods, boolean fields, boolean ignoreNested, boolean serialization,
-            BuildProducer<ReflectiveClassBuildItem> reflectiveClass) {
+    private void registerClass(Class<?> type, String className, boolean methods, boolean fields, boolean ignoreNested,
+            boolean serialization, BuildProducer<ReflectiveClassBuildItem> reflectiveClass) {
         reflectiveClass.produce(serialization
                 ? ReflectiveClassBuildItem.serializationClass(className)
                 : new ReflectiveClassBuildItem(methods, fields, className));
@@ -173,10 +182,9 @@ public class JavaJoorDslProcessor {
         }
 
         try {
-            Class<?>[] declaredClasses = Thread.currentThread().getContextClassLoader().loadClass(className)
-                    .getDeclaredClasses();
-            for (Class<?> clazz : declaredClasses) {
-                registerClass(clazz.getName(), methods, fields, false, serialization, reflectiveClass);
+            Class<?> aClass = type == null ? Thread.currentThread().getContextClassLoader().loadClass(className) : type;
+            for (Class<?> clazz : aClass.getDeclaredClasses()) {
+                registerClass(clazz, clazz.getName(), methods, fields, false, serialization, reflectiveClass);
             }
         } catch (ClassNotFoundException e) {
             LOG.warn("Failed to load Class {}", className, e);


[camel-quarkus] 02/06: Ref #4731: java-joor-dsl - Add support of inner classes (#4732)

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

nfilotto pushed a commit to branch 2.16.x
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git

commit 38e38bf6de3233c3f575b47ddcf3e1478b6a0b8f
Author: Nicolas Filotto <es...@users.noreply.github.com>
AuthorDate: Mon Apr 3 15:25:48 2023 +0200

    Ref #4731: java-joor-dsl - Add support of inner classes (#4732)
    
    When a `RouteBuilder` class has an inner class, the inner class is unknown by Quarkus in native mode which causes a native compilation issue. The goal of this PR is to add the support of inner classes to prevent the native compilation issue.
    
    * Produce `JavaJoorGeneratedClassBuildItem` for inner classes too
    * Add a unit test to ensure that it works as expected
---
 .../dsl/java/joor/deployment/JavaJoorDslProcessor.java    |  9 ++++++++-
 .../camel/quarkus/dsl/java/joor/JavaJoorDslResource.java  |  8 ++++++++
 .../java-joor-dsl/src/main/resources/routes/MyRoutes.java | 15 +++++++++++++++
 .../camel/quarkus/dsl/java/joor/JavaJoorDslTest.java      | 12 +++++++++++-
 4 files changed, 42 insertions(+), 2 deletions(-)

diff --git a/extensions/java-joor-dsl/deployment/src/main/java/org/apache/camel/quarkus/dsl/java/joor/deployment/JavaJoorDslProcessor.java b/extensions/java-joor-dsl/deployment/src/main/java/org/apache/camel/quarkus/dsl/java/joor/deployment/JavaJoorDslProcessor.java
index a782e772c8..7e72562f78 100644
--- a/extensions/java-joor-dsl/deployment/src/main/java/org/apache/camel/quarkus/dsl/java/joor/deployment/JavaJoorDslProcessor.java
+++ b/extensions/java-joor-dsl/deployment/src/main/java/org/apache/camel/quarkus/dsl/java/joor/deployment/JavaJoorDslProcessor.java
@@ -108,8 +108,15 @@ public class JavaJoorDslProcessor {
                 generatedClass
                         .produce(new JavaJoorGeneratedClassBuildItem(className, nameToResource.get(className).getLocation(),
                                 result.getByteCode(className)));
+                Class<?> aClass = result.getClass(className);
+                for (Class<?> clazz : aClass.getDeclaredClasses()) {
+                    String name = clazz.getName();
+                    generatedClass
+                            .produce(new JavaJoorGeneratedClassBuildItem(name, nameToResource.get(className).getLocation(),
+                                    result.getByteCode(name)));
+                }
                 registerForReflection(reflectiveClass, lambdaCapturingTypeProducer,
-                        result.getClass(className).getAnnotation(RegisterForReflection.class));
+                        aClass.getAnnotation(RegisterForReflection.class));
             }
         } finally {
             // Restore the CP
diff --git a/integration-tests/java-joor-dsl/src/main/java/org/apache/camel/quarkus/dsl/java/joor/JavaJoorDslResource.java b/integration-tests/java-joor-dsl/src/main/java/org/apache/camel/quarkus/dsl/java/joor/JavaJoorDslResource.java
index 049f24a358..5f08ccbeea 100644
--- a/integration-tests/java-joor-dsl/src/main/java/org/apache/camel/quarkus/dsl/java/joor/JavaJoorDslResource.java
+++ b/integration-tests/java-joor-dsl/src/main/java/org/apache/camel/quarkus/dsl/java/joor/JavaJoorDslResource.java
@@ -88,4 +88,12 @@ public class JavaJoorDslResource {
         return producerTemplate.requestBody("direct:joorHi", name, String.class);
     }
 
+    @POST
+    @Path("/echo")
+    @Consumes(MediaType.TEXT_PLAIN)
+    @Produces(MediaType.TEXT_PLAIN)
+    public String echo(String msg) {
+        return producerTemplate.requestBody("direct:joorEcho", msg, String.class);
+    }
+
 }
diff --git a/integration-tests/java-joor-dsl/src/main/resources/routes/MyRoutes.java b/integration-tests/java-joor-dsl/src/main/resources/routes/MyRoutes.java
index fdcfa82266..065f921c43 100644
--- a/integration-tests/java-joor-dsl/src/main/resources/routes/MyRoutes.java
+++ b/integration-tests/java-joor-dsl/src/main/resources/routes/MyRoutes.java
@@ -14,6 +14,8 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+import java.util.function.Function;
+
 import io.quarkus.runtime.annotations.RegisterForReflection;
 import org.apache.camel.builder.RouteBuilder;
 
@@ -32,5 +34,18 @@ public class MyRoutes extends RouteBuilder {
                 Class<?> c2 = Thread.currentThread().getContextClassLoader().loadClass("org.apache.camel.quarkus.dsl.java.joor.JavaJoorDslBean$Inner");
                 exchange.getMessage().setBody(c2.getMethod("addSource", String.class).invoke(null, hi));
             });
+        from("direct:joorEcho")
+                .id("inner-classes-route")
+                .process(exchange -> {
+                    exchange.getMessage().setBody(Inner.format((String) exchange.getMessage().getBody()));
+                });
+    }
+
+    public static class Inner {
+
+        public static String format(String result) {
+            Function<String, String> toUpperCase = String::toUpperCase;
+            return String.format("Msg: %s", toUpperCase.apply(result));
+        }
     }
 }
\ No newline at end of file
diff --git a/integration-tests/java-joor-dsl/src/test/java/org/apache/camel/quarkus/dsl/java/joor/JavaJoorDslTest.java b/integration-tests/java-joor-dsl/src/test/java/org/apache/camel/quarkus/dsl/java/joor/JavaJoorDslTest.java
index 56862ea213..52bfde5bbd 100644
--- a/integration-tests/java-joor-dsl/src/test/java/org/apache/camel/quarkus/dsl/java/joor/JavaJoorDslTest.java
+++ b/integration-tests/java-joor-dsl/src/test/java/org/apache/camel/quarkus/dsl/java/joor/JavaJoorDslTest.java
@@ -45,6 +45,16 @@ class JavaJoorDslTest {
                 .body(CoreMatchers.is("Hi Will Smith from jOOR!"));
     }
 
+    @Test
+    void joorEcho() {
+        RestAssured.given()
+                .body("Ping")
+                .post("/java-joor-dsl/echo")
+                .then()
+                .statusCode(200)
+                .body(CoreMatchers.is("Msg: PING"));
+    }
+
     @Test
     void testMainInstanceWithJavaRoutes() {
         RestAssured.given()
@@ -63,6 +73,6 @@ class JavaJoorDslTest {
                 .get("/java-joor-dsl/main/routes")
                 .then()
                 .statusCode(200)
-                .body(CoreMatchers.is("my-java-route,reflection-route"));
+                .body(CoreMatchers.is("inner-classes-route,my-java-route,reflection-route"));
     }
 }


[camel-quarkus] 01/06: Ref #4716: java-joor-dsl - Add RegisterForReflection support (#4726)

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

nfilotto pushed a commit to branch 2.16.x
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git

commit 42c3c013c456c1c679e187d35acba206ff603ff7
Author: Nicolas Filotto <es...@users.noreply.github.com>
AuthorDate: Mon Apr 3 08:06:28 2023 +0200

    Ref #4716: java-joor-dsl - Add RegisterForReflection support (#4726)
    
    All the annotations added to a class managed by the extension `java-joor-dsl` are not considered by Quarkus since it is not part of the Jandex index.
    
    This change aims to support the annotation `RegisterForReflection` to easily configure the reflection in Camel-K.
    
    * Produce the corresponding `ReflectiveClassBuildItem` and  `LambdaCapturingTypeBuildItem` if a `RouteBuilder` is annotated with `RegisterForReflection`.
    * Add some doc to explain the limitations
    * Add a unit test to ensure that it works as expected
---
 .../pages/reference/extensions/java-joor-dsl.adoc  |  8 ++++
 .../java/joor/deployment/JavaJoorDslProcessor.java | 55 ++++++++++++++++++++++
 .../runtime/src/main/doc/limitations.adoc          |  3 ++
 .../quarkus/dsl/java/joor/JavaJoorDslBean.java}    | 20 +++++---
 .../quarkus/dsl/java/joor/JavaJoorDslResource.java | 10 +++-
 .../src/main/resources/routes/MyRoutes.java        | 14 +++++-
 .../quarkus/dsl/java/joor/JavaJoorDslTest.java     | 12 ++++-
 7 files changed, 112 insertions(+), 10 deletions(-)

diff --git a/docs/modules/ROOT/pages/reference/extensions/java-joor-dsl.adoc b/docs/modules/ROOT/pages/reference/extensions/java-joor-dsl.adoc
index 2461a370a6..edbf914728 100644
--- a/docs/modules/ROOT/pages/reference/extensions/java-joor-dsl.adoc
+++ b/docs/modules/ROOT/pages/reference/extensions/java-joor-dsl.adoc
@@ -43,3 +43,11 @@ Or add the coordinates to your existing project:
 ifeval::[{doc-show-user-guide-link} == true]
 Check the xref:user-guide/index.adoc[User guide] for more information about writing Camel Quarkus applications.
 endif::[]
+
+[id="extensions-java-joor-dsl-camel-quarkus-limitations"]
+== Camel Quarkus limitations
+
+The annotations added to the classes to be compiled by the component are ignored by Quarkus. The only annotation that is
+partially supported by the extension is the annotation `RegisterForReflection` to ease the configuration of the reflection
+for the native mode however please note that the element `registerFullHierarchy` is not supported.
+
diff --git a/extensions/java-joor-dsl/deployment/src/main/java/org/apache/camel/quarkus/dsl/java/joor/deployment/JavaJoorDslProcessor.java b/extensions/java-joor-dsl/deployment/src/main/java/org/apache/camel/quarkus/dsl/java/joor/deployment/JavaJoorDslProcessor.java
index c27528d110..a782e772c8 100644
--- a/extensions/java-joor-dsl/deployment/src/main/java/org/apache/camel/quarkus/dsl/java/joor/deployment/JavaJoorDslProcessor.java
+++ b/extensions/java-joor-dsl/deployment/src/main/java/org/apache/camel/quarkus/dsl/java/joor/deployment/JavaJoorDslProcessor.java
@@ -33,12 +33,14 @@ import io.quarkus.deployment.annotations.ExecutionTime;
 import io.quarkus.deployment.annotations.Record;
 import io.quarkus.deployment.builditem.FeatureBuildItem;
 import io.quarkus.deployment.builditem.GeneratedClassBuildItem;
+import io.quarkus.deployment.builditem.nativeimage.LambdaCapturingTypeBuildItem;
 import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
 import io.quarkus.deployment.pkg.builditem.CurateOutcomeBuildItem;
 import io.quarkus.deployment.pkg.steps.NativeBuild;
 import io.quarkus.maven.dependency.ResolvedDependency;
 import io.quarkus.paths.PathCollection;
 import io.quarkus.runtime.RuntimeValue;
+import io.quarkus.runtime.annotations.RegisterForReflection;
 import org.apache.camel.CamelContext;
 import org.apache.camel.dsl.java.joor.CompilationUnit;
 import org.apache.camel.dsl.java.joor.MultiCompile;
@@ -67,6 +69,8 @@ public class JavaJoorDslProcessor {
 
     @BuildStep(onlyIf = NativeBuild.class)
     void compileClassesAOT(BuildProducer<JavaJoorGeneratedClassBuildItem> generatedClass,
+            BuildProducer<ReflectiveClassBuildItem> reflectiveClass,
+            BuildProducer<LambdaCapturingTypeBuildItem> lambdaCapturingTypeProducer,
             CurateOutcomeBuildItem curateOutcomeBuildItem) throws Exception {
         Map<String, Resource> nameToResource = new HashMap<>();
         LOG.debug("Loading .java resources");
@@ -104,6 +108,8 @@ public class JavaJoorDslProcessor {
                 generatedClass
                         .produce(new JavaJoorGeneratedClassBuildItem(className, nameToResource.get(className).getLocation(),
                                 result.getByteCode(className)));
+                registerForReflection(reflectiveClass, lambdaCapturingTypeProducer,
+                        result.getClass(className).getAnnotation(RegisterForReflection.class));
             }
         } finally {
             // Restore the CP
@@ -111,6 +117,55 @@ public class JavaJoorDslProcessor {
         }
     }
 
+    private void registerForReflection(BuildProducer<ReflectiveClassBuildItem> reflectiveClass,
+            BuildProducer<LambdaCapturingTypeBuildItem> lambdaCapturingTypeProducer,
+            RegisterForReflection annotation) {
+        if (annotation == null) {
+            return;
+        }
+
+        for (String lambdaCapturingType : annotation.lambdaCapturingTypes()) {
+            lambdaCapturingTypeProducer.produce(new LambdaCapturingTypeBuildItem(lambdaCapturingType));
+        }
+        boolean methods = annotation.methods();
+        boolean fields = annotation.fields();
+        boolean ignoreNested = annotation.ignoreNested();
+        boolean serialization = annotation.serialization();
+
+        if (annotation.registerFullHierarchy()) {
+            LOG.warn(
+                    "The element 'registerFullHierarchy' of the annotation 'RegisterForReflection' is not supported by the extension Camel Java jOOR DSL");
+        }
+        for (Class<?> type : annotation.targets()) {
+            registerClass(type.getName(), methods, fields, ignoreNested, serialization, reflectiveClass);
+        }
+
+        for (String className : annotation.classNames()) {
+            registerClass(className, methods, fields, ignoreNested, serialization, reflectiveClass);
+        }
+    }
+
+    private void registerClass(String className, boolean methods, boolean fields, boolean ignoreNested, boolean serialization,
+            BuildProducer<ReflectiveClassBuildItem> reflectiveClass) {
+        reflectiveClass.produce(serialization
+                ? ReflectiveClassBuildItem.serializationClass(className)
+                : new ReflectiveClassBuildItem(methods, fields, className));
+
+        if (ignoreNested) {
+            return;
+        }
+
+        try {
+            Class<?>[] declaredClasses = Thread.currentThread().getContextClassLoader().loadClass(className)
+                    .getDeclaredClasses();
+            for (Class<?> clazz : declaredClasses) {
+                registerClass(clazz.getName(), methods, fields, false, serialization, reflectiveClass);
+            }
+        } catch (ClassNotFoundException e) {
+            LOG.warn("Failed to load Class {}", className, e);
+        }
+    }
+
     @BuildStep(onlyIf = NativeBuild.class)
     void registerGeneratedClasses(BuildProducer<GeneratedClassBuildItem> generatedClass,
             BuildProducer<ReflectiveClassBuildItem> reflectiveClass,
diff --git a/extensions/java-joor-dsl/runtime/src/main/doc/limitations.adoc b/extensions/java-joor-dsl/runtime/src/main/doc/limitations.adoc
new file mode 100644
index 0000000000..a818c7f8a9
--- /dev/null
+++ b/extensions/java-joor-dsl/runtime/src/main/doc/limitations.adoc
@@ -0,0 +1,3 @@
+The annotations added to the classes to be compiled by the component are ignored by Quarkus. The only annotation that is
+partially supported by the extension is the annotation `RegisterForReflection` to ease the configuration of the reflection
+for the native mode however please note that the element `registerFullHierarchy` is not supported.
\ No newline at end of file
diff --git a/integration-tests/java-joor-dsl/src/main/resources/routes/MyRoutes.java b/integration-tests/java-joor-dsl/src/main/java/org/apache/camel/quarkus/dsl/java/joor/JavaJoorDslBean.java
similarity index 70%
copy from integration-tests/java-joor-dsl/src/main/resources/routes/MyRoutes.java
copy to integration-tests/java-joor-dsl/src/main/java/org/apache/camel/quarkus/dsl/java/joor/JavaJoorDslBean.java
index 590dfe1d97..cea1834ff0 100644
--- a/integration-tests/java-joor-dsl/src/main/resources/routes/MyRoutes.java
+++ b/integration-tests/java-joor-dsl/src/main/java/org/apache/camel/quarkus/dsl/java/joor/JavaJoorDslBean.java
@@ -14,11 +14,17 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-public class MyRoutes extends org.apache.camel.builder.RouteBuilder {
-    @Override
-    public void configure() throws Exception {
-        from("direct:joorHello")
-            .id("my-java-route")
-            .setBody(exchange -> "Hello " + exchange.getMessage().getBody()  + " from jOOR!");
+package org.apache.camel.quarkus.dsl.java.joor;
+
+public class JavaJoorDslBean {
+
+    public static String hi(String name) {
+        return String.format("Hi %s", name);
     }
-}
\ No newline at end of file
+
+    public static class Inner {
+        public static String addSource(String value) {
+            return String.format("%s from jOOR!", value);
+        }
+    }
+}
diff --git a/integration-tests/java-joor-dsl/src/main/java/org/apache/camel/quarkus/dsl/java/joor/JavaJoorDslResource.java b/integration-tests/java-joor-dsl/src/main/java/org/apache/camel/quarkus/dsl/java/joor/JavaJoorDslResource.java
index 1c5cd0bf0e..049f24a358 100644
--- a/integration-tests/java-joor-dsl/src/main/java/org/apache/camel/quarkus/dsl/java/joor/JavaJoorDslResource.java
+++ b/integration-tests/java-joor-dsl/src/main/java/org/apache/camel/quarkus/dsl/java/joor/JavaJoorDslResource.java
@@ -76,8 +76,16 @@ public class JavaJoorDslResource {
     @Path("/hello")
     @Consumes(MediaType.TEXT_PLAIN)
     @Produces(MediaType.TEXT_PLAIN)
-    public String hello(String message) throws Exception {
+    public String hello(String message) {
         return producerTemplate.requestBody("direct:joorHello", message, String.class);
     }
 
+    @POST
+    @Path("/hi")
+    @Consumes(MediaType.TEXT_PLAIN)
+    @Produces(MediaType.TEXT_PLAIN)
+    public String hi(String name) {
+        return producerTemplate.requestBody("direct:joorHi", name, String.class);
+    }
+
 }
diff --git a/integration-tests/java-joor-dsl/src/main/resources/routes/MyRoutes.java b/integration-tests/java-joor-dsl/src/main/resources/routes/MyRoutes.java
index 590dfe1d97..fdcfa82266 100644
--- a/integration-tests/java-joor-dsl/src/main/resources/routes/MyRoutes.java
+++ b/integration-tests/java-joor-dsl/src/main/resources/routes/MyRoutes.java
@@ -14,11 +14,23 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-public class MyRoutes extends org.apache.camel.builder.RouteBuilder {
+import io.quarkus.runtime.annotations.RegisterForReflection;
+import org.apache.camel.builder.RouteBuilder;
+
+@RegisterForReflection(classNames = "org.apache.camel.quarkus.dsl.java.joor.JavaJoorDslBean", ignoreNested = false)
+public class MyRoutes extends RouteBuilder {
     @Override
     public void configure() throws Exception {
         from("direct:joorHello")
             .id("my-java-route")
             .setBody(exchange -> "Hello " + exchange.getMessage().getBody()  + " from jOOR!");
+        from("direct:joorHi")
+            .id("reflection-route")
+            .process(exchange -> {
+                Class<?> c = Thread.currentThread().getContextClassLoader().loadClass("org.apache.camel.quarkus.dsl.java.joor.JavaJoorDslBean");
+                Object hi = c.getMethod("hi", String.class).invoke(null, exchange.getMessage().getBody());
+                Class<?> c2 = Thread.currentThread().getContextClassLoader().loadClass("org.apache.camel.quarkus.dsl.java.joor.JavaJoorDslBean$Inner");
+                exchange.getMessage().setBody(c2.getMethod("addSource", String.class).invoke(null, hi));
+            });
     }
 }
\ No newline at end of file
diff --git a/integration-tests/java-joor-dsl/src/test/java/org/apache/camel/quarkus/dsl/java/joor/JavaJoorDslTest.java b/integration-tests/java-joor-dsl/src/test/java/org/apache/camel/quarkus/dsl/java/joor/JavaJoorDslTest.java
index 3fbf057b98..56862ea213 100644
--- a/integration-tests/java-joor-dsl/src/test/java/org/apache/camel/quarkus/dsl/java/joor/JavaJoorDslTest.java
+++ b/integration-tests/java-joor-dsl/src/test/java/org/apache/camel/quarkus/dsl/java/joor/JavaJoorDslTest.java
@@ -35,6 +35,16 @@ class JavaJoorDslTest {
                 .body(CoreMatchers.is("Hello Camelus bactrianus from jOOR!"));
     }
 
+    @Test
+    void joorHi() {
+        RestAssured.given()
+                .body("Will Smith")
+                .post("/java-joor-dsl/hi")
+                .then()
+                .statusCode(200)
+                .body(CoreMatchers.is("Hi Will Smith from jOOR!"));
+    }
+
     @Test
     void testMainInstanceWithJavaRoutes() {
         RestAssured.given()
@@ -53,6 +63,6 @@ class JavaJoorDslTest {
                 .get("/java-joor-dsl/main/routes")
                 .then()
                 .statusCode(200)
-                .body(CoreMatchers.is("my-java-route"));
+                .body(CoreMatchers.is("my-java-route,reflection-route"));
     }
 }


[camel-quarkus] 05/06: Ref #4447: java-joor-dsl - Improve the test coverage

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

nfilotto pushed a commit to branch 2.16.x
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git

commit 25a814735a077efc7401b175abe909a6313342d7
Author: Nicolas Filotto <nf...@talend.com>
AuthorDate: Mon Apr 3 15:44:10 2023 +0200

    Ref #4447: java-joor-dsl - Improve the test coverage
---
 integration-tests/java-joor-dsl/pom.xml            | 51 ++++++++++++++++++++++
 .../quarkus/dsl/java/joor/JavaJoorDslResource.java | 21 +++++++++
 .../src/main/resources/application.properties      |  2 +-
 .../src/main/resources/routes/MyBar.java           | 29 ++++++++++++
 .../src/main/resources/routes/MyBarEcho.java       | 30 +++++++++++++
 .../src/main/resources/routes/MyBarRoute.java      | 28 ++++++++++++
 .../main/resources/routes/MyRoutesWithBeans.java   | 38 ++++++++++++++++
 .../main/resources/routes/MyRoutesWithModel.java   | 36 +++++++++++++++
 .../resources/routes/MyRoutesWithNestedClass.java  | 40 +++++++++++++++++
 .../src/main/resources/routes/MyUser.java          | 46 +++++++++++++++++++
 .../quarkus/dsl/java/joor/JavaJoorDslTest.java     | 21 ++++++++-
 11 files changed, 340 insertions(+), 2 deletions(-)

diff --git a/integration-tests/java-joor-dsl/pom.xml b/integration-tests/java-joor-dsl/pom.xml
index 905f083e95..1ca826a316 100644
--- a/integration-tests/java-joor-dsl/pom.xml
+++ b/integration-tests/java-joor-dsl/pom.xml
@@ -39,6 +39,18 @@
             <groupId>org.apache.camel.quarkus</groupId>
             <artifactId>camel-quarkus-direct</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.apache.camel.quarkus</groupId>
+            <artifactId>camel-quarkus-jackson</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.camel.quarkus</groupId>
+            <artifactId>camel-quarkus-bean</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.camel.quarkus</groupId>
+            <artifactId>camel-quarkus-rest</artifactId>
+        </dependency>
         <dependency>
             <groupId>io.quarkus</groupId>
             <artifactId>quarkus-resteasy</artifactId>
@@ -72,6 +84,19 @@
             </activation>
             <dependencies>
                 <!-- The following dependencies guarantee that this module is built after them. You can update them by running `mvn process-resources -Pformat -N` from the source tree root directory -->
+                <dependency>
+                    <groupId>org.apache.camel.quarkus</groupId>
+                    <artifactId>camel-quarkus-bean-deployment</artifactId>
+                    <version>${project.version}</version>
+                    <type>pom</type>
+                    <scope>test</scope>
+                    <exclusions>
+                        <exclusion>
+                            <groupId>*</groupId>
+                            <artifactId>*</artifactId>
+                        </exclusion>
+                    </exclusions>
+                </dependency>
                 <dependency>
                     <groupId>org.apache.camel.quarkus</groupId>
                     <artifactId>camel-quarkus-direct-deployment</artifactId>
@@ -98,6 +123,32 @@
                         </exclusion>
                     </exclusions>
                 </dependency>
+                <dependency>
+                    <groupId>org.apache.camel.quarkus</groupId>
+                    <artifactId>camel-quarkus-jackson-deployment</artifactId>
+                    <version>${project.version}</version>
+                    <type>pom</type>
+                    <scope>test</scope>
+                    <exclusions>
+                        <exclusion>
+                            <groupId>*</groupId>
+                            <artifactId>*</artifactId>
+                        </exclusion>
+                    </exclusions>
+                </dependency>
+                <dependency>
+                    <groupId>org.apache.camel.quarkus</groupId>
+                    <artifactId>camel-quarkus-rest-deployment</artifactId>
+                    <version>${project.version}</version>
+                    <type>pom</type>
+                    <scope>test</scope>
+                    <exclusions>
+                        <exclusion>
+                            <groupId>*</groupId>
+                            <artifactId>*</artifactId>
+                        </exclusion>
+                    </exclusions>
+                </dependency>
             </dependencies>
         </profile>
         <profile>
diff --git a/integration-tests/java-joor-dsl/src/main/java/org/apache/camel/quarkus/dsl/java/joor/JavaJoorDslResource.java b/integration-tests/java-joor-dsl/src/main/java/org/apache/camel/quarkus/dsl/java/joor/JavaJoorDslResource.java
index 5f08ccbeea..f780863002 100644
--- a/integration-tests/java-joor-dsl/src/main/java/org/apache/camel/quarkus/dsl/java/joor/JavaJoorDslResource.java
+++ b/integration-tests/java-joor-dsl/src/main/java/org/apache/camel/quarkus/dsl/java/joor/JavaJoorDslResource.java
@@ -16,6 +16,7 @@
  */
 package org.apache.camel.quarkus.dsl.java.joor;
 
+import java.util.Set;
 import java.util.stream.Collectors;
 
 import javax.enterprise.context.ApplicationScoped;
@@ -27,13 +28,16 @@ import javax.ws.rs.Path;
 import javax.ws.rs.Produces;
 import javax.ws.rs.core.MediaType;
 
+import io.quarkus.runtime.annotations.RegisterForReflection;
 import org.apache.camel.ExtendedCamelContext;
 import org.apache.camel.ProducerTemplate;
 import org.apache.camel.Route;
+import org.apache.camel.component.direct.DirectEndpoint;
 import org.apache.camel.dsl.java.joor.JavaRoutesBuilderLoader;
 import org.apache.camel.quarkus.main.CamelMain;
 import org.apache.camel.spi.RoutesBuilderLoader;
 
+@RegisterForReflection(targets = String.class)
 @Path("/java-joor-dsl")
 @ApplicationScoped
 public class JavaJoorDslResource {
@@ -72,6 +76,23 @@ public class JavaJoorDslResource {
                 .collect(Collectors.joining(","));
     }
 
+    @GET
+    @Path("/main/successful/routes")
+    @Consumes(MediaType.TEXT_PLAIN)
+    @Produces(MediaType.TEXT_PLAIN)
+    public int successfulRoutes() {
+        int successful = 0;
+        Set<String> excluded = Set.of("my-java-route", "reflection-route", "inner-classes-route", "routes-with-rest");
+        for (Route route : main.getCamelContext().getRoutes()) {
+            String name = route.getRouteId();
+            if (route.getEndpoint() instanceof DirectEndpoint && !excluded.contains(name)
+                    && Boolean.TRUE.equals(producerTemplate.requestBody(route.getEndpoint(), "", Boolean.class))) {
+                successful++;
+            }
+        }
+        return successful;
+    }
+
     @POST
     @Path("/hello")
     @Consumes(MediaType.TEXT_PLAIN)
diff --git a/integration-tests/java-joor-dsl/src/main/resources/application.properties b/integration-tests/java-joor-dsl/src/main/resources/application.properties
index 0b17e9e265..e03850aeee 100644
--- a/integration-tests/java-joor-dsl/src/main/resources/application.properties
+++ b/integration-tests/java-joor-dsl/src/main/resources/application.properties
@@ -18,4 +18,4 @@
 #
 # Main
 #
-camel.main.routes-include-pattern = classpath:routes/MyRoutes.java
+camel.main.routes-include-pattern = classpath:routes/*.java
diff --git a/integration-tests/java-joor-dsl/src/main/resources/routes/MyBar.java b/integration-tests/java-joor-dsl/src/main/resources/routes/MyBar.java
new file mode 100644
index 0000000000..2bf03dcf76
--- /dev/null
+++ b/integration-tests/java-joor-dsl/src/main/resources/routes/MyBar.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.
+ */
+
+public class MyBar {
+
+    private String name;
+
+    public MyBar(String name) {
+        this.name = name;
+    }
+
+    public String getName() {
+        return name;
+    }
+}
\ No newline at end of file
diff --git a/integration-tests/java-joor-dsl/src/main/resources/routes/MyBarEcho.java b/integration-tests/java-joor-dsl/src/main/resources/routes/MyBarEcho.java
new file mode 100644
index 0000000000..f2efc91170
--- /dev/null
+++ b/integration-tests/java-joor-dsl/src/main/resources/routes/MyBarEcho.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
+ *
+ *      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.
+ */
+import io.quarkus.runtime.annotations.RegisterForReflection;
+import org.apache.camel.BindToRegistry;
+
+@RegisterForReflection
+@BindToRegistry("myBarEcho")
+public class MyBarEcho {
+
+    private MyBar bar = new MyBar("Moes Bar");
+
+    public String echo(String s) {
+        return s + " is at " + bar.getName();
+    }
+
+}
\ No newline at end of file
diff --git a/integration-tests/java-joor-dsl/src/main/resources/routes/MyBarRoute.java b/integration-tests/java-joor-dsl/src/main/resources/routes/MyBarRoute.java
new file mode 100644
index 0000000000..202f18d0fb
--- /dev/null
+++ b/integration-tests/java-joor-dsl/src/main/resources/routes/MyBarRoute.java
@@ -0,0 +1,28 @@
+/*
+ * 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.
+ */
+import org.apache.camel.builder.RouteBuilder;
+
+public class MyBarRoute extends RouteBuilder {
+
+    @Override
+    public void configure() throws Exception {
+        from("direct:routes-with-bean")
+                .id("routes-with-bean")
+                .bean("myBarEcho")
+                .setBody().simple("${body.endsWith(' is at Moes Bar')}");
+    }
+}
\ No newline at end of file
diff --git a/integration-tests/java-joor-dsl/src/main/resources/routes/MyRoutesWithBeans.java b/integration-tests/java-joor-dsl/src/main/resources/routes/MyRoutesWithBeans.java
new file mode 100644
index 0000000000..3896398a32
--- /dev/null
+++ b/integration-tests/java-joor-dsl/src/main/resources/routes/MyRoutesWithBeans.java
@@ -0,0 +1,38 @@
+/*
+ * 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.
+ */
+import io.quarkus.runtime.annotations.RegisterForReflection;
+import org.apache.camel.BindToRegistry;
+import org.apache.camel.builder.RouteBuilder;
+
+@RegisterForReflection(ignoreNested = false)
+public class MyRoutesWithBeans extends RouteBuilder {
+    @Override
+    public void configure() throws Exception {
+        from("direct:routes-with-inner-bean")
+            .id("routes-with-inner-bean")
+            .bean("myBean")
+            .setBody().simple("${body.endsWith('John!')}");
+    }
+
+    @BindToRegistry("myBean")
+    public static class MyBean {
+
+        public String hi() {
+            return "Hi John!";
+        }
+    }
+}
\ No newline at end of file
diff --git a/integration-tests/java-joor-dsl/src/main/resources/routes/MyRoutesWithModel.java b/integration-tests/java-joor-dsl/src/main/resources/routes/MyRoutesWithModel.java
new file mode 100644
index 0000000000..c5997b823b
--- /dev/null
+++ b/integration-tests/java-joor-dsl/src/main/resources/routes/MyRoutesWithModel.java
@@ -0,0 +1,36 @@
+/*
+ * 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.
+ */
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.model.dataformat.JsonLibrary;
+
+public class MyRoutesWithModel extends RouteBuilder {
+    @Override
+    public void configure() throws Exception {
+        rest("/say")
+            .get("/emp/{id}")
+                .id("routes-with-rest-get")
+                .produces("application/json")
+                .outType(MyUser.class)
+                .to("direct:routes-with-rest");
+
+        from("direct:routes-with-rest")
+            .id("routes-with-rest")
+            .process(exchange -> exchange.getMessage().setBody(new MyUser("Bruce", 68)))
+            .marshal().json(JsonLibrary.Jackson);
+    }
+}
\ No newline at end of file
diff --git a/integration-tests/java-joor-dsl/src/main/resources/routes/MyRoutesWithNestedClass.java b/integration-tests/java-joor-dsl/src/main/resources/routes/MyRoutesWithNestedClass.java
new file mode 100644
index 0000000000..aaac2f15e9
--- /dev/null
+++ b/integration-tests/java-joor-dsl/src/main/resources/routes/MyRoutesWithNestedClass.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
+ *
+ *      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.
+ */
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+
+public class MyRoutesWithNestedClass extends RouteBuilder {
+    @Override
+    public void configure() throws Exception {
+        Processor toUpper = new Processor() {
+            @Override
+            public void process(Exchange exchange) throws Exception {
+                String body = exchange.getIn().getBody(String.class);
+                body = body.toUpperCase();
+
+                exchange.getMessage().setBody(body);
+            }
+        };
+
+        from("direct:routes-with-nested-class")
+            .id("routes-with-nested-class")
+            .setBody().constant("Some Content")
+            .process(toUpper)
+            .setBody().simple("${body.endsWith('CONTENT')}");
+    }
+}
\ No newline at end of file
diff --git a/integration-tests/java-joor-dsl/src/main/resources/routes/MyUser.java b/integration-tests/java-joor-dsl/src/main/resources/routes/MyUser.java
new file mode 100644
index 0000000000..104791b080
--- /dev/null
+++ b/integration-tests/java-joor-dsl/src/main/resources/routes/MyUser.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.
+ */
+
+import io.quarkus.runtime.annotations.RegisterForReflection;
+
+@RegisterForReflection
+public class MyUser {
+
+    private String name;
+    private int age;
+
+    public MyUser(String name, int age) {
+        this.name = name;
+        this.age = age;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public int getAge() {
+        return age;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public void setAge(int age) {
+        this.age = age;
+    }
+}
diff --git a/integration-tests/java-joor-dsl/src/test/java/org/apache/camel/quarkus/dsl/java/joor/JavaJoorDslTest.java b/integration-tests/java-joor-dsl/src/test/java/org/apache/camel/quarkus/dsl/java/joor/JavaJoorDslTest.java
index 52bfde5bbd..38998a3cb5 100644
--- a/integration-tests/java-joor-dsl/src/test/java/org/apache/camel/quarkus/dsl/java/joor/JavaJoorDslTest.java
+++ b/integration-tests/java-joor-dsl/src/test/java/org/apache/camel/quarkus/dsl/java/joor/JavaJoorDslTest.java
@@ -22,6 +22,8 @@ import org.apache.camel.dsl.java.joor.JavaRoutesBuilderLoader;
 import org.hamcrest.CoreMatchers;
 import org.junit.jupiter.api.Test;
 
+import static org.hamcrest.CoreMatchers.equalTo;
+
 @QuarkusTest
 class JavaJoorDslTest {
 
@@ -73,6 +75,23 @@ class JavaJoorDslTest {
                 .get("/java-joor-dsl/main/routes")
                 .then()
                 .statusCode(200)
-                .body(CoreMatchers.is("inner-classes-route,my-java-route,reflection-route"));
+                .body(CoreMatchers.is(
+                        "inner-classes-route,my-java-route,reflection-route,routes-with-bean,routes-with-inner-bean,routes-with-nested-class,routes-with-rest,routes-with-rest-get"));
+
+        RestAssured.given()
+                .get("/java-joor-dsl/main/successful/routes")
+                .then()
+                .statusCode(200)
+                .body(CoreMatchers.is("3"));
+    }
+
+    @Test
+    void testRestEndpoints() {
+        RestAssured.given()
+                .get("/say/emp/123")
+                .then()
+                .log().ifValidationFails()
+                .statusCode(200)
+                .body("name", equalTo("Bruce"), "age", equalTo(68));
     }
 }


[camel-quarkus] 03/06: Ref #4731: java-joor-dsl - Add support of anonymous classes

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

nfilotto pushed a commit to branch 2.16.x
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git

commit 3b54f7bf5adfd58a0b4478192dcc7ddbaf3de60f
Author: Nicolas Filotto <nf...@talend.com>
AuthorDate: Mon Apr 3 15:41:14 2023 +0200

    Ref #4731: java-joor-dsl - Add support of anonymous classes
---
 .../quarkus/dsl/java/joor/deployment/JavaJoorDslProcessor.java | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/extensions/java-joor-dsl/deployment/src/main/java/org/apache/camel/quarkus/dsl/java/joor/deployment/JavaJoorDslProcessor.java b/extensions/java-joor-dsl/deployment/src/main/java/org/apache/camel/quarkus/dsl/java/joor/deployment/JavaJoorDslProcessor.java
index 7e72562f78..4b1d577c26 100644
--- a/extensions/java-joor-dsl/deployment/src/main/java/org/apache/camel/quarkus/dsl/java/joor/deployment/JavaJoorDslProcessor.java
+++ b/extensions/java-joor-dsl/deployment/src/main/java/org/apache/camel/quarkus/dsl/java/joor/deployment/JavaJoorDslProcessor.java
@@ -115,6 +115,16 @@ public class JavaJoorDslProcessor {
                             .produce(new JavaJoorGeneratedClassBuildItem(name, nameToResource.get(className).getLocation(),
                                     result.getByteCode(name)));
                 }
+                for (int i = 1;; i++) {
+                    String name = String.format("%s$%d", className, i);
+                    byte[] content = result.getByteCode(name);
+                    if (content == null) {
+                        break;
+                    }
+                    generatedClass
+                            .produce(new JavaJoorGeneratedClassBuildItem(name, nameToResource.get(className).getLocation(),
+                                    content));
+                }
                 registerForReflection(reflectiveClass, lambdaCapturingTypeProducer,
                         aClass.getAnnotation(RegisterForReflection.class));
             }