I am trying to download multiple PDF files as one zip file and then update the details on a JSF page - effectively showing that I am working on these files. I have achieved this using two requests behind the scene - 1) to update the DB details and refresh the screen 2) to download the zip file.
This works fine in single workstation windows environment, but the moment I deploy this in Linux environment, behind a load balancer, I get a blank page while trying to download the zip. I have written SOP stats to print the size of the file that is being sent to the ServletOutputStream via the JSF BB and I find that the right file sizes are being printed. But somehow I keep losing the zip as well as the updated JSF. This scenario also occurs randomly in Windows, which makes me worried :(. Please provide your valuable suggestions and help me out of this issue.
Some points that you might think for consideration: I am using Richfaces 3.3.3 Final, IE 8 browser, response transmission encoding type is chunked.
==== The BB method is as given below:
String checkoutDoc = service.checkout(docId,true,contract, error);
FacesContext ctx = FacesContext.getCurrentInstance();
HttpServletResponse response = (HttpServletResponse) ctx.getExternalContext().getResponse();
File tempPdf = new File(checkoutDoc);URI tempURI = tempPdf.toURI();
URL pdfURL = tempURI.toURL();ServletOutputStream outstream =response.getOutputStream();
try
{
URLConnection urlConn = pdfURL.openConnection();
response.setContentType("application/zip");
response.setHeader("Transfer-Encoding", "chunked");
response.addHeader("Content-disposition", "attachment;filename="+docId.toString()+".zip" );
BufferedInputStream bufInStrm = new BufferedInputStream (urlConn.getInputStream());
int readBytes = 0;
int bufferSize = 8192;
byte[] buffer = new byte[bufferSize];
while ((readBytes = bufInStrm.read(buffer)) != -1){
if (readBytes == bufferSize) {
outstream.write(buffer);
}else{
outstream.write(buffer, 0, readBytes);
}
outstream.flush();
response.flushBuffer();
}
bufInStrm.close();
}finally{
outstream.close();
}
FacesContext.getCurrentInstance().responseComplete();
}
The response headers that I captured using Firefox Http monitor are given below.
(Request-Line) POST /XXX/application/pages/xxx.xhtml HTTP/1.1
Host xxx.xxx.com
User-Agent Mozilla/5.0 (Windows NT 5.1; rv:5.0.1) Gecko/20100101 Firefox/5.0.1
Accept text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language en-us,en;q=0.5
Accept-Encoding gzip, deflate
Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7
Connection keep-alive
Referer http://xxx.com/xxx/application/pages/xxx.xhtml
Cookie JSESSIONID=E27C156AA37E5984073FAB847E4958D2.XXXX; fontSize=null; pageWidth=fullWidth
Content-Type multipart/form-data; boundary=---------------------------288695814700
Content-Length 1442