title: How to use HttpServletRequest#getParts() in a servlet filter running on Tomcat?
body: <p>I would like to upload a file in my JSF application. I am using a <code>Filter</code> and <code>HttpServletRequestWrapper</code> to access the upload file. </p>
  
  <pre><code> public MultipartRequestWrapper(HttpServletRequest request) {
      super(request);
      System.out.println("Created multipart wrapper....");
      try {
          System.out.println("Looping parts"+getParts().size());
  
          for (Part p : getParts()) {
              System.out.println(String.format("Part name: %1$s, contentType : %2$s", p.getName(), p.getContentType()));
              for(String header : p.getHeaderNames()){
                  System.out.println("Header name : " + header + ", value : " + p.getHeader(header));
              }
              byte[] b = new byte[(int) p.getSize()];
              p.getInputStream().read(b);
              params.put(p.getName(), new String[]{new String(b)});
          }
      } catch (IOException ex) {
          ex.printStackTrace();
          Logger.getLogger(MultipartRequestWrapper.class.getName()).log(Level.SEVERE, null, ex);
      } catch (ServletException ex) {
           ex.printStackTrace();
          Logger.getLogger(MultipartRequestWrapper.class.getName()).log(Level.SEVERE, null, ex);
      }
  </code></pre>
  
  <p>However, <code>getParts()</code> returns an empty collection. How can I enable <code>multipart/form-data</code> parsing in a servlet filter in Tomcat 7.0.8?</p>