File Upload: catching exception from application server

We are using WildFly as application server and as it happens the web server (Undertow) will throw an IOException if an uploaded file is bigger than the maximum allowed filesize in WildFly/Undertow preferencecs. We could naturally set some arbitrarily large value for the maximum file size (and handle file size restrictions in our Vaadin code), but it would seem better that we could some how handle the exception.

So, is there some way we can handle the exception with Upload component? It seems that the exception thrown by Undertow is not even getting catched by the DefaultErrorHandler in Vaadin.

Stack trace of the error (occurs after the upload button has been pressed):

SEVERE [com.vaadin.server.DefaultErrorHandler]
 (default task-28) : UT000020: Connection terminated as request was larger than 10485760
        at io.undertow.conduits.FixedLengthStreamSourceConduit.checkMaxSize( [undertow-core-1.1.0.Final.jar:1.1.0.Final]

        at [undertow-core-1.1.0.Final.jar:1.1.0.Final]

        at [undertow-core-1.1.0.Final.jar:1.1.0.Final]

        at io.undertow.server.HttpServerExchange$ [undertow-core-1.1.0.Final.jar:1.1.0.Final]

        at org.xnio.channels.Channels.readBlocking(
        at io.undertow.servlet.spec.ServletInputStreamImpl.readIntoBuffer( [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]

        at [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]

        at [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]

        at [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]

        at com.vaadin.server.communication.FileUploadHandler.readLine( [vaadin-server-7.7.6.jar:7.7.6]

        at com.vaadin.server.communication.FileUploadHandler.doHandleSimpleMultipartFileUpload( [vaadin-server-7.7.6.jar:7.7.6]

        at com.vaadin.server.communication.FileUploadHandler.handleRequest( [vaadin-server-7.7.6.jar:7.7.6


The EasyUploads add-on supports HTML5 max file size (haven’t tried it, but
saw it in the sources
). If you want to keep using Upload, you could do some post processing step before you save the file - save it to memory first and check the size before creating the actual file.


If I understand correctly the exception is thrown before any of the normal Upload component methods are called. That is, this happens before
of Receiver is called. I guess the exception gets thrown because the content-length reported by the browser is greater than the maximum allowed. The file does not actually get transferred to the server at all, but the exception is thrown before anything is even uploaded.
Thus, I don’t know how I can implement post processing in this case. Any tips?

I guess you could look into either disabling the size check entirely or something on the client side, like the above mentioned add-on.