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 30b22198cc..b16fcba882 100755 --- a/activemq-client/src/main/java/org/apache/activemq/TransactionContext.java +++ b/activemq-client/src/main/java/org/apache/activemq/TransactionContext.java @@ -772,6 +772,11 @@ public class TransactionContext implements XAResource { XAException original = (XAException)e.getCause(); XAException xae = new XAException(original.getMessage()); 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.initCause(original); return xae; } 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 87f618e81e..7da3035a86 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 @@ -411,12 +411,35 @@ public class ActiveMQXAConnectionFactoryTest extends CombinationTestSupport { } catch (javax.jms.IllegalStateException expected) {} } + public void testRollbackXaErrorCode() throws Exception { + String brokerName = "rollbackErrorCode"; + BrokerService broker = BrokerFactory.createBroker(new URI("broker:(tcp://localhost:0)/" + brokerName)); + broker.start(); + broker.waitUntilStarted(); + ActiveMQXAConnectionFactory cf = new ActiveMQXAConnectionFactory(broker.getTransportConnectors().get(0).getConnectUri()); + XAConnection connection = (XAConnection)cf.createConnection(); + connection.start(); + XASession session = connection.createXASession(); + XAResource resource = session.getXAResource(); + + Xid tid = createXid(); + try { + resource.rollback(tid); + fail("Expected xa exception on no tx"); + } catch (XAException expected) { + LOG.info("got expected xa", expected); + assertTrue("not zero", expected.errorCode != XAResource.XA_OK); + } + connection.close(); + broker.stop(); + } + private void assertTransactionGoneFromFailoverState( ActiveMQXAConnection connection1, Xid tid) throws Exception { FailoverTransport transport = (FailoverTransport) connection1.getTransport().narrow(FailoverTransport.class); TransactionInfo info = new TransactionInfo(connection1.getConnectionInfo().getConnectionId(), new XATransactionId(tid), TransactionInfo.COMMIT_ONE_PHASE); - assertNull("transaction shold not exist in the state tracker", + assertNull("transaction should not exist in the state tracker", transport.getStateTracker().processCommitTransactionOnePhase(info)); }