MultipartAttachmentStreams.javaAPI DocApache Axis 1.46308Sat Apr 22 18:57:28 BST 2006org.apache.axis.attachments


public final class MultipartAttachmentStreams extends IncomingAttachmentStreams
The MultipartAttachmentStreams class is used to create IncomingAttachmentInputStream objects when the HTTP stream shows a marked separation between the SOAP and each attachment parts. Unlike the DIME version, this class will use the BoundaryDelimitedStream to parse data in the SwA format. Another difference between the two is that the MultipartAttachmentStreams class must also provide a way to hold attachment parts parsed prior to where the SOAP part appears in the HTTP stream (i.e. the root part of the multipart-related message). Our DIME counterpart didnt have to worry about this since the SOAP part is guaranteed to be the first in the stream. But since SwA has no such guarantee, we must fall back to caching these first parts. Afterwards, we can stream the rest of the attachments that are after the SOAP part of the request message.
David Wong
Brian Husted

Fields Summary
private BoundaryDelimitedStream
private Iterator
Constructors Summary
public MultipartAttachmentStreams(BoundaryDelimitedStream delimitedStream)

        this(delimitedStream, null);
public MultipartAttachmentStreams(BoundaryDelimitedStream delimitedStream, Collection priorParts)

        if (delimitedStream == null) {
            throw new AxisFault(Messages.getMessage("nullDelimitedStream"));
        _delimitedStream = delimitedStream;
        if (priorParts != null) {
Methods Summary
public IncomingAttachmentInputStreamgetNextStream()


        IncomingAttachmentInputStream stream;
        if (!isReadyToGetNextStream()) {
            throw new IllegalStateException(Messages
        if (_attachmentParts != null && _attachmentParts.hasNext()) {
            AttachmentPart part = (AttachmentPart);

            try {
                stream = new IncomingAttachmentInputStream(part
            } catch (IOException e) {
                throw new AxisFault(Messages
                        .getMessage("failedToGetAttachmentPartStream"), e);
            } catch (SOAPException e) {
                throw new AxisFault(Messages
                        .getMessage("failedToGetAttachmentPartStream"), e);
            stream.addHeader(HTTPConstants.HEADER_CONTENT_ID, part
            stream.addHeader(HTTPConstants.HEADER_CONTENT_LOCATION, part
            stream.addHeader(HTTPConstants.HEADER_CONTENT_TYPE, part
        } else {
            InternetHeaders headers;

            try {
                _delimitedStream = _delimitedStream.getNextStream();
                if (_delimitedStream == null) {
                    return null;
                headers = new InternetHeaders(_delimitedStream);
                String delimiter = null; // null for the first header
                String encoding = headers.getHeader(
                if (encoding != null && encoding.length() > 0) {
                    encoding = encoding.trim();
                    stream = new IncomingAttachmentInputStream(MimeUtility
                            .decode(_delimitedStream, encoding));
                } else {
                    stream = new IncomingAttachmentInputStream(_delimitedStream);
            } catch (IOException e) {
                throw new AxisFault(Messages
                        .getMessage("failedToGetDelimitedAttachmentStream"), e);
            } catch (MessagingException e) {
                throw new AxisFault(Messages
                        .getMessage("failedToGetDelimitedAttachmentStream"), e);
            Header header;
            String name;
            String value;
            Enumeration e = headers.getAllHeaders();
            while (e != null && e.hasMoreElements()) {
                header = (Header) e.nextElement();
                name = header.getName();
                value = header.getValue();
                if (HTTPConstants.HEADER_CONTENT_ID.equals(name)
                        || HTTPConstants.HEADER_CONTENT_TYPE.equals(name)
                        || HTTPConstants.HEADER_CONTENT_LOCATION.equals(name)) {
                    value = value.trim();
                    if ((HTTPConstants.HEADER_CONTENT_ID.equals(name) || HTTPConstants.HEADER_CONTENT_LOCATION
                            && (name.indexOf('>") > 0 || name.indexOf('<") > 0)) {
                        value = new StringTokenizer(value, "<>").nextToken();
                stream.addHeader(name, value);
        return stream;
public voidsetAttachmentsPriorToSoapPart(java.util.Iterator iterator)

        _attachmentParts = iterator;