如何在 java 中编程以获取附件?我终于得到了这个程序来发送 mtom,并接收状态更新。来自美国国税局的那条肥皂消息的一部分带有提交文件中错误列表的附件。我一直在网上搜索,试图找出如何从响应中下载附件。我收到响应肥皂消息,然后尝试使用它执行此操作:
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--