diff options
-rw-r--r-- | documentation/articles/LettingTheUserDownloadAFile.asciidoc | 29 | ||||
-rw-r--r-- | server/src/main/java/com/vaadin/server/FileDownloader.java | 11 |
2 files changed, 35 insertions, 5 deletions
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. diff --git a/server/src/main/java/com/vaadin/server/FileDownloader.java b/server/src/main/java/com/vaadin/server/FileDownloader.java index e20ed3634b..b41e75f4cc 100644 --- a/server/src/main/java/com/vaadin/server/FileDownloader.java +++ b/server/src/main/java/com/vaadin/server/FileDownloader.java @@ -81,7 +81,6 @@ public class FileDownloader extends AbstractExtension { * * @param eventTrigger * the trigger to attach this extension to - * * @since 8.4 */ public void extend(EventTrigger eventTrigger) { @@ -132,16 +131,22 @@ public class FileDownloader extends AbstractExtension { /** * Checks whether the content type should be overridden. * - * @see #setOverrideContentType(boolean) - * * @return <code>true</code> if the content type will be overridden when * possible; <code>false</code> if the original content type will be * used. + * @see #setOverrideContentType(boolean) */ public boolean isOverrideContentType() { return overrideContentType; } + /** + * {@inheritDoc} + * + * @throws IOException + * if something goes wrong with the download or the user + * cancelled the file download process. + */ @Override public boolean handleConnectorRequest(VaadinRequest request, VaadinResponse response, String path) throws IOException { |