Search in sources :

Example 1 with NoActivityException

use of com.arjuna.mw.wsas.exceptions.NoActivityException in project narayana by jbosstm.

the class ContextFactoryImple method create.

/**
 * Creates a coordination context.
 *
 * @param coordinationTypeURI
 *            the coordination type uri
 * @param expires
 *            the expire date/time for the returned context, can be null
 * @param currentContext
 *            the current context, can be null
 *
 * @return the created coordination context
 *
 * @throws com.arjuna.wsc.InvalidCreateParametersException
 *             if a parameter passed is invalid this activity identifier.
 */
public CoordinationContext create(final String coordinationTypeURI, final Long expires, final CoordinationContextType currentContext, final boolean isSecure) throws InvalidCreateParametersException {
    if (coordinationTypeURI.equals(AtomicTransactionConstants.WSAT_PROTOCOL)) {
        try {
            if (currentContext == null) {
                // make sure no transaction is currently associated
                _coordManager.suspend();
                final int timeout;
                if (expires == null) {
                    timeout = 0;
                } else {
                    final long timeoutVal = expires.longValue();
                    timeout = (timeoutVal > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) timeoutVal);
                }
                _coordManager.begin(ArjunaContextImple.serviceType, timeout);
                final ArjunaContextImple arjunaContext = ArjunaContextImple.getContext();
                final ServiceRegistry serviceRegistry = PrivilegedServiceRegistryFactory.getInstance().getServiceRegistry();
                final String registrationCoordinatorURI = serviceRegistry.getServiceURI(CoordinationConstants.REGISTRATION_SERVICE_NAME, isSecure);
                final CoordinationContext coordinationContext = new CoordinationContext();
                coordinationContext.setCoordinationType(coordinationTypeURI);
                CoordinationContextType.Identifier identifier = new CoordinationContextType.Identifier();
                identifier.setValue("urn:" + arjunaContext.getTransactionIdentifier());
                coordinationContext.setIdentifier(identifier);
                final int transactionExpires = arjunaContext.getTransactionExpires();
                if (transactionExpires > 0) {
                    Expires expiresInstance = new Expires();
                    expiresInstance.setValue(transactionExpires);
                    coordinationContext.setExpires(expiresInstance);
                }
                W3CEndpointReference registrationCoordinator = getRegistrationCoordinator(registrationCoordinatorURI, arjunaContext);
                coordinationContext.setRegistrationService(registrationCoordinator);
                /*
				 * Now add the registrar for this specific coordinator to the
				 * mapper.
				 */
                _coordManager.enlistSynchronization(new CleanupSynchronization(_coordManager.identifier().toString(), _theRegistrar));
                /*
				 * TODO Uughh! This does a suspend for us! Left over from original
				 * WS-AS stuff.
				 *
				 * TODO
				 * REFACTOR, REFACTOR, REFACTOR.
				 */
                _theRegistrar.associate();
                return coordinationContext;
            } else {
                // we need to create a subordinate transaction and register it as both a durable and volatile
                // participant with the registration service defined in the current context
                SubordinateATCoordinator subTx = (SubordinateATCoordinator) createSubordinate();
                // hmm, need to create wrappers here as the subTx is in WSCF which only knows
                // about WSAS and WS-C and the participant is in WS-T
                String vtppid = subTx.getVolatile2PhaseId();
                String dtppid = subTx.getDurable2PhaseId();
                Volatile2PCParticipant vtpp = new SubordinateVolatile2PCStub(subTx);
                Durable2PCParticipant dtpp = new SubordinateDurable2PCStub(subTx);
                final String messageId = MessageId.getMessageId();
                W3CEndpointReference participant;
                W3CEndpointReference coordinator;
                participant = getParticipant(vtppid, isSecure);
                coordinator = RegistrationCoordinator.register(currentContext, messageId, participant, AtomicTransactionConstants.WSAT_SUB_PROTOCOL_VOLATILE_2PC);
                ParticipantProcessor.getProcessor().activateParticipant(new ParticipantEngine(vtpp, vtppid, coordinator), vtppid);
                participant = getParticipant(dtppid, isSecure);
                coordinator = RegistrationCoordinator.register(currentContext, messageId, participant, AtomicTransactionConstants.WSAT_SUB_PROTOCOL_DURABLE_2PC);
                ParticipantProcessor.getProcessor().activateParticipant(new ParticipantEngine(dtpp, dtppid, coordinator), dtppid);
                // 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(coordinationTypeURI);
                CoordinationContextType.Identifier identifier = new CoordinationContextType.Identifier();
                String txId = subTx.get_uid().stringForm();
                identifier.setValue("urn:" + txId);
                coordinationContext.setIdentifier(identifier);
                Expires expiresInstance = currentContext.getExpires();
                final long transactionExpires = (expiresInstance != null ? expiresInstance.getValue() : 0);
                if (transactionExpires > 0) {
                    expiresInstance = new Expires();
                    expiresInstance.setValue(transactionExpires);
                    coordinationContext.setExpires(expiresInstance);
                }
                W3CEndpointReference registrationCoordinator = getRegistrationCoordinator(registrationCoordinatorURI, txId);
                coordinationContext.setRegistrationService(registrationCoordinator);
                // now associate the tx id with the sub transaction
                _theRegistrar.associate(subTx);
                return coordinationContext;
            }
        } catch (NoActivityException ex) {
            ex.printStackTrace();
            throw new InvalidCreateParametersException();
        } catch (SystemException ex) {
            ex.printStackTrace();
        } catch (com.arjuna.mw.wsas.exceptions.WrongStateException ex) {
            ex.printStackTrace();
            throw new InvalidCreateParametersException();
        } catch (Exception ex) {
            // TODO handle properly
            ex.printStackTrace();
        }
    } else {
        wstxLogger.i18NLogger.warn_mwlabs_wst_at_Context11FactoryImple_1(AtomicTransactionConstants.WSAT_PROTOCOL, coordinationTypeURI);
        throw new InvalidCreateParametersException(wstxLogger.i18NLogger.get_mwlabs_wst_at_Context11FactoryImple_3() + " < " + AtomicTransactionConstants.WSAT_PROTOCOL + ", " + coordinationTypeURI + " >");
    }
    return null;
}
Also used : Durable2PCParticipant(com.arjuna.wst.Durable2PCParticipant) CleanupSynchronization(com.arjuna.mwlabs.wst11.at.participants.CleanupSynchronization) InvalidCreateParametersException(com.arjuna.wsc.InvalidCreateParametersException) InstanceIdentifier(com.arjuna.webservices11.wsarj.InstanceIdentifier) Volatile2PCParticipant(com.arjuna.wst.Volatile2PCParticipant) SystemException(com.arjuna.mw.wsas.exceptions.SystemException) ParticipantEngine(com.arjuna.wst11.messaging.engines.ParticipantEngine) SubordinateVolatile2PCStub(com.arjuna.wst11.stub.SubordinateVolatile2PCStub) CoordinationContextType(org.oasis_open.docs.ws_tx.wscoor._2006._06.CoordinationContextType) NoActivityException(com.arjuna.mw.wsas.exceptions.NoActivityException) InvalidProtocolException(com.arjuna.wsc.InvalidProtocolException) InvalidCreateParametersException(com.arjuna.wsc.InvalidCreateParametersException) SystemException(com.arjuna.mw.wsas.exceptions.SystemException) NoActivityException(com.arjuna.mw.wsas.exceptions.NoActivityException) CoordinationContext(org.oasis_open.docs.ws_tx.wscoor._2006._06.CoordinationContext) ArjunaContextImple(com.arjuna.mwlabs.wst11.at.context.ArjunaContextImple) SubordinateATCoordinator(com.arjuna.mwlabs.wscf.model.twophase.arjunacore.subordinate.SubordinateATCoordinator) W3CEndpointReference(javax.xml.ws.wsaddressing.W3CEndpointReference) ServiceRegistry(com.arjuna.webservices11.ServiceRegistry) Expires(org.oasis_open.docs.ws_tx.wscoor._2006._06.Expires) SubordinateDurable2PCStub(com.arjuna.wst11.stub.SubordinateDurable2PCStub)

Example 2 with NoActivityException

use of com.arjuna.mw.wsas.exceptions.NoActivityException in project narayana by jbosstm.

the class ContextFactoryImple method createBridgedTransaction.

/**
 * create a bridged to subordinate WS-AT 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-AT
 * transaction bridge code.
 * @param subordinateType a unique string which groups subordinates for the benefit of their parent tx/app and
 * allows them to be identified and retrieved as a group during recovery
 * @param expires the timeout for the bridged to AT 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(String subordinateType, final Long expires, final boolean isSecure) {
    // we must have a type and it must not be the AT-AT subordinate type
    if (subordinateType == null || SubordinateATCoordinator.SUBORDINATE_TX_TYPE_AT_AT.equals(subordinateType)) {
        return null;
    }
    // we need to create a subordinate transaction and register it as both a durable and volatile
    // participant with the registration service defined in the current context
    SubordinateATCoordinator subTx = null;
    try {
        subTx = (SubordinateATCoordinator) createSubordinate(subordinateType);
    } 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(AtomicTransactionConstants.WSAT_PROTOCOL);
    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;
}
Also used : NoActivityException(com.arjuna.mw.wsas.exceptions.NoActivityException) InvalidProtocolException(com.arjuna.wsc.InvalidProtocolException) InvalidCreateParametersException(com.arjuna.wsc.InvalidCreateParametersException) SystemException(com.arjuna.mw.wsas.exceptions.SystemException) NoActivityException(com.arjuna.mw.wsas.exceptions.NoActivityException) CoordinationContext(org.oasis_open.docs.ws_tx.wscoor._2006._06.CoordinationContext) SubordinateATCoordinator(com.arjuna.mwlabs.wscf.model.twophase.arjunacore.subordinate.SubordinateATCoordinator) InstanceIdentifier(com.arjuna.webservices11.wsarj.InstanceIdentifier) SystemException(com.arjuna.mw.wsas.exceptions.SystemException) InvalidProtocolException(com.arjuna.wsc.InvalidProtocolException) W3CEndpointReference(javax.xml.ws.wsaddressing.W3CEndpointReference) ServiceRegistry(com.arjuna.webservices11.ServiceRegistry) Expires(org.oasis_open.docs.ws_tx.wscoor._2006._06.Expires) CoordinationContextType(org.oasis_open.docs.ws_tx.wscoor._2006._06.CoordinationContextType)

Example 3 with NoActivityException

use of com.arjuna.mw.wsas.exceptions.NoActivityException in project narayana by jbosstm.

the class ContextFactoryImple method createSubordinate.

public final Object createSubordinate(String subordinateType) throws NoActivityException, InvalidProtocolException, SystemException {
    try {
        CoordinatorServiceImple coordManager = (CoordinatorServiceImple) _coordManager;
        CoordinatorControl theControl = coordManager.coordinatorControl();
        ATCoordinator subordinateTransaction = theControl.createSubordinate(subordinateType);
        /*
			 * 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());
    }
}
Also used : CleanupSynchronization(com.arjuna.mwlabs.wst11.at.participants.CleanupSynchronization) SystemException(com.arjuna.mw.wsas.exceptions.SystemException) SubordinateATCoordinator(com.arjuna.mwlabs.wscf.model.twophase.arjunacore.subordinate.SubordinateATCoordinator) ATCoordinator(com.arjuna.mwlabs.wscf.model.twophase.arjunacore.ATCoordinator) CoordinatorServiceImple(com.arjuna.mwlabs.wscf.model.twophase.arjunacore.CoordinatorServiceImple) CoordinatorControl(com.arjuna.mwlabs.wscf.model.twophase.arjunacore.CoordinatorControl) InvalidProtocolException(com.arjuna.wsc.InvalidProtocolException) InvalidCreateParametersException(com.arjuna.wsc.InvalidCreateParametersException) SystemException(com.arjuna.mw.wsas.exceptions.SystemException) NoActivityException(com.arjuna.mw.wsas.exceptions.NoActivityException)

Example 4 with NoActivityException

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.
 *
 * @param cs The CompletionStatus to use.
 *
 * @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.Outcome
 */
public Outcome end(CompletionStatus cs) throws InvalidActivityException, WrongStateException, ProtocolViolationException, SystemException, NoActivityException, NoPermissionException, ActiveChildException {
    ActivityImple currentActivity = current();
    if (currentActivity == null) {
        throw new NoActivityException();
    }
    /*
	if (currentActivity.parent() != null)
	    throw new ActiveChildException();
	*/
    Outcome res = null;
    String serviceType = currentActivity.serviceType();
    try {
        res = currentActivity.end(cs);
    } catch (Exception ex) {
        wsasLogger.i18NLogger.warn_UserActivityImple_2(ex);
    }
    HLS hls = HLSManager.getHighLevelService(serviceType);
    if (hls != null) {
        try {
            hls.completed();
        } catch (SystemException ex) {
            wsasLogger.i18NLogger.warn_UserActivityImple_3(ex);
        }
    }
    pop();
    return res;
}
Also used : SystemException(com.arjuna.mw.wsas.exceptions.SystemException) ActivityImple(com.arjuna.mwlabs.wsas.activity.ActivityImple) Outcome(com.arjuna.mw.wsas.activity.Outcome) NoActivityException(com.arjuna.mw.wsas.exceptions.NoActivityException) EmptyStackException(java.util.EmptyStackException) SystemException(com.arjuna.mw.wsas.exceptions.SystemException) InvalidTimeoutException(com.arjuna.mw.wsas.exceptions.InvalidTimeoutException) ActiveChildException(com.arjuna.mw.wsas.exceptions.ActiveChildException) NoPermissionException(com.arjuna.mw.wsas.exceptions.NoPermissionException) NoActivityException(com.arjuna.mw.wsas.exceptions.NoActivityException) WrongStateException(com.arjuna.mw.wsas.exceptions.WrongStateException) InvalidActivityException(com.arjuna.mw.wsas.exceptions.InvalidActivityException) ProtocolViolationException(com.arjuna.mw.wsas.exceptions.ProtocolViolationException) HLS(com.arjuna.mw.wsas.activity.HLS)

Example 5 with NoActivityException

use of com.arjuna.mw.wsas.exceptions.NoActivityException in project narayana by jbosstm.

the class UserActivityImple method setCompletionStatus.

/**
 * Set the termination status for the current activity, if any.
 *
 * @param endStatus The state in which the activity
 * should attempt to terminate. This may
 * be one of the default values provided by WSAS or may be extended in
 * an implementation specific manner by an HLS.
 *
 * @exception NoActivityException Thrown if there is no activity
 * associated with the invoking thread.
 * @exception WrongStateException Thrown if the completion status is
 * incompatible with the current state of the activity.
 * @exception SystemException Thrown if any other error occurs.
 */
public void setCompletionStatus(CompletionStatus endStatus) throws NoActivityException, WrongStateException, SystemException {
    ActivityImple curr = current();
    if (curr == null)
        throw new NoActivityException();
    curr.setCompletionStatus(endStatus);
}
Also used : ActivityImple(com.arjuna.mwlabs.wsas.activity.ActivityImple) NoActivityException(com.arjuna.mw.wsas.exceptions.NoActivityException)

Aggregations

NoActivityException (com.arjuna.mw.wsas.exceptions.NoActivityException)12 SystemException (com.arjuna.mw.wsas.exceptions.SystemException)7 InvalidCreateParametersException (com.arjuna.wsc.InvalidCreateParametersException)5 InvalidProtocolException (com.arjuna.wsc.InvalidProtocolException)5 UserActivity (com.arjuna.mw.wsas.UserActivity)3 HLS (com.arjuna.mw.wsas.activity.HLS)3 ActivityImple (com.arjuna.mwlabs.wsas.activity.ActivityImple)3 SubordinateATCoordinator (com.arjuna.mwlabs.wscf.model.twophase.arjunacore.subordinate.SubordinateATCoordinator)3 ServiceRegistry (com.arjuna.webservices11.ServiceRegistry)3 InstanceIdentifier (com.arjuna.webservices11.wsarj.InstanceIdentifier)3 W3CEndpointReference (javax.xml.ws.wsaddressing.W3CEndpointReference)3 Test (org.junit.Test)3 CoordinationContext (org.oasis_open.docs.ws_tx.wscoor._2006._06.CoordinationContext)3 CoordinationContextType (org.oasis_open.docs.ws_tx.wscoor._2006._06.CoordinationContextType)3 Expires (org.oasis_open.docs.ws_tx.wscoor._2006._06.Expires)3 Outcome (com.arjuna.mw.wsas.activity.Outcome)2 ActiveChildException (com.arjuna.mw.wsas.exceptions.ActiveChildException)2 InvalidActivityException (com.arjuna.mw.wsas.exceptions.InvalidActivityException)2 InvalidTimeoutException (com.arjuna.mw.wsas.exceptions.InvalidTimeoutException)2 NoPermissionException (com.arjuna.mw.wsas.exceptions.NoPermissionException)2