2

I want to process a large File with Java EE Batch while the file is uplaoding with JSF 2.2.

Is there a way to get the upload stream ?

If i upload a large file with JSF i alwasy running into following Error's:

java.lang.OutOfMemoryError: Java heap space
..
Caused by: java.lang.OutOfMemoryError: GC overhead limit exceeded
Giulio Vian
  • 8,248
  • 2
  • 33
  • 41
Khinsu
  • 1,487
  • 11
  • 27
  • Answer depends on who's parsing request and reading the uploaded file. As you explicitly mentioned JSF 2.2, may we assume that you're using its new `` for this? – BalusC Aug 06 '15 at 16:03
  • Yes, currently i am using `` to uplaoad the file, but if there is an other way to do this, im open for suggestions. – Khinsu Aug 06 '15 at 16:11
  • I'll assume that this all has got nothing to do with batch processing (as you didn't advance to that step yet due to the OOM) and I've posted an answer in case it was the file upload itself causing the OOM and not the batch processing. – BalusC Aug 06 '15 at 16:30
  • I thought it would be possible to process some bytes from the (uploading)file even before the upload is finished, so nothing has to be written to the filesystem. And i woudl have used Batch to process the recived file bytes. – Khinsu Aug 06 '15 at 16:39
  • "Raw" Apache Commons FileUpload supports this (consult manual using keyword "streaming mode"). But this requires a homegrown servlet. – BalusC Aug 07 '15 at 19:29

1 Answers1

2

The file size threshold of <h:inputFile> can be configured in <servlet> entry of the FacesServlet in web.xml as below:

<servlet>
    <servlet-name>facesServlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <multipart-config>
        <file-size-threshold>1048576</file-size-threshold>
    </multipart-config>
</servlet>

(note: if you didn't already had one and are thus relying on JSF 2.2+ implicit servlet registration, then you need to explicitly add a <servlet-mapping> on the desired URL pattern too)

Anything beyond the in <file-size-threshold> specified size (1MiB in above example) will be written to a temporary file in local disk file system instead of be kept in server memory. This will avoid potential OOM when the server-configured maximum POST size is larger than the available heap.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555