Is it possible to process a filestream while uploading with JSF and Java EE Batch?

328 views Asked by At

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
1

There are 1 answers

0
BalusC On BEST ANSWER

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.