tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bruce W. Perry" <brucewpe...@attbi.com>
Subject Connection reset by peer: socket write error
Date Wed, 07 May 2003 14:02:49 GMT
hello list,

I have a servlet that sends files such as PDFs and Word files to clients as
binary data (rather than a typical straightforward download of the file).
The code below works fine in displaying the "Save As" window and sending
along the file, but consistently throws "Connection reset by peer" type
exceptions...only when using Internet Explorer. These exceptions show up in
the Tomcat logs but do not disrupt the application.

Searching the archives I found many similar comments, but I wondered if
anyone had found a solution yet. I've already tried the usual Cache-Control
response headers, just in case IE was resetting the connection when it found
the same document in its browser cache. The exceptions have occurred with
Tomcat 4.1.12 and 4.1.24 (as well as Weblogic 7), but only with the IE
browser. If it turns out to be "harmless" is there any way to suppress the
continuous logging of the exception?

Thanks very much,

Bruce


////////////////////////////////////////////////
relevant part of code
////////////////////////////////////////////////
      ServletOutputStream stream = null;
      BufferedInputStream buf = null;

     try{

     stream = response.getOutputStream();
     File pdf = new File(pdfDir + "/" + fileName);

      //set response headers
      response.setContentType("application/pdf");
   //disable caching
   response.setHeader("Cache-Control", "no-store, no-cache,
must-revalidate");
   response.setHeader("Expires","Wed, 2 Jan 2002 12:00:00 GMT");
   response.setHeader("Cache-Control", "post-check=0, pre-check=0");
   response.setHeader("Pragma", "no-cache");

      response.addHeader("Content-Disposition","attachment;
filename="+fileName );
      response.setContentLength( (int) pdf.length() );

     FileInputStream input = new FileInputStream(pdf);
     buf = new BufferedInputStream(input);
    int readBytes = 0;

     //read from the file; write to the ServletOutputStream
     while((readBytes = buf.read()) != -1)
        stream.write(readBytes);

    stream.close();
    buf.close();

     } catch (IOException ioe){

        throw new ServletException(ioe.getMessage());

     }

////////////////////////////////////////////////
about first half of stack trace
////////////////////////////////////////////////
Servlet.service() for servlet sendpdf threw exception
javax.servlet.ServletException: Connection reset by peer: socket write error
 at com.jspservletcookbook.SendPdf.doGet(Unknown Source)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
 at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Application
FilterChain.java:247)
 at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterCh
ain.java:193)
 at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.ja
va:256)
 at
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invok
eNext(StandardPipeline.java:643)
 at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
 at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
 at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.ja
va:191)
 at
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invok
eNext(StandardPipeline.java:643)
 at
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase
.java:494)
 at
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invok
eNext(StandardPipeline.java:641)
 at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
 at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
 at
org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2415)
 at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180
)
 at
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invok
eNext(StandardPipeline.java:643)
 at
org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.
java:171)


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Mime
View raw message