I have a REST Java service which returns a file as a stream. It's similar to the output approaches described here:
Input and Output binary streams using JERSEY?
I also use StreamingOuput
as described above.
I now wonder now how to call this method on the client side. I use Swagger but I am not very good with it, and I have no idea how to call my method.
Currently in the web service I have defined
@ApiOperation(value = "Export file from the database", response = File.class)
but I doubt this File.class
is a good idea here.
Do I need to modify this response type? What is a good way of calling my service?
When I call my service from the Swagger UI interface I see these response headers.
{
"date": "Sun, 27 Aug 2017 11:14:20 GMT",
"content-disposition": "attachment; filename=\"DealerTexts.xlsx\"",
"x-powered-by": "Servlet/3.1 JSP/2.3 ( Java/Oracle Corporation/1.8)",
"transfer-encoding": "chunked",
"server": "",
"content-type": "application/octet-stream"
}
In the response body it gives me a link which I can click and download the file generated by the web service. So my question is just how I can call this same thing from Java code on the client side.