Search in sources :

Example 1 with BusinessActivityManager

use of com.arjuna.mw.wst11.BusinessActivityManager 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 2 with BusinessActivityManager

use of com.arjuna.mw.wst11.BusinessActivityManager in project narayana by jbosstm.

the class CloseBeforeCompletedTest method test.

@Test
public void test() throws Exception {
    ParticipantCompletionCoordinatorCloseBeforeCompletedRules.setParticipantCount(1);
    UserBusinessActivity uba = UserBusinessActivity.getUserBusinessActivity();
    BusinessActivityManager bam = BusinessActivityManager.getBusinessActivityManager();
    com.arjuna.wst11.BAParticipantManager bpm = null;
    DemoBusinessParticipant p = new DemoBusinessParticipant(DemoBusinessParticipant.CLOSE, "1235");
    try {
        uba.begin();
        bpm = bam.enlistForBusinessAgreementWithParticipantCompletion(p, p.identifier());
        bpm.completed();
    } catch (Exception eouter) {
        try {
            uba.cancel();
        } catch (Exception einner) {
            einner.printStackTrace();
        }
        throw eouter;
    }
    boolean caughtTransactionRolledBackException = false;
    try {
        uba.close();
    } catch (TransactionRolledBackException e) {
        caughtTransactionRolledBackException = true;
    }
    assertTrue(caughtTransactionRolledBackException);
}
Also used : DemoBusinessParticipant(com.arjuna.wstx.tests.common.DemoBusinessParticipant) BusinessActivityManager(com.arjuna.mw.wst11.BusinessActivityManager) UserBusinessActivity(com.arjuna.mw.wst11.UserBusinessActivity) TransactionRolledBackException(com.arjuna.wst.TransactionRolledBackException) TransactionRolledBackException(com.arjuna.wst.TransactionRolledBackException) Test(org.junit.Test)

Example 3 with BusinessActivityManager

use of com.arjuna.mw.wst11.BusinessActivityManager in project narayana by jbosstm.

the class ExitTest method testExit.

@Test
public void testExit() throws Exception {
    UserBusinessActivity uba = UserBusinessActivity.getUserBusinessActivity();
    BusinessActivityManager bam = BusinessActivityManager.getBusinessActivityManager();
    com.arjuna.wst11.BAParticipantManager bpm = null;
    DemoBusinessParticipant p = new DemoBusinessParticipant(DemoBusinessParticipant.EXIT, "1238");
    try {
        uba.begin();
        bpm = bam.enlistForBusinessAgreementWithParticipantCompletion(p, "1238");
        bpm.exit();
    } catch (Exception eouter) {
        try {
            uba.cancel();
        } catch (Exception einner) {
        }
        throw eouter;
    }
    uba.close();
    assertTrue(p.passed());
}
Also used : DemoBusinessParticipant(com.arjuna.wstx.tests.common.DemoBusinessParticipant) BusinessActivityManager(com.arjuna.mw.wst11.BusinessActivityManager) UserBusinessActivity(com.arjuna.mw.wst11.UserBusinessActivity) Test(org.junit.Test)

Example 4 with BusinessActivityManager

use of com.arjuna.mw.wst11.BusinessActivityManager in project narayana by jbosstm.

the class CloseTest method testClose.

@Test
public void testClose() throws Exception {
    ParticipantCompletionCoordinatorRules.setParticipantCount(1);
    UserBusinessActivity uba = UserBusinessActivity.getUserBusinessActivity();
    BusinessActivityManager bam = BusinessActivityManager.getBusinessActivityManager();
    com.arjuna.wst11.BAParticipantManager bpm = null;
    DemoBusinessParticipant p = new DemoBusinessParticipant(DemoBusinessParticipant.CLOSE, "1235");
    try {
        uba.begin();
        bpm = bam.enlistForBusinessAgreementWithParticipantCompletion(p, p.identifier());
        bpm.completed();
    } catch (Exception eouter) {
        try {
            uba.cancel();
        } catch (Exception einner) {
        }
        throw eouter;
    }
    uba.close();
    assertTrue(p.passed());
}
Also used : DemoBusinessParticipant(com.arjuna.wstx.tests.common.DemoBusinessParticipant) BusinessActivityManager(com.arjuna.mw.wst11.BusinessActivityManager) UserBusinessActivity(com.arjuna.mw.wst11.UserBusinessActivity) Test(org.junit.Test)

Example 5 with BusinessActivityManager

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

the class BAParticipantCompletionSuperService method saveData.

/**
 * Add an item to a set Enrolls a Participant if necessary and passes the call through to the business logic.
 *
 * @param value the value to add to the set.
 * @throws
 * @throws AlreadyInSetException if value is already in the set
 * @throws SetServiceException   if an error occurred when attempting to add the item to the set.
 */
public void saveData(String value, ServiceCommand... serviceCommands) throws TestApplicationException {
    log.trace("[BA PARTICIPANT COMPL SERVICE] invoked saveData('" + value + "')");
    eventLog.foundEventLogName(value);
    BAParticipantManager participantManager;
    BusinessActivityManager activityManager = BusinessActivityManagerFactory.businessActivityManager();
    String txid;
    try {
        txid = activityManager.currentTransaction().toString();
    } catch (SystemException se) {
        throw new RuntimeException("Error on getting TX id from BusinessActivityManager", se);
    }
    if (participantRegistry.keySet().contains(txid) && ServiceCommand.isPresent(REUSE_BA_PARTICIPANT, serviceCommands)) {
        log.trace("[BA PARTICIPANT COMPL SERVICE] Reusing BA participant manager - command: " + REUSE_BA_PARTICIPANT);
        participantManager = participantRegistry.get(txid);
    } else {
        try {
            // Enlist the Participant for this service:
            BAParticipantCompletionParticipant participant = new BAParticipantCompletionParticipant(serviceCommands, eventLog, value);
            log.trace("[BA PARTICIPANT COMPL SERVICE] Enlisting a participant into the BA");
            participantManager = activityManager.enlistForBusinessAgreementWithParticipantCompletion(participant, "BAParticipantCompletition:" + new Uid().toString());
            participantRegistry.put(txid, participantManager);
        } catch (Exception e) {
            log.error("[BA PARTICIPANT COMPL SERVICE]  Participant enlistment failed", e);
            throw new RuntimeException("Error enlisting participant", e);
        }
    }
    if (ServiceCommand.isPresent(APPLICATION_EXCEPTION, serviceCommands)) {
        throw new TestApplicationException("Intentionally thrown Application Exception - service command set to: " + APPLICATION_EXCEPTION);
    }
    // There could be invoked some back-end business logic here
    /*
         * This service employs the participant completion protocol which means it decides when it wants to commit local
         * changes. If the local changes (adding the item to the set) succeeded, we notify the coordinator that we have
         * completed. Otherwise, we notify the coordinator that we cannot complete. If any other participant fails or the client
         * decides to cancel we can rely upon being told to compensate.
         */
    log.trace("[BA PARTICIPANT COMPL SERVICE] Prepare the backend resource and if successful notify the coordinator that we have completed our work");
    if (ServiceCommand.isPresent(DO_COMPLETE, serviceCommands)) {
        try {
            // Tell the coordinator manager we have finished our work
            log.trace("[BA PARTICIPANT COMPL SERVICE] Prepare successful, notifying coordinator of completion");
            participantManager.completed();
        } catch (Exception e) {
            /* Failed to notify the coordinator that we have finished our work. Compensate the work and throw an Exception
                 * to notify the client that the add operation failed. */
            log.error("[BA PARTICIPANT COMPL SERVICE] 'completed' callback failed");
            throw new RuntimeException("Error when notifying the coordinator that the work is completed", e);
        }
    }
    if (ServiceCommand.isPresent(CANNOT_COMPLETE, serviceCommands)) {
        try {
            // Tell the participant manager we cannot complete. This will force the activity to fail.
            log.trace("[BA PARTICIPANT COMPL SERVICE] Prepared fail, notifying coordinator that we cannot complete");
            participantManager.cannotComplete();
            return;
        } catch (Exception e) {
            log.error("[BA PARTICIPANT COMPL SERVICE] 'cannotComplete' callback failed");
            throw new RuntimeException("Error when notifying the coordinator that the work is cannot be completed", e);
        }
    }
}
Also used : Uid(com.arjuna.ats.arjuna.common.Uid) TestApplicationException(org.jboss.as.test.xts.base.TestApplicationException) SystemException(com.arjuna.wst.SystemException) BusinessActivityManager(com.arjuna.mw.wst11.BusinessActivityManager) BAParticipantManager(com.arjuna.wst11.BAParticipantManager) TestApplicationException(org.jboss.as.test.xts.base.TestApplicationException) SystemException(com.arjuna.wst.SystemException)

Aggregations

BusinessActivityManager (com.arjuna.mw.wst11.BusinessActivityManager)15 UserBusinessActivity (com.arjuna.mw.wst11.UserBusinessActivity)9 Test (org.junit.Test)9 DemoBusinessParticipant (com.arjuna.wstx.tests.common.DemoBusinessParticipant)8 SystemException (com.arjuna.wst.SystemException)6 BAParticipantManager (com.arjuna.wst11.BAParticipantManager)3 FailureBusinessParticipant (com.arjuna.wstx.tests.common.FailureBusinessParticipant)3 Uid (com.arjuna.ats.arjuna.common.Uid)2 WebMethod (javax.jws.WebMethod)2 TestApplicationException (org.jboss.as.test.xts.base.TestApplicationException)2 Context (com.arjuna.mw.wsc11.context.Context)1 TxContext (com.arjuna.mw.wst.TxContext)1 TransactionManager (com.arjuna.mw.wst11.TransactionManager)1 TxContextImple (com.arjuna.mwlabs.wst11.at.context.TxContextImple)1 FaultedException (com.arjuna.wst.FaultedException)1 TransactionRolledBackException (com.arjuna.wst.TransactionRolledBackException)1 WrongStateException (com.arjuna.wst.WrongStateException)1 DemoBusinessParticipantWithComplete (com.arjuna.wstx.tests.common.DemoBusinessParticipantWithComplete)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 Name (javax.xml.soap.Name)1