The net.sf.jasperreports.engine.export.JRHtmlExporter class assumes that it has to call xxx.flush() on any of the streams/writers that it is working with.
Test Case:
We are generating a net.sf.jasperreports.engine.JasperPrint instance in our Spring Web Controller and passing that instance through the javax.servlet.http.HttpServletRequest to our JSP. In our JSP we use a Java Tag to generate the net.sf.jasperreports.engine.export.JRHtmlExporter and then pass the JspWriter to the JRHtmlExporter as the JRExporterParameter.OUTPUT_WRITER.
When JRHtmlExporter calls .flush on the JspWriter the following exception occurs:
<parent exception removed...>
Caused by: java.io.IOException: Illegal to flush within a custom tag
at javax.servlet.jsp.tagext.BodyContent.flush(BodyContent.java:80)
at java.io.FilterWriter.flush(Unknown Source)
at net.sf.jasperreports.engine.export.JRHtmlExporter.exportReportToWriter(JRHtmlExporter.java:710)
at net.sf.jasperreports.engine.export.JRHtmlExporter.exportReport(JRHtmlExporter.java:389)
... 78 more
It might be preferable if the Exporter classes had a settable parameter for controlling the flush behavior.
There is a nice work around that Lucian provided on the JasperForge.org Forum.
We extended the java.io.FilterWriter class on overrode the .flush() method with no behavior:
private class ExtendedFilterWriter extends FilterWriter {
public ExtendedFilterWriter(Writer writer) {
super(writer);
}
public void flush() {
}
}
We then wrapped the JspWriter class with the ExtendedFilterWriter before handing the Writer to the JRHtmlExporter.
Please see the following JasperForge.org Forum post for more information:
An export parameter (JRHtmlExporterParameter.FLUSH_OUTPUT) and a property (net.sf.jasperreports.export.html.flush.output) have been introduced to control whether the HTML exporter flushes the output after export. By default the output is flushed (for backward compatibility).
"Due to the fact that JasperServer is tightly coupled with Tomcat and works great out of the box with the installer, we are leaning towards that set up."