Message Boards

PrimeFaces 8 - Uploaded file is deleted too soon by Liferay Faces Bridge

Tomáš Havelka, modified 3 Years ago.

PrimeFaces 8 - Uploaded file is deleted too soon by Liferay Faces Bridge

New Member Posts: 6 Join Date: 7/9/20 Recent Posts
Hi,

​​​​​​​I am facing an opposite issue to this one https://issues.liferay.com/browse/FACES-3468 with PrimeFaces 8 and Liferay Faces Bridge 4.1.4. It seems to me that the uploaded file is deleted too soon before its completely processed.

The problem is when using PF with native FileUpload configured. The Liferay Faces Bridge handles the file upload correctly creating an UploadedFileBridgeImpl facade. This is fine and this facade is propagated to PF's FileUpload object properly. But, within PF8 this bug https://github.com/primefaces/primefaces/issues/5408 was fixed.  Now, when the mentioned methods
  • org.primefaces.util.FileUploadUtils#isValidType
  • org.primefaces.util.FileUploadUtils#isValidFile
are called, the underlying temporary file's input stream is being closed, which causing the UploadedFileBridgeImpl deletes the file. This is wrong, because the file is still referenced in a wrapping PF's FileUpload object, thus it cannot read it due its deletion when processed.

I think, this is an issue, that has to be fixed. Am I correct?

​​​​​​​
Thx Tom
thumbnail
Neil Griffin, modified 3 Years ago.

RE: PrimeFaces 8 - Uploaded file is deleted too soon by Liferay Faces Bridg

Liferay Legend Posts: 2655 Join Date: 7/27/05 Recent Posts
Hi Tom,
Thanks for bringing this to my attention. I'll try to reproduce it today and let you know my findings.
Kind Regards,
Neil
thumbnail
Neil Griffin, modified 3 Years ago.

RE: PrimeFaces 8 - Uploaded file is deleted too soon by Liferay Faces Bridg

Liferay Legend Posts: 2655 Join Date: 7/27/05 Recent Posts
Hi Tom,
I developed a fix for UploadedFileBridgeImpl.java and plan to commit the changes upstream tomorrow. I will post another comment here in this thread when I have a -SNAPSHOT version of the bridge that you can try with the fix.
Kind Regards,
Neil
Tomáš Havelka, modified 3 Years ago.

RE: PrimeFaces 8 - Uploaded file is deleted too soon by Liferay Faces Bridg

New Member Posts: 6 Join Date: 7/9/20 Recent Posts
Hi Neil,
thanks for your quick answer!
I'm glad that you confirmed the bug. I am going to wait for the fix being available.
Best regards,
Tom.
thumbnail
Neil Griffin, modified 3 Years ago.

RE: PrimeFaces 8 - Uploaded file is deleted too soon by Liferay Faces Bridg

Liferay Legend Posts: 2655 Join Date: 7/27/05 Recent Posts
Hi Tom,
I pushed the commits related to the fix upstream to liferay-faces-bridge-impl-4.x and published an updated com.liferay.faces.bridge.impl-4.2.0-SNAPSHOT.jar to our snapshot repository.
Please give it a try and let me know if it fixes the issue.
For more details and updates, please click the "follow" link on https://issues.liferay.com/browse/FACES-3551
Kind Regards,
Neil
Tomáš Havelka, modified 3 Years ago.

RE: PrimeFaces 8 - Uploaded file is deleted too soon by Liferay Faces Bridg

New Member Posts: 6 Join Date: 7/9/20 Recent Posts
Hi Neil,

thanks for your fix. Now, it works as expected.

First, maybe one little remark for the implementation. So far the file content was stored on a file system and provided using the (deleting) stream over it. Now, with this fix for the PF8 and above, the file content is stored in a memory as bytes. Is it a good approach for the potentially big files?
Second, when will this fix be available in a release?


Best regards,
Tom
thumbnail
Neil Griffin, modified 3 Years ago.

RE: PrimeFaces 8 - Uploaded file is deleted too soon by Liferay Faces Bridg

Liferay Legend Posts: 2655 Join Date: 7/27/05 Recent Posts
Hi Tom,
Thanks for reporting back. I'm glad to know that it worked for you.
One reason why Liferay Faces Bridge deletes the uploaded file, is to prevent developers from needing to create custom disk/filesystem "cleanup" mechanisms. That is established legacy behavior, and so I think it is important to keep that in place as the default.
But as I developed the fix, I also considered the problem of potentially big files being stored in memory. The benefit is that the legacy behavior (deleting the file) is preserved. As you pointed out, the drawback is that memory consumption could be high, until the JVM is forced to collect garbage.
One compromise could be to introduce a web.xml context-param that allows you to control whether or not Liferay Faces Bridge deletes the file. If file deletion is enabled, then the file contents would be kept in memory until the next time the JVM is forced to collect garbage. If deletion is disabled, then the file could be left on the disk, but the developer would have to create a custom disk/filesystem "cleanup" mechanism.What do you think? If you have a different idea, I'd be happy to discuss it.Kind Regards,Neil
Tomáš Havelka, modified 3 Years ago.

RE: PrimeFaces 8 - Uploaded file is deleted too soon by Liferay Faces Bridg

New Member Posts: 6 Join Date: 7/9/20 Recent Posts
Hi Neil,
I have not a better solution for this then the one proposed by you. But this is not a blocker for our project. The real blocker is, the upload does not work without your fix.So, when will this fix be available in a release?
Best regards,
Tom
thumbnail
Neil Griffin, modified 3 Years ago.

RE: PrimeFaces 8 - Uploaded file is deleted too soon by Liferay Faces Bridg

Liferay Legend Posts: 2655 Join Date: 7/27/05 Recent Posts
We are currently scheduled to release by the end of next month (September, 2020).
Tomáš Havelka, modified 3 Years ago.

RE: PrimeFaces 8 - Uploaded file is deleted too soon by Liferay Faces Bridg

New Member Posts: 6 Join Date: 7/9/20 Recent Posts
Hi Neil,
What about the release, please?
We need it for the production.


Thx Tom
thumbnail
Neil Griffin, modified 3 Years ago.

RE: PrimeFaces 8 - Uploaded file is deleted too soon by Liferay Faces Bridg

Liferay Legend Posts: 2655 Join Date: 7/27/05 Recent Posts
Hi Tom,
Thanks for asking about the release. I'm sorry we missed the end of September target date, but I have good news to report...
We are well underway with testing the release:

- Testing Complete: Liferay 7.0, 7.1, and 7.2 "thick" WARs (meaning all JSF dependencies are in WEB-INF/lib)

- Testing Complete: Liferay 7.1 and 7.2 "thin" WARs (meaning, most or all JSF dependencies are in $LIFERAY_HOME/osgi/modules)

- Testing Complete: Apache Pluto 2.x "thick" WARs- Testing Complete: Apache Pluto 3.x "thin" WARs (not for release yet since it relies on JSR 378)

At this time we are testing the latest builds of Liferay 7.3 CE GA6 and fixing some issues such as https://issues.liferay.com/browse/FACES-3562

We will continue to fix these 7.3 issues and re-run our tests. After that we should be able to release. At our current pace we are looking at mid-October, perhaps as late as October 23.

This release is very exciting because of the "thin" WAR capability. Our "thin" test WARs are now measured in kilobytes ( KB ) rather than megabytes ( MB ). That's true even for CDI based portlets, since Liferay 7.1, 7.2, and 7.3 feature OSGi CDI Integration, meaning we will be able to take advantage of weld-osgi-bundle.jar which ships with Liferay.

Kind Regards,

Neil
thumbnail
Neil Griffin, modified 3 Years ago.

RE: RE: PrimeFaces 8 - Uploaded file is deleted too soon by Liferay Faces B

Liferay Legend Posts: 2655 Join Date: 7/27/05 Recent Posts

Hi Tom,

We're still finalizing the release of Liferay Faces artifacts, and haven't put out a formal release announcement yet, but I just wanted to mention that Liferay Faces Bridge 4.2.0 has been released to Maven Central:

https://search.maven.org/artifact/com.liferay.faces/com.liferay.faces.bridge.impl/4.2.0/jar

Kind Regards,

Neil