Search code examples
javasoapsaajmm7

How can I parse attachment part, which type is multipart/related in SAAJ (SOAP Messages with Attachments)?


I receive an SAAJ message with SOAP with Attachments API for Java, that contain multipart/related attachment. One part of this attachment is multipart/related too. That is I have AttachmentPart with multipart/related content. Is there a standard way to parse it?

In particular, I need to parse MMS(MM7)-message

enter image description here


Solution

  • Solved

    All I need is cast AttachmentPart.getContent()'s result to MimeMultipart

    MimeMultipart mp = (MimeMultipart) attachment.getContent();
    for (int i = 0; i < mp.getCount(); i++) {
        Part bp = mp.getBodyPart(i);
        if (bp.isMimeType("text/*")) {
            String text = (String)bp.getContent();
            //process text
        } else if (bp.isMimeType("image/*")) {
            InputStream is = bp.getInputStream();
            //process image 
        }
    }