Java:从MTOM中提取内容

时间:2018-12-14 18:32:31

标签: java soap mtom

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

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

其中msgSOAPMessage的MIME类型,但rawContent是null的名称,在获取AttachmentPart时会崩溃

还有其他获取MTOM内容的方法吗?得到界限并循环通过?

1 个答案:

答案 0 :(得分:0)

我结束了下面的代码

 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
     }
 }