use of com.arjuna.mw.wsas.exceptions.NoActivityException in project narayana by jbosstm.
the class NestedActivityTest method testNestedActivity.
@Test
public void testNestedActivity() throws Exception {
UserActivity ua = UserActivityFactory.userActivity();
try {
ua.start("dummy");
System.out.println("Started: " + ua.activityName());
ua.start("dummy");
String nested = ua.activityName();
System.out.println("Started: " + nested);
System.out.println("\nEnding: " + nested);
ua.end();
String parent = ua.activityName();
System.out.println("\nCurrent: " + parent);
System.out.println("\nEnding: " + parent);
ua.end();
try {
if (ua.activityName() != null) {
fail("activity name should be null but is " + ua.activityName());
}
} catch (NoActivityException ex) {
// ok if we get here
}
System.out.println("\nEnded.");
} catch (Exception ex) {
WSASTestUtils.cleanup(ua);
throw ex;
}
}
use of com.arjuna.mw.wsas.exceptions.NoActivityException in project narayana by jbosstm.
the class UserActivityImple method end.
/**
* Complete the activity with the completion status provided.
*
* @exception InvalidActivityException Thrown if the current activity is
* invalid in the execution environment.
* @exception ActiveChildException Thrown if the current activity is a
* @exception WrongStateException Thrown if the current activity is not in a
* state that allows it to be completed, or is incompatible with the
* completion status provided.
* @exception ProtocolViolationException Thrown if the a violation of the
* activity service or HLS protocol occurs.
* @exception NoActivityException Thrown if there is no activity
* associated with the invoking thread or none with the given type of coordinator.
* @exception NoPermissionException Thrown if the invoking thread does
* not have permission to terminate the transaction.
* @exception SystemException Thrown if some other error occurred.
*
* @return the result of completing the activity. Null is valid and must
* be interpreted within the context of any HLS that may exist.
*
* @see com.arjuna.mw.wsas.activity.Outcome
* @message com.arjuna.mwlabs.wsas.UserActivityImple_2 [com.arjuna.mwlabs.wsas.UserActivityImple_2] - currentActivity.end threw:
* @message com.arjuna.mwlabs.wsas.UserActivityImple_3 [com.arjuna.mwlabs.wsas.UserActivityImple_3] - Activity.completed caught:
*/
public Outcome end() throws InvalidActivityException, WrongStateException, ProtocolViolationException, SystemException, NoActivityException, SystemException, NoPermissionException, ActiveChildException {
ActivityImple currentActivity = current();
if (currentActivity == null) {
throw new NoActivityException();
}
Outcome res = null;
String serviceType = currentActivity.serviceType();
try {
res = currentActivity.end();
} catch (Exception ex) {
wsasLogger.i18NLogger.warn_UserActivityImple_1(ex);
}
HLS hls = HLSManager.getHighLevelService(serviceType);
if (hls != null) {
try {
hls.completed();
} catch (SystemException ex) {
wsasLogger.i18NLogger.warn_UserActivityImple_3(ex);
}
}
pop();
return res;
}
use of com.arjuna.mw.wsas.exceptions.NoActivityException in project narayana by jbosstm.
the class ContextManager method context.
/**
* message com.arjuna.mw.wsas.context.ContextManager_3 [com.arjuna.mw.wsas.context.ContextManager_3] - getHighLevelServices threw:
* message com.arjuna.mw.wsas.context.ContextManager_4 [com.arjuna.mw.wsas.context.ContextManager_4] - assembling context and received:
*/
public final Context context(String serviceType) {
Context ctx = null;
HLS service = null;
try {
// ensure we are in an activity associated with the correct service type
String currentServiceType = UserActivityFactory.userActivity().serviceType();
if (currentServiceType.equals(serviceType)) {
service = _manager.getHighLevelService(serviceType);
}
} catch (NoActivityException nae) {
// ignore
} catch (Exception ex) {
wsasLogger.i18NLogger.warn_context_ContextManager_1(ex);
}
if (service != null) {
try {
ctx = service.context();
} catch (Exception ex) {
wsasLogger.i18NLogger.warn_context_ContextManager_2(ex);
ctx = null;
}
}
return ctx;
}
use of com.arjuna.mw.wsas.exceptions.NoActivityException in project narayana by jbosstm.
the class ContextFactoryImple method createBridgedTransaction.
/**
* create a bridged to subordinate WS-BA 1.1 transaction, associate it with the registrar and create and return
* a coordination context for it. n.b. this is a private, behind-the-scenes method for use by the JTA-BA
* transaction bridge code.
* @param expires the timeout for the bridged to BA transaction
* @param isSecure true if the registration cooridnator URL should use a secure address, otherwise false.
* @return a coordination context for the bridged to transaction
*/
public BridgeTxData createBridgedTransaction(final Long expires, final boolean isSecure) {
// we need to create a subordinate transaction and expose it to the bridge layer so it can
// be driven to completion
SubordinateBACoordinator subTx = null;
try {
subTx = (SubordinateBACoordinator) createSubordinate();
} catch (NoActivityException e) {
// will not happen
return null;
} catch (InvalidProtocolException e) {
// will not happen
return null;
} catch (SystemException e) {
// may happen
return null;
}
// ok now create the context
final ServiceRegistry serviceRegistry = PrivilegedServiceRegistryFactory.getInstance().getServiceRegistry();
final String registrationCoordinatorURI = serviceRegistry.getServiceURI(CoordinationConstants.REGISTRATION_SERVICE_NAME, isSecure);
final CoordinationContext coordinationContext = new CoordinationContext();
coordinationContext.setCoordinationType(BusinessActivityConstants.WSBA_PROTOCOL_ATOMIC_OUTCOME);
CoordinationContextType.Identifier identifier = new CoordinationContextType.Identifier();
String txId = subTx.get_uid().stringForm();
identifier.setValue("urn:" + txId);
coordinationContext.setIdentifier(identifier);
if (expires != null && expires.longValue() > 0) {
Expires expiresInstance = new Expires();
expiresInstance.setValue(expires);
coordinationContext.setExpires(expiresInstance);
}
W3CEndpointReference registrationCoordinator = getRegistrationCoordinator(registrationCoordinatorURI, txId);
coordinationContext.setRegistrationService(registrationCoordinator);
try {
_theRegistrar.associate(subTx);
} catch (Exception e) {
// will not happen
}
BridgeTxData bridgeTxData = new BridgeTxData();
bridgeTxData.context = coordinationContext;
bridgeTxData.coordinator = subTx;
bridgeTxData.identifier = txId;
return bridgeTxData;
}
use of com.arjuna.mw.wsas.exceptions.NoActivityException in project narayana by jbosstm.
the class ContextFactoryImple method createSubordinate.
public final Object createSubordinate() throws NoActivityException, InvalidProtocolException, SystemException {
try {
CoordinatorServiceImple coordManager = (CoordinatorServiceImple) _coordManager;
BACoordinator subordinateTransaction = coordManager.createSubordinate();
/*
* Now add the registrar for this specific coordinator to the
* mapper.
*/
subordinateTransaction.enlistSynchronization(new CleanupSynchronization(subordinateTransaction.get_uid().stringForm(), _theRegistrar));
_theRegistrar.associate(subordinateTransaction);
return subordinateTransaction;
} catch (Exception ex) {
throw new SystemException(ex.toString());
}
}
Aggregations