【问题标题】:Java: Extract content from MTOMJava:从 MTOM 中提取内容
【发布时间】:2019-05-16 01:02:51
【问题描述】:

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

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

其中msgSOAPMessage MIME 类型,但rawContent 以null 出现,并且在获取AttachmentPart 时会崩溃

还有其他方法可以获取 MTOM 内容吗?获得边界和循环?

【问题讨论】:

    标签: java soap mtom


    【解决方案1】:

    我得到了下面的代码

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-11-01
      • 1970-01-01
      • 2021-09-24
      • 2011-08-26
      • 1970-01-01
      • 2015-03-03
      • 2011-05-25
      • 2017-06-14
      相关资源
      最近更新 更多