use of com.sun.xml.ws.api.message.Attachment 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.message.Attachment in project metro-jax-ws by eclipse-ee4j.
the class MimeMultipartParser method getAttachmentPart.
/**
* This method can be called to get a matching MIME attachment part for the
* given contentId. It parses the stream until it finds a matching part.
*
* @return StreamAttachment attachment for contentId
* null if there is no attachment for contentId
*/
@Nullable
public Attachment getAttachmentPart(String contentId) throws IOException {
// first see if this attachment is already parsed, if so return it
Attachment attach = attachments.get(contentId);
if (attach == null) {
MIMEPart part = message.getPart(contentId);
attach = new PartAttachment(part);
attachments.put(contentId, attach);
}
return attach;
}
use of com.sun.xml.ws.api.message.Attachment in project metro-jax-ws by eclipse-ee4j.
the class MtomCodec method writeNonMtomAttachments.
// Compiler warning for not calling close, but cannot call close,
// will consume attachment bytes.
@SuppressWarnings("resource")
private void writeNonMtomAttachments(AttachmentSet attachments, OutputStream out, String boundary) throws IOException {
for (Attachment att : attachments) {
DataHandler dh = att.asDataHandler();
if (dh instanceof StreamingDataHandler) {
StreamingDataHandler sdh = (StreamingDataHandler) dh;
// If DataHandler has href Content-ID, it is MTOM, so skip.
if (sdh.getHrefCid() != null)
continue;
}
// build attachment frame
writeln("--" + boundary, out);
writeMimeHeaders(att.getContentType(), att.getContentId(), out);
att.writeTo(out);
// write \r\n
writeln(out);
}
}
use of com.sun.xml.ws.api.message.Attachment 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.message.Attachment in project metro-jax-ws by eclipse-ee4j.
the class ClientMessageHandlerTube method callHandlersOnRequest.
boolean callHandlersOnRequest(MessageUpdatableContext context, boolean isOneWay) {
boolean handlerResult;
// Lets copy all the MessageContext.OUTBOUND_ATTACHMENT_PROPERTY to the message
Map<String, DataHandler> atts = (Map<String, DataHandler>) context.get(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS);
AttachmentSet attSet = context.packet.getMessage().getAttachments();
for (Entry<String, DataHandler> entry : atts.entrySet()) {
String cid = entry.getKey();
if (attSet.get(cid) == null) {
// Otherwise we would be adding attachments twice
Attachment att = new DataHandlerAttachment(cid, atts.get(cid));
attSet.add(att);
}
}
try {
// CLIENT-SIDE
handlerResult = processor.callHandlersRequest(HandlerProcessor.Direction.OUTBOUND, context, !isOneWay);
} catch (WebServiceException wse) {
remedyActionTaken = true;
// no rewrapping
throw wse;
} catch (RuntimeException re) {
remedyActionTaken = true;
throw new WebServiceException(re);
}
if (!handlerResult) {
remedyActionTaken = true;
}
return handlerResult;
}
Aggregations