Search in sources :

Example 1 with UserTransaction

use of com.arjuna.mw.wst11.UserTransaction 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.infof("[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 2 with UserTransaction

use of com.arjuna.mw.wst11.UserTransaction in project quickstarts by jboss-switchyard.

the class AirportService method order.

/**
     * Order flight ticket defined by fltid for a user identified by name.
     * @param name username
     * @param fltid flight identifier
     */
@WebMethod
public void order(@WebParam(name = "name") String name, @WebParam(name = "fltid") String fltid) {
    log.info("AirportService:order");
    UserTransaction transactionId = UserTransactionFactory.userTransaction();
    if (transactionId != null) {
        log.info("Transaction ID = " + transactionId.toString());
        if (transactionId.toString().compareTo("Unknown") == 0) {
            log.info("JBoss AS is badly configured. (Enable XTS)");
            return;
        }
        // Create order participant (fly ticket)
        OrderParticipant op = new OrderParticipant(transactionId.toString(), fltid);
        try {
            // Enlist order participant to the transaction
            TransactionManagerFactory.transactionManager().enlistForDurableTwoPhase(op, "org.switchyard.quickstarts.bpel.xts.wsat.ws:AirportService:" + name + ":" + fltid);
        } catch (Exception e) {
            log.log(Level.SEVERE, e.getMessage());
            e.printStackTrace();
        }
    }
}
Also used : UserTransaction(com.arjuna.mw.wst11.UserTransaction) WebMethod(javax.jws.WebMethod)

Example 3 with UserTransaction

use of com.arjuna.mw.wst11.UserTransaction in project wildfly by wildfly.

the class TransactionalTestCase method testActiveTransaction.

@Test
public void testActiveTransaction() throws Exception {
    final String deploymentUrl = DEPLOYMENT_URL;
    final TransactionalService transactionalService = TransactionalClient.newInstance(deploymentUrl);
    final UserTransaction userTransaction = UserTransaction.getUserTransaction();
    userTransaction.begin();
    final boolean isTransactionActive = transactionalService.isTransactionActive();
    userTransaction.commit();
    Assert.assertEquals(true, isTransactionActive);
}
Also used : UserTransaction(com.arjuna.mw.wst11.UserTransaction) TransactionalService(org.jboss.as.test.xts.annotation.service.TransactionalService) Test(org.junit.Test)

Aggregations

UserTransaction (com.arjuna.mw.wst11.UserTransaction)3 Uid (com.arjuna.ats.arjuna.common.Uid)1 TransactionManager (com.arjuna.mw.wst11.TransactionManager)1 UnknownTransactionException (com.arjuna.wst.UnknownTransactionException)1 WrongStateException (com.arjuna.wst.WrongStateException)1 WebMethod (javax.jws.WebMethod)1 TransactionalService (org.jboss.as.test.xts.annotation.service.TransactionalService)1 TestApplicationException (org.jboss.as.test.xts.base.TestApplicationException)1 Test (org.junit.Test)1