Issue Details (XML | Word | Printable)

Key: FILEUPLOAD-100
Type: Improvement Improvement
Status: Closed Closed
Resolution: Fixed
Priority: Minor Minor
Assignee: Unassigned
Reporter: Ralf Hauser
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Commons FileUpload

[fileupload] Allow to set headerEncoding to other than platform default encoding for fall-back

Created: 13/Apr/05 10:04 PM   Updated: 09/Mar/07 08:32 PM
Return to search
Component/s: None
Affects Version/s: None
Fix Version/s: None

Time Tracking:
Not Specified

File Attachments:
  Size
Text File MultipartStream.java.patch 2005-04-13 10:07 PM Ralf Hauser 2 kB
Environment:
Operating System: other
Platform: Other

Bugzilla Id: 34436


 Description  « Hide
it happens often that headers do not have an encoding.

Also in J2EE containers, there may be multiple web applications running, so it
may not be permitted change the platform encoding.

Therefore, it should be possible to change the default for
org.apache.commons.fileupload.MultipartStream without altering the
System.getProperty("file.encoding").



 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Ralf Hauser added a comment - 13/Apr/05 10:07 PM
Created an attachment (id=14702)
MultipartStream.java.patch

To have this effective, after loading, an init() must set the
org.apache.commons.fileupload.MultipartStream.headerEncodingDefault
— since this is static, this obviously only works if the fileUpload.jar is
not shared between the web-apps.

see also Created an attachment (id=14702)
MultipartStream.java.patch

To have this effective, after loading, an init() must set the
org.apache.commons.fileupload.MultipartStream.headerEncodingDefault
— since this is static, this obviously only works if the fileUpload.jar is
not shared between the web-apps.

see also Bug 34291


Martin Cooper added a comment - 14/Apr/05 12:52 AM
It is already possible to set the header encoding on a per-instance basis using
FileUploadBase.setHeaderEncoding(). I admit that's a little buried, which is
why I'm going to leave this bug report open for now. I do not like the idea of
using a static default value for exactly the reason you state - it will cause
problems, and likely much confusion, in situations where a shared FileUpload
jar is in use.

Ralf Hauser added a comment - 14/Apr/05 01:33 AM
Martin,

Now, I am confused: The javadoc for FileUploadBase.setHeaderEncoding() says:
/**

  • Specifies the character encoding to be used when reading the headers of
  • individual parts. When not specified, or <code>null</code>, the platform
  • default encoding is used.
    *
  • @param encoding The encoding used to read part headers.
    */
    so to me, it appears that this is complementary to what I am proposing:

In fact, I see that struts as I am using it in
org.apache.struts.upload.CommonsMultipartRequestHandler.handleRequest does call
your setHeaderEncoding(), but it turns out that (be it struts' or the browser's
fault) arrives as null.
So, this is exactly the case where I want to avoid it being set to the system's
file.encoding.

Short from patching struts, I do not see an option where I as an application
programmer who neither wants to touch the the struts nor the fileupload jar, can
call your setHeaderEncoding() before it's already set to the platform encoding.

So, what is probably needed that the FileUpload has an init() that creates a
singleton per web-application for the headerEncodingDefault and the user can set
that to a different value BEFORE e.g. struts or other frameworks start to use
the FileUploadBase - what do you think?


Martin Cooper added a comment - 14/Apr/05 01:45 AM
If you look at that particular code in Struts, you will see:

// The following line is to support an "EncodingFilter"
// see http://issues.apache.org/bugzilla/show_bug.cgi?id=23255
upload.setHeaderEncoding(request.getCharacterEncoding());

The comment is important...


Ralf Hauser added a comment - 14/Apr/05 02:40 AM
Thx, this is an interesting hint, haven't tested it but I trust the folks over
there did.

Suggestion: for a new javadoc for the FileUploadBase.setHeaderEncoding():
/**

  • Specifies the character encoding to be used when reading the headers of
  • individual parts. When not specified, or <code>null</code>, the platform
  • default encoding is used. If you prefer some other encoding without
  • changing the platform's "file.encoding", use an "Encoding filter" as
  • discussed in http://issues.apache.org/bugzilla/show_bug.cgi?id=23255
  • for the requests coming from the browser that do not delare their
  • encoding.
    *
  • @param encoding The encoding used to read part headers.
    */

Ralf Hauser added a comment - 14/Apr/05 03:21 PM
more on struts possibly not really doing it right --> more on struts possibly not really doing it right --> Bug 34445

Martin Cooper added a comment - 28/Nov/05 08:39 AM
Closing this as fixed, since the encoding used may be specified using the
FileUpload.setHeaderEncoding() method. If that returns null, the encoding is
taken from the request object, and so may be set using
request.setCharacterEncoding() before invoking FileUpload.parseRequest().