0

File uploads are working for small files (under the default 2MB limit), but will not work for larger files. I'm using JSF on Tomcat 8.0 and have modified my web.xml appropriately to increase the limit. I've put breakpoints in the constructor of javax.servlet.MultipartConfig so I can see it reads the web.xml configuration. When the action is called though, it defaults back to the default of 2MB (specifically in Request.parseParts(...) the wrapper's config is null, so uses the connector's default).

WEB.xml:

<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
<multipart-config>
  <max-file-size>-1</max-file-size>
  <max-request-size>-1</max-request-size>
  <file-size-threshold>0</file-size-threshold>
</multipart-config>
</servlet>

home.xhtml

<h:form id="contentFormId" enctype="multipart/form-data">
...
  <h:inputFile style="display:none;" id="fileUpload" value="#{bean.uploadItem}">
  </h:inputFile>
  <h:commandButton id="browse" action="#{bean.fileUploadListener}" value="Add Files" onclick="$('#contentFormId-fileUpload').click()">
  </h:commandButton>
...
</h:form>

context.xml

<?xml version="1.0" encoding="utf-8"?>
<Context allowCasualMultipartParsing="true" 
...
</Context>

Updated After creating a simplified application, it appears that the Rewrite library is causing a different container wrapper to be used in the request.

Without Rewrite: Request.getWrapper() returns StandardEngine[Catalina].StandardHost[localhost].StandardContext[/TestWeb].StandardWrapper[Faces Servlet]

With Rewrite @URLMapping annotation: Request.getWrapper() returns StandardEngine[Catalina].StandardHost[localhost].StandardContext[/TestWeb].StandardWrapper[default]

So it seems that I need to configure this application's default container similar to how Faces is configured, or find a way to get Rewrite to delegate to the Faces Servlet container. Editing the maxPostSize in Tomcat is an option (change the default), but not one I want to take if I can avoid it.

JSub
  • 111
  • 8
  • You should probably remove your multipart config since the default values are what you want. See https://docs.oracle.com/javaee/7/tutorial/servlets011.htm – Grayson Jun 22 '16 at 22:33
  • Not with Tomcat 8.0 as I understand it. Without a specified configuration the default comes from the connector's MaxPostSize(), which is 2MB – JSub Jun 23 '16 at 15:53
  • I made a simplified application, and it didn't show the same issue, so I think I have a configuration problem somewhere. – JSub Jun 23 '16 at 15:53
  • Seems like the issue is the rewrite library (2.0.12). Adding just the following line to my bean causes the default 2MB to be used instead of the configured values. `@URLMapping(id="home",pattern="/home",viewId="/faces/home.xhtml")` Doesn't matter if I browser to /home or to /faces/home.xhtml, it behaves the same. In fact, I can have 2 identical xhtml / beans running at the same time with only the @URLMapping difference (and bean name) and the one without it works. – JSub Jun 23 '16 at 17:07

1 Answers1

0

I don't like this solution, but it serves my purposes for now. It seems like it should default to the FacesServlet's settings because that's the final destination after rewrite.

My solution was to move (or copy) the multipart-config setting to the default servlet in web.xml:

<servlet>
  <servlet-name>Faces Servlet</servlet-name>
  <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
  <load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>default</servlet-name>
  <multipart-config>
    <max-file-size>-1</max-file-size>
    <max-request-size>-1</max-request-size>
    <file-size-threshold>0</file-size-threshold>
  </multipart-config>
</servlet>
JSub
  • 111
  • 8