我怎样才能用java编程来获取附件?我终于让这个程序发送mtom,并接收状态更新。来自IRS返回soap消息的一部分带有附件,其中包含提交的文件中的错误列表。我一直在网上搜索,想知道如何从回复中下载附件。我得到了响应soap消息,然后尝试对其执行以下操作:
private void logToSystemOut(SOAPMessageContext smc) {
Boolean outboundProperty = (Boolean)
smc.get (MessageContext.MESSAGE_OUTBOUND_PROPERTY);
if (outboundProperty.booleanValue()) {
out.println("\nOutbound message:");
} else {
out.println("\nInbound message:");
}
SOAPMessage message = smc.getMessage();
try {ByteArrayOutputStream bout = new ByteArrayOutputStream();
message.writeTo(bout);
String outfpn =p.getPath()+File.separator+"ErrorReport_"+getRecieptID()+icec+".xml";
icec++;
FileOutputStream fileOut = new FileOutputStream(outfpn);
message.writeTo(fileOut);
fileOut.close();
out.println(""); // just to add a newline
} catch (Exception e) {
out.println("Exception in handler: " + e);
}
}
Soap message response:
------=_Part_3_10783799.1471300737900
Content-Type: text/xml; charset=utf-8
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<ns5:ACABusinessHeader xmlns="urn:us:gov:treasury:irs:common" xmlns:ns2="urn:us:gov:treasury:irs:ext:aca:air:7.0" xmlns:ns3="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity- utility-1.0.xsd" xmlns:ns4="http://www.w3.org/2000/09/xmldsig#" xmlns:ns5="urn:us:gov:treasury:irs:msg:irstransmitterstatusrequest" xmlns:ns6="urn:us:gov:treasury:irs:msg:acasecurityheader" xmlns:ns7="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity- secext-1.0.xsd" ns3:Id="id-962DC498C98A4E58A8DF4AA1861A4E81">
<ns2:UniqueTransmissionId>e6b9f6c9-01df-4003-993a- 47b15fc2c236:SYS12:::T</ns2:UniqueTransmissionId>
<Timestamp>2016-08-15T22:37:50Z</Timestamp>
</ns5:ACABusinessHeader>
</soap:Header>
<soap:Body>
<ns5:ACABulkRequestTransmitterStatusDetailResponse xmlns="urn:us:gov:treasury:irs:common" xmlns:ns2="urn:us:gov:treasury:irs:ext:aca:air:7.0" xmlns:ns3="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity- utility-1.0.xsd" xmlns:ns4="http://www.w3.org/2000/09/xmldsig#" xmlns:ns5="urn:us:gov:treasury:irs:msg:irstransmitterstatusrequest" xmlns:ns6="urn:us:gov:treasury:irs:msg:acasecurityheader" xmlns:ns7="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity- secext-1.0.xsd">
<ns2:ACABulkRequestTransmitterResponse>
<ns2:TransmissionStatusCd>Rejected</ns2:TransmissionStatusCd>
<ReceiptId>1095B-16-0</ReceiptId>
</ns2:ACABulkRequestTransmitterResponse>
<ns2:ACABulkReqTrnsmtStsRespGrpDtl>
<BulkExchangeFile>
<xop:Include xmlns:xop="http://www.w3.org/2004/08/xop/include" href="cid:5aadb03f-8cb4-44bb- 8657-3f63b545904d-374@urn%3Aus%3Agov%3Atreasury%3Airs%3Acommon"/>
</BulkExchangeFile>
</ns2:ACABulkReqTrnsmtStsRespGrpDtl>
</ns5:ACABulkRequestTransmitterStatusDetailResponse>
</soap:Body>
</soap:Envelope>
------=_Part_3_10783799.1471300737900
Content-Type: application/xml
Content-Disposition: attachment;name="respMTOM"
Content-ID: <5aadb03f-8cb4-44bb-8657-3f63b545904d- 374@urn:us:gov:treasury:irs:common>
Content-Transfer-Encoding: binary
------=_Part_3_10783799.1471300737900--发布于 2016-11-24 00:51:14
我知道这来得太晚了,我的解决方案是C#,而你的解决方案是java。然而,也许我可以解释我是如何做到这一点的,如果你还没有这样做的话,你可以在你的解决方案中应用一些类似的东西。
读取/处理响应的
UUID和MimeBoundary,MimeBoundary包含用于控制换行/换行符(\r\n)的字符,其余的响应对象使用ReadToEnd()方法。将这个连接在一起的字符串读入一个字符串属性,ResponseString.match)以存储Regex.Match()方法的返回,并使用一个模式在ResponseString.Deserializer<T>方法中查找ACABulkRequestTransmitterStatusDetailResponse节点,该方法将使用XmlSerializer将match变量转换为一个ACABulkRequestTransmitterStatusDetailResponseType对象。将其分配给一个属性StatusDetailResponse.StatusDetailResponse属性,以查找TransmissionStatus的值。如果TransmissionStatus等于"AcceptedwithErrors“、"PartiallyAccepted”或"Rejected",则响应中将出现错误附件。读取/处理附件
ResponseString中查找声明XML (DeclarationIndex)的索引。如果索引为-1,则未找到任何附件。根据美国国税局的说法,这可能会发生,当这种情况发生时,更新ContactPersonLastName字段并将传输作为Replacement重新发送。如果大于-1,则应该有一个attachment.ResponseString的Substring,从DeclarationIndex开始,以LastIndexOf MimeBoundry减去DeclarationIndex结束附件的整个字符串。SubmissionDetailResponse创建了一个类,它是通过对Error Attachment的XML输出进行采样并在.NET中创建一个类来创建的。Deserialize the AttachmentXML for this SubmissionDetailResponse Deserialize the data from the SubmissionDetailResponse for the database for error review. (将SubmissionDetailResponse中的数据写入数据库以进行错误检查)
https://stackoverflow.com/questions/38964322
复制相似问题