Return-Path: X-Original-To: apmail-activemq-commits-archive@www.apache.org Delivered-To: apmail-activemq-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 508C811FA6 for ; Thu, 7 Aug 2014 12:48:37 +0000 (UTC) Received: (qmail 3218 invoked by uid 500); 7 Aug 2014 12:48:37 -0000 Delivered-To: apmail-activemq-commits-archive@activemq.apache.org Received: (qmail 3176 invoked by uid 500); 7 Aug 2014 12:48:37 -0000 Mailing-List: contact commits-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@activemq.apache.org Delivered-To: mailing list commits@activemq.apache.org Received: (qmail 3167 invoked by uid 99); 7 Aug 2014 12:48:37 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 07 Aug 2014 12:48:37 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id B19399C24A6; Thu, 7 Aug 2014 12:48:36 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: gtully@apache.org To: commits@activemq.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: git commit: https://issues.apache.org/jira/browse/AMQ-5311 - encode xaErrorCode in xaexception message Date: Thu, 7 Aug 2014 12:48:36 +0000 (UTC) Repository: activemq Updated Branches: refs/heads/trunk 8fb690f17 -> ab1e9c78e https://issues.apache.org/jira/browse/AMQ-5311 - encode xaErrorCode in xaexception message Project: http://git-wip-us.apache.org/repos/asf/activemq/repo Commit: http://git-wip-us.apache.org/repos/asf/activemq/commit/ab1e9c78 Tree: http://git-wip-us.apache.org/repos/asf/activemq/tree/ab1e9c78 Diff: http://git-wip-us.apache.org/repos/asf/activemq/diff/ab1e9c78 Branch: refs/heads/trunk Commit: ab1e9c78ef45fa6b8702a0890c2ae3edf9824a86 Parents: 8fb690f Author: gtully Authored: Thu Aug 7 13:42:03 2014 +0100 Committer: gtully Committed: Thu Aug 7 13:42:10 2014 +0100 ---------------------------------------------------------------------- .../activemq/broker/TransactionBroker.java | 3 +-- .../activemq/transaction/XATransaction.java | 24 +++++++++++--------- .../org/apache/activemq/TransactionContext.java | 15 ++++++++++-- .../ActiveMQXAConnectionFactoryTest.java | 2 +- 4 files changed, 28 insertions(+), 16 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/activemq/blob/ab1e9c78/activemq-broker/src/main/java/org/apache/activemq/broker/TransactionBroker.java ---------------------------------------------------------------------- diff --git a/activemq-broker/src/main/java/org/apache/activemq/broker/TransactionBroker.java b/activemq-broker/src/main/java/org/apache/activemq/broker/TransactionBroker.java index 26ddfab..4b5ff8f 100755 --- a/activemq-broker/src/main/java/org/apache/activemq/broker/TransactionBroker.java +++ b/activemq-broker/src/main/java/org/apache/activemq/broker/TransactionBroker.java @@ -365,8 +365,7 @@ public class TransactionBroker extends BrokerFilter { return transaction; } if (xid.isXATransaction()) { - XAException e = new XAException("Transaction '" + xid + "' has not been started."); - e.errorCode = XAException.XAER_NOTA; + XAException e = XATransaction.newXAException("Transaction '" + xid + "' has not been started.", XAException.XAER_NOTA); throw e; } else { throw new JMSException("Transaction '" + xid + "' has not been started."); http://git-wip-us.apache.org/repos/asf/activemq/blob/ab1e9c78/activemq-broker/src/main/java/org/apache/activemq/transaction/XATransaction.java ---------------------------------------------------------------------- diff --git a/activemq-broker/src/main/java/org/apache/activemq/transaction/XATransaction.java b/activemq-broker/src/main/java/org/apache/activemq/transaction/XATransaction.java index 3062125..8e31ec7 100755 --- a/activemq-broker/src/main/java/org/apache/activemq/transaction/XATransaction.java +++ b/activemq-broker/src/main/java/org/apache/activemq/transaction/XATransaction.java @@ -19,6 +19,7 @@ package org.apache.activemq.transaction; import java.io.IOException; import javax.transaction.xa.XAException; import javax.transaction.xa.XAResource; +import org.apache.activemq.TransactionContext; import org.apache.activemq.broker.TransactionBroker; import org.apache.activemq.command.ConnectionId; import org.apache.activemq.command.TransactionId; @@ -89,23 +90,20 @@ public class XATransaction extends Transaction { } catch (Throwable t) { LOG.warn("Store COMMIT FAILED: ", t); rollback(); - XAException xae = new XAException("STORE COMMIT FAILED: Transaction rolled back"); - xae.errorCode = XAException.XA_RBOTHER; + XAException xae = newXAException("STORE COMMIT FAILED: Transaction rolled back", XAException.XA_RBOTHER); xae.initCause(t); throw xae; } } private void illegalStateTransition(String callName) throws XAException { - XAException xae = new XAException("Cannot call " + callName + " now."); - xae.errorCode = XAException.XAER_PROTO; + XAException xae = newXAException("Cannot call " + callName + " now.", XAException.XAER_PROTO); throw xae; } private void checkForPreparedState(boolean onePhase) throws XAException { if (!onePhase) { - XAException xae = new XAException("Cannot do 2 phase commit if the transaction has not been prepared"); - xae.errorCode = XAException.XAER_PROTO; + XAException xae = newXAException("Cannot do 2 phase commit if the transaction has not been prepared", XAException.XAER_PROTO); throw xae; } } @@ -118,8 +116,7 @@ public class XATransaction extends Transaction { } catch (Throwable e) { LOG.warn("PRE-PREPARE FAILED: ", e); rollback(); - XAException xae = new XAException("PRE-PREPARE FAILED: Transaction rolled back"); - xae.errorCode = XAException.XA_RBOTHER; + XAException xae = newXAException("PRE-PREPARE FAILED: Transaction rolled back", XAException.XA_RBOTHER); xae.initCause(e); throw xae; } @@ -155,7 +152,7 @@ public class XATransaction extends Transaction { doPostRollback(); break; default: - throw new XAException("Invalid state"); + throw newXAException("Invalid state: " + getState(), XAException.XA_RBPROTO); } } @@ -167,13 +164,18 @@ public class XATransaction extends Transaction { // I guess this could happen. Post commit task failed // to execute properly. LOG.warn("POST ROLLBACK FAILED: ", e); - XAException xae = new XAException("POST ROLLBACK FAILED"); - xae.errorCode = XAException.XAER_RMERR; + XAException xae = newXAException("POST ROLLBACK FAILED", XAException.XAER_RMERR); xae.initCause(e); throw xae; } } + public static XAException newXAException(String s, int errorCode) { + XAException xaException = new XAException(s + " " + TransactionContext.xaErrorCodeMarker + errorCode); + xaException.errorCode = errorCode; + return xaException; + } + @Override public int prepare() throws XAException, IOException { if (LOG.isDebugEnabled()) { http://git-wip-us.apache.org/repos/asf/activemq/blob/ab1e9c78/activemq-client/src/main/java/org/apache/activemq/TransactionContext.java ---------------------------------------------------------------------- diff --git a/activemq-client/src/main/java/org/apache/activemq/TransactionContext.java b/activemq-client/src/main/java/org/apache/activemq/TransactionContext.java index c86f448..a444d61 100755 --- a/activemq-client/src/main/java/org/apache/activemq/TransactionContext.java +++ b/activemq-client/src/main/java/org/apache/activemq/TransactionContext.java @@ -66,6 +66,7 @@ import org.slf4j.LoggerFactory; */ public class TransactionContext implements XAResource { + public static final String xaErrorCodeMarker = "xaErrorCode:"; private static final Logger LOG = LoggerFactory.getLogger(TransactionContext.class); // XATransactionId -> ArrayList of TransactionContext objects @@ -786,8 +787,7 @@ public class TransactionContext implements XAResource { xae.errorCode = original.errorCode; if (xae.errorCode == XA_OK) { // detail not unmarshalled see: org.apache.activemq.openwire.v1.BaseDataStreamMarshaller.createThrowable - // so use a valid generic error code in place of ok - xae.errorCode = XAException.XAER_RMERR; + xae.errorCode = parseFromMessageOr(original.getMessage(), XAException.XAER_RMERR); } xae.initCause(original); return xae; @@ -799,6 +799,17 @@ public class TransactionContext implements XAResource { return xae; } + private int parseFromMessageOr(String message, int fallbackCode) { + final String marker = "xaErrorCode:"; + final int index = message.lastIndexOf(marker); + if (index > -1) { + try { + return Integer.parseInt(message.substring(index + marker.length())); + } catch (Exception ignored) {} + } + return fallbackCode; + } + public ActiveMQConnection getConnection() { return connection; } http://git-wip-us.apache.org/repos/asf/activemq/blob/ab1e9c78/activemq-unit-tests/src/test/java/org/apache/activemq/ActiveMQXAConnectionFactoryTest.java ---------------------------------------------------------------------- diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/ActiveMQXAConnectionFactoryTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/ActiveMQXAConnectionFactoryTest.java index 5fd6e5c..4b89851 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/ActiveMQXAConnectionFactoryTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/ActiveMQXAConnectionFactoryTest.java @@ -468,7 +468,7 @@ public class ActiveMQXAConnectionFactoryTest extends CombinationTestSupport { fail("Expected xa exception on no tx"); } catch (XAException expected) { LOG.info("got expected xa", expected); - assertTrue("not zero", expected.errorCode != XAResource.XA_OK); + assertEquals("no tx", XAException.XAER_NOTA, expected.errorCode); } connection.close(); broker.stop();