Search in sources :

Example 1 with XMLHTTPBindingCodec

use of com.sun.xml.ws.encoding.XMLHTTPBindingCodec in project metro-jax-ws by eclipse-ee4j.

the class XMLMessage method getDataSource.

public static DataSource getDataSource(Message msg, WSFeatureList f) {
    if (msg == null)
        return null;
    if (msg instanceof MessageDataSource) {
        return ((MessageDataSource) msg).getDataSource();
    } else {
        AttachmentSet atts = msg.getAttachments();
        if (atts != null && !atts.isEmpty()) {
            final ByteArrayBuffer bos = new ByteArrayBuffer();
            try {
                Codec codec = new XMLHTTPBindingCodec(f);
                Packet packet = new Packet(msg);
                com.sun.xml.ws.api.pipe.ContentType ct = codec.getStaticContentType(packet);
                codec.encode(packet, bos);
                return createDataSource(ct.getContentType(), bos.newInputStream());
            } catch (IOException ioe) {
                throw new WebServiceException(ioe);
            }
        } else {
            final ByteArrayBuffer bos = new ByteArrayBuffer();
            XMLStreamWriter writer = XMLStreamWriterFactory.create(bos);
            try {
                msg.writePayloadTo(writer);
                writer.flush();
            } catch (XMLStreamException e) {
                throw new WebServiceException(e);
            }
            return XMLMessage.createDataSource("text/xml", bos.newInputStream());
        }
    }
}
Also used : XMLHTTPBindingCodec(com.sun.xml.ws.encoding.XMLHTTPBindingCodec) WebServiceException(jakarta.xml.ws.WebServiceException) IOException(java.io.IOException) ByteArrayBuffer(com.sun.xml.ws.util.ByteArrayBuffer) MimeAttachmentSet(com.sun.xml.ws.message.MimeAttachmentSet) Codec(com.sun.xml.ws.api.pipe.Codec) XMLHTTPBindingCodec(com.sun.xml.ws.encoding.XMLHTTPBindingCodec) XMLStreamException(javax.xml.stream.XMLStreamException) XMLStreamWriter(javax.xml.stream.XMLStreamWriter)

Aggregations

Codec (com.sun.xml.ws.api.pipe.Codec)1 XMLHTTPBindingCodec (com.sun.xml.ws.encoding.XMLHTTPBindingCodec)1 MimeAttachmentSet (com.sun.xml.ws.message.MimeAttachmentSet)1 ByteArrayBuffer (com.sun.xml.ws.util.ByteArrayBuffer)1 WebServiceException (jakarta.xml.ws.WebServiceException)1 IOException (java.io.IOException)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)1