0

I'm having trouble downloading files from a SOAP response using Java. First, I show a SOAP-Ui screenshot:

SOAPUI

When I try to consume using SOAP Client's (Spring-WS, etc.), I only get the XML response. When I make a HttpRequest (cURL) I'm getting:

------=_Part_156_25962124.1632296037066
Content-Type: text/xml; charset=utf-8

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Body><RetrieveChangeIAM (rest of soap response)

------=_Part_156_25962124.1632296037066
Content-Type: application/octet-stream
Content-Location: CH00672832.xlsx
Content-ID: cid:6123a4a00036402980f50f70
(binary-data)

(multiple ---=part)

I'm trying use Apache Http Client in order to split these parts but I can't find a way to do it. Can someone help me? (My actual code download a txt file with binary data)

try (CloseableHttpClient httpClient = HttpClientBuilder.create().build()) {
            HttpPost post = new HttpPost("http://endpoint/ws");
            post.addHeader("Authorization:", "Basic myauthbase64==");
            post.addHeader("Content-Type:", "text/xml; charset=utf-8");
            post.addHeader("Accept", "text/xml, multipart/related");

            StringEntity stringEntity = new StringEntity("<?xml version=\"1.0\" ?><S:Envelope xmlns:S=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"><SOAP-ENV:Header></SOAP-ENV:Header><S:Body><Rq>rq</Rq></S:Body></S:Envelope>");
            post.setEntity(stringEntity);

            final CloseableHttpResponse response = httpClient.execute(post);
            final HttpEntity entity = response.getEntity();

            log.info("HttpEntity: {}", entity);
            log.info("CloseableHttpResponse: {}", response);

            //observe all headers by this
            final Header[] h = response.getAllHeaders();
            for (int i = 0; i < h.length; i++) {
                log.info("\tHeader:{} => {}", h[i].getName(), h[i].getValue());
            }

            File targetFile = new File("out2.txt");

            if (entity != null) {
                InputStream inputStream = entity.getContent();
                OutputStream outputStream = new FileOutputStream(targetFile);
                IOUtils.copy(inputStream, outputStream);
                outputStream.close();
            }


        } catch (Exception e) {
            log.error("ERROR...", e);
        }
Olaf Kock
  • 45,059
  • 7
  • 56
  • 86
Jose A. Matarán
  • 776
  • 3
  • 10
  • 25
  • Does this answer your question? [Receiving Multipart Response on client side (ClosableHttpResponse)](https://stackoverflow.com/questions/42533237/receiving-multipart-response-on-client-side-closablehttpresponse) – GPI Sep 22 '21 at 09:35

0 Answers0