0

我们在 Tomcat 1.6 环境中运行 Grails 1.3.7 应用程序。几天前,我们的一些 Pdf 报告开始给我们带来问题。较小的报告(大小约为 1MB 或更小)可以正常工作,但较大的报告会给我们一个“java.net.SocketException: Broken pipe”异常。

为了生成 Pdf 报告,我们使用 itext-2.1.0。然后我们使用 java.net.URLConnection 使用户能够下载生成的文件。代码如下:

// 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()
  }

'response.outputStream << pdfInputStream' 对于较大的文件大小失败,给我们以下异常:

输出流异常

提前致谢!!

4

1 回答 1

2

检查您的服务器中是否有负载均衡器。这可能会导致您的连接超时

于 2012-11-29T14:20:27.177 回答