After my servlet is run, JBoss returns an inconsistent and usually bad http response mime type to the browser. Mostly it becomes "application/octet-stream" instead of "application/pdf" which I explicitly set. But not always... This is the output part:
ServletOutputStream out = res.getOutputStream();
res.setContentType("application/pdf");
res.setContentLength((int)outfile.length());
bis = new BufferedInputStream(new FileInputStream(outfile));
bos = new BufferedOutputStream(out);
byte[] buff = new byte[2048];
int bytesRead;
while(-1 != (bytesRead = bis.read(buff, 0, buff.length)))
{
bos.write(buff, 0, bytesRead);
}
bos.flush();
bos.close();