Could a session timeout happen if there are several very big files are uploaded? Imagine I upload one 5 GByte big file and a short session timeout is set. Could the session timeout occur during streaming the file?
Yes, it can. The servlet specification does nowhere forbid that a session could be destroyed during an active request. You'll thus risk a ViewExpiredException
when such an upload arrives at bean.
If this is your concern, you've several options:
Let the upload form asynchronously poll to the server at intervals to keep the session alive. You can in EL use #{session.maxInactiveInterval}
to obtain the current timeout in seconds.
<p:fileUpload ... />
<p:poll interval="#{session.maxInactiveInterval - 10}" async="true" />
The 10 seconds difference is just to prevent that it arrives a few seconds too late because the page itself may also take some time to load all the HTML and to initialize the poll. You can if necessary conditionally start/render the poll on start of upload.
Let the "onstart" event of upload increase the session timeout to a certain limit (hour?) and let the "oncomplete" event of upload put it back.
<p:fileUpload ... onstart="increaseTimeout()" oncomplete="resetTimeout()" />
<p:remoteCommand name="increaseTimeout" listener="#{bean.increaseTimeout}" />
<p:remoteCommand name="resetTimeout" listener="#{bean.resetTimeout}" />
You can in bean use ExternalContext#setSessionMaxInactiveInterval()
to set the desired session timeout in seconds.
Use a stateless JSF form. The view will never expire, regardless of how the HTTP session behaves.
<f:view transient="true">
...
</f:view>
Note: any view scoped beans tied to such a view will behave like request scoped ones. To avoid confusion, replace the annotations if necessary.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With