Java: 从 MTOM 中提取内容

Java: Extract content from MTOM

我正在尝试使用以下代码提取 MTOM 的内容

Iterator i = msg.getAttachments();
while (i.hasNext())
{
  AttachmentPart att = (AttachmentPart)i.next();
  Object obj = att.getContent();
}

其中 msgSOAPMessage MIME 类型,但 rawContent 是 null 并且会在获取 AttachmentPart

时崩溃

有没有其他方式获取MTOM内容?获得边界并循环通过?

我得到了下面的代码

 MimeMultipart mp = new MimeMultipart(new ByteArrayDataSource(InputStream, "multipart/related"));
 int count = mp.getCount();
 for (int i = 0; i < count; i++) {
     BodyPart bodyPart = mp.getBodyPart(i);
     String content = new String(read(bodyPart));

     String partContentType =  bodyPart.getContentType();


  if(partContentType.toLowerCase().contains(SOAPConstants.SOAP_1_2_CONTENT_TYPE)) {

        //process SOAP 1.2
     }

    if(partContentType.toLowerCase().contains(SOAPConstants.SOAP_1_1_CONTENT_TYPE)) {

        //process SOAP 1.1
     }

     if(partContentType.toLowerCase().contains("application/octet-stream")) {

        // process binary part
     }
 }