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 13:50:23 UTC

[GitHub] [camel] rmannibucau opened a new pull request #6705: light rework of CDI module to make it using CDI 2 API and have jta an…

rmannibucau opened a new pull request #6705:
URL: https://github.com/apache/camel/pull/6705


   …d mocks deps optional
   
   <!-- Uncomment and fill this section if your PR is not trivial
   - [ ] Make sure there is a [JIRA issue](https://issues.apache.org/jira/browse/CAMEL) filed for the change (usually before you start working on it).  Trivial changes like typos do not require a JIRA issue.  Your pull request should address just this issue, without pulling in other changes.
   - [ ] Each commit in the pull request should have a meaningful subject line and body.
   - [ ] If you're unsure, you can format the pull request title like `[CAMEL-XXX] Fixes bug in camel-file component`, where you replace `CAMEL-XXX` with the appropriate JIRA issue.
   - [ ] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
   - [ ] Run `mvn clean install -Psourcecheck` in your module with source check enabled to make sure basic checks pass and there are no checkstyle violations. A more thorough check will be performed on your pull request automatically.
   Below are the contribution guidelines:
   https://github.com/apache/camel/blob/main/CONTRIBUTING.md
   -->
   


-- 
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



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

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

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



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

Posted by GitBox <gi...@apache.org>.
rmannibucau commented on a change in pull request #6705:
URL: https://github.com/apache/camel/pull/6705#discussion_r781406351



##########
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:
       Fixed




-- 
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



[GitHub] [camel] davsclaus merged pull request #6705: light rework of CDI module to make it using CDI 2 API and have jta an…

Posted by GitBox <gi...@apache.org>.
davsclaus merged pull request #6705:
URL: https://github.com/apache/camel/pull/6705


   


-- 
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



[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…

Posted by GitBox <gi...@apache.org>.
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



[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…

Posted by GitBox <gi...@apache.org>.
zhfeng commented on a change in pull request #6705:
URL: https://github.com/apache/camel/pull/6705#discussion_r781702551



##########
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.TransactionManager.transactionManager",

Review comment:
       It should be ```com.arjuna.ats.jta.TransactionManager.transactionManager```
   




-- 
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