Search in sources :

Example 6 with Attachment

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;
}
Also used : Codec(com.sun.xml.ws.api.pipe.Codec) Message(com.sun.xml.ws.api.message.Message) ContentType(com.sun.xml.ws.api.pipe.ContentType) Attachment(com.sun.xml.ws.api.message.Attachment)

Example 7 with Attachment

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;
}
Also used : Attachment(com.sun.xml.ws.api.message.Attachment) MIMEPart(org.jvnet.mimepull.MIMEPart) Nullable(com.sun.istack.Nullable)

Example 8 with Attachment

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);
    }
}
Also used : Attachment(com.sun.xml.ws.api.message.Attachment) DataHandler(jakarta.activation.DataHandler) StreamingDataHandler(com.sun.xml.ws.developer.StreamingDataHandler) StreamingDataHandler(com.sun.xml.ws.developer.StreamingDataHandler)

Example 9 with Attachment

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());
        }
    }
}
Also used : Codec(com.sun.xml.ws.api.pipe.Codec) Attachment(com.sun.xml.ws.api.message.Attachment) MimeAttachmentSet(com.sun.xml.ws.message.MimeAttachmentSet) Map(java.util.Map)

Example 10 with Attachment

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;
}
Also used : AttachmentSet(com.sun.xml.ws.api.message.AttachmentSet) DataHandlerAttachment(com.sun.xml.ws.message.DataHandlerAttachment) WebServiceException(jakarta.xml.ws.WebServiceException) DataHandlerAttachment(com.sun.xml.ws.message.DataHandlerAttachment) Attachment(com.sun.xml.ws.api.message.Attachment) DataHandler(jakarta.activation.DataHandler)

Aggregations

Attachment (com.sun.xml.ws.api.message.Attachment)20 DataHandler (jakarta.activation.DataHandler)12 AttachmentSet (com.sun.xml.ws.api.message.AttachmentSet)9 DataHandlerAttachment (com.sun.xml.ws.message.DataHandlerAttachment)8 Map (java.util.Map)7 HashMap (java.util.HashMap)5 Packet (com.sun.xml.ws.api.message.Packet)4 Message (com.sun.xml.ws.api.message.Message)3 StreamingDataHandler (com.sun.xml.ws.developer.StreamingDataHandler)3 WebServiceException (jakarta.xml.ws.WebServiceException)3 JavaCallInfo (com.oracle.webservices.api.databinding.JavaCallInfo)2 MessageContext (com.oracle.webservices.api.message.MessageContext)2 Nullable (com.sun.istack.Nullable)2 SOAPVersion (com.sun.xml.ws.api.SOAPVersion)2 Databinding (com.sun.xml.ws.api.databinding.Databinding)2 DatabindingConfig (com.sun.xml.ws.api.databinding.DatabindingConfig)2 WSDLPort (com.sun.xml.ws.api.model.wsdl.WSDLPort)2 Codec (com.sun.xml.ws.api.pipe.Codec)2 MIMEPartStreamingDataHandler (com.sun.xml.ws.encoding.MIMEPartStreamingDataHandler)2 SOAPMessageContextImpl (com.sun.xml.ws.handler.SOAPMessageContextImpl)2