I've got a threading issue that I can't work out.

I've got a servlet that gets called from my web application.  It
takes an object model that's stored in the session, asks the object
model to cough up a representation of itself in XML-FO, then
generates a PDF representation using FOP.  It then writes that to the
response output stream.

The servlet is mapped to the name "report.pdf:, because using that
extension seems to be the only way I can get IE to open the thing
inline, even tho' I call resp.setContentType("application/pdf").  (IE
reports the content-type as text/html, although other browser seem to
get it fine).  Other browsers work fine.  That's not the item,
though. 

The item is that my servlet gets called four times in succession by
IE.  Eventually, (on the fourth go), the servlet throws an IO
exception ("Broken Pipe") on the out.write(byte[]) call that I use to
write the PDF file to the Servlet's outputstream.  After that, the
file displays fine in IE.

Here's the code after the PDF is generated and put into the byte[]
data:

outs = resp.getOutputStream();
resp.setContentType("application/pdf");
resp.setContentLength(data.length);
resp.setDateHeader("Expires", 0L);
resp.setHeader("Cache-Control", "no-cache");
outs.write(data);
outs.flush();
resp.flushBuffer();

The outputstream is closed in a finally block.

I've also tried wrapping the outputstream in a bufferedoutput stream.
I've also tried a call to 

resp.setBufferSize(data.length);

neither of which had any effect: IE calls the servlet four times; the
fourth time the call to outs.write(data) fails with an IO exception,
and the page displays successfully in the IE window.

This doesn't happen with other browsers: Netscape and Opera both call
the servlet only once. I could live with it (big hack: just catch the
fourth-call IO exception), except generation of the PDF is a 4-5
second operation.

The data I'm sending is about 200k in length.

Any ideas?
Rod  

Reply via email to