Search in sources :

Example 6 with BusinessActivityManager

use of com.arjuna.mw.wst11.BusinessActivityManager in project quickstart by wildfly.

the class SetServiceBAImpl method addValueToSet.

/**
 * Add an item to a set and enroll a Participant if necessary then pass the call through to the business logic.
 *
 * @param value the value to add to the set.
 * @throws AlreadyInSetException if value is already in the set
 * @throws SetServiceException if an error occurred when attempting to add the item to the set.
 */
@WebMethod
public void addValueToSet(String value) throws AlreadyInSetException, SetServiceException {
    System.out.println("[SERVICE] invoked addValueToSet('" + value + "')");
    BusinessActivityManager activityManager = BusinessActivityManagerFactory.businessActivityManager();
    /*
         * get the transaction context of this thread:
         */
    String transactionId;
    try {
        transactionId = activityManager.currentTransaction().toString();
    } catch (SystemException e) {
        throw new SetServiceException("Unable to lookup existing BusinesActivity", e);
    }
    /*
         * Lookup existing participant or register new participant
         */
    SetParticipantBA participantBA = SetParticipantBA.getParticipant(transactionId);
    if (participantBA == null) {
        try {
            // enlist the Participant for this service:
            SetParticipantBA participant = new SetParticipantBA(transactionId, value);
            SetParticipantBA.recordParticipant(transactionId, participant);
            System.out.println("[SERVICE] Enlisting a participant into the BA");
            activityManager.enlistForBusinessAgreementWithCoordinatorCompletion(participant, "SetServiceBAImpl:" + UUID.randomUUID());
        } catch (Exception e) {
            System.err.println("Participant enlistment failed");
            throw new SetServiceException("Error enlisting participant", e);
        }
    } else {
        System.out.println("[SERVICE] Re-using the existing participant, already registered for this BA");
        participantBA.addValue(value);
    }
    // invoke the back-end business logic
    System.out.println("[SERVICE] Invoking the back-end business logic");
    MockSetManager.add(value);
}
Also used : SystemException(com.arjuna.wst.SystemException) BusinessActivityManager(com.arjuna.mw.wst11.BusinessActivityManager) SystemException(com.arjuna.wst.SystemException) WebMethod(javax.jws.WebMethod)

Example 7 with BusinessActivityManager

use of com.arjuna.mw.wst11.BusinessActivityManager 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 8 with BusinessActivityManager

use of com.arjuna.mw.wst11.BusinessActivityManager in project narayana by jbosstm.

the class ConfirmWithCompleteTest method testConfirmWithComplete.

@Test
public void testConfirmWithComplete() throws Exception {
    UserBusinessActivity uba = UserBusinessActivity.getUserBusinessActivity();
    BusinessActivityManager bam = BusinessActivityManager.getBusinessActivityManager();
    DemoBusinessParticipantWithComplete p = new DemoBusinessParticipantWithComplete(DemoBusinessParticipantWithComplete.COMPLETE, "1234");
    try {
        uba.begin();
        bam.enlistForBusinessAgreementWithCoordinatorCompletion(p, "1237");
        uba.complete();
    } catch (Exception eouter) {
        try {
            uba.cancel();
        } catch (Exception einner) {
        }
        throw eouter;
    }
    uba.cancel();
    assertTrue(p.passed());
}
Also used : DemoBusinessParticipantWithComplete(com.arjuna.wstx.tests.common.DemoBusinessParticipantWithComplete) BusinessActivityManager(com.arjuna.mw.wst11.BusinessActivityManager) UserBusinessActivity(com.arjuna.mw.wst11.UserBusinessActivity) Test(org.junit.Test)

Example 9 with BusinessActivityManager

use of com.arjuna.mw.wst11.BusinessActivityManager in project narayana by jbosstm.

the class MultiCloseTest method testMultiClose.

@Test
public void testMultiClose() throws Exception {
    ParticipantCompletionCoordinatorRules.setParticipantCount(2);
    UserBusinessActivity uba = UserBusinessActivity.getUserBusinessActivity();
    BusinessActivityManager bam = BusinessActivityManager.getBusinessActivityManager();
    com.arjuna.wst11.BAParticipantManager bpm1 = null;
    com.arjuna.wst11.BAParticipantManager bpm2 = null;
    DemoBusinessParticipant p = new DemoBusinessParticipant(DemoBusinessParticipant.CLOSE, "1240");
    FailureBusinessParticipant fp = new FailureBusinessParticipant(FailureBusinessParticipant.FAIL_IN_CLOSE, "5679");
    try {
        uba.begin();
        bpm1 = bam.enlistForBusinessAgreementWithParticipantCompletion(p, "1240");
        bpm2 = bam.enlistForBusinessAgreementWithParticipantCompletion(fp, "5679");
        bpm1.completed();
        bpm2.completed();
    } catch (Exception eouter) {
        try {
            uba.cancel();
        } catch (Exception einner) {
        }
        throw eouter;
    }
    uba.close();
    assertTrue(p.passed());
}
Also used : DemoBusinessParticipant(com.arjuna.wstx.tests.common.DemoBusinessParticipant) BusinessActivityManager(com.arjuna.mw.wst11.BusinessActivityManager) UserBusinessActivity(com.arjuna.mw.wst11.UserBusinessActivity) FailureBusinessParticipant(com.arjuna.wstx.tests.common.FailureBusinessParticipant) Test(org.junit.Test)

Example 10 with BusinessActivityManager

use of com.arjuna.mw.wst11.BusinessActivityManager in project narayana by jbosstm.

the class CompensateTest method testCompensate.

@Test
public void testCompensate() throws Exception {
    ParticipantCompletionCoordinatorRules.setParticipantCount(1);
    UserBusinessActivity uba = UserBusinessActivity.getUserBusinessActivity();
    BusinessActivityManager bam = BusinessActivityManager.getBusinessActivityManager();
    com.arjuna.wst11.BAParticipantManager bpm = null;
    String participantId = "1236";
    DemoBusinessParticipant p = new DemoBusinessParticipant(DemoBusinessParticipant.COMPENSATE, participantId);
    try {
        uba.begin();
        bpm = bam.enlistForBusinessAgreementWithParticipantCompletion(p, participantId);
        bpm.completed();
    } catch (Exception eouter) {
        try {
            uba.cancel();
        } catch (Exception einner) {
        }
        throw eouter;
    }
    uba.cancel();
    assertTrue(p.passed());
}
Also used : DemoBusinessParticipant(com.arjuna.wstx.tests.common.DemoBusinessParticipant) BusinessActivityManager(com.arjuna.mw.wst11.BusinessActivityManager) UserBusinessActivity(com.arjuna.mw.wst11.UserBusinessActivity) Test(org.junit.Test)

Aggregations

BusinessActivityManager (com.arjuna.mw.wst11.BusinessActivityManager)15 UserBusinessActivity (com.arjuna.mw.wst11.UserBusinessActivity)9 Test (org.junit.Test)9 DemoBusinessParticipant (com.arjuna.wstx.tests.common.DemoBusinessParticipant)8 SystemException (com.arjuna.wst.SystemException)6 BAParticipantManager (com.arjuna.wst11.BAParticipantManager)3 FailureBusinessParticipant (com.arjuna.wstx.tests.common.FailureBusinessParticipant)3 Uid (com.arjuna.ats.arjuna.common.Uid)2 WebMethod (javax.jws.WebMethod)2 TestApplicationException (org.jboss.as.test.xts.base.TestApplicationException)2 Context (com.arjuna.mw.wsc11.context.Context)1 TxContext (com.arjuna.mw.wst.TxContext)1 TransactionManager (com.arjuna.mw.wst11.TransactionManager)1 TxContextImple (com.arjuna.mwlabs.wst11.at.context.TxContextImple)1 FaultedException (com.arjuna.wst.FaultedException)1 TransactionRolledBackException (com.arjuna.wst.TransactionRolledBackException)1 WrongStateException (com.arjuna.wst.WrongStateException)1 DemoBusinessParticipantWithComplete (com.arjuna.wstx.tests.common.DemoBusinessParticipantWithComplete)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 Name (javax.xml.soap.Name)1