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");
}
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);
}
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());
}
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());
}
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);
}
}
}
Aggregations