Search in sources :

Example 1 with SystemException

use of com.arjuna.wst.SystemException in project quickstart by wildfly.

the class SetServiceBAImpl method addValueToSet.

/**
 * Add an item to a set and enroll a Participant if necessary then pass the call through to the business logic.
 *
 * @param value the value to add to the set.
 * @throws AlreadyInSetException if value is already in the set
 * @throws SetServiceException if an error occurred when attempting to add the item to the set.
 */
@WebMethod
public void addValueToSet(String value) throws AlreadyInSetException, SetServiceException {
    System.out.println("[SERVICE] invoked addValueToSet('" + value + "')");
    BusinessActivityManager activityManager = BusinessActivityManagerFactory.businessActivityManager();
    /*
         * get the transaction context of this thread:
         */
    String transactionId;
    try {
        transactionId = activityManager.currentTransaction().toString();
    } catch (SystemException e) {
        throw new SetServiceException("Unable to lookup existing BusinesActivity", e);
    }
    /*
         * Lookup existing participant or register new participant
         */
    SetParticipantBA participantBA = SetParticipantBA.getParticipant(transactionId);
    if (participantBA == null) {
        try {
            // enlist the Participant for this service:
            SetParticipantBA participant = new SetParticipantBA(transactionId, value);
            SetParticipantBA.recordParticipant(transactionId, participant);
            System.out.println("[SERVICE] Enlisting a participant into the BA");
            activityManager.enlistForBusinessAgreementWithCoordinatorCompletion(participant, "SetServiceBAImpl:" + UUID.randomUUID());
        } catch (Exception e) {
            System.err.println("Participant enlistment failed");
            throw new SetServiceException("Error enlisting participant", e);
        }
    } else {
        System.out.println("[SERVICE] Re-using the existing participant, already registered for this BA");
        participantBA.addValue(value);
    }
    // invoke the back-end business logic
    System.out.println("[SERVICE] Invoking the back-end business logic");
    MockSetManager.add(value);
}
Also used : SystemException(com.arjuna.wst.SystemException) BusinessActivityManager(com.arjuna.mw.wst11.BusinessActivityManager) SystemException(com.arjuna.wst.SystemException) WebMethod(javax.jws.WebMethod)

Example 2 with SystemException

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

the class HandlerFactory method getCurrentTXID.

private static String getCurrentTXID() throws TXFrameworkException {
    String txid;
    // Try WS-AT
    txid = UserTransactionFactory.userTransaction().transactionIdentifier();
    if (!txid.equals("Unknown")) {
        return txid;
    }
    // Try WS-BA
    try {
        BusinessActivityManager businessActivityManager = BusinessActivityManagerFactory.businessActivityManager();
        if (businessActivityManager.currentTransaction() != null) {
            txid = businessActivityManager.currentTransaction().toString();
            if (!txid.equals("Unknown")) {
                return txid;
            }
        }
    } catch (SystemException e) {
        throw new TXFrameworkException("Error when looking up Business Activity", e);
    }
    // Try REST-AT
    HttpServletRequest req = ResteasyProviderFactory.getContextData(HttpServletRequest.class);
    String enlistUrl = req.getHeader("enlistURL");
    if (enlistUrl != null) {
        String[] parts = enlistUrl.split("/");
        return parts[parts.length - 1];
    }
    throw new TXFrameworkException("No Transaction detected");
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) SystemException(com.arjuna.wst.SystemException) TXFrameworkException(org.jboss.narayana.txframework.api.exception.TXFrameworkException) BusinessActivityManager(com.arjuna.mw.wst11.BusinessActivityManager)

Example 3 with SystemException

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

the class BAParticipantManagerImple method fail.

public void fail(final QName exceptionIdentifier) throws SystemException {
    if (wstxLogger.logger.isTraceEnabled()) {
        wstxLogger.logger.trace(getClass().getSimpleName() + ".fail. Participant id: " + _participantId + ", exceptionIdentifier: " + exceptionIdentifier);
    }
    try {
        if (_hier == null)
            throw new UnknownTransactionException();
        _coordManager.resume(_hier);
        // fail means faulted as far as the coordinator manager is concerned
        _coordManager.participantFaulted(_participantId);
        _coordManager.suspend();
    } catch (final InvalidActivityException iae) {
        throw new SystemException("UnknownTransactionException");
    } catch (final UnknownTransactionException ute) {
        throw new SystemException("UnknownTransactionException");
    } catch (com.arjuna.mw.wscf.exceptions.InvalidParticipantException ex) {
        throw new SystemException("UnknownParticipantException");
    } catch (com.arjuna.mw.wsas.exceptions.NoActivityException ex) {
        throw new SystemException("UnknownTransactionException");
    } catch (com.arjuna.mw.wsas.exceptions.SystemException ex) {
        throw new SystemException(ex.toString());
    }
}
Also used : InvalidActivityException(com.arjuna.mw.wsas.exceptions.InvalidActivityException) UnknownTransactionException(com.arjuna.wst.UnknownTransactionException) SystemException(com.arjuna.wst.SystemException)

Example 4 with SystemException

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

the class UserBusinessActivityStandaloneImple method complete.

public void complete() throws UnknownTransactionException, SystemException, WrongStateException {
    try {
        final TxContextImple ctx = ((TxContextImple) _ctxManager.currentTransaction());
        if (ctx == null) {
            throw new WrongStateException();
        }
        final String id = ctx.identifier();
        final W3CEndpointReference terminatorCoordinatorRPC = getTerminationCoordinatorRPC(ctx);
        BusinessActivityTerminatorRPCStub terminatorRPCStub = new BusinessActivityTerminatorRPCStub(id, terminatorCoordinatorRPC);
        terminatorRPCStub.complete();
    } catch (SystemException ex) {
        throw ex;
    } catch (UnknownTransactionException ex) {
        throw ex;
    } catch (WrongStateException ex) {
        throw ex;
    } catch (Exception ex) {
        throw new SystemException(ex.toString());
    }
}
Also used : BusinessActivityTerminatorRPCStub(com.arjuna.wst11.stub.BusinessActivityTerminatorRPCStub) 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.ba.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)

Example 5 with SystemException

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

the class UserBusinessActivityStandaloneImple method begin.

public void begin(int timeout) throws WrongStateException, SystemException {
    try {
        if (_ctxManager.currentTransaction() != null)
            throw new WrongStateException();
        Context ctx = startTransaction(timeout, null);
        _ctxManager.resume(new TxContextImple(ctx));
    } catch (InvalidCreateParametersException ex) {
        tidyup();
        throw new SystemException(ex.toString());
    } catch (UnknownTransactionException ex) {
        tidyup();
        throw new SystemException(ex.toString());
    } catch (SystemException ex) {
        tidyup();
        throw ex;
    }
}
Also used : Context(com.arjuna.mw.wsc11.context.Context) CoordinationContext(org.oasis_open.docs.ws_tx.wscoor._2006._06.CoordinationContext) SystemException(com.arjuna.wst.SystemException) UnknownTransactionException(com.arjuna.wst.UnknownTransactionException) WrongStateException(com.arjuna.wst.WrongStateException) TxContextImple(com.arjuna.mwlabs.wst11.ba.context.TxContextImple) InvalidCreateParametersException(com.arjuna.wsc.InvalidCreateParametersException)

Aggregations

SystemException (com.arjuna.wst.SystemException)74 UnknownTransactionException (com.arjuna.wst.UnknownTransactionException)63 WrongStateException (com.arjuna.wst.WrongStateException)45 TransactionRolledBackException (com.arjuna.wst.TransactionRolledBackException)39 InvalidCreateParametersException (com.arjuna.wsc.InvalidCreateParametersException)20 ArrayList (java.util.ArrayList)19 W3CEndpointReference (javax.xml.ws.wsaddressing.W3CEndpointReference)16 UserBusinessActivity (com.arjuna.mw.wst11.UserBusinessActivity)15 SoapFault (com.arjuna.webservices.SoapFault)15 InstanceIdentifier (com.arjuna.webservices11.wsarj.InstanceIdentifier)13 TxContextImple (com.arjuna.mwlabs.wst11.at.context.TxContextImple)11 TxContextImple (com.arjuna.mwlabs.wst11.ba.context.TxContextImple)11 MAP (org.jboss.ws.api.addressing.MAP)11 CoordinationContext (org.oasis_open.docs.ws_tx.wscoor._2006._06.CoordinationContext)10 Context (com.arjuna.mw.wsc11.context.Context)6 FaultedException (com.arjuna.wst.FaultedException)6 BusinessActivityTerminator (com.arjuna.wst11.BusinessActivityTerminator)6 CoordinationContextType (org.oasis_open.docs.ws_tx.wscoor._2006._06.CoordinationContextType)6 TxContext (com.arjuna.mw.wst.TxContext)5 BusinessActivityManager (com.arjuna.mw.wst11.BusinessActivityManager)5