camel-quarkus icon indicating copy to clipboard operation
camel-quarkus copied to clipboard

Inspect routes to detect classes that may require reflection

Open lburgazzoli opened this issue 6 years ago • 9 comments

Assuming we have a route that contains something like:

.bean(OrderService.class, "doSomething")

Then the OrderService should be listed among the classes that require reflection.

lburgazzoli avatar Jul 26 '19 07:07 lburgazzoli

Plz. assign to me.

ppalaga avatar Aug 23 '19 13:08 ppalaga

We should also find a way for the end user to add RegisterForReflection to third party classes.

ppalaga avatar Aug 29 '19 13:08 ppalaga

We should also find a way for the end user to add RegisterForReflection to third party classes.

Quarkus offers a solution for that https://quarkus.io/guides/writing-native-applications-tips#using-a-configuration-file

ppalaga avatar Sep 05 '19 09:09 ppalaga

well, this is just plain substrate thing that we know it works, would be nice to detect such files and automatically add the related build config bits

lburgazzoli avatar Sep 05 '19 09:09 lburgazzoli

Yes, I am working on the autodetection part.

ppalaga avatar Sep 05 '19 11:09 ppalaga

To autodetect anything in the Routes, we'd need a way to get the org.apache.camel.model.Model at build time without having to instantiate the CamelContext. That would be handy not only for registering beans for reflection, but also for other things such as finding which XSLT resources need to get compiled into translets or which XSD resources need to get included in the native executable.

Getting org.apache.camel.model.Model without a CamelContext is not possible now, at least not with the current Route(s)Builder. Perhaps we could introduce a new implementation able do that.

ppalaga avatar Nov 28 '19 21:11 ppalaga

onException handling would also profit from build time route inspection as onException(MyException.class) would require MyException.class to be listed among the classes that require reflection.

aldettinger avatar Aug 25 '20 13:08 aldettinger

And a more tricky case described here: https://camel.zulipchat.com/#narrow/stream/257302-camel-quarkus/topic/MethodNotFoundException.20using.20YAML.20DSL.20with.20native-image

Executing the simple expression below would need to register the String class as reflective:

 simple:
                    expression: '${body.replaceAll("^data: *", "")}'
                    resultType: java.lang.String

This is even language level inspection. Maybe in such a case, it's even better to log a warning stating that csimple is a better option. Let's see.

aldettinger avatar Feb 07 '23 09:02 aldettinger

onException handling would also profit from build time route inspection as onException(MyException.class) would require MyException.class to be listed among the classes that require reflection.

reported https://github.com/apache/camel-quarkus/issues/7841

There are also some other cases related to "exceptions":

  • failoverLoadBalancer https://github.com/apache/camel/blob/3391efae2d468908f739ce7b1163a0308279d66a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/failoverLoadBalancer.json#L16
  • doCatch https://github.com/apache/camel/blob/3391efae2d468908f739ce7b1163a0308279d66a/core/camel-core-model/src/generated/resources/META-INF/org/apache/camel/model/doCatch.json#L18
  • resilience4j (?) https://github.com/apache/camel/blob/3391efae2d468908f739ce7b1163a0308279d66a/core/camel-core-model/src/generated/resources/META-INF/org/apache/camel/model/resilience4jConfiguration.json#L37
  • throwException https://github.com/apache/camel/blob/3391efae2d468908f739ce7b1163a0308279d66a/core/camel-core-model/src/generated/resources/META-INF/org/apache/camel/model/throwException.json#L19

apupier avatar Oct 15 '25 16:10 apupier