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) : java.io.IOException: UT000020: Connection terminated as request was larger than 10485760
        at io.undertow.conduits.FixedLengthStreamSourceConduit.checkMaxSize(FixedLengthStreamSourceConduit.java:161) [undertow-core-1.1.0.Final.jar:1.1.0.Final]

        at io.undertow.conduits.FixedLengthStreamSourceConduit.read(FixedLengthStreamSourceConduit.java:219) [undertow-core-1.1.0.Final.jar:1.1.0.Final]

        at org.xnio.conduits.ConduitStreamSourceChannel.read(ConduitStreamSourceChannel.java:127)
        at io.undertow.channels.DetachableStreamSourceChannel.read(DetachableStreamSourceChannel.java:207) [undertow-core-1.1.0.Final.jar:1.1.0.Final]

        at io.undertow.server.HttpServerExchange$ReadDispatchChannel.read(HttpServerExchange.java:2083) [undertow-core-1.1.0.Final.jar:1.1.0.Final]

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

        at io.undertow.servlet.spec.ServletInputStreamImpl.read(ServletInputStreamImpl.java:146) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]

        at io.undertow.servlet.spec.ServletInputStreamImpl.read(ServletInputStreamImpl.java:133) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]

        at io.undertow.servlet.spec.ServletInputStreamImpl.read(ServletInputStreamImpl.java:124) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]

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

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

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

Hi,

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.

-Olli

If I understand correctly the exception is thrown before any of the normal Upload component methods are called. That is, this happens before
receiveUpload
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.

-Olli