0

I am downloading a large file from a third party URL using Spring RestTemplate . Im using the below method to download the file so as not to load the entirety into memory.


// Optional Accept header
RequestCallback requestCallback = request -> request.getHeaders()
        .setAccept(Arrays.asList(MediaType.APPLICATION_OCTET_STREAM, MediaType.ALL));

// Streams the response instead of loading it all in memory
ResponseExtractor<Void> responseExtractor = response -> {
    // Here I write the response to a file but do what you like
    Path path = Paths.get("some/path");
    Files.copy(response.getBody(), path);
    return null;
};
restTemplate.execute(URI.create("www.something.com"), HttpMethod.GET, requestCallback, responseExtractor

This works fine, however we intermittently get a Premature end of Content-Length delimited message body

I read from another stack overflow post that this is a server side issue. How can I make sure it's a server side issue? How can I know if it's a memory issue on the third party side or incorrect content length in the response header and such? I need to make sure before I approach the third party for a resolution.

Ananya Antony
  • 338
  • 3
  • 15

1 Answers1

0

Depending how easy it is to trigger the error, you can use a tool like curl to call the URL (just for testing, outside your application). If you still see the failure, then it is definitely not because of the client, because those well-known third-party tools are well tested and do not have such bugs.

jhyot
  • 3,733
  • 1
  • 27
  • 44