Search in sources :

Example 16 with TransactionRolledBackException

use of com.arjuna.wst.TransactionRolledBackException in project narayana by jbosstm.

the class SubtransactionCommitRollbackInPrepareTest method testSubTransactionCommitRollbackInPrepare.

@Test
public void testSubTransactionCommitRollbackInPrepare() throws Exception {
    final UserTransaction ut = UserTransactionFactory.userTransaction();
    final UserTransaction ust = UserTransactionFactory.userSubordinateTransaction();
    final TransactionManager tm = TransactionManager.getTransactionManager();
    final DemoDurableParticipant p1 = new DemoDurableParticipant();
    final DemoVolatileParticipant p2 = new DemoVolatileParticipant();
    final FailureParticipant p3 = new FailureParticipant(FailureParticipant.FAIL_IN_PREPARE, FailureParticipant.NONE);
    final DemoVolatileParticipant p4 = new DemoVolatileParticipant();
    ut.begin();
    final TxContext tx = tm.suspend();
    tm.resume(tx);
    tm.enlistForDurableTwoPhase(p1, p1.identifier());
    tm.enlistForVolatileTwoPhase(p2, p2.identifier());
    ust.begin();
    final TxContext stx = tm.suspend();
    tm.resume(stx);
    tm.enlistForDurableTwoPhase(p3, "failure in prepare");
    tm.enlistForVolatileTwoPhase(p4, p4.identifier());
    tm.resume(tx);
    try {
        ut.commit();
        fail("expecting TransactionRolledBackException");
    } catch (TransactionRolledBackException trbe) {
    // expect this
    }
    assertTrue(p1.prepared() && p1.resolved() && !p1.passed());
    assertTrue(p2.prepared() && p2.resolved() && !p2.passed());
    assertTrue(!p3.passed());
    assertTrue(p4.prepared() && p4.resolved() && !p4.passed());
}
Also used : UserTransaction(com.arjuna.mw.wst11.UserTransaction) FailureParticipant(com.arjuna.wstx.tests.common.FailureParticipant) DemoVolatileParticipant(com.arjuna.wstx.tests.common.DemoVolatileParticipant) TransactionManager(com.arjuna.mw.wst11.TransactionManager) DemoDurableParticipant(com.arjuna.wstx.tests.common.DemoDurableParticipant) TxContext(com.arjuna.mw.wst.TxContext) TransactionRolledBackException(com.arjuna.wst.TransactionRolledBackException) Test(org.junit.Test)

Example 17 with TransactionRolledBackException

use of com.arjuna.wst.TransactionRolledBackException in project narayana by jbosstm.

the class SubtransactionCommitFailInPrepareTest method testSubTransactionCommitFailInPrepare.

@Test
public void testSubTransactionCommitFailInPrepare() throws Exception {
    final UserTransaction ut = UserTransactionFactory.userTransaction();
    final UserTransaction ust = UserTransactionFactory.userSubordinateTransaction();
    final TransactionManager tm = TransactionManager.getTransactionManager();
    final DemoDurableParticipant p1 = new DemoDurableParticipant();
    final DemoVolatileParticipant p2 = new DemoVolatileParticipant();
    final FailureParticipant p3 = new FailureParticipant(FailureParticipant.FAIL_IN_PREPARE, FailureParticipant.WRONG_STATE);
    final DemoVolatileParticipant p4 = new DemoVolatileParticipant();
    ut.begin();
    final TxContext tx = tm.suspend();
    tm.resume(tx);
    tm.enlistForDurableTwoPhase(p1, p1.identifier());
    tm.enlistForVolatileTwoPhase(p2, p2.identifier());
    ust.begin();
    final TxContext stx = tm.suspend();
    tm.resume(stx);
    tm.enlistForDurableTwoPhase(p3, "failure in prepare");
    tm.enlistForVolatileTwoPhase(p4, p4.identifier());
    tm.resume(tx);
    try {
        ut.commit();
        fail("expecting TransactionRolledBackException");
    } catch (TransactionRolledBackException wse) {
    // expect this
    }
    assertTrue(p1.prepared() && p1.resolved() && !p1.passed());
    assertTrue(p2.prepared() && p2.resolved() && !p2.passed());
    assertTrue(!p3.passed());
    assertTrue(p4.prepared() && p4.resolved() && !p4.passed());
}
Also used : UserTransaction(com.arjuna.mw.wst11.UserTransaction) FailureParticipant(com.arjuna.wstx.tests.common.FailureParticipant) DemoVolatileParticipant(com.arjuna.wstx.tests.common.DemoVolatileParticipant) TransactionManager(com.arjuna.mw.wst11.TransactionManager) DemoDurableParticipant(com.arjuna.wstx.tests.common.DemoDurableParticipant) TxContext(com.arjuna.mw.wst.TxContext) TransactionRolledBackException(com.arjuna.wst.TransactionRolledBackException) Test(org.junit.Test)

Example 18 with TransactionRolledBackException

use of com.arjuna.wst.TransactionRolledBackException in project narayana by jbosstm.

the class CompletionCoordinatorProcessorImpl method commit.

/**
 * Commit.
 * @param commit The commit notification.
 * @param map The addressing context.
 * @param arjunaContext The arjuna context.
 */
public void commit(final Notification commit, final MAP map, final ArjunaContext arjunaContext) {
    final InstanceIdentifier instanceIdentifier = arjunaContext.getInstanceIdentifier();
    final CompletionCoordinatorParticipant participant = getParticipant(instanceIdentifier);
    try {
        if (participant != null) {
            final String messageId = MessageId.getMessageId();
            try {
                participant.commit();
            } catch (final TransactionRolledBackException trbe) {
                final MAP responseAddressingContext = AddressingHelper.createResponseContext(map, messageId);
                CompletionInitiatorClient.getClient().sendAborted(participant.getParticipant(), responseAddressingContext, instanceIdentifier);
                return;
            } catch (final UnknownTransactionException ute) {
                final MAP faultAddressingContext = AddressingHelper.createFaultContext(map, messageId);
                final SoapFault soapFault = new SoapFault11(SoapFaultType.FAULT_SENDER, ArjunaTXConstants.UNKNOWNTRANSACTION_ERROR_CODE_QNAME, WSTLogger.i18NLogger.get_wst11_messaging_CompletionCoordinatorProcessorImpl_1());
                CompletionInitiatorClient.getClient().sendSoapFault(participant.getParticipant(), faultAddressingContext, soapFault, instanceIdentifier);
                return;
            } catch (final SystemException se) {
                final MAP faultAddressingContext = AddressingHelper.createFaultContext(map, messageId);
                final String pattern = WSTLogger.i18NLogger.get_wst11_messaging_CompletionCoordinatorProcessorImpl_2();
                final String message = MessageFormat.format(pattern, new Object[] { se });
                final SoapFault soapFault = new SoapFault11(SoapFaultType.FAULT_SENDER, ArjunaTXConstants.UNKNOWNERROR_ERROR_CODE_QNAME, message);
                CompletionInitiatorClient.getClient().sendSoapFault(participant.getParticipant(), faultAddressingContext, soapFault, instanceIdentifier);
                return;
            } catch (final Throwable th) {
                if (WSTLogger.logger.isTraceEnabled()) {
                    WSTLogger.logger.tracev("Unexpected exception thrown from commit:", th);
                }
                final MAP faultAddressingContext = AddressingHelper.createFaultContext(map, MessageId.getMessageId());
                final SoapFault soapFault = new SoapFault11(th);
                CompletionInitiatorClient.getClient().sendSoapFault(participant.getParticipant(), faultAddressingContext, soapFault, instanceIdentifier);
                return;
            }
            final MAP responseAddressingContext = AddressingHelper.createResponseContext(map, messageId);
            CompletionInitiatorClient.getClient().sendCommitted(participant.getParticipant(), responseAddressingContext, instanceIdentifier);
        } else {
            if (WSTLogger.logger.isTraceEnabled()) {
                WSTLogger.logger.tracev("Commit called on unknown participant: {0}", new Object[] { instanceIdentifier });
            }
            final MAP faultAddressingContext = AddressingHelper.createFaultContext(map, MessageId.getMessageId());
            final SoapFault soapFault = new SoapFault11(SoapFaultType.FAULT_SENDER, ArjunaTXConstants.UNKNOWNTRANSACTION_ERROR_CODE_QNAME, WSTLogger.i18NLogger.get_wst11_messaging_CompletionCoordinatorProcessorImpl_5());
            CompletionInitiatorClient.getClient().sendSoapFault(faultAddressingContext, soapFault, instanceIdentifier);
        }
    } catch (Throwable throwable) {
        throwable.printStackTrace(System.err);
    }
}
Also used : SoapFault(com.arjuna.webservices.SoapFault) UnknownTransactionException(com.arjuna.wst.UnknownTransactionException) SystemException(com.arjuna.wst.SystemException) InstanceIdentifier(com.arjuna.webservices11.wsarj.InstanceIdentifier) TransactionRolledBackException(com.arjuna.wst.TransactionRolledBackException) SoapFault11(com.arjuna.webservices11.SoapFault11) CompletionCoordinatorParticipant(com.arjuna.wst11.CompletionCoordinatorParticipant) MAP(org.jboss.ws.api.addressing.MAP)

Example 19 with TransactionRolledBackException

use of com.arjuna.wst.TransactionRolledBackException in project narayana by jbosstm.

the class BusinessActivityTerminatorStub method close.

public void close() throws TransactionRolledBackException, UnknownTransactionException, SystemException {
    final MAP map = AddressingHelper.createNotificationContext(MessageId.getMessageId());
    final RequestCallback callback = new RequestCallback();
    final TerminationParticipantProcessor terminationParticipantProcessor = TerminationParticipantProcessor.getProcessor();
    terminationParticipantProcessor.registerCallback(_id, callback);
    try {
        TerminationCoordinatorClient.getClient().sendClose(_terminationCoordinator, map, new InstanceIdentifier(_id));
        callback.waitUntilTriggered();
    } catch (final Throwable th) {
        throw new SystemException();
    } finally {
        terminationParticipantProcessor.removeCallback(_id);
    }
    if (callback.hasTriggered()) {
        if (callback.receivedClosed()) {
            return;
        }
        final SoapFault soapFault = callback.getSoapFault();
        if (soapFault != null) {
            final QName subcode = soapFault.getSubcode();
            if (ArjunaTXConstants.TRANSACTIONROLLEDBACK_ERROR_CODE_QNAME.equals(subcode)) {
                throw new TransactionRolledBackException();
            } else if (ArjunaTXConstants.UNKNOWNTRANSACTION_ERROR_CODE_QNAME.equals(subcode)) {
                throw new UnknownTransactionException();
            }
        }
    }
    throw new SystemException();
}
Also used : SoapFault(com.arjuna.webservices.SoapFault) SystemException(com.arjuna.wst.SystemException) UnknownTransactionException(com.arjuna.wst.UnknownTransactionException) QName(javax.xml.namespace.QName) InstanceIdentifier(com.arjuna.webservices11.wsarj.InstanceIdentifier) TransactionRolledBackException(com.arjuna.wst.TransactionRolledBackException) MAP(org.jboss.ws.api.addressing.MAP) TerminationParticipantProcessor(com.arjuna.webservices11.wsarjtx.processors.TerminationParticipantProcessor)

Example 20 with TransactionRolledBackException

use of com.arjuna.wst.TransactionRolledBackException in project narayana by jbosstm.

the class CompletionStub method commit.

public void commit() throws TransactionRolledBackException, UnknownTransactionException, SystemException {
    final MAP map = AddressingHelper.createNotificationContext(MessageId.getMessageId());
    final CompletionStub.RequestCallback callback = new CompletionStub.RequestCallback();
    final CompletionInitiatorProcessor completionInitiator = CompletionInitiatorProcessor.getProcessor();
    completionInitiator.registerCallback(_id, callback);
    try {
        CompletionCoordinatorClient.getClient().sendCommit(_completionCoordinator, map, new InstanceIdentifier(_id));
        callback.waitUntilTriggered();
    } catch (final Throwable th) {
        th.printStackTrace();
        throw new SystemException();
    } finally {
        completionInitiator.removeCallback(_id);
    }
    if (callback.hasTriggered()) {
        if (callback.receivedCommitted()) {
            return;
        } else if (callback.receivedAborted()) {
            throw new TransactionRolledBackException();
        }
        final SoapFault soapFault = callback.getSoapFault();
        if ((soapFault != null) && ArjunaTXConstants.UNKNOWNTRANSACTION_ERROR_CODE_QNAME.equals(soapFault.getSubcode())) {
            throw new UnknownTransactionException();
        }
    }
    throw new SystemException();
}
Also used : SoapFault(com.arjuna.webservices.SoapFault) SystemException(com.arjuna.wst.SystemException) UnknownTransactionException(com.arjuna.wst.UnknownTransactionException) CompletionInitiatorProcessor(com.arjuna.webservices11.wsat.processors.CompletionInitiatorProcessor) InstanceIdentifier(com.arjuna.webservices11.wsarj.InstanceIdentifier) TransactionRolledBackException(com.arjuna.wst.TransactionRolledBackException) MAP(org.jboss.ws.api.addressing.MAP)

Aggregations

TransactionRolledBackException (com.arjuna.wst.TransactionRolledBackException)41 SystemException (com.arjuna.wst.SystemException)29 UnknownTransactionException (com.arjuna.wst.UnknownTransactionException)29 WrongStateException (com.arjuna.wst.WrongStateException)22 ArrayList (java.util.ArrayList)18 UserBusinessActivity (com.arjuna.mw.wst11.UserBusinessActivity)15 CompletionCoordinatorParticipant (com.arjuna.wst.CompletionCoordinatorParticipant)8 CoordinationContextType (org.oasis_open.docs.ws_tx.wscoor._2006._06.CoordinationContextType)8 UserTransaction (com.arjuna.mw.wst11.UserTransaction)7 SoapFault (com.arjuna.webservices.SoapFault)5 InstanceIdentifier (com.arjuna.webservices11.wsarj.InstanceIdentifier)5 W3CEndpointReference (javax.xml.ws.wsaddressing.W3CEndpointReference)5 MAP (org.jboss.ws.api.addressing.MAP)5 InvalidCreateParametersException (com.arjuna.wsc.InvalidCreateParametersException)4 Test (org.junit.Test)3 TxContext (com.arjuna.mw.wst.TxContext)2 TransactionManager (com.arjuna.mw.wst11.TransactionManager)2 TxContextImple (com.arjuna.mwlabs.wst11.at.context.TxContextImple)2 TxContextImple (com.arjuna.mwlabs.wst11.ba.context.TxContextImple)2 SoapFault11 (com.arjuna.webservices11.SoapFault11)2