commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Piotr Gaertig <>
Subject [fileupload] class contribution - HttpServletRequest wrapping
Date Sun, 24 Apr 2005 22:59:35 GMT

Current FileUpload component involves user in current code changes or
usage of the nonstandard semantics of the parameter retrieval. That would be
nightmare for projects based on huge forms, form digesters (struts) or 
just maintenanced projects.
So I developed small class, which is remedy for presented problems.

It just simply inherits the HttpServletRequestWrapper class,
so it's Servlets version independent (2.3+).

I'm also using latest FileUpload codebase from the ASF public SVN.

A brief description:

 * <p>This class is "multipart" extension to servlets'
 * <code>HttpServletRequest</code>, each instance wraps a genuine 
request object
 * containing multipart data and acts as a traditional POST request allowing
 * access to parameters in standarized way.</p>

.. the other details in the class file.

An usage example:

        File tmp = new File(System.getProperty(""));
        FileItemFactory fif = new DiskFileItemFactory(1*1024*1024,tmp);
        ServletFileUpload uploader = new ServletFileUpload(fif);
        UploadHttpServletRequest request = new 

You can even integrate it with the ServletFileUpload through following 

    public UploadHttpServletRequest wrapRequest(HttpServletRequest request)
            throws FileUploadException {
        return new UploadHttpServletRequest(request, this);
    //wrapRequest, convertRequest, extendRequest or whatever

Here are few use cases:
 * <ul>
 *  <li> wrap a request at the begining of servlet's doPost and use
 *     the extended request</li>
 *  <li> wrap a request in a servlet filter, so all following servlets 
will be given
 *    the extended request with no code change, casting is necessary
 *   only in code processing files</li>
 *  <li> wrap before RequestDispatcher invocation, this is similar
      to the filter use case </li>
 * </ul>

... thus wrapper gains code reuse and reduces current code modifications.
I think this class can come in useful to many developers (as it was for me),
so it is my contribution to the Commons FileUpload component project.
The class and examples on this mail are licensed under the Apache License.

I will make some test cases for this class if you decide it's worth to
add to the project.

Best regards,
Piotr Gaertig

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message