ClientAbortException:java.io.IOException解决方案

时间:2024-02-20 17:19:38

org.apache.catalina.connector 
Class ClientAbortException

java.lang.Object
  
extended by
java.lang.Throwable
      
extended by
java.lang.Exception
          
extended by
java.io.IOException
              
extended by
org.apache.catalina.connector.ClientAbortException
All Implemented Interfaces:
java.io.Serializable
 
 
ERROR [http-8080-5]: (ExportPdfController.java:196) - 
ClientAbortException java.io.IOException
at org.apache.catalina.connector.OutputBuffer.realWriteBytes(OutputBuffer.java:369)
at org.apache.tomcat.util.buf.ByteChunk.append(ByteChunk.java:368)
at org.apache.catalina.connector.OutputBuffer.writeBytes(OutputBuffer.java:392)
at org.apache.catalina.connector.OutputBuffer.write(OutputBuffer.java:381)
at org.apache.catalina.connector.CoyoteOutputStream.write(CoyoteOutputStream.java:89)
at java.io.ByteArrayOutputStream.writeTo(ByteArrayOutputStream.java:109)
at com.shihuan.web.controller.ExportPdfController.writefile(ExportPdfController.java:189)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:176)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:426)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:414)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:790)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:549)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:879)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:600)
at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1703)
at java.lang.Thread.run(Thread.java:619)
WARN [http-8080-4]: (MyInterceptor.java:60) - 调用方法:com.shihuan.web.controller.ExportPdfController.writefile();  花费时间:153 ms.返回网页:原网页
Caused byjava.io.IOException
at org.apache.coyote.http11.InternalAprOutputBuffer.flushBuffer(InternalAprOutputBuffer.java:712)
at org.apache.coyote.http11.InternalAprOutputBuffer$SocketOutputBuffer.doWrite(InternalAprOutputBuffer.java:742)
at org.apache.coyote.http11.filters.IdentityOutputFilter.doWrite(IdentityOutputFilter.java:118)
at org.apache.coyote.http11.InternalAprOutputBuffer.doWrite(InternalAprOutputBuffer.java:552)
at org.apache.coyote.Response.doWrite(Response.java:560)
at org.apache.catalina.connector.OutputBuffer.realWriteBytes(OutputBuffer.java:364)
... 35 more
 
-------------------------------------------------------------------------------------------------------------------
 
上述问题分析:
在网上查找了了下原因,大概归结为: 
ClientAbortException: java.net.SocketException: Connection reset by peer: socket write error的原因是由于处理http连接时,正在输出内容时,用户关闭了IE,会出现一个"ClientAbortException",属于I/O处理中出现的一个异常,应用服务器应该会捕捉。 
Connection reset by peer的原因: 
经常出现的Connection reset by peer: 原因可能是多方面的,不过更常见的原因是: 
①:服务器的并发连接数超过了其承载量,服务器会将其中一些连接Down掉; 
②:客户关掉了浏览器,而服务器还在给客户端发送数据; 
③:浏览器端按了Stop 

        很多人都说是客户端造成的,没有办法控制,而且后台会记录这个异常,日志也会疯狂爆满,时间长了,肯定会DOWN掉的.
       
        本人觉得大多数可能是第二条问题的原因引起的,即大多数浏览器阻止了窗口的弹出,相当于客户关掉了浏览器,可等效于浏览器端按了Stop ,而这时服务器端还在给客户端发送数据,所以产生了上异常,经过本人的测试,发现只需将网站地址(或本机地址)加入"受信任的站点"即可解决问题,因为这样设置了以后,浏览器就不会阻止窗口的弹出了,这样浏览器就会等到服务器端发送完数据后再进行下面的动作.因而异常就不会发生了.
 
上述问题解决办法:  "工具->internet(选项..)->安全->受信任的站点->站点",将地址加入即可避免这个异常。
 
-------------------------------------------------------------------------------------------------------------------
 
今天也遇到这个问题了,查看了下tomcat源码对于这个异常的描述无非也就是说请求被中断,我的原因是由于调用导出文件方法是用这样子的代码的
   先执行了onclick中js  然后又去执行了href中js引起的,导致前面的请求被中断。改成 或者 问题就解决了  主要是懒复制前面的写法了 要是自己写的话也肯定是也不会写成这种形式。 所以建议楼主还是从请求为什么会被中断着手去找原因吧。看看在输出流在还没有结束的时候是不是又发送了新的请求。
 
本文转自http://cache.baiducontent.com/c?m=9f65cb4a8c8507ed4fece7631046893b4c4380147d8c8c4668d4e419ce3b4c413037bfa6663f405a8e906b6075a91d57eaf76223360123b59b8fc20bdfac925f75ce786a6459db0144dc48f2971a729066cd1afeae69f0ba872592de838d84030f8c005527c0b6dc1051438829ab496df4a7e95f142c&p=9765c64ad4934eac59eecb685f0e89&newp=c272ce1785cc43ec10bd9b7d0c1580231610db2151d7d1156b82c825d7331b001c3bbfb42324110fd8c27a6d01ad4d56edf33473340127a3dda5c91d9fb4c57479cb6f&user=baidu&fm=sc&query=connector%2EClientAbortException%3A&qid=a9c593a8000392fe&p1=4