title: Glassfish Servlet Error 500 (not exception) - Upload file bigger than 20mb
body: <p><strong>UPDATE</strong></p>
  <p>Tried it now on another computer and it worked fine, should be something wrong with my glassfish, if anyone have an idea without reinstalling it i would be glad.</p>
  <p><strong>END_UPDATE</strong></p>
  <p>I'm trying to create an simple servlet that receive an file and do something with it, but even with the simplest example possible it's not working for file larger than 20mb.</p>
  <p>The big problem is that glassfish does not log anything and the error does not show any exception at all and the message is very generic.</p>
  <p>Another important thing is that the doPost() is not even called when the file is larger than 20mb, the error is throw before that.</p>
  <p>Here is the error that is displayed:</p>
  <p><a href="https://i.stack.imgur.com/ZwBKB.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ZwBKB.png" alt="" /></a></p>
  <p>Other thing is that the message show HTTP Status 500, but the real status is 400 (Bad Request).</p>
  <p>Here is the Servlet that i'm using:</p>
  <pre><code>import java.io.IOException;
  import java.util.Collection;
  import javax.servlet.ServletException;
  import javax.servlet.annotation.MultipartConfig;
  import javax.servlet.annotation.WebServlet;
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  import javax.servlet.http.Part;
  
  @WebServlet(&quot;/upload&quot;)
  @MultipartConfig(location = &quot;/tmp&quot;)
  public class FileUploadServlet extends HttpServlet {
  
      @Override
      protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
          getServletContext().getRequestDispatcher(&quot;/WEB-INF/views/upload.jsp&quot;).forward(req, res);
      }
  
      @Override
      protected void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
          Collection&lt;Part&gt; parts = req.getParts();
          for(Part part : parts) {
              System.out.println(&quot;Name:&quot;);
              System.out.println(part.getName());
              System.out.println(&quot;Header: &quot;);
              for(String headerName : part.getHeaderNames()) {
                  System.out.println(headerName);
                  System.out.println(part.getHeader(headerName));
              }
              System.out.println(&quot;Size: &quot;);
              System.out.println(part.getSize());
              part.write(part.getName() + &quot;-down&quot;);
          }
          res.sendRedirect(&quot;/upload&quot;);
      }
  }
  </code></pre>
  <p>And here is the simple jsp (but the error is throw even using an POST tool, like Postman):</p>
  <pre><code>&lt;!doctype html&gt;
  &lt;html&gt;
      &lt;head&gt;
          &lt;meta charset=&quot;UTF-8&quot;/&gt;
          &lt;title&gt;File Upload Sample&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;form action=&quot;&quot; enctype=&quot;multipart/form-data&quot; method=&quot;post&quot;&gt;
              &lt;p&gt;
                  &lt;label&gt;Select a file: &lt;/label&gt;
                  &lt;input type=&quot;file&quot; name=&quot;file&quot;/&gt;
              &lt;/p&gt;
              &lt;input type=&quot;submit&quot; value=&quot;Upload&quot; /&gt;
          &lt;/form&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  <p>web.xml:</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;web-app xmlns=&quot;http://xmlns.jcp.org/xml/ns/javaee&quot;
           xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
           xsi:schemaLocation=&quot;http://xmlns.jcp.org/xml/ns/javaee 
              http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd&quot;
           version=&quot;3.1&quot;&gt;
      &lt;display-name&gt;Portabilidade&lt;/display-name&gt;
      &lt;!-- location of log4j config file --&gt;
      &lt;session-config&gt;
          &lt;session-timeout&gt;120&lt;/session-timeout&gt;
      &lt;/session-config&gt;
      &lt;context-param&gt;
          &lt;param-name&gt;javax.faces.PROJECT_STAGE&lt;/param-name&gt;
          &lt;param-value&gt;Development&lt;/param-value&gt;
      &lt;/context-param&gt;
      &lt;context-param&gt;
          &lt;param-name&gt;log4jConfigLocation&lt;/param-name&gt;
          &lt;param-value&gt;/WEB-INF/classes/log4j.properties&lt;/param-value&gt;
      &lt;/context-param&gt;
      &lt;servlet&gt;
          &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
          &lt;servlet-class&gt;javax.faces.webapp.FacesServlet&lt;/servlet-class&gt;
          &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
      &lt;/servlet&gt;
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
          &lt;url-pattern&gt;*.xhtml&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
  &lt;/web-app&gt;
  </code></pre>
  <p>I'm already with no more idea on how to fix that...</p>