Search in sources :

Example 1 with Header

use of org.apache.axiom.mime.Header in project webservices-axiom by apache.

the class IncomingAttachmentStreams method getNextStream.

/**
     * Returns the next attachment stream in sequence.
     *
     * @return The next stream or null if no additional streams are left.
     */
public IncomingAttachmentInputStream getNextStream() throws OMException {
    if (!readyToGetNextStream) {
        throw new IllegalStateException("nextStreamNotReady");
    }
    Part part = null;
    while (part == null && partIterator.hasNext()) {
        part = partIterator.next();
        // Skip the root part
        if (part == rootPart) {
            part = null;
        }
    }
    if (part != null) {
        IncomingAttachmentInputStream stream = new IncomingAttachmentInputStream(part.getInputStream(false), this);
        for (Header header : part.getHeaders()) {
            String name = header.getName();
            String value = header.getValue();
            if (IncomingAttachmentInputStream.HEADER_CONTENT_ID.equals(name) || IncomingAttachmentInputStream.HEADER_CONTENT_TYPE.equals(name) || IncomingAttachmentInputStream.HEADER_CONTENT_LOCATION.equals(name)) {
                value = value.trim();
            }
            stream.addHeader(name, value);
        }
        readyToGetNextStream = false;
        return stream;
    } else {
        return null;
    }
}
Also used : Header(org.apache.axiom.mime.Header) Part(org.apache.axiom.mime.Part)

Example 2 with Header

use of org.apache.axiom.mime.Header in project webservices-axiom by apache.

the class MultipartBodyWriter method writePart.

/**
     * Start writing a MIME part. The methods returns an {@link OutputStream} that the caller can
     * use to write the content of the MIME part. After writing the content,
     * {@link OutputStream#close()} must be called to complete the writing of the MIME part.
     * 
     * @param contentType
     *            the value of the <tt>Content-Type</tt> header of the MIME part; may be {@code null}
     * @param contentTransferEncoding
     *            the content transfer encoding to be used (see above); must not be
     *            <code>null</code>
     * @param contentID
     *            the content ID of the MIME part (see above); may be {@code null}
     * @param extraHeaders
     *            a list of {@link Header} objects with additional headers to write to the MIME
     *            part; may be {@code null}
     * @return an output stream to write the content of the MIME part
     * @throws IOException
     *             if an I/O error occurs when writing to the underlying stream
     */
public OutputStream writePart(String contentType, String contentTransferEncoding, String contentID, List<Header> extraHeaders) throws IOException {
    OutputStream transferEncoder;
    if (contentTransferEncoding.equals("8bit") || contentTransferEncoding.equals("binary")) {
        transferEncoder = out;
    } else {
        // We support no content transfer encodings other than 8bit, binary and base64.
        transferEncoder = new Base64EncodingOutputStream(out);
        contentTransferEncoding = "base64";
    }
    writeAscii("--");
    writeAscii(boundary);
    // text/plain; charset=us-ascii).
    if (contentType != null) {
        writeAscii("\r\nContent-Type: ");
        writeAscii(contentType);
    }
    writeAscii("\r\nContent-Transfer-Encoding: ");
    writeAscii(contentTransferEncoding);
    if (contentID != null) {
        writeAscii("\r\nContent-ID: <");
        writeAscii(contentID);
        out.write('>');
    }
    if (extraHeaders != null) {
        for (Header header : extraHeaders) {
            writeAscii("\r\n");
            writeAscii(header.getName());
            writeAscii(": ");
            writeAscii(header.getValue());
        }
    }
    writeAscii("\r\n\r\n");
    return new PartOutputStream(transferEncoder);
}
Also used : Header(org.apache.axiom.mime.Header) OutputStream(java.io.OutputStream) Base64EncodingOutputStream(org.apache.axiom.util.base64.Base64EncodingOutputStream) Base64EncodingOutputStream(org.apache.axiom.util.base64.Base64EncodingOutputStream)

Example 3 with Header

use of org.apache.axiom.mime.Header in project webservices-axiom by apache.

the class MultipartWriterImpl method writePart.

@Override
public void writePart(DataHandler dataHandler, String contentTransferEncoding, String contentID, List extraHeaders) throws IOException {
    MimeBodyPart mimeBodyPart = new MimeBodyPart();
    try {
        mimeBodyPart.setDataHandler(dataHandler);
        mimeBodyPart.addHeader("Content-ID", "<" + contentID + ">");
        mimeBodyPart.addHeader("Content-Type", dataHandler.getContentType());
        mimeBodyPart.addHeader("Content-Transfer-Encoding", contentTransferEncoding);
        mimeBodyPart.addHeader("Content-Transfer-Encoding", contentTransferEncoding);
        if (extraHeaders != null) {
            for (Iterator it = extraHeaders.iterator(); it.hasNext(); ) {
                Header header = (Header) it.next();
                mimeBodyPart.addHeader(header.getName(), header.getValue());
            }
        }
    } catch (MessagingException ex) {
        IOException ex2 = new IOException("Unable to create MimeBodyPart");
        ex2.initCause(ex);
        throw ex2;
    }
    out.write(DASH_DASH);
    out.write(boundary);
    out.write(CR_LF);
    try {
        mimeBodyPart.writeTo(out);
    } catch (MessagingException ex) {
        IOException ex2 = new IOException("Unable to write the MimeBodyPart object");
        ex2.initCause(ex);
        throw ex2;
    }
    out.write(CR_LF);
}
Also used : Header(org.apache.axiom.mime.Header) MessagingException(javax.mail.MessagingException) Iterator(java.util.Iterator) IOException(java.io.IOException) MimeBodyPart(javax.mail.internet.MimeBodyPart)

Aggregations

Header (org.apache.axiom.mime.Header)3 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 Iterator (java.util.Iterator)1 MessagingException (javax.mail.MessagingException)1 MimeBodyPart (javax.mail.internet.MimeBodyPart)1 Part (org.apache.axiom.mime.Part)1 Base64EncodingOutputStream (org.apache.axiom.util.base64.Base64EncodingOutputStream)1