Inspect routes to detect classes that may require reflection
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.
Plz. assign to me.
We should also find a way for the end user to add RegisterForReflection to third party classes.
We should also find a way for the end user to add
RegisterForReflectionto third party classes.
Quarkus offers a solution for that https://quarkus.io/guides/writing-native-applications-tips#using-a-configuration-file
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
Yes, I am working on the autodetection part.
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.
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.
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.
onException handling would also profit from build time route inspection as
onException(MyException.class)would requireMyException.classto 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