Search in sources :

Example 21 with SOAPHeaderElement

use of javax.xml.soap.SOAPHeaderElement 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 22 with SOAPHeaderElement

use of javax.xml.soap.SOAPHeaderElement 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)

Example 23 with SOAPHeaderElement

use of javax.xml.soap.SOAPHeaderElement in project narayana by jbosstm.

the class CoordinationContextHandler method handlemessageInbound.

/**
 * check for an arjuna instance identifier element embedded in the soap message headesr and, if found, use it to
 * label an arjuna context attached to the message context
 * @param context
 * @return
 * @throws ProtocolException
 */
private boolean handlemessageInbound(SOAPMessageContext context) throws ProtocolException {
    try {
        final SOAPMessage soapMessage = context.getMessage();
        final SOAPEnvelope soapEnvelope = soapMessage.getSOAPPart().getEnvelope();
        Iterator<SOAPHeaderElement> iterator = soapEnvelope.getHeader().examineAllHeaderElements();
        while (iterator.hasNext()) {
            final SOAPHeaderElement headerElement = iterator.next();
            if (CoordinationConstants.WSCOOR_ELEMENT_COORDINATION_CONTEXT_QNAME.equals(headerElement.getElementQName())) {
                // found it - clear the must understand flag, retrieve the value and store an arjuna
                // context in the message context
                headerElement.setMustUnderstand(false);
                final JAXBContext jaxbCtx = getJaxbContext();
                final JAXBElement<CoordinationContextType> elt = jaxbCtx.createUnmarshaller().unmarshal(headerElement, CoordinationContextType.class);
                final CoordinationContextType coordinationContext = elt.getValue();
                CoordinationContextManager.setContext(context, coordinationContext);
            }
        }
    } catch (Exception se) {
        throw new ProtocolException(se);
    }
    return true;
}
Also used : SOAPHeaderElement(javax.xml.soap.SOAPHeaderElement) ProtocolException(javax.xml.ws.ProtocolException) JAXBContext(javax.xml.bind.JAXBContext) SOAPEnvelope(javax.xml.soap.SOAPEnvelope) CoordinationContextType(org.oasis_open.docs.ws_tx.wscoor._2006._06.CoordinationContextType) SOAPMessage(javax.xml.soap.SOAPMessage) ProtocolException(javax.xml.ws.ProtocolException) JAXBException(javax.xml.bind.JAXBException)

Example 24 with SOAPHeaderElement

use of javax.xml.soap.SOAPHeaderElement in project narayana by jbosstm.

the class AbstractJTAOverWSATHandler method getHeaderElement.

/**
 * Extracts and returns SOAP header element from the SOAP message context based on <code>uri</code> and <code>name</code>.
 *
 * @param soapMessageContext
 * @param uri
 * @param name
 * @return SOAP header element if such element existed and <code>null</code> if not.
 */
private SOAPHeaderElement getHeaderElement(final SOAPMessageContext soapMessageContext, final String uri, final String name) {
    SOAPHeaderElement soapHeaderElement = null;
    try {
        final SOAPMessage soapMessage = soapMessageContext.getMessage();
        final SOAPEnvelope soapEnvelope = soapMessage.getSOAPPart().getEnvelope();
        final SOAPHeader soapHeader = soapEnvelope.getHeader();
        if (soapHeader != null) {
            soapHeaderElement = getHeaderElement(soapHeader, uri, name);
        }
    } catch (SOAPException e) {
    }
    return soapHeaderElement;
}
Also used : SOAPHeaderElement(javax.xml.soap.SOAPHeaderElement) SOAPException(javax.xml.soap.SOAPException) SOAPEnvelope(javax.xml.soap.SOAPEnvelope) SOAPMessage(javax.xml.soap.SOAPMessage) SOAPHeader(javax.xml.soap.SOAPHeader)

Example 25 with SOAPHeaderElement

use of javax.xml.soap.SOAPHeaderElement in project narayana by jbosstm.

the class AbstractJTAOverWSATHandler method getHeaderElement.

/**
 * Extracts and returns SOAP header element from the SOAP header based on <code>uri</code> and <code>name</code>.
 *
 * @param soapHeader
 * @param uri
 * @param name
 * @return SOAP header element if such element existed and <code>null</code> if not.
 */
private SOAPHeaderElement getHeaderElement(final SOAPHeader soapHeader, final String uri, final String name) throws SOAPException {
    @SuppressWarnings("unchecked") final Iterator<SOAPHeaderElement> iterator = SOAPUtil.getChildElements(soapHeader);
    while (iterator.hasNext()) {
        final SOAPHeaderElement current = iterator.next();
        final Name currentName = current.getElementName();
        if ((currentName != null) && match(name, currentName.getLocalName()) && match(uri, currentName.getURI())) {
            return current;
        }
    }
    return null;
}
Also used : SOAPHeaderElement(javax.xml.soap.SOAPHeaderElement) Name(javax.xml.soap.Name)

Aggregations

SOAPHeaderElement (javax.xml.soap.SOAPHeaderElement)36 SOAPMessage (javax.xml.soap.SOAPMessage)24 SOAPHeader (javax.xml.soap.SOAPHeader)21 SOAPException (javax.xml.soap.SOAPException)17 SOAPEnvelope (javax.xml.soap.SOAPEnvelope)14 Name (javax.xml.soap.Name)10 SOAPElement (javax.xml.soap.SOAPElement)10 SOAPBody (javax.xml.soap.SOAPBody)9 SOAPBodyElement (javax.xml.soap.SOAPBodyElement)7 WebServiceException (javax.xml.ws.WebServiceException)7 QName (javax.xml.namespace.QName)6 SOAPFactory (javax.xml.soap.SOAPFactory)6 ProtocolException (javax.xml.ws.ProtocolException)6 CoordinationContextType (org.oasis_open.docs.ws_tx.wscoor._2006._06.CoordinationContextType)6 Iterator (java.util.Iterator)5 JAXBException (javax.xml.bind.JAXBException)5 SOAPPart (javax.xml.soap.SOAPPart)5 Node (org.w3c.dom.Node)4 IOException (java.io.IOException)3 JAXBContext (javax.xml.bind.JAXBContext)3