/** * Returns true if the given exception is caused by a broken connection. * * @param exception * The exception to inspect. * @return True if the given exception is caused by a broken connection. */ public boolean isConnectionBroken(Throwable exception) { return isBroken(exception); }
/** * Returns true if the given exception is caused by a broken connection. * * @param exception * The exception to inspect. * @return True if the given exception is caused by a broken connection. */ public static boolean isBroken(Throwable exception) { boolean result = false; // detect Tomcat and Jetty exceptions if (exception instanceof IOException) { String exceptionName = exception.getClass().getName(); result = (exceptionName.endsWith("ClientAbortException") || exceptionName.endsWith("jetty.io.EofException")); } // check for known exception messages if (!result) { String exceptionMessage = exception.getMessage(); if (exceptionMessage != null) { result = (exceptionMessage.indexOf("Broken pipe") != -1) || (exceptionMessage.equals("An existing connection must have been closed by the remote party.") || (exceptionMessage.equals("An open connection has been abandonned by your network stack."))); } } if (!result && exception.getCause() != null) { result = isBroken(exception.getCause()); } return result; }