cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ashaki...@apache.org
Subject cxf git commit: [CXF-6425]: Added check for existing transactions
Date Thu, 28 May 2015 10:57:17 GMT
Repository: cxf
Updated Branches:
  refs/heads/master 985b824e0 -> aa5ef9fc7


[CXF-6425]: Added check for existing transactions


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/aa5ef9fc
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/aa5ef9fc
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/aa5ef9fc

Branch: refs/heads/master
Commit: aa5ef9fc7ed198021a246f99429d00863f336948
Parents: 985b824
Author: Andrei Shakirin <andrei.shakirin@gmail.com>
Authored: Thu May 28 12:57:03 2015 +0200
Committer: Andrei Shakirin <andrei.shakirin@gmail.com>
Committed: Thu May 28 12:57:03 2015 +0200

----------------------------------------------------------------------
 .../jms/util/MessageListenerContainer.java       |  4 +++-
 .../util/PollingMessageListenerContainer.java    | 19 ++++++++++++++-----
 2 files changed, 17 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/aa5ef9fc/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/util/MessageListenerContainer.java
----------------------------------------------------------------------
diff --git a/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/util/MessageListenerContainer.java
b/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/util/MessageListenerContainer.java
index 605c43f..3fc9918 100644
--- a/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/util/MessageListenerContainer.java
+++ b/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/util/MessageListenerContainer.java
@@ -106,7 +106,9 @@ public class MessageListenerContainer extends AbstractMessageListenerContainer
{
         private void safeRollback(Throwable t) {
             LOG.log(Level.WARNING, "Exception while processing jms message in cxf. Rolling
back" , t);
             try {
-                session.rollback();
+                if (session.getTransacted()) {
+                    session.rollback();
+                }
             } catch (Exception e) {
                 LOG.log(Level.WARNING, "Rollback of Local transaction failed", e);
             }

http://git-wip-us.apache.org/repos/asf/cxf/blob/aa5ef9fc/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/util/PollingMessageListenerContainer.java
----------------------------------------------------------------------
diff --git a/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/util/PollingMessageListenerContainer.java
b/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/util/PollingMessageListenerContainer.java
index 8c68338..37d0080 100644
--- a/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/util/PollingMessageListenerContainer.java
+++ b/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/util/PollingMessageListenerContainer.java
@@ -104,7 +104,10 @@ public class PollingMessageListenerContainer extends AbstractMessageListenerCont
                 MessageConsumer consumer = null;
                 Session session = null;
                 try {
-                    transactionManager.begin();
+                    boolean isExternalTransaction = transactionManager.getTransaction() !=
null;
+                    if (!isExternalTransaction) {
+                        transactionManager.begin();
+                    }
                     /*
                      * Create session inside transaction to give it the 
                      * chance to enlist itself as a resource
@@ -116,10 +119,12 @@ public class PollingMessageListenerContainer extends AbstractMessageListenerCont
                         if (message != null) {
                             listenerHandler.onMessage(message);
                         }
-                        transactionManager.commit();
+                        if (!isExternalTransaction) {
+                            transactionManager.commit();
+                        }
                     } catch (Exception e) {
                         LOG.log(Level.WARNING, "Exception while processing jms message in
cxf. Rolling back", e);
-                        safeRollBack(session);
+                        safeRollBack(session, isExternalTransaction);
                     } finally {
                         ResourceCloser.close(consumer);
                         ResourceCloser.close(session);
@@ -132,9 +137,13 @@ public class PollingMessageListenerContainer extends AbstractMessageListenerCont
 
         }
         
-        private void safeRollBack(Session session) {
+        private void safeRollBack(Session session, boolean isExternalTransaction) {
             try {
-                transactionManager.rollback();
+                if (isExternalTransaction) {
+                    transactionManager.setRollbackOnly();
+                } else {
+                    transactionManager.rollback();
+                }
             } catch (Exception e) {
                 LOG.log(Level.WARNING, "Rollback of XA transaction failed", e);
             }


Mime
View raw message