use of com.sun.xml.ws.api.pipe.Codec in project metro-jax-ws by eclipse-ee4j.
the class SAAJFactoryTest method getLogicalMessage.
private Message getLogicalMessage(byte[] bytes, String contentType) throws IOException {
ByteArrayInputStream in = new ByteArrayInputStream(bytes);
WSBinding binding = BindingImpl.create(BindingID.SOAP11_HTTP);
Codec codec = new SOAPBindingCodec(binding.getFeatures());
Packet packet = new Packet();
codec.decode(in, contentType, packet);
return packet.getMessage();
}
use of com.sun.xml.ws.api.pipe.Codec in project metro-jax-ws by eclipse-ee4j.
the class MimeCodec method encode.
// TODO: preencode String literals to byte[] so that they don't have to
// go through char[]->byte[] conversion at runtime.
public ContentType encode(Packet packet, OutputStream out) throws IOException {
Message msg = packet.getMessage();
if (msg == null) {
return null;
}
ContentTypeImpl ctImpl = (ContentTypeImpl) getStaticContentType(packet);
String boundary = ctImpl.getBoundary();
String rootId = ctImpl.getRootId();
boolean hasAttachments = (boundary != null);
Codec rootCodec = getMimeRootCodec(packet);
if (hasAttachments) {
writeln("--" + boundary, out);
ContentType ct = rootCodec.getStaticContentType(packet);
String ctStr = (ct != null) ? ct.getContentType() : rootCodec.getMimeType();
if (rootId != null)
writeln("Content-ID: " + rootId, out);
writeln("Content-Type: " + ctStr, out);
writeln(out);
}
ContentType primaryCt = rootCodec.encode(packet, out);
if (hasAttachments) {
writeln(out);
// Encode all the attchments
for (Attachment att : msg.getAttachments()) {
writeln("--" + boundary, out);
// SAAJ's AttachmentPart.getContentId() returns content id already enclosed with
// angle brackets. For now put angle bracket only if its not there
String cid = att.getContentId();
if (cid != null && cid.length() > 0 && cid.charAt(0) != '<')
cid = '<' + cid + '>';
writeln("Content-Id:" + cid, out);
writeln("Content-Type: " + att.getContentType(), out);
writeCustomMimeHeaders(att, out);
writeln("Content-Transfer-Encoding: binary", out);
// write \r\n
writeln(out);
att.writeTo(out);
// write \r\n
writeln(out);
}
writeAsAscii("--" + boundary, out);
writeAsAscii("--", out);
}
// TODO not returing correct multipart/related type(no boundary)
return hasAttachments ? ctImpl : primaryCt;
}
use of com.sun.xml.ws.api.pipe.Codec in project metro-jax-ws by eclipse-ee4j.
the class SwACodec method decode.
@Override
protected void decode(MimeMultipartParser mpp, Packet packet) throws IOException {
// TODO: handle attachments correctly
Attachment root = mpp.getRootPart();
Codec rootCodec = getMimeRootCodec(packet);
if (rootCodec instanceof RootOnlyCodec) {
((RootOnlyCodec) rootCodec).decode(root.asInputStream(), root.getContentType(), packet, new MimeAttachmentSet(mpp));
} else {
rootCodec.decode(root.asInputStream(), root.getContentType(), packet);
Map<String, Attachment> atts = mpp.getAttachmentParts();
for (Map.Entry<String, Attachment> att : atts.entrySet()) {
packet.getMessage().getAttachments().add(att.getValue());
}
}
}
use of com.sun.xml.ws.api.pipe.Codec in project metro-jax-ws by eclipse-ee4j.
the class XMLHTTPBindingCodec method transformDataSource.
public static DataSource transformDataSource(DataSource in, boolean isFastInfoset, boolean useFastInfoset, WSFeatureList f) {
try {
if (isFastInfoset && !useFastInfoset) {
// Convert from Fast Infoset to XML
Codec codec = new XMLHTTPBindingCodec(f);
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(f);
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.ws.api.pipe.ContentType ct = codec.encode(p, bos);
return XMLMessage.createDataSource(ct.getContentType(), bos.newInputStream());
}
} catch (Exception ex) {
throw new WebServiceException(ex);
}
return in;
}
use of com.sun.xml.ws.api.pipe.Codec 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