IRS正在检索错误响应文件



如何在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--

我知道这已经太晚了,我的解决方案是在C#中,而你的解决方案是在java中。但是,也许我可以解释我是如何做到这一点的,如果你还没有,你可以应用一些类似于你的解决方案。

读取/处理响应

    读取响应的第一行,并将其分配给MimeBoundary属性。第一行是响应对象的UUIDMimeBoundary
  1. MimeBoundary与控制换行/换行(rn)的字符连接起来,并使用ReadToEnd()方法将响应对象的其余部分连接起来。将此连接的字符串读入字符串属性ResponseString
  2. 创建一个变量(match)来存储Regex.Match()方法的返回,并使用模式在ResponseString中查找ACABulkRequestTransmitterStatusDetailResponse节点。
  3. 调用Deserializer<T>方法,使用XmlSerializermatch变量转换为ACABulkRequestTransmitterStatusDetailResponseType对象。将其分配给属性StatusDetailResponse
  4. 使用StatusDetailResponse属性查找TransmissionStatus的值。如果TransmissionStatus等于"AcceptedwithErrors","PartiallyAccepted"或"Rejected",则在响应中会出现一个错误附件。

读取/处理附件

  1. ResponseString中查找声明XML (DeclarationIndex)的索引。如果索引为-1,则没有找到附件。根据IRS的说法,这种情况可能发生,当这种情况发生时,更新ContactPersonLastName字段并作为Replacement重新发送传输。如果它大于-1,则应该有附件。
  2. 通过检索ResponseStringSubstring(从DeclarationIndex开始,以LastIndexOf结束)(MimeBoundry减去DeclarationIndex)来查找附件的整个字符串。将此字符串赋值给AttachmentXML变量。
  3. 我为SubmissionDetailResponse创建了一个类,这是通过获取Error Attachment的XML输出样本并在.NET中创建一个类来创建的。DeserializeAttachmentXML放入SubmissionDetailResponse类。
  4. SubmissionDetailResponse的数据处理到数据库中进行错误检查

相关内容

  • 没有找到相关文章

最新更新