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());
}
}
}
Aggregations