You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by GitBox <gi...@apache.org> on 2022/01/10 15:05:29 UTC

[GitHub] [camel] zhfeng commented on a change in pull request #6705: light rework of CDI module to make it using CDI 2 API and have jta an…

zhfeng commented on a change in pull request #6705:
URL: https://github.com/apache/camel/pull/6705#discussion_r781271454



##########
File path: components/camel-cdi-jta/src/main/java/org/apache/camel/cdi/transaction/TransactionalJtaTransactionPolicy.java
##########
@@ -47,6 +52,13 @@
             "java:pm/TransactionManager",
             "java:/TransactionManager"
     };
+    private static final String[] METHODS = new String[] {
+            "org.openejb.OpenEJB.getTransactionManager",
+            "com.arjuna.jta.JTA_TransactionManager.transactionManager",

Review comment:
       It should be "com.arjuna.ats.jta.TransactionManager.transactionManager" for narayana.

##########
File path: components/camel-cdi-jta/src/main/java/org/apache/camel/cdi/transaction/TransactionalJtaTransactionPolicy.java
##########
@@ -81,6 +94,30 @@ 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);
+                    return (TransactionManager) getter.invoke(null);

Review comment:
       It could be better to check the result is not **null**.




-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org