Search in sources :

Example 1 with DOMMessage

use of com.sun.xml.ws.message.DOMMessage in project metro-jax-ws by eclipse-ee4j.

the class Messages method create.

/**
 * Creates a {@link Message} from an {@link Element} that represents
 * the whole SOAP message.
 *
 * @param soapEnvelope
 *      The SOAP envelope element.
 */
public static Message create(Element soapEnvelope) {
    SOAPVersion ver = SOAPVersion.fromNsUri(soapEnvelope.getNamespaceURI());
    // find the headers
    Element header = DOMUtil.getFirstChild(soapEnvelope, ver.nsUri, "Header");
    HeaderList headers = null;
    if (header != null) {
        for (Node n = header.getFirstChild(); n != null; n = n.getNextSibling()) {
            if (n.getNodeType() == Node.ELEMENT_NODE) {
                if (headers == null)
                    headers = new HeaderList(ver);
                headers.add(Headers.create((Element) n));
            }
        }
    }
    // find the payload
    Element body = DOMUtil.getFirstChild(soapEnvelope, ver.nsUri, "Body");
    if (body == null)
        throw new WebServiceException("Message doesn't have <S:Body> " + soapEnvelope);
    Element payload = DOMUtil.getFirstChild(soapEnvelope, ver.nsUri, "Body");
    if (payload == null) {
        return new EmptyMessageImpl(headers, new AttachmentSetImpl(), ver);
    } else {
        return new DOMMessage(ver, headers, payload);
    }
}
Also used : WebServiceException(jakarta.xml.ws.WebServiceException) SOAPVersion(com.sun.xml.ws.api.SOAPVersion) Element(org.w3c.dom.Element) XmlRootElement(jakarta.xml.bind.annotation.XmlRootElement) JAXBElement(jakarta.xml.bind.JAXBElement) Node(org.w3c.dom.Node) AttachmentSetImpl(com.sun.xml.ws.message.AttachmentSetImpl) DOMMessage(com.sun.xml.ws.message.DOMMessage) EmptyMessageImpl(com.sun.xml.ws.message.EmptyMessageImpl)

Aggregations

SOAPVersion (com.sun.xml.ws.api.SOAPVersion)1 AttachmentSetImpl (com.sun.xml.ws.message.AttachmentSetImpl)1 DOMMessage (com.sun.xml.ws.message.DOMMessage)1 EmptyMessageImpl (com.sun.xml.ws.message.EmptyMessageImpl)1 JAXBElement (jakarta.xml.bind.JAXBElement)1 XmlRootElement (jakarta.xml.bind.annotation.XmlRootElement)1 WebServiceException (jakarta.xml.ws.WebServiceException)1 Element (org.w3c.dom.Element)1 Node (org.w3c.dom.Node)1