Class ClientAborts

java.lang.Object
org.apache.juneau.rest.server.ClientAborts

public final class ClientAborts extends Object
Internal utility for recognizing failures caused by the client disconnecting before the response completed.

A client that closes its connection mid-response (closed browser tab, cancelled request, timed-out proxy) is routine, not a server error. Servlet containers surface it as an IOException from the response output stream or writer, but the concrete type is container-specific. This class detects it without a compile-time dependency on any container.

Example:

try { res.flushBuffer(); } catch (Exception e) { if (ClientAborts.isClientAbort(e)) // Routine: the client went away. Don't record it as an error. return; throw e; }

Not part of the public REST API; subject to change without notice.

Since:
10.0.0
  • Method Details

    • isClientAbort

      public static boolean isClientAbort(Throwable t)
      Returns true if the specified throwable, or anything in its cause chain, indicates that the client disconnected.

      The cause chain is walked up to a bounded depth and guarded against cycles. A throwable matches if it is:

      • A class whose simple name is ClientAbortException (Tomcat; matched by name so there is no Tomcat dependency).
      • An EOFException (Jetty's EofException extends it).
      • A ClosedChannelException.
      • An IOException whose message contains "broken pipe" or "connection reset" (case-insensitive).
      Parameters:
      t - The throwable to test. Can be null.
      Returns:
      true if the throwable represents a client abort.
    • isContainerClientAbort

      public static boolean isContainerClientAbort(Throwable t)
      Returns true only if the throwable, or anything in its cause chain, is a servlet-container client-abort type.

      Matches only classes whose simple name is ClientAbortException (Tomcat, which wraps every response write/flush failure in it) or EofException (Jetty). Unlike isClientAbort(Throwable), plain EOFException, ClosedChannelException and "broken pipe"/"connection reset" IOExceptions do not match.

      Use this where the failure could have come from somewhere other than the client socket (e.g. an exception escaping operation execution or response rendering, where a backend call might also have reset). Use the lenient isClientAbort(Throwable) only for response flush paths, where the failure is necessarily on the client socket.

      Parameters:
      t - The throwable to test. Can be null.
      Returns:
      true if the throwable represents a container-reported client abort.