You need to use a StreamingResponse as your response entity. In my projects I've made a simple method to return on of these from a byte array. You just have to ready the file into a byte are first, then call this:
private StreamingOutput getOut(final byte[] excelBytes) {
return new StreamingOutput() {
@Override
public void write(OutputStream out) throws IOException, WebApplicationException {
out.write(excelBytes);
}
};
}
Then in your main method you would something like:
return Response.ok(getOut(byteArray)).build(); //add content-disp stuff here too if wanted