Search in sources :

Example 11 with TxContext

use of com.arjuna.mw.wst.TxContext in project wildfly by wildfly.

the class CompensatableServiceImpl method isTransactionActive.

@Override
public boolean isTransactionActive() {
    LOG.debug("CompensatableServiceImpl.isTransactionActive()");
    TxContext txContext = null;
    try {
        txContext = BusinessActivityManager.getBusinessActivityManager().currentTransaction();
    } catch (com.arjuna.wst.SystemException e) {
    }
    return txContext != null;
}
Also used : TxContext(com.arjuna.mw.wst.TxContext)

Example 12 with TxContext

use of com.arjuna.mw.wst.TxContext in project narayana by jbosstm.

the class SubordinateImporter method importContext.

public static TxContext importContext(CoordinationContextType cc) {
    // get the subordinate transaction manager to install any existing
    // subordinate tx for this one or create and install a new one.
    final String identifier = cc.getIdentifier().getValue();
    TxContext subordinateTxContext = subordinateContextMap.get(identifier);
    if (subordinateTxContext == null) {
        // create a context for a local coordinator
        CoordinationContext context = null;
        try {
            context = baContextFactory.create(BusinessActivityConstants.WSBA_PROTOCOL_ATOMIC_OUTCOME, 0L, cc, false);
        } catch (InvalidCreateParametersException e) {
        // should not happen
        }
        subordinateTxContext = new TxContextImple(context);
        subordinateContextMap.put(identifier, subordinateTxContext);
        // register a cleanup callback with the subordinate transactionso that the entry gets removed
        // when the transcation commits or rolls back
        // remove "urn:" prefix
        String subordinateId = context.getIdentifier().getValue().substring(4);
        SubordinateBACoordinator.SubordinateCallback callback = new SubordinateBACoordinator.SubordinateCallback() {

            public String parentId = identifier;

            public void run() {
                subordinateContextMap.remove(parentId);
            }
        };
        SubordinateBACoordinator.addCallback(subordinateId, callback);
    }
    return subordinateTxContext;
}
Also used : SubordinateBACoordinator(com.arjuna.mwlabs.wscf.model.sagas.arjunacore.subordinate.SubordinateBACoordinator) TxContext(com.arjuna.mw.wst.TxContext) TxContextImple(com.arjuna.mwlabs.wst11.ba.context.TxContextImple) InvalidCreateParametersException(com.arjuna.wsc.InvalidCreateParametersException) CoordinationContext(org.oasis_open.docs.ws_tx.wscoor._2006._06.CoordinationContext)

Example 13 with TxContext

use of com.arjuna.mw.wst.TxContext in project narayana by jbosstm.

the class UserBusinessActivityImple method beginSubordinate.

public void beginSubordinate(int timeout) throws WrongStateException, SystemException {
    try {
        TxContext current = _ctxManager.currentTransaction();
        if ((current == null) || !(current instanceof TxContextImple))
            throw new WrongStateException();
        TxContextImple currentImple = (TxContextImple) current;
        Context ctx = startTransaction(timeout, currentImple);
        _ctxManager.resume(new TxContextImple(ctx));
    // n.b. we don't enlist the subordinate transaction for completion
    // that ensures that any attempt to commit or rollback will fail
    } catch (com.arjuna.wsc.InvalidCreateParametersException ex) {
        tidyup();
        throw new SystemException(ex.toString());
    } catch (com.arjuna.wst.UnknownTransactionException ex) {
        tidyup();
        throw new SystemException(ex.toString());
    } catch (SystemException ex) {
        tidyup();
        throw ex;
    }
}
Also used : TxContext(com.arjuna.mw.wst.TxContext) Context(com.arjuna.mw.wsc11.context.Context) CoordinationContext(org.oasis_open.docs.ws_tx.wscoor._2006._06.CoordinationContext) InvalidCreateParametersException(com.arjuna.wsc.InvalidCreateParametersException) UnknownTransactionException(com.arjuna.wst.UnknownTransactionException) SystemException(com.arjuna.wst.SystemException) WrongStateException(com.arjuna.wst.WrongStateException) TxContext(com.arjuna.mw.wst.TxContext) TxContextImple(com.arjuna.mwlabs.wst11.ba.context.TxContextImple)

Example 14 with TxContext

use of com.arjuna.mw.wst.TxContext 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;
}
Also used : TxContext(com.arjuna.mw.wst.TxContext) Context(com.arjuna.mw.wsc11.context.Context) SOAPHeaderElement(javax.xml.soap.SOAPHeaderElement) SOAPEnvelope(javax.xml.soap.SOAPEnvelope) TxContextImple(com.arjuna.mwlabs.wst11.at.context.TxContextImple) Name(javax.xml.soap.Name) TransactionManager(com.arjuna.mw.wst11.TransactionManager) CoordinationContextType(org.oasis_open.docs.ws_tx.wscoor._2006._06.CoordinationContextType) SOAPHeader(javax.xml.soap.SOAPHeader)

Example 15 with TxContext

use of com.arjuna.mw.wst.TxContext in project narayana by jbosstm.

the class JaxBaseHeaderContextProcessor method resumeTransaction.

/**
 * Resume the current transaction.
 */
protected void resumeTransaction(final SOAPMessage soapMessage) {
    if (soapMessage != null) {
        try {
            final SOAPEnvelope soapEnvelope = soapMessage.getSOAPPart().getEnvelope();
            final SOAPHeaderElement soapHeaderElement = getHeaderElement(soapEnvelope, CoordinationConstants.WSCOOR_NAMESPACE, CoordinationConstants.WSCOOR_ELEMENT_COORDINATION_CONTEXT);
            if (soapHeaderElement != null) {
                final CoordinationContextType cc = CoordinationContextHelper.deserialise(soapHeaderElement);
                if (cc != null) {
                    final String coordinationType = cc.getCoordinationType();
                    if (AtomicTransactionConstants.WSAT_PROTOCOL.equals(coordinationType)) {
                        final TxContext txContext = new TxContextImple(cc);
                        TransactionManagerFactory.transactionManager().resume(txContext);
                    } else if (BusinessActivityConstants.WSBA_PROTOCOL_ATOMIC_OUTCOME.equals(coordinationType)) {
                        final TxContext txContext = new com.arjuna.mwlabs.wst11.ba.context.TxContextImple(cc);
                        BusinessActivityManagerFactory.businessActivityManager().resume(txContext);
                    } else {
                        wstxLogger.i18NLogger.warn_mw_wst11_client_JaxHC11P_2("com.arjuna.mw.wst11.client.JaxBaseHeaderContextProcessor.resumeTransaction()", coordinationType);
                    }
                }
            }
        } catch (final Throwable th) {
            wstxLogger.i18NLogger.warn_mw_wst11_client_JaxHC11P_1("com.arjuna.mw.wst11.client.JaxBaseHeaderContextProcessor.resumeTransaction()", th);
        }
    }
}
Also used : SOAPHeaderElement(javax.xml.soap.SOAPHeaderElement) TxContext(com.arjuna.mw.wst.TxContext) SOAPEnvelope(javax.xml.soap.SOAPEnvelope) CoordinationContextType(org.oasis_open.docs.ws_tx.wscoor._2006._06.CoordinationContextType) TxContextImple(com.arjuna.mwlabs.wst11.at.context.TxContextImple)

Aggregations

TxContext (com.arjuna.mw.wst.TxContext)20 TransactionManager (com.arjuna.mw.wst11.TransactionManager)11 Test (org.junit.Test)10 UserTransaction (com.arjuna.mw.wst11.UserTransaction)9 DemoDurableParticipant (com.arjuna.wstx.tests.common.DemoDurableParticipant)6 TxContextImple (com.arjuna.mwlabs.wst11.at.context.TxContextImple)5 InvalidCreateParametersException (com.arjuna.wsc.InvalidCreateParametersException)4 DemoVolatileParticipant (com.arjuna.wstx.tests.common.DemoVolatileParticipant)4 CoordinationContext (org.oasis_open.docs.ws_tx.wscoor._2006._06.CoordinationContext)4 Context (com.arjuna.mw.wsc11.context.Context)3 SystemException (com.arjuna.wst.SystemException)3 WrongStateException (com.arjuna.wst.WrongStateException)3 CoordinationContextType (org.oasis_open.docs.ws_tx.wscoor._2006._06.CoordinationContextType)3 TxContextImple (com.arjuna.mwlabs.wst11.ba.context.TxContextImple)2 TransactionRolledBackException (com.arjuna.wst.TransactionRolledBackException)2 UnknownTransactionException (com.arjuna.wst.UnknownTransactionException)2 FailureParticipant (com.arjuna.wstx.tests.common.FailureParticipant)2 SOAPEnvelope (javax.xml.soap.SOAPEnvelope)2 SOAPHeaderElement (javax.xml.soap.SOAPHeaderElement)2 com.arjuna.mw.wst11 (com.arjuna.mw.wst11)1