From 4b1fc2e1fbbd5ab63cc6f5077bb4afe19834992e Mon Sep 17 00:00:00 2001 From: Elmot Date: Fri, 20 Jul 2018 13:27:32 +0300 Subject: Document how to handle cancelled file downloads. Fixes #9014 (cherry picked from commit 65d2baf) --- .../articles/LettingTheUserDownloadAFile.asciidoc | 29 ++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'documentation') diff --git a/documentation/articles/LettingTheUserDownloadAFile.asciidoc b/documentation/articles/LettingTheUserDownloadAFile.asciidoc index 4b595fc6de..209ef27c38 100644 --- a/documentation/articles/LettingTheUserDownloadAFile.asciidoc +++ b/documentation/articles/LettingTheUserDownloadAFile.asciidoc @@ -62,8 +62,7 @@ along with the file to ensure the browser doesn't try to open the file even if it's is a file type that the browser knows how to deal with. [[lazily-determine-the-content-and-the-name-of-the-file-being-server]] -Lazily determine the content and the name of the file being server -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +==== Lazily determine the content and the name of the file being server One can lazily determine the content of the file using a `StreamResource`. Yet the name of the file that is going to be @@ -110,3 +109,29 @@ public class OnDemandFileDownloader extends FileDownloader { } } .... + +[[lazily-determine-the-content-and-the-name-of-the-file-being-server]] +==== Cancelled downloads + +Since downloadable files may be quite big, and the download process may take time, the user might decide to +cancel the download process. It this case `IOException` may be thrown by the web server. In this case the exception +does not mean that something went wrong with the application, but it the. To prevent those exceptions to be logged, you can catch +and ignore it as here: + +```java +public class IgnoreCancelDownloader extends FileDownloader { + + ... + + @Override + public boolean handleConnectorRequest(final VaadinRequest request, final VaadinResponse response, final String path) { + try { + return super.handleConnectorRequest(request, response, path); + } catch (final IOException ignored) { + return true; + } + } +} + +``` +Note that the exception is a sublclass of `IOException`, but the particular class depends of the web container. -- cgit v1.2.3