views:

314

answers:

2

I have the following code below in my Servlet, but when IE hits the page, it returns a blank html page. If I use the response.getOutputStream() directly in the StreamResult constructor, the page loads fine. What am I missing?

response is an instance of HttpServletResponse and xsl is an instance of Transformer from XSLTC TransformerFactory

response.setHeader("Content-Encoding", "gzip");
GZIPOutputStream gzipOut = new GZIPOutputStream(response.getOutputStream());
Result outputResult = new StreamResult(gzipOut);

xsl.transform(xmlSource, outputResult);
+1  A: 

I'm going to guess that you aren't closing the gzipOut stream and therefore it isn't sending the "footer" information.

jsight
Would closing the underlying response like: resp.getOutputStream().close(); work?
Adam
I honestly don't know. However, another technique may be to call gzipOut.finish() as it is able to print the final CRCs without closing the underlying stream. I'm not sure if/how GzipOutputStream would detect you calling close on the underlying stream, so I suspect that would actually make it worse.
jsight
A: 

Turns out there is a .finish() on this stream that is required. It is similar to flush, but since it is a different call, the Transformer does not know to use it.

Adam