We are running a Grails 1.3.7 application on Tomcat 1.6 environment. A few days back some of our Pdf reports started giving us issues. The smaller reports, sized around 1MB or less, work but the bigger ones give us a 'java.net.SocketException: Broken pipe' exception.
For generating Pdf reports we use itext-2.1.0. We then use the java.net.URLConnection to enable a user to download the generated file. The code follows:
// retrives file generated using itext
def thisUrl = new File(session.getServletContext().getRealPath("/reports /${pdffilename}")).toURI().toURL();
def connection = null
def pdfInputStream = null
try {
connection = thisUrl.openConnection() //returns a java.net.UrlConnection
pdfInputStream = connection.inputStream
if (connection && pdfInputStream) {
connection.connectTimeout = 25* 60*1000;
connection.readTimeout = 25* 60*1000
response.setHeader "Content-disposition", "attachment; filename = ${pdffilename}"
response.contentType = 'pdf/pdf'
response.outputStream << pdfInputStream // This line fails for large files
} else {
redirect(action: 'failHandler')
}
} catch (e) {
log.info('Could not report, connection may have terminated')
throw e;
} finally {
response.outputStream.flush()
response.outputStream.close()
}
The 'response.outputStream << pdfInputStream' fails for larger file sizes giving us the following exception:
Thanks in advance!!
Check if you have a Load Balancer in you server. That could be causing your connections to time out