orpiske commented on a change in pull request #6705:
URL: https://github.com/apache/camel/pull/6705#discussion_r781478259
##########
File path:
components/camel-cdi-jta/src/main/java/org/apache/camel/cdi/transaction/TransactionalJtaTransactionPolicy.java
##########
@@ -81,6 +94,33 @@ private TransactionManager lookupTransactionManager() {
LOG.debug("No JTA TransactionManager found at JNDI location
[{}]", jndiName, ex);
}
}
+ var loaders =
Stream.of(Thread.currentThread().getContextClassLoader(),
getClass().getClassLoader())
+ .filter(Objects::nonNull)
+ .distinct()
+ .collect(toList());
+ for (String method : METHODS) {
+ final int sep = method.lastIndexOf('.');
+ try {
+ Class<?> clazz = null;
+ for (final var loader : loaders) {
+ try {
+ clazz = loader.loadClass(method.substring(0, sep));
+ } catch (final NoClassDefFoundError |
ClassNotFoundException cnfe) {
+ // continue
+ }
+ }
+ if (clazz != null) {
+ final var getter =
clazz.getDeclaredMethod(method.substring(sep + 1));
+ getter.setAccessible(true);
+ final var txMgr = (TransactionManager) getter.invoke(null);
+ if (txMgr != null) {
+ return txMgr;
+ }
+ }
+ } catch (final Throwable t) {
Review comment:
I'd probably avoid caching Throwable, as it can catch serious JVM-raised
errors like OutOfMemoryError and StackOverFlowError.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]