public static DataSource transformDataSource(DataSource in,
boolean isFastInfoset, boolean useFastInfoset, WSBinding binding) {
try {
if (isFastInfoset && !useFastInfoset) {
// Convert from Fast Infoset to XML
Codec codec = new XMLHTTPBindingCodec(binding);
Packet p = new Packet();
codec.decode(in.getInputStream(), in.getContentType(), p);
p.getMessage().getAttachments();
codec.getStaticContentType(p);
ByteArrayBuffer bos = new ByteArrayBuffer();
ContentType ct = codec.encode(p, bos);
return XMLMessage.createDataSource(ct.getContentType(), bos.newInputStream());
} else if (!isFastInfoset && useFastInfoset) {
// Convert from XML to Fast Infoset
Codec codec = new XMLHTTPBindingCodec(binding);
Packet p = new Packet();
codec.decode(in.getInputStream(), in.getContentType(), p);
p.contentNegotiation = ContentNegotiation.optimistic;
p.getMessage().getAttachments();
codec.getStaticContentType(p);
ByteArrayBuffer bos = new ByteArrayBuffer();
com.sun.xml.internal.ws.api.pipe.ContentType ct = codec.encode(p, bos);
return XMLMessage.createDataSource(ct.getContentType(), bos.newInputStream());
}
} catch(Exception ex) {
throw new WebServiceException(ex);
}