Search in sources :

Example 21 with WrongStateException

use of com.arjuna.wst.WrongStateException in project wildfly by wildfly.

the class ATSuperService method invokeWithCallName.

/**
 * Adding 2 participants - Volatile and Durable
 *
 * @param callName        call name works for differentiate several calls to the same webservice
 *                        if you don't want care pass null (or overloaded method :)
 * @param serviceCommands service commands that service will react on
 * @throws WrongStateException
 * @throws com.arjuna.wst.SystemException
 * @throws UnknownTransactionException
 * @throws SecurityException
 * @throws javax.transaction.SystemException
 * @throws IllegalStateException
 */
public void invokeWithCallName(String callName, ServiceCommand[] serviceCommands) throws TestApplicationException {
    log.debugf("[AT SERVICE] web method invoke(%s) with eventLog %s", callName, eventLog);
    eventLog.foundEventLogName(callName);
    UserTransaction userTransaction;
    try {
        userTransaction = UserTransactionFactory.userTransaction();
        String transactionId = userTransaction.transactionIdentifier();
        log.debug("RestaurantServiceAT transaction id =" + transactionId);
        // Enlist the Durable Participant for this service
        TransactionManager transactionManager = TransactionManagerFactory.transactionManager();
        ATDurableParticipant durableParticipant = new ATDurableParticipant(serviceCommands, callName, eventLog, transactionId);
        log.trace("[SERVICE] Enlisting a Durable2PC participant into the AT");
        transactionManager.enlistForDurableTwoPhase(durableParticipant, "ATServiceDurable:" + new Uid().toString());
        // Enlist the Volatile Participant for this service
        ATVolatileParticipant volatileParticipant = new ATVolatileParticipant(serviceCommands, callName, eventLog, transactionId);
        log.trace("[SERVICE] Enlisting a VolatilePC participant into the AT");
        transactionManager.enlistForVolatileTwoPhase(volatileParticipant, "ATServiceVolatile:" + new Uid().toString());
    } catch (Exception e) {
        throw new RuntimeException("Error when enlisting participants", e);
    }
    if (ServiceCommand.isPresent(APPLICATION_EXCEPTION, serviceCommands)) {
        throw new TestApplicationException("Intentionally thrown Application Exception - service command was set to: " + APPLICATION_EXCEPTION);
    }
    if (ServiceCommand.isPresent(ROLLBACK_ONLY, serviceCommands)) {
        log.trace("Intentionally the service settings transaction to rollback only - service command was set to: " + ROLLBACK_ONLY);
        try {
            userTransaction.rollback();
        } catch (Exception e) {
            throw new RuntimeException("The rollback is not possible", e);
        }
    }
    // There will be some business logic here normally
    log.trace("|AT SERVICE] I'm working on nothing...");
}
Also used : UserTransaction(com.arjuna.mw.wst11.UserTransaction) Uid(com.arjuna.ats.arjuna.common.Uid) TestApplicationException(org.jboss.as.test.xts.base.TestApplicationException) TransactionManager(com.arjuna.mw.wst11.TransactionManager) TestApplicationException(org.jboss.as.test.xts.base.TestApplicationException) UnknownTransactionException(com.arjuna.wst.UnknownTransactionException) WrongStateException(com.arjuna.wst.WrongStateException)

Example 22 with WrongStateException

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

the class UserTransactionStandaloneImple method commitWithoutAck.

private final void commitWithoutAck() throws TransactionRolledBackException, UnknownTransactionException, SecurityException, SystemException, WrongStateException {
    TxContextImple ctx = null;
    String id = null;
    try {
        ctx = (TxContextImple) _ctxManager.suspend();
        if (ctx == null) {
            throw new WrongStateException();
        }
        id = ctx.identifier();
        /*
			 * By default the completionParticipantURL won't be set for an interposed (imported)
			 * bridged transaction. This is fine, because you shouldn't be able to commit that
			 * transaction from a node in the tree, only from the root. So, we can prevent commit
			 * or rollback at this stage. The alternative would be to setup the completionParticipantURL
			 * and throw the exception from the remote coordinator side (see enlistCompletionParticipants
			 * for how to do this).
			 *
			 * The same applies for an interposed subordinate transaction created via beginSubordinate.
			 */
        final W3CEndpointReference completionCoordinator = (W3CEndpointReference) _completionCoordinators.get(id);
        if (completionCoordinator == null)
            throw new WrongStateException();
        CompletionRPCStub completionStub = new CompletionRPCStub(id, completionCoordinator);
        completionStub.commit();
    } catch (SystemException ex) {
        throw ex;
    } catch (TransactionRolledBackException ex) {
        throw ex;
    } catch (UnknownTransactionException ex) {
        throw ex;
    } catch (SecurityException ex) {
        throw ex;
    } catch (WrongStateException ex) {
        throw ex;
    } catch (Exception ex) {
        ex.printStackTrace();
        throw new SystemException(ex.toString());
    } finally {
        try {
            if (ctx != null)
                _ctxManager.resume(ctx);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        if (id != null)
            _completionCoordinators.remove(id);
    }
}
Also used : SystemException(com.arjuna.wst.SystemException) UnknownTransactionException(com.arjuna.wst.UnknownTransactionException) WrongStateException(com.arjuna.wst.WrongStateException) W3CEndpointReference(javax.xml.ws.wsaddressing.W3CEndpointReference) CompletionRPCStub(com.arjuna.wst11.stub.CompletionRPCStub) TransactionRolledBackException(com.arjuna.wst.TransactionRolledBackException) TxContextImple(com.arjuna.mwlabs.wst11.at.context.TxContextImple) UnknownTransactionException(com.arjuna.wst.UnknownTransactionException) CannotRegisterException(com.arjuna.wsc.CannotRegisterException) WrongStateException(com.arjuna.wst.WrongStateException) SystemException(com.arjuna.wst.SystemException) InvalidStateException(com.arjuna.wsc.InvalidStateException) InvalidProtocolException(com.arjuna.wsc.InvalidProtocolException) InvalidCreateParametersException(com.arjuna.wsc.InvalidCreateParametersException) TransactionRolledBackException(com.arjuna.wst.TransactionRolledBackException)

Example 23 with WrongStateException

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

the class UserTransactionStandaloneImple method enlistCompletionParticipants.

/*
	 * enlist the client for the completiopn protocol so it can commit or ro0ll back the transaction
	 */
private final void enlistCompletionParticipants() throws WrongStateException, UnknownTransactionException, SystemException {
    TransactionManagerImple tm = (TransactionManagerImple) TransactionManager.getTransactionManager();
    final TxContextImple currentTx = (TxContextImple) tm.currentTransaction();
    if (currentTx == null)
        throw new UnknownTransactionException();
    final String id = currentTx.identifier();
    W3CEndpointReference completionCoordinator = null;
    try {
        completionCoordinator = tm.registerParticipant(null, AtomicTransactionConstants.WSAT_SUB_PROTOCOL_COMPLETION_RPC);
    } catch (InvalidProtocolException ex) {
        ex.printStackTrace();
        throw new SystemException(ex.toString());
    } catch (InvalidStateException ex) {
        throw new WrongStateException();
    } catch (CannotRegisterException ex) {
        // cause could actually be no activity or already registered
        throw new UnknownTransactionException();
    }
    _completionCoordinators.put(id, completionCoordinator);
}
Also used : UnknownTransactionException(com.arjuna.wst.UnknownTransactionException) SystemException(com.arjuna.wst.SystemException) W3CEndpointReference(javax.xml.ws.wsaddressing.W3CEndpointReference) InvalidProtocolException(com.arjuna.wsc.InvalidProtocolException) WrongStateException(com.arjuna.wst.WrongStateException) InvalidStateException(com.arjuna.wsc.InvalidStateException) TxContextImple(com.arjuna.mwlabs.wst11.at.context.TxContextImple) CannotRegisterException(com.arjuna.wsc.CannotRegisterException)

Example 24 with WrongStateException

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

the class UserTransactionStandaloneImple method abortWithoutAck.

private final void abortWithoutAck() throws UnknownTransactionException, SecurityException, SystemException, WrongStateException {
    TxContextImple ctx = null;
    String id = null;
    try {
        ctx = (TxContextImple) _ctxManager.suspend();
        if (ctx == null) {
            throw new WrongStateException();
        }
        id = ctx.identifier();
        /*
			 * By default the completionParticipantURL won't be set for an interposed (imported)
			 * bridged transaction. This is fine, because you shouldn't be able to commit that
			 * transaction from a node in the tree, only from the root. So, we can prevent commit
			 * or rollback at this stage. The alternative would be to setup the completionParticipantURL
			 * and throw the exception from the remote coordinator side (see enlistCompletionParticipants
			 * for how to do this).
			 *
			 * The same applies for an interposed subordinate transaction created via beginSubordinate.
			 */
        W3CEndpointReference completionCoordinator = (W3CEndpointReference) _completionCoordinators.get(id);
        if (completionCoordinator == null)
            throw new WrongStateException();
        CompletionRPCStub completionStub = new CompletionRPCStub(id, completionCoordinator);
        completionStub.rollback();
    } catch (SystemException ex) {
        throw ex;
    } catch (UnknownTransactionException ex) {
        throw ex;
    } catch (SecurityException ex) {
        throw ex;
    } catch (WrongStateException ex) {
        throw ex;
    } catch (Exception ex) {
        throw new SystemException(ex.toString());
    } finally {
        try {
            if (ctx != null)
                _ctxManager.resume(ctx);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        if (id != null)
            _completionCoordinators.remove(id);
    }
}
Also used : SystemException(com.arjuna.wst.SystemException) UnknownTransactionException(com.arjuna.wst.UnknownTransactionException) WrongStateException(com.arjuna.wst.WrongStateException) W3CEndpointReference(javax.xml.ws.wsaddressing.W3CEndpointReference) CompletionRPCStub(com.arjuna.wst11.stub.CompletionRPCStub) TxContextImple(com.arjuna.mwlabs.wst11.at.context.TxContextImple) UnknownTransactionException(com.arjuna.wst.UnknownTransactionException) CannotRegisterException(com.arjuna.wsc.CannotRegisterException) WrongStateException(com.arjuna.wst.WrongStateException) SystemException(com.arjuna.wst.SystemException) InvalidStateException(com.arjuna.wsc.InvalidStateException) InvalidProtocolException(com.arjuna.wsc.InvalidProtocolException) InvalidCreateParametersException(com.arjuna.wsc.InvalidCreateParametersException) TransactionRolledBackException(com.arjuna.wst.TransactionRolledBackException)

Example 25 with WrongStateException

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

the class UserTransactionImple method abortWithoutAck.

private final void abortWithoutAck() throws UnknownTransactionException, SecurityException, SystemException, WrongStateException {
    TxContextImple ctx = null;
    String id = null;
    try {
        ctx = (TxContextImple) _ctxManager.suspend();
        if (ctx == null) {
            throw new WrongStateException();
        }
        id = ctx.identifier();
        /*
			 * By default the completionParticipantURL won't be set for an interposed (imported)
			 * bridged transaction. This is fine, because you shouldn't be able to commit that
			 * transaction from a node in the tree, only from the root. So, we can prevent commit
			 * or rollback at this stage. The alternative would be to setup the completionParticipantURL
			 * and throw the exception from the remote coordinator side (see enlistCompletionParticipants
			 * for how to do this).
			 *
			 * The same applies for an interposed subordinate transaction created via beginSubordinate.
			 */
        W3CEndpointReference completionCoordinator = (W3CEndpointReference) _completionCoordinators.get(id);
        if (completionCoordinator == null)
            throw new WrongStateException();
        CompletionStub completionStub = new CompletionStub(id, completionCoordinator);
        completionStub.rollback();
    } catch (SystemException ex) {
        throw ex;
    } catch (UnknownTransactionException ex) {
        throw ex;
    } catch (SecurityException ex) {
        throw ex;
    } catch (WrongStateException ex) {
        throw ex;
    } catch (Exception ex) {
        throw new SystemException(ex.toString());
    } finally {
        try {
            if (ctx != null)
                _ctxManager.resume(ctx);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        if (id != null)
            _completionCoordinators.remove(id);
    }
}
Also used : CompletionStub(com.arjuna.wst11.stub.CompletionStub) SystemException(com.arjuna.wst.SystemException) UnknownTransactionException(com.arjuna.wst.UnknownTransactionException) WrongStateException(com.arjuna.wst.WrongStateException) W3CEndpointReference(javax.xml.ws.wsaddressing.W3CEndpointReference) TxContextImple(com.arjuna.mwlabs.wst11.at.context.TxContextImple) UnknownTransactionException(com.arjuna.wst.UnknownTransactionException) WrongStateException(com.arjuna.wst.WrongStateException) SystemException(com.arjuna.wst.SystemException) InvalidCreateParametersException(com.arjuna.wsc.InvalidCreateParametersException) TransactionRolledBackException(com.arjuna.wst.TransactionRolledBackException)

Aggregations

WrongStateException (com.arjuna.wst.WrongStateException)43 UnknownTransactionException (com.arjuna.wst.UnknownTransactionException)42 SystemException (com.arjuna.wst.SystemException)41 TransactionRolledBackException (com.arjuna.wst.TransactionRolledBackException)28 ArrayList (java.util.ArrayList)18 InvalidCreateParametersException (com.arjuna.wsc.InvalidCreateParametersException)16 UserBusinessActivity (com.arjuna.mw.wst11.UserBusinessActivity)14 W3CEndpointReference (javax.xml.ws.wsaddressing.W3CEndpointReference)12 TxContextImple (com.arjuna.mwlabs.wst11.at.context.TxContextImple)9 TxContextImple (com.arjuna.mwlabs.wst11.ba.context.TxContextImple)9 Context (com.arjuna.mw.wsc11.context.Context)6 UserTransaction (com.arjuna.mw.wst11.UserTransaction)6 CoordinationContext (org.oasis_open.docs.ws_tx.wscoor._2006._06.CoordinationContext)6 TxContext (com.arjuna.mw.wst.TxContext)5 InvalidActivityException (com.arjuna.mw.wsas.exceptions.InvalidActivityException)3 CannotRegisterException (com.arjuna.wsc.CannotRegisterException)3 InvalidProtocolException (com.arjuna.wsc.InvalidProtocolException)3 InvalidStateException (com.arjuna.wsc.InvalidStateException)3 BusinessActivityTerminatorRPCStub (com.arjuna.wst11.stub.BusinessActivityTerminatorRPCStub)3 BusinessActivityTerminatorStub (com.arjuna.wst11.stub.BusinessActivityTerminatorStub)3