1
這裏服務於請求的結果的PDF是從一個服務器獲取PDF和在servlet的服務於它作爲響應的代碼:在空響應
GAELogger.logInfo(LOG, "download request. url: " + downloadURLStr);
HTTPResponse fetchResponse = URLFetchServiceFactory.getURLFetchService().fetch(new URL(downloadURLStr));
byte[] pdfContent = fetchResponse.getContent();
Integer totalLength = pdfContent.length;
String fileName = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss").format(new Date());
GAELogger.logInfo(LOG, "writing. total: " + totalLength.toString());
response.reset();
response.setStatus(HttpServletResponse.SC_OK);
response.setContentType("application/pdf");
response.addHeader("Content-Disposition", "attachment; filename=\"" + fileName + ".pdf\"");
response.setHeader("Content-Length", totalLength.toString());
ServletOutputStream outputStream = response.getOutputStream();
outputStream.write(pdfContent);
outputStream.flush();
outputStream.close();
GAELogger.logInfo(LOG, "done.");
這裏是日誌請求的服務PDF:
download request. url: http://someurl/test.pdf
writing. total: 43497
logInfo: done.
,有時響應是空的和鉻給出這樣的錯誤:
雖然有時它確實服務於請求並下載了pdf。我已經嘗試了多種方案,例如:
String downloadURLStr = outputFiles.get(0).getUrl();
URL downloadURL = new URL(downloadURLStr);
URLConnection connection = downloadURL.openConnection();
InputStream inputStream = downloadURL.openStream();
OutputStream outputStream = response.getOutputStream();
Integer totalLength = connection.getContentLength();
response.setContentType("application/pdf");
response.addHeader("Content-Disposition", "inline; filename=\"" + id + ".pdf\"");
response.setHeader("Content-Length", totalLength.toString());
IOUtils.copy(inputStream, outputStream);
IOUtils.closeQuietly(inputStream);
IOUtils.closeQuietly(outputStream);
這也失敗了。任何想法爲什麼?
問題是,當開始出現問題就一直失敗。並開始服務時,它做它一貫:(和日誌告訴它所做的一切,所以我不知道WCH限制將是導致問題的2013年7月5日03:42:01.423 - 2013年7月5日03:42: 05.979是請求時間和文件大小是4.5KB。服務器是完全空閒的,所以我不明白我可能遇到的其他限制。 – Srinivas