Search in sources :

Example 6 with Expires

use of org.oasis_open.docs.ws_tx.wscoor._2006._06.Expires in project narayana by jbosstm.

the class ActivationCoordinator method createCoordinationContext.

/**
 * Create the coordination context.
 * @param activationCoordinatorURI The URI of the activation coordinator.
 * @param messageID The messageID to use.
 * @param coordinationTypeURI The coordination type.
 * @param expires The expiry time or null.
 * @param currentContext The currnt context or null.
 * @return The coordination context.
 * @throws com.arjuna.wsc.InvalidCreateParametersException if the create parameters are invalid.
 * @throws SoapFault for errors during processing.
 */
public static CoordinationContextType createCoordinationContext(final String activationCoordinatorURI, final String messageID, final String coordinationTypeURI, final Long expires, final CoordinationContext currentContext) throws InvalidCreateParametersException, SoapFault {
    final MAP map = AddressingHelper.createRequestContext(activationCoordinatorURI, messageID);
    final Expires expiresValue;
    if (expires == null) {
        expiresValue = null;
    } else {
        expiresValue = new Expires();
        expiresValue.setValue(expires.longValue());
    }
    try {
        CreateCoordinationContextResponseType response;
        ActivationCoordinatorClient client = ActivationCoordinatorClient.getClient();
        response = client.sendCreateCoordination(map, coordinationTypeURI, expiresValue, currentContext);
        return response.getCoordinationContext();
    } catch (final IOException ioe) {
        throw new SoapFault11(ioe);
    } catch (SOAPFaultException sfe) {
        // TODO -- work out which faults we should really throw. in particular do we need to retain SoapFault
        final SOAPFault soapFault = sfe.getFault();
        final QName subcode = soapFault.getFaultCodeAsQName();
        if (CoordinationConstants.WSCOOR_ERROR_CODE_INVALID_PARAMETERS_QNAME.equals(subcode)) {
            Detail detail = soapFault.getDetail();
            String message = (detail != null ? detail.getTextContent() : soapFault.getFaultString());
            throw new InvalidCreateParametersException(message);
        }
        throw SoapFault11.create(sfe);
    }
}
Also used : ActivationCoordinatorClient(com.arjuna.webservices11.wscoor.client.ActivationCoordinatorClient) QName(javax.xml.namespace.QName) SoapFault11(com.arjuna.webservices11.SoapFault11) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) SOAPFault(javax.xml.soap.SOAPFault) Expires(org.oasis_open.docs.ws_tx.wscoor._2006._06.Expires) IOException(java.io.IOException) MAP(org.jboss.ws.api.addressing.MAP) CreateCoordinationContextResponseType(org.oasis_open.docs.ws_tx.wscoor._2006._06.CreateCoordinationContextResponseType) Detail(javax.xml.soap.Detail) InvalidCreateParametersException(com.arjuna.wsc.InvalidCreateParametersException)

Example 7 with Expires

use of org.oasis_open.docs.ws_tx.wscoor._2006._06.Expires in project narayana by jbosstm.

the class UserBusinessActivityStandaloneImple method startTransaction.

private final Context startTransaction(int timeout, TxContextImple current) throws InvalidCreateParametersException, SystemException {
    try {
        final Long expires = (timeout > 0 ? new Long(timeout) : null);
        final String messageId = MessageId.getMessageId();
        final CoordinationContext currentContext = (current != null ? getContext(current) : null);
        final CoordinationContextType coordinationContext = ActivationCoordinator.createCoordinationContext(_activationCoordinatorService, messageId, BusinessActivityConstants.WSBA_PROTOCOL_ATOMIC_OUTCOME, expires, currentContext);
        if (coordinationContext == null) {
            throw new SystemException(wstxLogger.i18NLogger.get_mwlabs_wst11_ba_remote_UserBusinessActivityImple_2());
        }
        return new ContextImple(coordinationContext);
    } catch (final InvalidCreateParametersException icpe) {
        throw icpe;
    } catch (final SoapFault sf) {
        throw new SystemException(sf.getMessage());
    } catch (final Exception ex) {
        throw new SystemException(ex.toString());
    }
}
Also used : SoapFault(com.arjuna.webservices.SoapFault) TxContextImple(com.arjuna.mwlabs.wst11.ba.context.TxContextImple) ContextImple(com.arjuna.mwlabs.wst11.ba.ContextImple) SystemException(com.arjuna.wst.SystemException) CoordinationContextType(org.oasis_open.docs.ws_tx.wscoor._2006._06.CoordinationContextType) InvalidCreateParametersException(com.arjuna.wsc.InvalidCreateParametersException) UnknownTransactionException(com.arjuna.wst.UnknownTransactionException) WrongStateException(com.arjuna.wst.WrongStateException) SystemException(com.arjuna.wst.SystemException) InvalidCreateParametersException(com.arjuna.wsc.InvalidCreateParametersException) TransactionRolledBackException(com.arjuna.wst.TransactionRolledBackException) CoordinationContext(org.oasis_open.docs.ws_tx.wscoor._2006._06.CoordinationContext)

Example 8 with Expires

use of org.oasis_open.docs.ws_tx.wscoor._2006._06.Expires 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 9 with Expires

use of org.oasis_open.docs.ws_tx.wscoor._2006._06.Expires 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 10 with Expires

use of org.oasis_open.docs.ws_tx.wscoor._2006._06.Expires in project narayana by jbosstm.

the class ActivationTest method executeRequestTest.

private void executeRequestTest(final String messageId, final String coordinationType, final Long expires, final CoordinationContext coordinationContext) throws Exception {
    final MAP map = AddressingHelper.createRequestContext(TestUtil11.activationCoordinatorService, messageId);
    Expires expiresInstance;
    if (expires == null) {
        expiresInstance = null;
    } else {
        expiresInstance = new Expires();
        expiresInstance.setValue(expires.longValue());
    }
    CreateCoordinationContextResponseType createCoordinationContextResponseType;
    createCoordinationContextResponseType = ActivationCoordinatorClient.getClient().sendCreateCoordination(map, coordinationType, expiresInstance, coordinationContext);
    final CreateCoordinationContextDetails details = testActivationCoordinatorProcessor.getCreateCoordinationContextDetails(messageId, 10000);
    final CreateCoordinationContextType requestCreateCoordinationContext = details.getCreateCoordinationContext();
    final MAP requestMAP = details.getMAP();
    assertNotNull(requestMAP.getTo());
    assertEquals(requestMAP.getTo(), TestUtil11.activationCoordinatorService);
    // we don't care about the reply to field --  this is an RPC style message
    // assertNotNull(requestMAP.getReplyTo());
    // assertTrue(AddressingHelper.isNoneReplyTo(requestMAP));
    assertNotNull(requestMAP.getMessageID());
    assertEquals(requestMAP.getMessageID(), messageId);
    if (expires == null) {
        assertNull(requestCreateCoordinationContext.getExpires());
    } else {
        assertNotNull(requestCreateCoordinationContext.getExpires());
        assertEquals(expires.longValue(), requestCreateCoordinationContext.getExpires().getValue());
    }
    if (coordinationContext == null) {
        assertNull(requestCreateCoordinationContext.getCurrentContext());
    } else {
        assertNotNull(requestCreateCoordinationContext.getCurrentContext());
        assertEquals(requestCreateCoordinationContext.getCurrentContext().getIdentifier().getValue(), coordinationContext.getIdentifier().getValue());
        if (coordinationContext.getExpires() == null) {
            assertNull(requestCreateCoordinationContext.getCurrentContext().getExpires());
        } else {
            assertNotNull(requestCreateCoordinationContext.getCurrentContext().getExpires());
            assertEquals(requestCreateCoordinationContext.getCurrentContext().getExpires().getValue(), coordinationContext.getExpires().getValue());
        }
        assertNotNull(requestCreateCoordinationContext.getCurrentContext().getIdentifier());
        assertEquals(requestCreateCoordinationContext.getCurrentContext().getIdentifier().getValue(), coordinationContext.getIdentifier().getValue());
    }
    assertNotNull(requestCreateCoordinationContext.getCoordinationType());
    assertEquals(requestCreateCoordinationContext.getCoordinationType(), coordinationType);
    // make sure we got a sensible response
    checkResponse(coordinationType, expiresInstance, createCoordinationContextResponseType);
}
Also used : CreateCoordinationContextType(org.oasis_open.docs.ws_tx.wscoor._2006._06.CreateCoordinationContextType) CreateCoordinationContextDetails(com.arjuna.wsc.tests.arq.TestActivationCoordinatorProcessor.CreateCoordinationContextDetails) Expires(org.oasis_open.docs.ws_tx.wscoor._2006._06.Expires) MAP(org.jboss.ws.api.addressing.MAP) CreateCoordinationContextResponseType(org.oasis_open.docs.ws_tx.wscoor._2006._06.CreateCoordinationContextResponseType)

Aggregations

CoordinationContext (org.oasis_open.docs.ws_tx.wscoor._2006._06.CoordinationContext)16 CoordinationContextType (org.oasis_open.docs.ws_tx.wscoor._2006._06.CoordinationContextType)12 InvalidCreateParametersException (com.arjuna.wsc.InvalidCreateParametersException)10 W3CEndpointReference (javax.xml.ws.wsaddressing.W3CEndpointReference)9 Expires (org.oasis_open.docs.ws_tx.wscoor._2006._06.Expires)9 Test (org.junit.Test)7 ServiceRegistry (com.arjuna.webservices11.ServiceRegistry)5 InvalidProtocolException (com.arjuna.wsc.InvalidProtocolException)5 Message (org.apache.cxf.message.Message)5 DestinationPolicyType (org.apache.cxf.ws.rm.manager.DestinationPolicyType)5 Expires (org.apache.cxf.ws.rm.v200702.Expires)5 CreateCoordinationContextType (org.oasis_open.docs.ws_tx.wscoor._2006._06.CreateCoordinationContextType)5 NoActivityException (com.arjuna.mw.wsas.exceptions.NoActivityException)4 SystemException (com.arjuna.mw.wsas.exceptions.SystemException)4 SoapFault (com.arjuna.webservices.SoapFault)4 InstanceIdentifier (com.arjuna.webservices11.wsarj.InstanceIdentifier)4 SystemException (com.arjuna.wst.SystemException)4 TransactionRolledBackException (com.arjuna.wst.TransactionRolledBackException)4 UnknownTransactionException (com.arjuna.wst.UnknownTransactionException)4 WrongStateException (com.arjuna.wst.WrongStateException)4