title: Capturing Attachment from SOAP response in JAVA
body: <p>One of my requirement is to send SOAP request, and receive response from Oracle UCM Cloud. I am using Java transformation to do the same. In one of the response, we receive a zip file as attachment, I am not able to capture and download the attachment.</p>
  
  <p>Is there anyway to download the attachment and save to server. The code below captures the whole response into a file, but i want to capture the attachment only.</p>
  
  <p>In Java, I send the below payload</p>
  
  <pre><code>payload = "&lt;soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:typ=\"http://xmlns.oracle.com/apps/financials/commonModules/shared/model/erpIntegrationService/types/\"&gt;"+
              "&lt;soapenv:Header/&gt;\n"+
                  "&lt;soapenv:Body&gt;\n"+
                      "&lt;typ:downloadESSJobExecutionDetails&gt;\n"+
                          "&lt;typ:requestId&gt;"+i_jobid+"&lt;/typ:requestId&gt;\n"+
                      "&lt;typ:fileType&gt;log&lt;/typ:fileType&gt;\n"+
                  "&lt;/typ:downloadESSJobExecutionDetails&gt;\n"+
              "&lt;/soapenv:Body&gt;\n"+
          "&lt;/soapenv:Envelope&gt;";
          System.out.println(payload);
          returnstring=httpPost("https://&lt;&lt;localhost&gt;&gt;.oraclecloud.com/fscmService/ErpIntegrationService?invoke=",payload, "&lt;&lt;credentials&gt;&gt;");
  </code></pre>
  
  <p>Then i capture the response as :</p>
  
  <pre><code>InputStream in = conn.getInputStream();
  InputStreamReader iReader = new InputStreamReader( in );
  BufferedReader bReader = new BufferedReader(iReader);
  
  String line;
  String response = "";
  String fresponse = "";
  
  int lcount = 0;
  while ((line = bReader.readLine()) != null) 
  {
   lcount++;
   response += line;
  }
  
  </code></pre>
  
  <p>Then I cut out the xml response part and use only the attachment portion to perform the below tasks
  Convert it into bytes and then try and save as zip</p>
  
  <pre><code>byte buf[] = response.getBytes();
  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  ZipOutputStream zos = new ZipOutputStream(baos);
  ZipEntry entry = new ZipEntry("abclog.zip");
  entry.setSize(buf.length);
  zos.putNextEntry(entry);
  zos.write(buf);
  zos.closeEntry();
  zos.close();
  java.io.FileOutputStream out_zip_file = new java.io.FileOutputStream("abclogfin.zip");
  out_zip_file.write(baos.toByteArray());
  </code></pre>
  
  <p>The raw response is:</p>
  
  <pre><code>------=_Part_2737_547225473.1557335354007Content-Type: application/xop+xml;charset=UTF-8;
  type="text/xml"Content-Transfer-Encoding: 8bitContent-ID: &lt;3196f51c-0526-4921-bde2-d8f8453a255a&gt;
  &lt;?xml version="1.0" encoding="UTF-8" ?&gt;&lt;env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsa="http://www.w3.org/2005/08/addressing"&gt;
  &lt;env:Header&gt;&lt;wsa:Action&gt;http://xmlns.oracle.com/apps/financials/commonModules/shared/model/erpIntegrationService//
  ErpIntegrationService/downloadESSJobExecutionDetailsResponse&lt;/wsa:Action&gt;&lt;wsa:MessageID&gt;urn:uuid:db614b6f-cee2-4218-9921-177fa5b71c32&lt;/wsa:MessageID&gt;
  &lt;/env:Header&gt;&lt;env:Body&gt;&lt;ns0:downloadESSJobExecutionDetailsResponse xmlns:ns0="http://xmlns.oracle.com/apps/financials/commonModules/shared/model/
  erpIntegrationService/types/"&gt;&lt;ns2:result xmlns:ns2="http://xmlns.oracle.com/apps/financials/commonModules/shared/model/erpIntegrationService/types/" 
  xmlns:ns1="http://xmlns.oracle.com/adf/svc/types/" xmlns:ns0="http://xmlns.oracle.com/apps/financials/commonModules/shared/model/erpIntegrationService/" 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns0:DocumentDetails"&gt;&lt;ns0:Content&gt;&lt;xop:Include xmlns:xop="http://www.w3.org/2004/08/xop/include" 
  href="cid:8a49811c-492b-4a51-aab2-16abdaf21ad3"/&gt;&lt;/ns0:Content&gt;&lt;ns0:FileName xsi:nil="true"/&gt;&lt;ns0:ContentType&gt;zip&lt;/ns0:ContentType&gt;&lt;ns0:DocumentTitle&gt;ESS_L_13077
  &lt;/ns0:DocumentTitle&gt;&lt;ns0:DocumentAuthor&gt;*****&lt;/ns0:DocumentAuthor&gt;&lt;ns0:DocumentSecurityGroup&gt;Attachments&lt;/ns0:DocumentSecurityGroup&gt;&lt;ns0:DocumentAccount xsi:nil="true"/&gt;
  &lt;ns0:DocumentName&gt;13077.zip&lt;/ns0:DocumentName&gt;&lt;ns0:DocumentId xsi:nil="true"/&gt;&lt;/ns2:result&gt;&lt;/ns0:downloadESSJobExecutionDetailsResponse&gt;&lt;/env:Body&gt;&lt;/env:Envelope&gt;
  ------=_Part_2737_547225473.1557335354007Content-Transfer-Encoding: binaryContent-ID: &lt;8a49811c-492b-4a51-aab2-16abdaf21ad3&gt;PK
  </code></pre>
  
  <p>As per my understanding, the values after </p>
  
  <pre><code> &lt;8a49811c-492b-4a51-aab2-16abdaf21ad3&gt;PK
  </code></pre>
  
  <p>is the attachment, But I am not able to download it. After doing the above process, i get a zip file of 5KB but no contents inside the file.</p>