Search in sources :

Example 36 with SystemException

use of com.arjuna.wst.SystemException in project wildfly by wildfly.

the class BAParticipantCompletionSuperService method saveData.

/**
 * Add an item to a set Enrolls a Participant if necessary and passes the call through to the business logic.
 *
 * @param value the value to add to the set.
 * @throws
 * @throws AlreadyInSetException if value is already in the set
 * @throws SetServiceException   if an error occurred when attempting to add the item to the set.
 */
public void saveData(String value, ServiceCommand... serviceCommands) throws TestApplicationException {
    log.trace("[BA PARTICIPANT COMPL SERVICE] invoked saveData('" + value + "')");
    eventLog.foundEventLogName(value);
    BAParticipantManager participantManager;
    BusinessActivityManager activityManager = BusinessActivityManagerFactory.businessActivityManager();
    String txid;
    try {
        txid = activityManager.currentTransaction().toString();
    } catch (SystemException se) {
        throw new RuntimeException("Error on getting TX id from BusinessActivityManager", se);
    }
    if (participantRegistry.keySet().contains(txid) && ServiceCommand.isPresent(REUSE_BA_PARTICIPANT, serviceCommands)) {
        log.trace("[BA PARTICIPANT COMPL SERVICE] Reusing BA participant manager - command: " + REUSE_BA_PARTICIPANT);
        participantManager = participantRegistry.get(txid);
    } else {
        try {
            // Enlist the Participant for this service:
            BAParticipantCompletionParticipant participant = new BAParticipantCompletionParticipant(serviceCommands, eventLog, value);
            log.trace("[BA PARTICIPANT COMPL SERVICE] Enlisting a participant into the BA");
            participantManager = activityManager.enlistForBusinessAgreementWithParticipantCompletion(participant, "BAParticipantCompletition:" + new Uid().toString());
            participantRegistry.put(txid, participantManager);
        } catch (Exception e) {
            log.error("[BA PARTICIPANT COMPL SERVICE]  Participant enlistment failed", e);
            throw new RuntimeException("Error enlisting participant", e);
        }
    }
    if (ServiceCommand.isPresent(APPLICATION_EXCEPTION, serviceCommands)) {
        throw new TestApplicationException("Intentionally thrown Application Exception - service command set to: " + APPLICATION_EXCEPTION);
    }
    // There could be invoked some back-end business logic here
    /*
         * This service employs the participant completion protocol which means it decides when it wants to commit local
         * changes. If the local changes (adding the item to the set) succeeded, we notify the coordinator that we have
         * completed. Otherwise, we notify the coordinator that we cannot complete. If any other participant fails or the client
         * decides to cancel we can rely upon being told to compensate.
         */
    log.trace("[BA PARTICIPANT COMPL SERVICE] Prepare the backend resource and if successful notify the coordinator that we have completed our work");
    if (ServiceCommand.isPresent(DO_COMPLETE, serviceCommands)) {
        try {
            // Tell the coordinator manager we have finished our work
            log.trace("[BA PARTICIPANT COMPL SERVICE] Prepare successful, notifying coordinator of completion");
            participantManager.completed();
        } catch (Exception e) {
            /* Failed to notify the coordinator that we have finished our work. Compensate the work and throw an Exception
                 * to notify the client that the add operation failed. */
            log.error("[BA PARTICIPANT COMPL SERVICE] 'completed' callback failed");
            throw new RuntimeException("Error when notifying the coordinator that the work is completed", e);
        }
    }
    if (ServiceCommand.isPresent(CANNOT_COMPLETE, serviceCommands)) {
        try {
            // Tell the participant manager we cannot complete. This will force the activity to fail.
            log.trace("[BA PARTICIPANT COMPL SERVICE] Prepared fail, notifying coordinator that we cannot complete");
            participantManager.cannotComplete();
            return;
        } catch (Exception e) {
            log.error("[BA PARTICIPANT COMPL SERVICE] 'cannotComplete' callback failed");
            throw new RuntimeException("Error when notifying the coordinator that the work is cannot be completed", e);
        }
    }
}
Also used : Uid(com.arjuna.ats.arjuna.common.Uid) TestApplicationException(org.jboss.as.test.xts.base.TestApplicationException) SystemException(com.arjuna.wst.SystemException) BusinessActivityManager(com.arjuna.mw.wst11.BusinessActivityManager) BAParticipantManager(com.arjuna.wst11.BAParticipantManager) TestApplicationException(org.jboss.as.test.xts.base.TestApplicationException) SystemException(com.arjuna.wst.SystemException)

Example 37 with SystemException

use of com.arjuna.wst.SystemException in project narayana by jbosstm.

the class TerminationCoordinatorRPCProcessorImpl method close.

/**
 * Close.
 * @param close The close notification.
 * @param map The addressing context.
 * @param arjunaContext The arjuna context.
 */
public void close(final NotificationType close, final MAP map, final ArjunaContext arjunaContext) {
    final InstanceIdentifier instanceIdentifier = arjunaContext.getInstanceIdentifier();
    final BusinessActivityTerminator participant = TerminationCoordinatorProcessor.getProcessor().getParticipant(instanceIdentifier);
    try {
        if (participant != null) {
            try {
                participant.close();
            } catch (final UnknownTransactionException ute) {
                SOAPFactory factory = SOAPFactory.newInstance();
                SOAPFault soapFault = factory.createFault(SoapFaultType.FAULT_SENDER.getValue(), ArjunaTXConstants.UNKNOWNTRANSACTION_ERROR_CODE_QNAME);
                soapFault.addDetail().addDetailEntry(ArjunaTXConstants.UNKNOWNTRANSACTION_ERROR_CODE_QNAME).addTextNode(WSTLogger.i18NLogger.get_wst11_messaging_TerminationCoordinatorProcessorImpl_6());
                throw new SOAPFaultException(soapFault);
            } catch (final TransactionRolledBackException trbe) {
                SOAPFactory factory = SOAPFactory.newInstance();
                SOAPFault soapFault = factory.createFault(SoapFaultType.FAULT_SENDER.getValue(), ArjunaTXConstants.UNKNOWNTRANSACTION_ERROR_CODE_QNAME);
                soapFault.addDetail().addDetailEntry(ArjunaTXConstants.TRANSACTIONROLLEDBACK_ERROR_CODE_QNAME).addTextNode(WSTLogger.i18NLogger.get_wst11_messaging_TerminationCoordinatorProcessorImpl_7());
                throw new SOAPFaultException(soapFault);
            } catch (final SystemException se) {
                SOAPFactory factory = SOAPFactory.newInstance();
                SOAPFault soapFault = factory.createFault(SoapFaultType.FAULT_RECEIVER.getValue(), ArjunaTXConstants.UNKNOWNERROR_ERROR_CODE_QNAME);
                soapFault.addDetail().addDetailEntry(ArjunaTXConstants.UNKNOWNERROR_ERROR_CODE_QNAME).addTextNode(WSTLogger.i18NLogger.get_wst11_messaging_TerminationCoordinatorProcessorImpl_8());
                throw new SOAPFaultException(soapFault);
            } catch (final Throwable th) {
                if (WSTLogger.logger.isTraceEnabled()) {
                    WSTLogger.logger.tracev("Unexpected exception thrown from close:", th);
                }
                SOAPFactory factory = SOAPFactory.newInstance();
                SOAPFault soapFault = factory.createFault(SoapFaultType.FAULT_RECEIVER.getValue(), ArjunaTXConstants.UNKNOWNERROR_ERROR_CODE_QNAME);
                soapFault.addDetail().addDetailEntry(ArjunaTXConstants.UNKNOWNERROR_ERROR_CODE_QNAME).addTextNode(WSTLogger.i18NLogger.get_wst11_messaging_TerminationCoordinatorProcessorImpl_8());
                throw new SOAPFaultException(soapFault);
            }
        } else {
            if (WSTLogger.logger.isTraceEnabled()) {
                WSTLogger.logger.tracev("Close called on unknown participant: {0}", new Object[] { instanceIdentifier });
            }
            SOAPFactory factory = SOAPFactory.newInstance();
            SOAPFault soapFault = factory.createFault(SoapFaultType.FAULT_SENDER.getValue(), ArjunaTXConstants.UNKNOWNTRANSACTION_ERROR_CODE_QNAME);
            soapFault.addDetail().addDetailEntry(ArjunaTXConstants.UNKNOWNTRANSACTION_ERROR_CODE_QNAME).addTextNode(WSTLogger.i18NLogger.get_wst11_messaging_TerminationCoordinatorProcessorImpl_6());
            throw new SOAPFaultException(soapFault);
        }
    } catch (SOAPException se) {
        se.printStackTrace(System.err);
        throw new ProtocolException(se);
    }
}
Also used : ProtocolException(javax.xml.ws.ProtocolException) UnknownTransactionException(com.arjuna.wst.UnknownTransactionException) SystemException(com.arjuna.wst.SystemException) BusinessActivityTerminator(com.arjuna.wst11.BusinessActivityTerminator) SOAPException(javax.xml.soap.SOAPException) InstanceIdentifier(com.arjuna.webservices11.wsarj.InstanceIdentifier) SOAPFault(javax.xml.soap.SOAPFault) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) TransactionRolledBackException(com.arjuna.wst.TransactionRolledBackException) SOAPFactory(javax.xml.soap.SOAPFactory)

Example 38 with SystemException

use of com.arjuna.wst.SystemException in project narayana by jbosstm.

the class CompletionCoordinatorProcessorImpl method rollback.

/**
 * Rollback.
 * @param rollback The rollback notification.
 * @param map The addressing context.
 * @param arjunaContext The arjuna context.
 */
public void rollback(final Notification rollback, final MAP map, final ArjunaContext arjunaContext) {
    final InstanceIdentifier instanceIdentifier = arjunaContext.getInstanceIdentifier();
    final CompletionCoordinatorParticipant participant = getParticipant(instanceIdentifier);
    try {
        if (participant != null) {
            final String messageId = MessageId.getMessageId();
            try {
                participant.rollback();
            } catch (final UnknownTransactionException ute) {
                final MAP faultAddressingContext = AddressingHelper.createFaultContext(map, messageId);
                final SoapFault soapFault = new SoapFault11(SoapFaultType.FAULT_SENDER, ArjunaTXConstants.UNKNOWNTRANSACTION_ERROR_CODE_QNAME, WSTLogger.i18NLogger.get_wst11_messaging_CompletionCoordinatorProcessorImpl_6());
                CompletionInitiatorClient.getClient().sendSoapFault(participant.getParticipant(), faultAddressingContext, soapFault, instanceIdentifier);
                return;
            } catch (SystemException systemException) {
                final MAP faultAddressingContext = AddressingHelper.createFaultContext(map, messageId);
                final String message = WSTLogger.i18NLogger.get_wst11_messaging_CompletionCoordinatorProcessorImpl_7();
                final SoapFault soapFault = new SoapFault11(SoapFaultType.FAULT_SENDER, ArjunaTXConstants.UNKNOWNERROR_ERROR_CODE_QNAME, message);
                CompletionInitiatorClient.getClient().sendSoapFault(participant.getParticipant(), faultAddressingContext, soapFault, instanceIdentifier);
                return;
            } catch (final Throwable th) {
                if (WSTLogger.logger.isTraceEnabled()) {
                    WSTLogger.logger.tracev("Unexpected exception thrown from rollback:", th);
                }
                final MAP faultAddressingContext = AddressingHelper.createFaultContext(map, MessageId.getMessageId());
                final SoapFault soapFault = new SoapFault11(th);
                CompletionInitiatorClient.getClient().sendSoapFault(participant.getParticipant(), faultAddressingContext, soapFault, instanceIdentifier);
                return;
            }
            final MAP responseAddressingContext = AddressingHelper.createResponseContext(map, messageId);
            CompletionInitiatorClient.getClient().sendAborted(participant.getParticipant(), responseAddressingContext, instanceIdentifier);
        } else {
            if (WSTLogger.logger.isTraceEnabled()) {
                WSTLogger.logger.tracev("Rollback called on unknown participant: {0}", new Object[] { instanceIdentifier });
            }
            final MAP faultAddressingContext = AddressingHelper.createFaultContext(map, MessageId.getMessageId());
            final SoapFault soapFault = new SoapFault11(SoapFaultType.FAULT_SENDER, ArjunaTXConstants.UNKNOWNTRANSACTION_ERROR_CODE_QNAME, WSTLogger.i18NLogger.get_wst11_messaging_CompletionCoordinatorProcessorImpl_10());
            CompletionInitiatorClient.getClient().sendSoapFault(faultAddressingContext, soapFault, instanceIdentifier);
        }
    } catch (Throwable throwable) {
        throwable.printStackTrace(System.err);
    }
}
Also used : SoapFault(com.arjuna.webservices.SoapFault) UnknownTransactionException(com.arjuna.wst.UnknownTransactionException) SystemException(com.arjuna.wst.SystemException) InstanceIdentifier(com.arjuna.webservices11.wsarj.InstanceIdentifier) SoapFault11(com.arjuna.webservices11.SoapFault11) CompletionCoordinatorParticipant(com.arjuna.wst11.CompletionCoordinatorParticipant) MAP(org.jboss.ws.api.addressing.MAP)

Example 39 with SystemException

use of com.arjuna.wst.SystemException in project narayana by jbosstm.

the class TerminationCoordinatorProcessorImpl method close.

/**
 * Close.
 * @param close The close notification.
 * @param map The addressing context.
 * @param arjunaContext The arjuna context.
 */
public void close(final NotificationType close, final MAP map, final ArjunaContext arjunaContext) {
    final InstanceIdentifier instanceIdentifier = arjunaContext.getInstanceIdentifier();
    final BusinessActivityTerminator participant = getParticipant(instanceIdentifier);
    try {
        if (participant != null) {
            W3CEndpointReference endpoint = participant.getEndpoint();
            final String messageId = MessageId.getMessageId();
            try {
                participant.close();
            } catch (final UnknownTransactionException ute) {
                final MAP faultMAP = AddressingHelper.createFaultContext(map, messageId);
                final SoapFault soapFault = new SoapFault11(SoapFaultType.FAULT_SENDER, ArjunaTXConstants.UNKNOWNTRANSACTION_ERROR_CODE_QNAME, WSTLogger.i18NLogger.get_wst11_messaging_TerminationCoordinatorProcessorImpl_6());
                TerminationParticipantClient.getClient().sendSoapFault(endpoint, faultMAP, soapFault, instanceIdentifier);
                return;
            } catch (final TransactionRolledBackException trbe) {
                final MAP faultMAP = AddressingHelper.createFaultContext(map, messageId);
                final SoapFault soapFault = new SoapFault11(SoapFaultType.FAULT_SENDER, ArjunaTXConstants.TRANSACTIONROLLEDBACK_ERROR_CODE_QNAME, WSTLogger.i18NLogger.get_wst11_messaging_TerminationCoordinatorProcessorImpl_7());
                TerminationParticipantClient.getClient().sendSoapFault(endpoint, faultMAP, soapFault, instanceIdentifier);
                return;
            } catch (final SystemException se) {
                final MAP faultMAP = AddressingHelper.createFaultContext(map, messageId);
                final String message = WSTLogger.i18NLogger.get_wst11_messaging_TerminationCoordinatorProcessorImpl_8();
                final SoapFault soapFault = new SoapFault11(SoapFaultType.FAULT_SENDER, ArjunaTXConstants.UNKNOWNERROR_ERROR_CODE_QNAME, message);
                TerminationParticipantClient.getClient().sendSoapFault(endpoint, faultMAP, soapFault, instanceIdentifier);
                return;
            } catch (final Throwable th) {
                if (WSTLogger.logger.isTraceEnabled()) {
                    WSTLogger.logger.tracev("Unexpected exception thrown from close:", th);
                }
                final MAP faultMAP = AddressingHelper.createFaultContext(map, MessageId.getMessageId());
                final SoapFault soapFault = new SoapFault11(th);
                TerminationParticipantClient.getClient().sendSoapFault(endpoint, faultMAP, soapFault, instanceIdentifier);
                return;
            }
            final MAP responseMAP = AddressingHelper.createNotificationContext(messageId);
            TerminationParticipantClient.getClient().sendClosed(endpoint, responseMAP, instanceIdentifier);
        } else {
            if (WSTLogger.logger.isTraceEnabled()) {
                WSTLogger.logger.tracev("Close called on unknown participant: {0}", new Object[] { instanceIdentifier });
            }
            final MAP faultMAP = AddressingHelper.createFaultContext(map, MessageId.getMessageId());
            final SoapFault soapFault = new SoapFault11(SoapFaultType.FAULT_SENDER, ArjunaTXConstants.UNKNOWNTRANSACTION_ERROR_CODE_QNAME, WSTLogger.i18NLogger.get_wst11_messaging_TerminationCoordinatorProcessorImpl_11());
            TerminationParticipantClient.getClient().sendSoapFault(soapFault, faultMAP, instanceIdentifier);
        }
    } catch (Throwable throwable) {
        throwable.printStackTrace(System.err);
    }
}
Also used : SoapFault(com.arjuna.webservices.SoapFault) UnknownTransactionException(com.arjuna.wst.UnknownTransactionException) SystemException(com.arjuna.wst.SystemException) BusinessActivityTerminator(com.arjuna.wst11.BusinessActivityTerminator) W3CEndpointReference(javax.xml.ws.wsaddressing.W3CEndpointReference) InstanceIdentifier(com.arjuna.webservices11.wsarj.InstanceIdentifier) SoapFault11(com.arjuna.webservices11.SoapFault11) TransactionRolledBackException(com.arjuna.wst.TransactionRolledBackException) MAP(org.jboss.ws.api.addressing.MAP)

Example 40 with SystemException

use of com.arjuna.wst.SystemException in project narayana by jbosstm.

the class BusinessActivityTerminatorStub method cancel.

public void cancel() throws FaultedException, UnknownTransactionException, SystemException {
    final MAP map = AddressingHelper.createNotificationContext(MessageId.getMessageId());
    final RequestCallback callback = new RequestCallback();
    final TerminationParticipantProcessor terminationParticipantProcessor = TerminationParticipantProcessor.getProcessor();
    terminationParticipantProcessor.registerCallback(_id, callback);
    try {
        TerminationCoordinatorClient.getClient().sendCancel(_terminationCoordinator, map, new InstanceIdentifier(_id));
        callback.waitUntilTriggered();
    } catch (final Throwable th) {
        throw new SystemException();
    } finally {
        terminationParticipantProcessor.removeCallback(_id);
    }
    if (callback.hasTriggered()) {
        if (callback.receivedCancelled()) {
            return;
        } else if (callback.receivedFaulted()) {
            throw new FaultedException();
        }
        final SoapFault soapFault = callback.getSoapFault();
        if (soapFault != null) {
            final QName subcode = soapFault.getSubcode();
            if (ArjunaTXConstants.UNKNOWNTRANSACTION_ERROR_CODE_QNAME.equals(subcode)) {
                throw new UnknownTransactionException();
            }
        }
    }
    throw new SystemException();
}
Also used : SoapFault(com.arjuna.webservices.SoapFault) SystemException(com.arjuna.wst.SystemException) UnknownTransactionException(com.arjuna.wst.UnknownTransactionException) QName(javax.xml.namespace.QName) InstanceIdentifier(com.arjuna.webservices11.wsarj.InstanceIdentifier) FaultedException(com.arjuna.wst.FaultedException) MAP(org.jboss.ws.api.addressing.MAP) TerminationParticipantProcessor(com.arjuna.webservices11.wsarjtx.processors.TerminationParticipantProcessor)

Aggregations

SystemException (com.arjuna.wst.SystemException)74 UnknownTransactionException (com.arjuna.wst.UnknownTransactionException)63 WrongStateException (com.arjuna.wst.WrongStateException)45 TransactionRolledBackException (com.arjuna.wst.TransactionRolledBackException)39 InvalidCreateParametersException (com.arjuna.wsc.InvalidCreateParametersException)20 ArrayList (java.util.ArrayList)19 W3CEndpointReference (javax.xml.ws.wsaddressing.W3CEndpointReference)16 UserBusinessActivity (com.arjuna.mw.wst11.UserBusinessActivity)15 SoapFault (com.arjuna.webservices.SoapFault)15 InstanceIdentifier (com.arjuna.webservices11.wsarj.InstanceIdentifier)13 TxContextImple (com.arjuna.mwlabs.wst11.at.context.TxContextImple)11 TxContextImple (com.arjuna.mwlabs.wst11.ba.context.TxContextImple)11 MAP (org.jboss.ws.api.addressing.MAP)11 CoordinationContext (org.oasis_open.docs.ws_tx.wscoor._2006._06.CoordinationContext)10 Context (com.arjuna.mw.wsc11.context.Context)6 FaultedException (com.arjuna.wst.FaultedException)6 BusinessActivityTerminator (com.arjuna.wst11.BusinessActivityTerminator)6 CoordinationContextType (org.oasis_open.docs.ws_tx.wscoor._2006._06.CoordinationContextType)6 TxContext (com.arjuna.mw.wst.TxContext)5 BusinessActivityManager (com.arjuna.mw.wst11.BusinessActivityManager)5