Search in sources :

Example 16 with TxContext

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

the class JaxBaseHeaderContextProcessor method handleInboundMessage.

/**
 * Handle the request.
 * @param soapMessage The current message context.
 * @param installSubordinateTx true if a subordinate transaction should be interposed and false
 * if the handler should just resume the incoming transaction. currently only works for AT
 * transactions but will eventually be extended to work for BA transactions too.
 */
protected boolean handleInboundMessage(final SOAPMessage soapMessage, boolean installSubordinateTx) {
    if (soapMessage != null) {
        try {
            final SOAPEnvelope soapEnvelope = soapMessage.getSOAPPart().getEnvelope();
            final SOAPHeader soapHeader = soapEnvelope.getHeader();
            final SOAPHeaderElement soapHeaderElement = getHeaderElement(soapHeader, CoordinationConstants.WSCOOR_NAMESPACE, CoordinationConstants.WSCOOR_ELEMENT_COORDINATION_CONTEXT);
            if (soapHeaderElement != null) {
                final CoordinationContextType cc = CoordinationContextHelper.deserialise(soapHeaderElement);
                final String coordinationType = cc.getCoordinationType();
                if (AtomicTransactionConstants.WSAT_PROTOCOL.equals(coordinationType)) {
                    clearMustUnderstand(soapHeader, soapHeaderElement);
                    TxContext txContext = new TxContextImple(cc);
                    if (installSubordinateTx) {
                        txContext = SubordinateImporter.importContext(cc);
                    }
                    TransactionManagerFactory.transactionManager().resume(txContext);
                } else if (BusinessActivityConstants.WSBA_PROTOCOL_ATOMIC_OUTCOME.equals(coordinationType)) {
                    // interposition is not yet implemented for business activities
                    clearMustUnderstand(soapHeader, soapHeaderElement);
                    TxContext txContext = new com.arjuna.mwlabs.wst11.ba.context.TxContextImple(cc);
                    if (installSubordinateTx) {
                        txContext = com.arjuna.mwlabs.wst11.ba.SubordinateImporter.importContext(cc);
                    }
                    BusinessActivityManagerFactory.businessActivityManager().resume(txContext);
                } else {
                    wstxLogger.i18NLogger.warn_mw_wst11_service_JaxHC11P_2("com.arjuna.mw.wst11.service.JaxBaseHeaderContextProcessor.handleRequest(MessageContext context)", coordinationType);
                }
            }
        } catch (final Throwable th) {
            wstxLogger.i18NLogger.warn_mw_wst11_service_JaxHC11P_1("com.arjuna.mw.wst11.service.JaxBaseHeaderContextProcessor.handleRequest(MessageContext context)", th);
        }
    }
    return true;
}
Also used : TxContext(com.arjuna.mw.wst.TxContext) com.arjuna.mw.wst11(com.arjuna.mw.wst11) CoordinationContextType(org.oasis_open.docs.ws_tx.wscoor._2006._06.CoordinationContextType) TxContextImple(com.arjuna.mwlabs.wst11.at.context.TxContextImple)

Example 17 with TxContext

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

the class SuspendResumeCommitTransactionTest method testSuspendResumeCommitTransaction.

@Test
public void testSuspendResumeCommitTransaction() throws Exception {
    UserTransaction ut = UserTransaction.getUserTransaction();
    TransactionManager tm = TransactionManager.getTransactionManager();
    ut.begin();
    TxContext ctx = tm.suspend();
    System.out.println("Suspended: " + ctx);
    tm.resume(ctx);
    System.out.println("\nResumed");
    ut.commit();
}
Also used : UserTransaction(com.arjuna.mw.wst11.UserTransaction) TransactionManager(com.arjuna.mw.wst11.TransactionManager) TxContext(com.arjuna.mw.wst.TxContext) Test(org.junit.Test)

Example 18 with TxContext

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

the class SuspendResumeSingleParticipantTest method testSuspendResumeSingleParticipant.

@Test
public void testSuspendResumeSingleParticipant() throws Exception {
    UserTransaction ut = UserTransaction.getUserTransaction();
    TransactionManager tm = TransactionManager.getTransactionManager();
    DemoDurableParticipant p = new DemoDurableParticipant();
    try {
        ut.begin();
        tm.enlistForDurableTwoPhase(p, p.identifier());
        TxContext ctx = tm.suspend();
        System.out.println("Suspended: " + ctx);
        tm.resume(ctx);
        System.out.println("\nResumed\n");
    } catch (Exception eouter) {
        try {
            ut.rollback();
        } catch (Exception einner) {
        }
        throw eouter;
    }
    ut.commit();
}
Also used : UserTransaction(com.arjuna.mw.wst11.UserTransaction) TransactionManager(com.arjuna.mw.wst11.TransactionManager) DemoDurableParticipant(com.arjuna.wstx.tests.common.DemoDurableParticipant) TxContext(com.arjuna.mw.wst.TxContext) Test(org.junit.Test)

Example 19 with TxContext

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

the class XTSServiceTestInterpreter method processCommands.

// / implementation of the interpreter functionality
/**
 * simple command interpreter which executes the commands in the command list, inserting the
 * corresponding results in the results list and using the supplied bindings list
 * to provide values for any parameters supplied in the commands and to bind any results
 * obtained by executing the commands
 *
 * @param commandList a list of command strings
 * @param resultsList a list into which results strings are to be inserted
 * @param bindings a list of bound variables to be substituted into commands
 * or updated with new bindings
 */
private void processCommands(List<String> commandList, List<String> resultsList, HashMap<String, String> bindings) throws WebServiceException {
    int size = commandList.size();
    if (size == 0) {
        throw new WebServiceException("empty command list");
    }
    String command = commandList.remove(0);
    size--;
    if (command.equals("block")) {
        // we don't bind the command block immediately since bindings may be produced
        // by intermediate bind commands
        processCommandBlock(commandList, resultsList, bindings);
    } else {
        int idx = 0;
        if (command.equals("enlistDurable")) {
            // enlistment commands
            bindCommands(commandList, bindings);
            String id = participantId("DurableTestParticipant");
            DurableTestParticipant participant = new DurableTestParticipant(id);
            TransactionManager txman = TransactionManagerFactory.transactionManager();
            try {
                txman.enlistForDurableTwoPhase(participant, id);
            } catch (Exception e) {
                throw new WebServiceException("enlistDurable failed ", e);
            }
            for (idx = 0; idx < size; idx++) {
                participant.addCommand(commandList.get(idx));
            }
            participantMap.put(id, participant);
            resultsList.add(id);
        } else if (command.equals("enlistVolatile")) {
            bindCommands(commandList, bindings);
            String id = participantId("VolatileTestParticipant");
            VolatileTestParticipant participant = new VolatileTestParticipant(id);
            TransactionManager txman = TransactionManagerFactory.transactionManager();
            try {
                txman.enlistForVolatileTwoPhase(participant, id);
            } catch (Exception e) {
                throw new WebServiceException("enlistVolatile failed ", e);
            }
            for (idx = 0; idx < size; idx++) {
                participant.addCommand(commandList.get(idx));
            }
            participantMap.put(id, participant);
            resultsList.add(id);
        } else if (command.equals("enlistCoordinatorCompletion")) {
            bindCommands(commandList, bindings);
            String id = participantId("CoordinatorCompletionParticipant");
            CoordinatorCompletionTestParticipant participant = new CoordinatorCompletionTestParticipant(id);
            BusinessActivityManager baman = BusinessActivityManagerFactory.businessActivityManager();
            try {
                BAParticipantManager partMan;
                partMan = baman.enlistForBusinessAgreementWithCoordinatorCompletion(participant, id);
                managerMap.put(id, partMan);
            } catch (Exception e) {
                throw new WebServiceException("enlistCoordinatorCompletion failed ", e);
            }
            for (idx = 0; idx < size; idx++) {
                participant.addCommand(commandList.get(idx));
            }
            participantMap.put(id, participant);
            resultsList.add(id);
        } else if (command.equals("enlistParticipantCompletion")) {
            bindCommands(commandList, bindings);
            String id = participantId("ParticipantCompletionParticipant");
            ParticipantCompletionTestParticipant participant = new ParticipantCompletionTestParticipant(id);
            BusinessActivityManager baman = BusinessActivityManagerFactory.businessActivityManager();
            try {
                BAParticipantManager partMan;
                partMan = baman.enlistForBusinessAgreementWithParticipantCompletion(participant, id);
                managerMap.put(id, partMan);
            } catch (Exception e) {
                throw new WebServiceException("enlistParticipantCompletion failed ", e);
            }
            for (idx = 0; idx < size; idx++) {
                participant.addCommand(commandList.get(idx));
            }
            participantMap.put(id, participant);
            resultsList.add(id);
        } else if (command.equals("addCommands")) {
            // add extra commands to a participant script
            bindCommands(commandList, bindings);
            String id = commandList.remove(idx);
            size--;
            ScriptedTestParticipant participant = participantMap.get(id);
            if (participant != null) {
                for (idx = 0; idx < size; idx++) {
                    participant.addCommand(commandList.get(idx));
                }
                resultsList.add("ok");
            } else {
                throw new WebServiceException("addCommands failed to find participant " + id);
            }
        } else if (command.equals("exit")) {
            // initiate BA manager activities
            bindCommands(commandList, bindings);
            String id = commandList.remove(idx);
            size--;
            ScriptedTestParticipant participant = participantMap.get(id);
            if (participant != null) {
                if (participant instanceof ParticipantCompletionTestParticipant) {
                    ParticipantCompletionTestParticipant baparticipant = (ParticipantCompletionTestParticipant) participant;
                    BAParticipantManager manager = managerMap.get(id);
                    try {
                        manager.exit();
                    } catch (Exception e) {
                        throw new WebServiceException("exit " + id + " failed with exception " + e);
                    }
                    resultsList.add("ok");
                } else {
                    throw new WebServiceException("exit invalid participant type " + id);
                }
            } else {
                throw new WebServiceException("exit unknown participant " + id);
            }
        } else if (command.equals("completed")) {
            bindCommands(commandList, bindings);
            String id = commandList.remove(idx);
            size--;
            ScriptedTestParticipant participant = participantMap.get(id);
            if (participant != null) {
                if (participant instanceof ParticipantCompletionTestParticipant) {
                    ParticipantCompletionTestParticipant baparticipant = (ParticipantCompletionTestParticipant) participant;
                    BAParticipantManager manager = managerMap.get(id);
                    try {
                        manager.completed();
                        resultsList.add("ok");
                    } catch (Exception e) {
                        throw new WebServiceException("completed " + id + " failed with exception " + e);
                    }
                } else {
                    throw new WebServiceException("completed invalid participant type " + id);
                }
            } else {
                throw new WebServiceException("completed unknown participant " + id);
            }
        } else if (command.equals("fail")) {
            bindCommands(commandList, bindings);
            String id = commandList.remove(idx);
            size--;
            ScriptedTestParticipant participant = participantMap.get(id);
            if (participant != null) {
                if (participant instanceof ParticipantCompletionTestParticipant) {
                    ParticipantCompletionTestParticipant baparticipant = (ParticipantCompletionTestParticipant) participant;
                    BAParticipantManager manager = managerMap.get(id);
                    QName qname = new QName("http://jbossts.jboss.org/xts/servicetests/", "fail");
                    try {
                        manager.fail(qname);
                        resultsList.add("ok");
                    } catch (Exception e) {
                        throw new WebServiceException("fail " + id + " failed with exception " + e);
                    }
                } else {
                    throw new WebServiceException("fail invalid participant type " + id);
                }
            } else {
                throw new WebServiceException("fail unknown participant " + id);
            }
        } else if (command.equals("cannotComplete")) {
            bindCommands(commandList, bindings);
            String id = commandList.remove(idx);
            size--;
            ScriptedTestParticipant participant = participantMap.get(id);
            if (participant != null) {
                if (participant instanceof ParticipantCompletionTestParticipant) {
                    ParticipantCompletionTestParticipant baparticipant = (ParticipantCompletionTestParticipant) participant;
                    BAParticipantManager manager = managerMap.get(id);
                    try {
                        manager.cannotComplete();
                        resultsList.add("ok");
                    } catch (Exception e) {
                        throw new WebServiceException("cannotComplete " + id + " failed with exception " + e);
                    }
                } else {
                    throw new WebServiceException("cannotComplete invalid participant type " + id);
                }
            } else {
                throw new WebServiceException("cannotComplete unknown participant " + id);
            }
        } else if (command.equals("serve")) {
            // dispatch commands to a server for execution
            // we should find a web service URL and a list of commands to dispatch to that service
            String url = commandList.remove(idx);
            size--;
            // we throw an error if the server url is unbound but we allow
            // unbound variables in the command list passed on to the server
            // since they may be bound by bind commands in the command list
            // being served.
            url = bindCommand(url, bindings, true);
            bindCommands(commandList, bindings, false);
            CommandsType newCommands = new CommandsType();
            List<String> newCommandList = newCommands.getCommandList();
            for (int i = 0; i < size; i++) {
                newCommandList.add(commandList.get(i));
            }
            ResultsType subResults = serveSubordinate(url, newCommands);
            List<String> subResultsList = subResults.getResultList();
            size = subResultsList.size();
            for (idx = 0; idx < size; idx++) {
                resultsList.add(subResultsList.get(idx));
            }
        } else if (command.equals("subtransaction")) {
            // create subordinate AT transaction
            // this is surplus to requirements since we should really be running against a service which uses
            // the subordinate interposition JaxWS handler to install a subordinate transaction before
            // entering the service method. we ought to test that handler rather than hand crank the
            // interposition in the service
            TxContext currentTx;
            TxContext newTx;
            try {
                currentTx = TransactionManager.getTransactionManager().currentTransaction();
            } catch (SystemException e) {
                throw new WebServiceException("subtransaction currentTransaction() failed with exception " + e);
            }
            try {
                UserTransaction userTransaction = UserTransactionFactory.userSubordinateTransaction();
                userTransaction.begin();
                newTx = TransactionManager.getTransactionManager().currentTransaction();
            } catch (Exception e) {
                throw new WebServiceException("subtransaction begin() failed with exception " + e);
            }
            String id = transactionId("at");
            subordinateTransactionMap.put(id, newTx);
            resultsList.add(id);
        } else if (command.equals("subactivity")) {
            // create subordinate BA transaction
            // this is surplus ot requirements since we should really be running against a service which uses
            // the subordinate interposition JaxWS handler to install a subordinate activity before
            // entering the service method. we ought to test that handler rather than hand crank the
            // interposition in the service
            TxContext currentTx;
            TxContext newTx;
            try {
                currentTx = BusinessActivityManagerFactory.businessActivityManager().currentTransaction();
            } catch (SystemException e) {
                throw new WebServiceException("subtransaction currentTransaction() failed with exception " + e);
            }
            try {
                UserBusinessActivity userBusinessActivity = UserBusinessActivityFactory.userBusinessActivity();
                // this is nto implemented yet!!!
                // userBusinessActivity.beginSubordinate();
                // and this will fail with a WrongStateException
                userBusinessActivity.begin();
                newTx = BusinessActivityManager.getBusinessActivityManager().currentTransaction();
            } catch (Exception e) {
                throw new WebServiceException("subtransaction begin() failed with exception " + e);
            }
            String id = transactionId("ba");
            subordinateActivityMap.put(id, newTx);
            resultsList.add(id);
        } else if (command.equals("subtransactionserve")) {
            // dispatch commands in a subordinate transaction or activity
            // we should find the id of a subordinate transaction, a web service URL
            // and a list of commands to dispatch to that transaction
            // the txid and url must be resolved if supplied as bindings
            String txId = bindCommand(commandList.remove(idx), bindings, true);
            size--;
            String url = bindCommand(commandList.remove(idx), bindings, true);
            size--;
            TxContext newTx = subordinateTransactionMap.get(txId);
            if (newTx != null) {
                try {
                    TransactionManager.getTransactionManager().resume(newTx);
                } catch (Exception e) {
                    throw new WebServiceException("subtransactioncommands resume() failed with exception " + e);
                }
            } else {
                throw new WebServiceException("subtransactioncommands unknown subordinate transaction id " + txId);
            }
            // ok, now we install the relevant transaction and then just pass the commands on to
            // the web service
            // we allow unresolved variable references in the rest of the command list as
            // they may be satisfied by embedded bind commands
            bindCommands(commandList, bindings, false);
            CommandsType newCommands = new CommandsType();
            List<String> newCommandList = newCommands.getCommandList();
            for (int i = 0; i < size; i++) {
                newCommandList.add(commandList.get(i));
            }
            ResultsType subResults = serveSubordinate(url, newCommands);
            List<String> subResultsList = subResults.getResultList();
            size = subResultsList.size();
            for (idx = 0; idx < size; idx++) {
                resultsList.add(subResultsList.get(idx));
            }
        } else if (command.equals("subactivityserve")) {
            // dispatch commands in a subordinate transaction or activity
            // we should find the id of a subordinate transaction, a web service URL
            // and a list of commands to dispatch to that transaction
            // the txid and url must be resolved if supplied as bindings
            String txId = bindCommand(commandList.remove(idx), bindings, true);
            size--;
            String url = bindCommand(commandList.remove(idx), bindings, true);
            size--;
            TxContext newTx = subordinateActivityMap.get(txId);
            if (newTx != null) {
                try {
                    TransactionManager.getTransactionManager().resume(newTx);
                } catch (Exception e) {
                    throw new WebServiceException("subactivitycommands resume() failed with exception " + e);
                }
            } else {
                throw new WebServiceException("subactivitycommands unknown subordinate transaction id " + txId);
            }
            // ok, now we install the relevant transaction and then just pass the commands on to
            // the web service
            // we allow unresolved variable references in the rest of the command list as
            // they may be satisfied by embedded bind commands
            bindCommands(commandList, bindings, false);
            CommandsType newCommands = new CommandsType();
            List<String> newCommandList = newCommands.getCommandList();
            for (int i = 0; i < size; i++) {
                newCommandList.add(commandList.get(i));
            }
            ResultsType subResults = serveSubordinate(url, newCommands);
            List<String> subResultsList = subResults.getResultList();
            size = subResultsList.size();
            for (idx = 0; idx < size; idx++) {
                resultsList.add(subResultsList.get(idx));
            }
        }
    }
}
Also used : ResultsType(org.jboss.jbossts.xts.servicetests.generated.ResultsType) WebServiceException(javax.xml.ws.WebServiceException) QName(javax.xml.namespace.QName) UnknownHostException(java.net.UnknownHostException) WebServiceException(javax.xml.ws.WebServiceException) SystemException(com.arjuna.wst.SystemException) CommandsType(org.jboss.jbossts.xts.servicetests.generated.CommandsType) SystemException(com.arjuna.wst.SystemException) ArrayList(java.util.ArrayList) List(java.util.List) TxContext(com.arjuna.mw.wst.TxContext) BAParticipantManager(com.arjuna.wst11.BAParticipantManager)

Example 20 with TxContext

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

the class SuspendNullTransactionTest method testSuspendNullTransaction.

@Test
public void testSuspendNullTransaction() throws Exception {
    TransactionManager ut = TransactionManager.getTransactionManager();
    TxContext ctx = ut.suspend();
    System.out.println("Suspended: " + ctx);
    assertTrue(ctx == null);
}
Also used : TransactionManager(com.arjuna.mw.wst11.TransactionManager) TxContext(com.arjuna.mw.wst.TxContext) Test(org.junit.Test)

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