Search in sources :

Example 1 with com.arjuna.mw.wst11

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

use of com.arjuna.mw.wst11 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)

Aggregations

TxContext (com.arjuna.mw.wst.TxContext)2 TxContextImple (com.arjuna.mwlabs.wst11.at.context.TxContextImple)2 CoordinationContextType (org.oasis_open.docs.ws_tx.wscoor._2006._06.CoordinationContextType)2 Context (com.arjuna.mw.wsc11.context.Context)1 com.arjuna.mw.wst11 (com.arjuna.mw.wst11)1 TransactionManager (com.arjuna.mw.wst11.TransactionManager)1 Name (javax.xml.soap.Name)1 SOAPEnvelope (javax.xml.soap.SOAPEnvelope)1 SOAPHeader (javax.xml.soap.SOAPHeader)1 SOAPHeaderElement (javax.xml.soap.SOAPHeaderElement)1