Search in sources :

Example 21 with AttachmentPart

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);
    }
}
Also used : AttachmentEx(com.sun.xml.ws.api.message.AttachmentEx) Attachment(com.sun.xml.ws.api.message.Attachment) AttachmentPart(jakarta.xml.soap.AttachmentPart)

Example 22 with AttachmentPart

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);
}
Also used : AttachmentPart(jakarta.xml.soap.AttachmentPart)

Example 23 with AttachmentPart

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);
}
Also used : AttachmentPart(jakarta.xml.soap.AttachmentPart)

Example 24 with AttachmentPart

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);
}
Also used : Packet(com.sun.xml.ws.api.message.Packet) Message(com.sun.xml.ws.api.message.Message) SOAPMessage(jakarta.xml.soap.SOAPMessage) ContentType(com.oracle.webservices.api.message.ContentType) MessageFactory(jakarta.xml.soap.MessageFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) MTOMFeature(jakarta.xml.ws.soap.MTOMFeature) AttachmentPart(jakarta.xml.soap.AttachmentPart) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SOAPMessage(jakarta.xml.soap.SOAPMessage) MimeHeaders(jakarta.xml.soap.MimeHeaders) MessageContextFactory(com.oracle.webservices.api.message.MessageContextFactory) ByteArrayInputStream(java.io.ByteArrayInputStream)

Aggregations

AttachmentPart (jakarta.xml.soap.AttachmentPart)24 SOAPMessage (jakarta.xml.soap.SOAPMessage)16 MessageFactory (jakarta.xml.soap.MessageFactory)9 ByteArrayInputStream (java.io.ByteArrayInputStream)7 InputStream (java.io.InputStream)7 Message (com.sun.xml.ws.api.message.Message)5 Packet (com.sun.xml.ws.api.message.Packet)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 MessageContextFactory (com.oracle.webservices.api.message.MessageContextFactory)4 DataHandler (jakarta.activation.DataHandler)4 MTOMFeature (jakarta.xml.ws.soap.MTOMFeature)4 Test (org.junit.Test)4 MessageContext (com.oracle.webservices.api.message.MessageContext)3 MimeHeaders (jakarta.xml.soap.MimeHeaders)3 SOAPElement (jakarta.xml.soap.SOAPElement)3 SOAPPart (jakarta.xml.soap.SOAPPart)3 Iterator (java.util.Iterator)3 Attachment (com.sun.xml.ws.api.message.Attachment)2 JAXBException (jakarta.xml.bind.JAXBException)2 SOAPBody (jakarta.xml.soap.SOAPBody)2