I am not familiar with Apache CXF, but the following should be applicable to any Java Servlet based framework.
In order to determine if a user has disconnected (stop button, closed browser, etc.) the server must attempt to send a packet. If the TCP/IP connection has been closed, an IOException
will be thrown.
In theory, a Java application could send a space character at various points during processing. An IOException
would signal that the client has gone away and processing can be aborted.
However, there may be a few issues with this technique:
Sending characters during processing will cause the response to be "committed", so it may be impossible to set HTTP headers, cookies, etc. based on the result of the long-running serverside processing.
If the output stream is buffered, the space characters will not be sent immediately, thereby not performing an adequate test. It may be possible to use flush()
as a workaround.
It may be difficult to implement this technique for a given framework or view technology (JSP, etc.) For example, the page rendering code will not be able to sent the content type after the response has been committed.