use of jakarta.xml.soap.AttachmentPart in project metro-jax-ws by eclipse-ee4j.
the class SAAJFactory method addAttachmentsToSOAPMessage.
protected static void addAttachmentsToSOAPMessage(SOAPMessage msg, Message message) {
for (Attachment att : message.getAttachments()) {
AttachmentPart part = msg.createAttachmentPart();
part.setDataHandler(att.asDataHandler());
// Be safe and avoid double angle-brackets.
String cid = att.getContentId();
if (cid != null) {
if (cid.startsWith("<") && cid.endsWith(">"))
part.setContentId(cid);
else
part.setContentId('<' + cid + '>');
}
// by the DataHandler above.
if (att instanceof AttachmentEx) {
AttachmentEx ax = (AttachmentEx) att;
Iterator<AttachmentEx.MimeHeader> imh = ax.getMimeHeaders();
while (imh.hasNext()) {
AttachmentEx.MimeHeader ame = imh.next();
if ((!"Content-ID".equalsIgnoreCase(ame.getName())) && (!"Content-Type".equalsIgnoreCase(ame.getName())))
part.addMimeHeader(ame.getName(), ame.getValue());
}
}
msg.addAttachmentPart(part);
}
}
use of jakarta.xml.soap.AttachmentPart in project metro-jax-ws by eclipse-ee4j.
the class DataHandlerAttachment method writeTo.
public void writeTo(SOAPMessage saaj) throws SOAPException {
AttachmentPart part = saaj.createAttachmentPart();
part.setDataHandler(dh);
part.setContentId(contentId);
saaj.addAttachmentPart(part);
}
use of jakarta.xml.soap.AttachmentPart in project metro-jax-ws by eclipse-ee4j.
the class ByteArrayAttachment method writeTo.
public void writeTo(SOAPMessage saaj) throws SOAPException {
AttachmentPart part = saaj.createAttachmentPart();
part.setDataHandler(asDataHandler());
part.setContentId(contentId);
saaj.addAttachmentPart(part);
}
use of jakarta.xml.soap.AttachmentPart in project metro-jax-ws by eclipse-ee4j.
the class StreamMessageTest method testWriteSwaToStreamClientRequest.
// Bug 17367334
public void testWriteSwaToStreamClientRequest() throws Exception {
String ctype = "multipart/related; boundary=MIME_Boundary; " + "start=\"<6232425701115978772--54bee05.140acdf4f8a.-7f3f>\"; " + "type=\"text/xml\"; start-info=\"text/xml\"";
MessageContextFactory mcf = MessageContextFactory.createFactory(new MTOMFeature(true));
InputStream is = getClass().getClassLoader().getResourceAsStream("etc/bug17367334InputMsg.txt");
Packet packet = (Packet) mcf.createContext(is, ctype);
Message message = packet.getInternalMessage();
assertTrue("StreamMessage not found, got : " + message.getClass(), StreamMessage.class.isAssignableFrom(message.getClass()));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
packet.setState(State.ClientRequest);
// System.out.println("SWA packet.getContentType(): " + packet.getContentType().getContentType() );
ContentType contentType = packet.writeTo(baos);
// System.out.println("etc/bug17367334InputMsg.txt\r\n" + contentType.getContentType() + "\r\n" + new String(baos.toByteArray()));
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
MessageFactory mf = MessageFactory.newInstance();
MimeHeaders mh = new MimeHeaders();
mh.addHeader("Content-Type", ctype);
SOAPMessage sm = mf.createMessage(mh, bais);
assertEquals("wrong attachment count", 1, sm.countAttachments());
AttachmentPart ap = (AttachmentPart) sm.getAttachments().next();
assertEquals("wrong attachemnt Content-Id", "<testAttachmentContentId>", ap.getContentId());
// NodeList nl = sm.getSOAPBody().getElementsByTagNameNS(MtomCodec.XOP_NAMESPACEURI, MtomCodec.XOP_LOCALNAME);
}
Aggregations