0

Tomcat1.6環境でGrails1.3.7アプリケーションを実行しています。数日前、私たちのPDFレポートのいくつかが私たちに問題を与え始めました。サイズが約1MB以下の小さいレポートは機能しますが、大きいレポートでは「java.net.SocketException:パイプの破損」例外が発生します。

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 に答える