This is a Spring (boot, MVC, REST) question.
This should be simple, but hours of searching hasn't revealed a good answer.
Basically I want to post a request to a server from within a service and return some object to the controller which would then, after filtering the headers, copy the bytes from the response of the post request to the response from the controller without making a copy on the file system or in memory. This means that none of the solutions that create a file or a byte array are appropriate.
The controller should be
@RequestMapping(value = "/files/{file_name}", method = RequestMethod.GET)
@ResponseBody
public XXXX getFile(@PathVariable("file_name") String fileName) throws Exception {
return service.getFile(file_name);
}
and the service should POST a request body to some URL, filter the response headers, and return something that can be copied to the response.
It is important that it is a stream-to-stream copy - the whole response should not be stored in memory nor need to be stored in the file system.
I have looked at the API documentation for RestTemplate and RequestEntity and the like and countless stack overflow answers, but nothing is clear (and restricting the search to this query isn't working - all sorts of things about saving to files or responding with files show up in any search).