use of com.arjuna.mw.wst11.BusinessActivityManager 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);
}
use of com.arjuna.mw.wst11.BusinessActivityManager in project narayana by jbosstm.
the class JaxBaseHeaderContextProcessor method handleOutboundMessage.
/**
* Handle the request.
*
* @param soapMessage The current message context.
* @param mustUnderstand Value of MustUnderstand attribute.
* @return whether the message was handled
*/
public boolean handleOutboundMessage(final SOAPMessage soapMessage, boolean mustUnderstand) {
if (soapMessage == null) {
return true;
}
try {
/*
* There should either be an Atomic Transaction *or* a Business Activity
* associated with the thread.
*/
final TransactionManager transactionManager = TransactionManagerFactory.transactionManager();
final com.arjuna.mw.wst11.BusinessActivityManager businessActivityManager = BusinessActivityManagerFactory.businessActivityManager();
final Context atContext;
if (transactionManager != null) {
final TxContextImple txContext = (TxContextImple) transactionManager.currentTransaction();
atContext = (txContext == null ? null : txContext.context());
} else {
atContext = null;
}
final Context baContext;
if (businessActivityManager != null) {
final com.arjuna.mwlabs.wst11.ba.context.TxContextImple txContext = (com.arjuna.mwlabs.wst11.ba.context.TxContextImple) businessActivityManager.currentTransaction();
baContext = (txContext == null ? null : txContext.context());
} else {
baContext = null;
}
final CoordinationContextType coordinationContext;
if (baContext != null) {
coordinationContext = baContext.getCoordinationContext();
} else if (atContext != null) {
coordinationContext = atContext.getCoordinationContext();
} else {
coordinationContext = null;
}
if (coordinationContext != null) {
final SOAPEnvelope env = soapMessage.getSOAPPart().getEnvelope();
SOAPHeader header = env.getHeader();
if (header == null) {
header = env.addHeader();
}
final Name name = env.createName(CoordinationConstants.WSCOOR_ELEMENT_COORDINATION_CONTEXT, CoordinationConstants.WSCOOR_PREFIX, CoordinationConstants.WSCOOR_NAMESPACE);
final SOAPHeaderElement headerElement = header.addHeaderElement(name);
headerElement.addNamespaceDeclaration(CoordinationConstants.WSCOOR_PREFIX, CoordinationConstants.WSCOOR_NAMESPACE);
headerElement.setMustUnderstand(mustUnderstand);
CoordinationContextHelper.serialise(coordinationContext, headerElement);
}
} catch (final Throwable th) {
wstxLogger.i18NLogger.warn_mw_wst11_client_JaxHC11P_1("com.arjuna.mw.wst11.client.JaxBaseHeaderContextProcessor.handleRequest()", th);
}
return true;
}
use of com.arjuna.mw.wst11.BusinessActivityManager in project narayana by jbosstm.
the class ConfirmWithCompleteTest method testConfirmWithComplete.
@Test
public void testConfirmWithComplete() throws Exception {
UserBusinessActivity uba = UserBusinessActivity.getUserBusinessActivity();
BusinessActivityManager bam = BusinessActivityManager.getBusinessActivityManager();
DemoBusinessParticipantWithComplete p = new DemoBusinessParticipantWithComplete(DemoBusinessParticipantWithComplete.COMPLETE, "1234");
try {
uba.begin();
bam.enlistForBusinessAgreementWithCoordinatorCompletion(p, "1237");
uba.complete();
} catch (Exception eouter) {
try {
uba.cancel();
} catch (Exception einner) {
}
throw eouter;
}
uba.cancel();
assertTrue(p.passed());
}
use of com.arjuna.mw.wst11.BusinessActivityManager in project narayana by jbosstm.
the class MultiCloseTest method testMultiClose.
@Test
public void testMultiClose() throws Exception {
ParticipantCompletionCoordinatorRules.setParticipantCount(2);
UserBusinessActivity uba = UserBusinessActivity.getUserBusinessActivity();
BusinessActivityManager bam = BusinessActivityManager.getBusinessActivityManager();
com.arjuna.wst11.BAParticipantManager bpm1 = null;
com.arjuna.wst11.BAParticipantManager bpm2 = null;
DemoBusinessParticipant p = new DemoBusinessParticipant(DemoBusinessParticipant.CLOSE, "1240");
FailureBusinessParticipant fp = new FailureBusinessParticipant(FailureBusinessParticipant.FAIL_IN_CLOSE, "5679");
try {
uba.begin();
bpm1 = bam.enlistForBusinessAgreementWithParticipantCompletion(p, "1240");
bpm2 = bam.enlistForBusinessAgreementWithParticipantCompletion(fp, "5679");
bpm1.completed();
bpm2.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 narayana by jbosstm.
the class CompensateTest method testCompensate.
@Test
public void testCompensate() throws Exception {
ParticipantCompletionCoordinatorRules.setParticipantCount(1);
UserBusinessActivity uba = UserBusinessActivity.getUserBusinessActivity();
BusinessActivityManager bam = BusinessActivityManager.getBusinessActivityManager();
com.arjuna.wst11.BAParticipantManager bpm = null;
String participantId = "1236";
DemoBusinessParticipant p = new DemoBusinessParticipant(DemoBusinessParticipant.COMPENSATE, participantId);
try {
uba.begin();
bpm = bam.enlistForBusinessAgreementWithParticipantCompletion(p, participantId);
bpm.completed();
} catch (Exception eouter) {
try {
uba.cancel();
} catch (Exception einner) {
}
throw eouter;
}
uba.cancel();
assertTrue(p.passed());
}
Aggregations