Open jojopad opened 11 years ago
I second this. I'm using RESTBuilder to communicate with JSON-based REST services, but it's failing when I try to download binary files.
Would be great for us.
Need this just now
Here's a workaround on how to do this. I also wrote up more detailed description on my blog:
def void download(String url, OutputStream outputStream) {
logger.info("url="+url)
RequestCallback requestCallback = new RequestCallback() {
void doWithRequest(ClientHttpRequest clientRequest) throws IOException {
clientRequest.headers.add('accept', 'application/octet-stream')
}
}
ResponseExtractor responseExtractor = new ResponseExtractor() {
Object extractData(ClientHttpResponse clientResponse) throws IOException {
System.out.println('Headers: '+clientResponse.headers)
outputStream << clientResponse.body
}
}
RestBuilder rest = new RestBuilder()
RestTemplate restTemplate = rest.getRestTemplate()
restTemplate.execute(url, HttpMethod.GET, requestCallback, responseExtractor)
}
It would be great to provide support for downloading a file via an InputStream when using the RestBuilder class.