[GLASSFISH-16740] Unable to get "multipart/form-data" request parameters by HttpServletRequest#getParameter Created: 26/May/11  Updated: 07/Mar/12  Resolved: 15/Dec/11

Status: Resolved
Project: glassfish
Component/s: web_container
Affects Version/s: 3.1
Fix Version/s: 3.1.2_b15

Type: Bug Priority: Major
Reporter: dened Assignee: kchung
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: Text File 20111214-GLASSFISH-16740.patch     File i_spec_802_war.war     Java Archive File javax.faces.jar    
Issue Links:
Dependency
blocks JAVASERVERFACES_SPEC_PUBLIC-802 Ajax fileupload capabilities Closed
Related
is related to GLASSFISH-18444 Incompatibel breaking changes to getP... Resolved
Tags: 3_1_2-approved

 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.



 Comments   
Comment by Shing Wai Chan [ 02/Jun/11 ]

The above paragraph is quoted from 3.2 File upload.

Comment by Ed Burns [ 09/Dec/11 ]

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

Comment by kchung [ 13/Dec/11 ]

Fixed

Comment by Ed Burns [ 14/Dec/11 ]

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

Comment by Ed Burns [ 14/Dec/11 ]

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.

Comment by Ed Burns [ 14/Dec/11 ]

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.

Comment by Ed Burns [ 14/Dec/11 ]

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.

Comment by Ed Burns [ 14/Dec/11 ]

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); }
Comment by kchung [ 15/Dec/11 ]

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;

Comment by kchung [ 15/Dec/11 ]

fix

Comment by Joe Di Pol [ 15/Dec/11 ]

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.

Comment by kchung [ 15/Dec/11 ]

Fixed

Generated at Sat May 30 10:58:24 UTC 2015 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.