Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to handle only ClientAbortException?

I am coding a download file controller
Sometime user will close the browser window before the file is fully written. - which is cool.

The problem is that my logs are full of this error:

org.apache.catalina.connector.ClientAbortException: java.io.IOException: An established connection was aborted by the software in your host machine at 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) at org.apache.catalina.connector.OutputBuffer.write(OutputBuffer.java:346) at org.apache.catalina.connector.CoyoteOutputStream.write(CoyoteOutputStream.java:96) at org.apache.commons.io.IOUtils.copyLarge(IOUtils.java:2147) at org.apache.commons.io.IOUtils.copy(IOUtils.java:2102) at org.apache.commons.io.IOUtils.copyLarge(IOUtils.java:2123) at org.apache.commons.io.IOUtils.copy(IOUtils.java:2078)

When I am trying to catch only this specific error eclipse is saying:

ClientAbortException cannot be resolved to a type

I have the project setup and running correctly so is it possible to catch only this specific exception:

   org.apache.catalina.connector.ClientAbortException

I would like to keep the IOException in case of another catastrophe.

try catch structure

like image 555
JavaSheriff Avatar asked Jul 09 '26 21:07

JavaSheriff


1 Answers

The ClientAbortException is derived from IOException. You have to inspect exactly what exception caused the 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;
like image 93
Nikolas Charalambidis Avatar answered Jul 11 '26 11:07

Nikolas Charalambidis