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.
p:fileUpload
fileUploadListener
specified method is called for each file. So probably each call of this method resets the session time counter? Right? If a very big file is uploaded the requests of the file upload servlet does not reset the timeout counter? Right or not? –
Danuloff multiple="true"
, the files are sent simultaneously, so onstart
is called once. The files are processed individually, so oncomplete
is called for each file. This would make option 2 a poor choice and option 1 a better choice. Nonetheless, option 1 is in any case most reliable as you never know beforehand how long an upload would take. Not sure what you mean with "file upload servlet" in context of this question. –
Glycogen p:poll
listener method which is called, but the session expires anyway. –
Danuloff Thread.sleep()
inside the upload handling method to exceed the session. –
Danuloff p:idleMonitor
somewhere in the code. After removing it, it works now. Unfortunately my "session expired" dialog is no more displayed when the session expired. –
Danuloff idleMonitor
has to be reset when the session time is extended. –
Danuloff © 2022 - 2024 — McMap. All rights reserved.
p:fileUpload
is no more visible in my case when the upload is done. It is inside a dialog which will be closed and the upload is initiated via javascript call. – Danuloff