glassfish
  1. glassfish
  2. GLASSFISH-16740

Unable to get "multipart/form-data" request parameters by HttpServletRequest#getParameter

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 3.1
    • Fix Version/s: 3.1.2_b15
    • Component/s: web_container
    • Labels:
      None

      Description

      The Java Servlet 3.0 Specification states:

      For parts with form-data as the Content-Disposition, but without a filename, the string value of the part will also be available via the getParameter / getParameterValues methods on HttpServletRequest, using the name of the part.

      But in GlassFish 3.1 I'm unable access non-file multipart/form-data parameters that way. Of course, I can get parameters using getParts, but a JSF implementation rely on ordinary HttpServletRequest parameters map and therefore currently can't process multipart/form-data postback requests.

      1. 20111214-GLASSFISH-16740.patch
        2 kB
        kchung

        Issue Links

          Activity

          Hide
          Shing Wai Chan added a comment -

          The above paragraph is quoted from 3.2 File upload.

          Show
          Shing Wai Chan added a comment - The above paragraph is quoted from 3.2 File upload.
          Hide
          Ed Burns added a comment -

          I'm upping this to major because I can't implement JAVASERVERFACES_SPEC_PUBLIC-802 until this is fixed.

          Show
          Ed Burns added a comment - I'm upping this to major because I can't implement JAVASERVERFACES_SPEC_PUBLIC-802 until this is fixed.
          Hide
          kchung added a comment -

          Fixed

          Show
          kchung added a comment - Fixed
          Hide
          Ed Burns added a comment -

          Still don't see this working even with fresh build of r 51565 of GlassFish 3.1.2 branch.

          Show
          Ed Burns added a comment - Still don't see this working even with fresh build of r 51565 of GlassFish 3.1.2 branch.
          Hide
          Ed Burns added a comment -

          This is JSF 2.2-SNAPSHOT that includes uncommitted support for fileupload.

          It is required to run the i_mojarra_802_war.war.

          Replace the file of the same name in glassfish3/glassfish/modules with this one.

          Show
          Ed Burns added a comment - This is JSF 2.2-SNAPSHOT that includes uncommitted support for fileupload. It is required to run the i_mojarra_802_war.war. Replace the file of the same name in glassfish3/glassfish/modules with this one.
          Hide
          Ed Burns added a comment -

          Deploy this war on a GlassFish 3.1.2 that has the javax.faces.jar from this issue. Visit < http://127.0.0.1:8080/i_spec_802_war/ > and upload a file.

          When you do, you'll see this output in the server log.

          INFO: The request content-type is not a multipart/form-data
          INFO: The request content-type is not a multipart/form-data
          INFO: part.getContentType() null
          INFO: part.getName() j_idt6
          INFO: part.getContentType() application/x-sh
          INFO: part.getName() j_idt6:j_idt7
          INFO: part.getContentType() null
          INFO: part.getName() j_idt6:j_idt9
          INFO: part.getContentType() null
          INFO: part.getName() javax.faces.ViewState
          INFO: part.getContentType() null
          INFO: part.getName() j_idt6
          INFO: part.getContentType() application/x-sh
          INFO: part.getName() j_idt6:j_idt7
          INFO: part.getContentType() null
          INFO: part.getName() j_idt6:j_idt9
          INFO: part.getContentType() null
          INFO: part.getName() javax.faces.ViewState
          INFO: The request content-type is not a multipart/form-data

          But you'll note that servletRequest.getParameter("javax.faces.ViewState") returns null.

          Show
          Ed Burns added a comment - Deploy this war on a GlassFish 3.1.2 that has the javax.faces.jar from this issue. Visit < http://127.0.0.1:8080/i_spec_802_war/ > and upload a file. When you do, you'll see this output in the server log. INFO: The request content-type is not a multipart/form-data INFO: The request content-type is not a multipart/form-data INFO: part.getContentType() null INFO: part.getName() j_idt6 INFO: part.getContentType() application/x-sh INFO: part.getName() j_idt6:j_idt7 INFO: part.getContentType() null INFO: part.getName() j_idt6:j_idt9 INFO: part.getContentType() null INFO: part.getName() javax.faces.ViewState INFO: part.getContentType() null INFO: part.getName() j_idt6 INFO: part.getContentType() application/x-sh INFO: part.getName() j_idt6:j_idt7 INFO: part.getContentType() null INFO: part.getName() j_idt6:j_idt9 INFO: part.getContentType() null INFO: part.getName() javax.faces.ViewState INFO: The request content-type is not a multipart/form-data But you'll note that servletRequest.getParameter("javax.faces.ViewState") returns null.
          Hide
          Ed Burns added a comment -

          Steps to reproduce.

          1. Build GlassFish 3.1.2 with the reported fix for this issue. This fix was committed on r51512.

          2. Replace the glassfish3/glassfish/modules/javax.faces.jar in the unzipped glassfish.zip with this one:

          http://java.net/jira/secure/attachment/48516/javax.faces.jar

          3. Start the server and deploy this war:

          http://java.net/jira/secure/attachment/48517/i_spec_802_war.war

          4. Visit < http://127.0.0.1:8080/i_spec_802_war/ >. Submit a file upload using the web page. This will cause a POST request with content type being multipart/form-data. During the processing of the request, servletRequest.getParameter("javax.faces.ViewState") is called.

          This should return the value, instead it returns null.

          Show
          Ed Burns added a comment - Steps to reproduce. 1. Build GlassFish 3.1.2 with the reported fix for this issue. This fix was committed on r51512. 2. Replace the glassfish3/glassfish/modules/javax.faces.jar in the unzipped glassfish.zip with this one: http://java.net/jira/secure/attachment/48516/javax.faces.jar 3. Start the server and deploy this war: http://java.net/jira/secure/attachment/48517/i_spec_802_war.war 4. Visit < http://127.0.0.1:8080/i_spec_802_war/ >. Submit a file upload using the web page. This will cause a POST request with content type being multipart/form-data. During the processing of the request, servletRequest.getParameter("javax.faces.ViewState") is called. This should return the value, instead it returns null.
          Hide
          Ed Burns added a comment -

          New mojarra that has this:

          @Override
          public boolean containsKey(Object key)

          { System.out.println("debug: edburns: containsKey(" + key + "): " + request.getParameter(key.toString())); return (request.getParameter(key.toString()) != null); }
          Show
          Ed Burns added a comment - New mojarra that has this: @Override public boolean containsKey(Object key) { System.out.println("debug: edburns: containsKey(" + key + "): " + request.getParameter(key.toString())); return (request.getParameter(key.toString()) != null); }
          Hide
          kchung added a comment -

          Multipart is not properly scanned, if getParmeter() is called before getParts() is called. Here is the diff for fixing this.

          misto:web-core%svn diff
          Index: src/main/java/org/apache/catalina/fileupload/Multipart.java
          ===================================================================
          — src/main/java/org/apache/catalina/fileupload/Multipart.java (revision 51512)+++ src/main/java/org/apache/catalina/fileupload/Multipart.java (working copy)
          @@ -57,6 +57,8 @@
          import java.util.Collections;
          import java.util.List;
          import java.util.Locale;
          +import java.util.logging.Level;
          +import java.util.logging.Logger;

          import com.sun.grizzly.util.http.Parameters;

          @@ -75,6 +77,9 @@
          private ArrayList<Part> parts;
          private List<Part> unmodifiableParts;

          + private static final Logger log =
          + Logger.getLogger(Multipart.class.getName());
          +
          public Multipart(HttpServletRequest request, Parameters parameters,
          String location, long maxFileSize, long maxRequestSize,
          int fileSizeThreshold)

          { @@ -96,6 +101,14 @@ }

          }

          + public void init() {
          + try

          { + initParts(); + }

          catch (Exception ex)

          { + log.severe("Error in multipart initialization."); + }

          + }
          +
          public String getLocation()

          { return location; }

          Index: src/main/java/org/apache/catalina/connector/Request.java
          ===================================================================
          — src/main/java/org/apache/catalina/connector/Request.java (revision 51512)+++ src/main/java/org/apache/catalina/connector/Request.java (working copy)
          @@ -3148,7 +3148,7 @@
          contentType = contentType.trim();
          }
          if ("multipart/form-data".equals(contentType))

          { - getMultipart(); + getMultipart().init(); }

          if (!("application/x-www-form-urlencoded".equals(contentType))) {
          return;

          Show
          kchung added a comment - Multipart is not properly scanned, if getParmeter() is called before getParts() is called. Here is the diff for fixing this. misto:web-core%svn diff Index: src/main/java/org/apache/catalina/fileupload/Multipart.java =================================================================== — src/main/java/org/apache/catalina/fileupload/Multipart.java (revision 51512)+++ src/main/java/org/apache/catalina/fileupload/Multipart.java (working copy) @@ -57,6 +57,8 @@ import java.util.Collections; import java.util.List; import java.util.Locale; +import java.util.logging.Level; +import java.util.logging.Logger; import com.sun.grizzly.util.http.Parameters; @@ -75,6 +77,9 @@ private ArrayList<Part> parts; private List<Part> unmodifiableParts; + private static final Logger log = + Logger.getLogger(Multipart.class.getName()); + public Multipart(HttpServletRequest request, Parameters parameters, String location, long maxFileSize, long maxRequestSize, int fileSizeThreshold) { @@ -96,6 +101,14 @@ } } + public void init() { + try { + initParts(); + } catch (Exception ex) { + log.severe("Error in multipart initialization."); + } + } + public String getLocation() { return location; } Index: src/main/java/org/apache/catalina/connector/Request.java =================================================================== — src/main/java/org/apache/catalina/connector/Request.java (revision 51512)+++ src/main/java/org/apache/catalina/connector/Request.java (working copy) @@ -3148,7 +3148,7 @@ contentType = contentType.trim(); } if ("multipart/form-data".equals(contentType)) { - getMultipart(); + getMultipart().init(); } if (!("application/x-www-form-urlencoded".equals(contentType))) { return;
          Hide
          kchung added a comment -

          fix

          Show
          kchung added a comment - fix
          Hide
          Joe Di Pol added a comment -

          Info from kchung:

          • What is the impact on the customer of the bug?

          Only for users using fileupload feature in servlet 3.0. But this fixes an important feature in fileupload.

          • What is the cost/risk of fixing the bug?

          Cost and risk minimal. Only affects two files relating to file upload.

          • Is there an impact on documentation or message strings?

          No.

          • Which tests should QA (re)run to verify the fix did not destabilize GlassFish?

          Run the test case attached to the issue tracker.

          • Which is the targeted build of 3.1.2 for this fix?

          B15.

          Show
          Joe Di Pol added a comment - Info from kchung: What is the impact on the customer of the bug? Only for users using fileupload feature in servlet 3.0. But this fixes an important feature in fileupload. What is the cost/risk of fixing the bug? Cost and risk minimal. Only affects two files relating to file upload. Is there an impact on documentation or message strings? No. Which tests should QA (re)run to verify the fix did not destabilize GlassFish? Run the test case attached to the issue tracker. Which is the targeted build of 3.1.2 for this fix? B15.
          Hide
          kchung added a comment -

          Fixed

          Show
          kchung added a comment - Fixed

            People

            • Assignee:
              kchung
              Reporter:
              dened
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: