Search in sources :

Example 1 with AttachmentSetImpl

use of com.sun.xml.ws.message.AttachmentSetImpl 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)

Example 2 with AttachmentSetImpl

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

the class JAXBMessage method create.

/**
 * Creates a {@link Message} backed by a JAXB bean.
 *
 * @param bridge
 *      Specify the payload tag name and how {@code jaxbObject} is bound.
 */
public static Message create(XMLBridge bridge, Object jaxbObject, SOAPVersion soapVer) {
    if (!bridge.context().hasSwaRef()) {
        return new JAXBMessage(bridge, jaxbObject, soapVer);
    }
    try {
        MutableXMLStreamBuffer xsb = new MutableXMLStreamBuffer();
        AttachmentSetImpl attachments = new AttachmentSetImpl();
        AttachmentMarshallerImpl am = new AttachmentMarshallerImpl(attachments);
        bridge.marshal(jaxbObject, xsb.createFromXMLStreamWriter(), am);
        am.cleanup();
        // any way to reuse this XMLStreamBuffer in StreamMessage?
        return new StreamMessage(null, attachments, xsb.readAsXMLStreamReader(), soapVer);
    } catch (JAXBException | XMLStreamException e) {
        throw new WebServiceException(e);
    }
}
Also used : MutableXMLStreamBuffer(com.sun.xml.stream.buffer.MutableXMLStreamBuffer) XMLStreamException(javax.xml.stream.XMLStreamException) WebServiceException(jakarta.xml.ws.WebServiceException) JAXBException(jakarta.xml.bind.JAXBException) StreamMessage(com.sun.xml.ws.message.stream.StreamMessage) AttachmentSetImpl(com.sun.xml.ws.message.AttachmentSetImpl)

Example 3 with AttachmentSetImpl

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

the class DispatchImpl method setOutboundAttachments.

protected AttachmentSet setOutboundAttachments() {
    HashMap<String, DataHandler> attachments = (HashMap<String, DataHandler>) getRequestContext().get(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS);
    if (attachments != null) {
        List<Attachment> alist = new ArrayList();
        for (Map.Entry<String, DataHandler> att : attachments.entrySet()) {
            DataHandlerAttachment dha = new DataHandlerAttachment(att.getKey(), att.getValue());
            alist.add(dha);
        }
        return new AttachmentSetImpl(alist);
    }
    return new AttachmentSetImpl();
}
Also used : DataHandlerAttachment(com.sun.xml.ws.message.DataHandlerAttachment) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) DataHandlerAttachment(com.sun.xml.ws.message.DataHandlerAttachment) Attachment(com.sun.xml.ws.api.message.Attachment) DataHandler(jakarta.activation.DataHandler) AttachmentSetImpl(com.sun.xml.ws.message.AttachmentSetImpl) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

AttachmentSetImpl (com.sun.xml.ws.message.AttachmentSetImpl)3 WebServiceException (jakarta.xml.ws.WebServiceException)2 MutableXMLStreamBuffer (com.sun.xml.stream.buffer.MutableXMLStreamBuffer)1 SOAPVersion (com.sun.xml.ws.api.SOAPVersion)1 Attachment (com.sun.xml.ws.api.message.Attachment)1 DOMMessage (com.sun.xml.ws.message.DOMMessage)1 DataHandlerAttachment (com.sun.xml.ws.message.DataHandlerAttachment)1 EmptyMessageImpl (com.sun.xml.ws.message.EmptyMessageImpl)1 StreamMessage (com.sun.xml.ws.message.stream.StreamMessage)1 DataHandler (jakarta.activation.DataHandler)1 JAXBElement (jakarta.xml.bind.JAXBElement)1 JAXBException (jakarta.xml.bind.JAXBException)1 XmlRootElement (jakarta.xml.bind.annotation.XmlRootElement)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 Element (org.w3c.dom.Element)1 Node (org.w3c.dom.Node)1