user3274923
user3274923

Reputation: 121

ClientAbortException: java.net.SocketException: Connection reset by peer: socket write error

Getting this error while reading pdf any help . I using a link to read the PDF file

ByteArrayOutputStream baos = new ByteArrayOutputStream(); 
PdfReader reader = null; 
PdfImportedPage page = null; 
try { PdfCopy writer = new PdfCopy(document, baos); 
document.open(); 
for (String pdfFile : pdfFiles) { 
  reader = new PdfReader(pdfFile); 
  for (int i = 1; i <= reader.getNumberOfPages(); i++) { 
     page = writer.getImportedPage(reader, i); 
     writer.addPage(page); 
  } 
  reader.close(); } 


  document.close(); 
} catch (Exception e) { System.out.println(e); 
} finally { if (document != null && document.isOpen()) { document.close(); } } 
response.setContentType("application/octet-stream"); 
response.setHeader("Content-disposition", "attachment; filename=Text.pdf"); 
response.setContentLength(baos.size()); 
OutputStream outStream = response.getOutputStream(); 
baos.writeTo(outStream); 

Upvotes: 0

Views: 5240

Answers (1)

cruftex
cruftex

Reputation: 5723

ClientAbortException is a tomcat exception that happens when the application is sending to the browser but the browser terminates or has terminated the request. This means, your code runs until the very final line and then generates the exception. Maybe the generation takes to long and the browser connection is timing out?

Test the pdf generation and the sending to the browser isolated. If the problem persistest, please also post the surrounding servlet code.

Upvotes: 2

Related Questions