我正在编写一个下载文件控制器
有时,用户会在文件完全写入之前关闭浏览器窗口。-这很酷。
问题是我的日志中充满了这个错误:
org.apache.catalina.connector.ClientAbortException:
java.io.IOException:已建立的连接已被位于org.apache.catalina.connector.OutputBuffer.realWriteBytes(OutputBuffer.java:333) at org.apache.catalina.connector.OutputBuffer.flushByteBuffer(OutputBuffer.java:758) at org.apache.catalina.connector.OutputBuffer.append(OutputBuffer.java:663) at org.apache.catalina.connector的主机软件中止。OutputBuffer.writeBytes(OutputBuffer.java:368)在org.apache.catalina.connector.OutputBuffer.write(OutputBuffer.java:346)在org.apache.catalina.connector.CoyoteOutputStream.write(CoyoteOutputStream.java:96)在org.apache.commons.io.IOUtils.copyLarge(IOUtils.java:2147)在org.apache.commons.io.IOUtils.copy(IOUtils.java:2102)在org.apacheorg.apache.commons.io.IOUtils.copy(IOUtils.java:2078)上的.commons.io.IOUtils.copyLarge(IOUtils.java:2123)
当我试图捕捉这个特定的错误时,eclipse说:
无法将
ClientAbortException解析为类型
我已经正确设置并运行了项目,所以是否可以仅捕获此特定异常:
org.apache.catalina.connector.ClientAbortException
我想保留IOException以防发生另一场灾难。
发布于 2018-08-24 04:44:04
ClientAbortException
是从IOException
派生的。您必须检查到底是什么异常导致了IOException e
...
} catch (FileNotFoundException fnfe) {
// ... handle FileNotFoundException
} catch (IOException e) {
String exceptionSimpleName = e.getCause().getClass().getSimpleName();
if ("ClientAbortException".equals(exceptionSimpleName)) {
// ... handle ClientAbortException
} else {
// ... handle general IOException or another cause
}
}
return null;
发布于 2019-06-07 14:46:06
我通常在写时处理IOExceptions
,而不是在读时处理IOExceptions,而不是寻找特定的类名(它将您的应用程序绑定到特定的servlet容器),如下所示(非常伪代码):
try {
byte[] buffer = ...
in.read(buffer);
try {
out.write(buffer);
} catch (IOException writeException) {
// client aborted request
}
} catch (IOException readException) {
// something went wrong -> signal 50x or something else
}
到目前为止一切都很顺利。
发布于 2021-05-23 01:58:03
(截至@Nikolas Charalambidis答案)
"org.apache.catalina.connector.ClientAbortException:java.io.IOException: Connection reset by peer"
e.getCause().getClass().getSimpleName()
== "IOException"
e.getMessage()
== "java.io.IOException:对等设备重置连接“
... } catch (IOException e) { if (!E.getMessage().contains(“对等重置连接”){抛出e;}}最后{关闭(输出);关闭(输入);} ...
https://stackoverflow.com/questions/51993008
复制相似问题