org.wings.session
Class MultipartRequest

java.lang.Object
  extended by javax.servlet.ServletRequestWrapper
      extended by javax.servlet.http.HttpServletRequestWrapper
          extended by org.wings.session.MultipartRequest
All Implemented Interfaces:
javax.servlet.http.HttpServletRequest, javax.servlet.ServletRequest

public final class MultipartRequest
extends javax.servlet.http.HttpServletRequestWrapper

A utility class to handle multipart/form-data requests, the kind of requests that support file uploads. This class can receive arbitrarily large files (up to an artificial limit you can set), and fairly efficiently too. And it knows and works around several browser bugs that don't know how to upload files correctly.

A client can upload files using an HTML form with the following structure. Note that not all browsers support file uploads.

 <FORM ACTION="/servlet/Handler" METHOD=POST
          ENCTYPE="multipart/form-data">
 What is your name? <INPUT TYPE=TEXT NAME=submitter> <BR>
 Which file to upload? <INPUT TYPE=FILE NAME=file> <BR>
 <INPUT TYPE=SUBMIT>
 </FORM>
 

The full file upload specification is contained in experimental RFC 1867, available at http://ds.internic.net/rfc/rfc1867.txt.

Author:
Holger Engels

Field Summary
 
Fields inherited from interface javax.servlet.http.HttpServletRequest
BASIC_AUTH, CLIENT_CERT_AUTH, DIGEST_AUTH, FORM_AUTH
 
Constructor Summary
MultipartRequest(javax.servlet.http.HttpServletRequest request)
           
MultipartRequest(javax.servlet.http.HttpServletRequest request, int maxPostSize)
           
 
Method Summary
 String getContentType(String name)
          Returns the content type of the specified file (as supplied by the client browser), or null if the file was not included in the upload.
 File getFile(String name)
          Returns a File object for the specified file saved on the server's filesystem, or null if the file was not included in the upload.
 String getFileId(String name)
          Returns the fileid of the specified file, or null if the file was not included in the upload.
 String getFileName(String name)
          Returns the filename of the specified file, or null if the file was not included in the upload.
 Iterator getFileNames()
          Returns the names of all the uploaded files as an Enumeration of Strings.
 Map getParameterMap()
           
 Enumeration getParameterNames()
          Returns the names of all the parameters as an Enumeration of Strings.
 String[] getParameterValues(String name)
           
 boolean isMultipart()
          Indicates if this class was successfully able to parse request as multipart request.
protected  void processRequest(javax.servlet.http.HttpServletRequest req)
          Parses passed request and stores contained parameters.
protected  void putParameter(String name, String value)
          Stores a parameter identified in this request.
protected  void setException(String param, Exception ex)
          Store exception as request parameter.
 
Methods inherited from class javax.servlet.http.HttpServletRequestWrapper
getAuthType, getContextPath, getCookies, getDateHeader, getHeader, getHeaderNames, getHeaders, getIntHeader, getMethod, getPathInfo, getPathTranslated, getQueryString, getRemoteUser, getRequestedSessionId, getRequestURI, getRequestURL, getServletPath, getSession, getSession, getUserPrincipal, isRequestedSessionIdFromCookie, isRequestedSessionIdFromUrl, isRequestedSessionIdFromURL, isRequestedSessionIdValid, isUserInRole
 
Methods inherited from class javax.servlet.ServletRequestWrapper
getAttribute, getAttributeNames, getCharacterEncoding, getContentLength, getContentType, getInputStream, getLocalAddr, getLocale, getLocales, getLocalName, getLocalPort, getParameter, getProtocol, getReader, getRealPath, getRemoteAddr, getRemoteHost, getRemotePort, getRequest, getRequestDispatcher, getScheme, getServerName, getServerPort, isSecure, removeAttribute, setAttribute, setCharacterEncoding, setRequest
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.servlet.ServletRequest
getAttribute, getAttributeNames, getCharacterEncoding, getContentLength, getContentType, getInputStream, getLocalAddr, getLocale, getLocales, getLocalName, getLocalPort, getParameter, getProtocol, getReader, getRealPath, getRemoteAddr, getRemoteHost, getRemotePort, getRequestDispatcher, getScheme, getServerName, getServerPort, isSecure, removeAttribute, setAttribute, setCharacterEncoding
 

Constructor Detail

MultipartRequest

public MultipartRequest(javax.servlet.http.HttpServletRequest request)
                 throws IOException
Parameters:
request - the servlet request
Throws:
IOException - if the uploaded content is larger than 1 Megabyte or there's a problem reading or parsing the request

MultipartRequest

public MultipartRequest(javax.servlet.http.HttpServletRequest request,
                        int maxPostSize)
                 throws IOException
Parameters:
request - the servlet request
maxPostSize - the maximum size of the POST content
Throws:
IOException - if the uploaded content is larger than maxPostSize or there's a problem reading or parsing the request
Method Detail

getParameterNames

public Enumeration getParameterNames()
Returns the names of all the parameters as an Enumeration of Strings. It returns an empty Enumeration if there are no parameters.

Specified by:
getParameterNames in interface javax.servlet.ServletRequest
Overrides:
getParameterNames in class javax.servlet.ServletRequestWrapper
Returns:
the names of all the parameters as an Enumeration of Strings

getFileNames

public Iterator getFileNames()
Returns the names of all the uploaded files as an Enumeration of Strings. It returns an empty Enumeration if there are no uploaded files. Each file name is the name specified by the form, not by the user.

Returns:
the names of all the uploaded files as an Enumeration of Strings

getParameterValues

public String[] getParameterValues(String name)
Specified by:
getParameterValues in interface javax.servlet.ServletRequest
Overrides:
getParameterValues in class javax.servlet.ServletRequestWrapper

getParameterMap

public Map getParameterMap()
Specified by:
getParameterMap in interface javax.servlet.ServletRequest
Overrides:
getParameterMap in class javax.servlet.ServletRequestWrapper

getFileName

public String getFileName(String name)
Returns the filename of the specified file, or null if the file was not included in the upload. The filename is the name specified by the user. It is not the name under which the file is actually saved.

Parameters:
name - the file name
Returns:
the filesystem name of the file

getFileId

public String getFileId(String name)
Returns the fileid of the specified file, or null if the file was not included in the upload. The fileid is the name under which the file is saved in the filesystem.

Parameters:
name - the file name
Returns:
the filesystem name of the file

getContentType

public String getContentType(String name)
Returns the content type of the specified file (as supplied by the client browser), or null if the file was not included in the upload.

Parameters:
name - the file name
Returns:
the content type of the file

getFile

public File getFile(String name)
Returns a File object for the specified file saved on the server's filesystem, or null if the file was not included in the upload.

Parameters:
name - the file name
Returns:
a File object for the named file

isMultipart

public final boolean isMultipart()
Indicates if this class was successfully able to parse request as multipart request.


setException

protected void setException(String param,
                            Exception ex)
Store exception as request parameter.


processRequest

protected void processRequest(javax.servlet.http.HttpServletRequest req)
                       throws IOException
Parses passed request and stores contained parameters.

Throws:
IOException - On unrecoverable parsing bugs due to old Tomcat version.

putParameter

protected void putParameter(String name,
                            String value)
Stores a parameter identified in this request.



wingS Swings ;-)