0

How can I program in java to get the attachment? I finally got this program to send mtom, and receive a status update. Part of that soap message from the IRS coming back has attachment with the list of errors in the submitted file. I have been searching the net trying to find out how to download the attachment from the response. I get the response soap message and I then try to do this with it:

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--
Michael B.
  • 11
  • 1
  • 4

1 Answers1

0

I know this is quite late to the party, and my solution is in C# whereas your solution is in java. However, maybe I can explain how I'm doing this, and you could apply something similar to your solution, if you haven't already.

Reading/Processing the Response

  1. Read the first line of the response and assign it to a MimeBoundary property. This first line is the UUID as well as the MimeBoundary of the response object.
  2. Concatenate the MimeBoundary with the characters for a control feed/line break (\r\n), and the rest of the response object by using the ReadToEnd() method. Read this concatenated string into a string property, ResponseString.
  3. Create a variable (match) to store the return of the Regex.Match() method and use a pattern to find the ACABulkRequestTransmitterStatusDetailResponse node within the ResponseString.
  4. Call a Deserializer<T> method which will use the XmlSerializer to convert the match variable into a ACABulkRequestTransmitterStatusDetailResponseType object. Assign this to a property StatusDetailResponse.
  5. Use the StatusDetailResponse property to find the value of the TransmissionStatus. If the TransmissionStatus is equal to "AcceptedwithErrors", "PartiallyAccepted" or "Rejected", an Error Attachment will be present in the Response.

Reading/Processing the Attachment

  1. Find the index of the Declaration XML (DeclarationIndex) within the ResponseString. If the index is -1, no attachment is found. According to the IRS, this can happen, when this happens, update the ContactPersonLastName field and re-send the Transmission as a Replacement. If it is greater than -1, there should be an attachment.
  2. Find the entire string of the attachment by retrieving a Substring of the ResponseString starting with the DeclarationIndex and ending with the LastIndexOf the MimeBoundry minus the DeclarationIndex. Assign this string to an AttachmentXML variable.
  3. I created a class for the SubmissionDetailResponse which was created by taking a sample of the XML output for the Error Attachment and creating a class out of it in .NET. Deserialize the AttachmentXML into this SubmissionDetailResponse class.
  4. Process the data from the SubmissionDetailResponse into the database for error review.
Russ
  • 678
  • 8
  • 26