Search in sources :

Example 1 with Part

use of org.apache.axiom.mime.Part 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 Part

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

the class BuilderSpec method from.

static BuilderSpec from(StAXParserConfiguration configuration, final MultipartBody message) {
    Part rootPart = message.getRootPart();
    InputSource is = new InputSource(rootPart.getInputStream(false));
    is.setEncoding(rootPart.getContentType().getParameter("charset"));
    BuilderSpec spec = create(configuration, is, false);
    return new BuilderSpec(new FilteredXmlInput(spec.getInput(), new XOPDecodingFilter(new OMAttachmentAccessor() {

        @Override
        public DataHandler getDataHandler(String contentID) {
            Part part = message.getPart(contentID);
            return part == null ? null : part.getDataHandler();
        }
    })), new Detachable() {

        @Override
        public void detach() {
            message.detach();
        }
    });
}
Also used : OMAttachmentAccessor(org.apache.axiom.om.OMAttachmentAccessor) Detachable(org.apache.axiom.om.impl.common.builder.Detachable) InputSource(org.xml.sax.InputSource) Part(org.apache.axiom.mime.Part) DataHandler(javax.activation.DataHandler) FilteredXmlInput(org.apache.axiom.core.stream.FilteredXmlInput) XOPDecodingFilter(org.apache.axiom.om.impl.stream.xop.XOPDecodingFilter)

Aggregations

Part (org.apache.axiom.mime.Part)2 DataHandler (javax.activation.DataHandler)1 FilteredXmlInput (org.apache.axiom.core.stream.FilteredXmlInput)1 Header (org.apache.axiom.mime.Header)1 OMAttachmentAccessor (org.apache.axiom.om.OMAttachmentAccessor)1 Detachable (org.apache.axiom.om.impl.common.builder.Detachable)1 XOPDecodingFilter (org.apache.axiom.om.impl.stream.xop.XOPDecodingFilter)1 InputSource (org.xml.sax.InputSource)1