I am trying to download xlsx file generated using Apache XSSF from RESTEasy based web service.
I can download the file but when double clicked to open, it says file can not be openend:
Below is the source code:
Web service controller:
@GET
@Path(/download)
@Produces(MediaType.APPLICATION_OCTET_STREAM)
public Response downloadFile() {
ByteArrayOutputStream baos = myService.processGbiValidationExceptions();
ResponseBuilder response = Response.ok((Object) baos.toByteArray());
response.header("Content-Disposition", "attachment;filename=My_File.xlsx");
return response.build();
}
Service:
public ByteArrayOutputStream processGbiValidationExceptions() {
XSSFWorkbook workbook = new XSSFWorkbook();
// code to write to workbook
// Create stream
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
workbook.write(baos);
} catch (IOException e) {
LOGGER.error("Error occurred while writing workbook to stream", e);
throw new IptException(e);
}
return baos;
}
Any clues what I am doing incorrect over here? Thanks
P.S.: I am on Mac!