public class

MultipartRequest

extends Object
java.lang.Object
   ↳ com.microstrategy.web.platform.MultipartRequest

Class Overview

The class MultipartRequest allows servlets to process file uploads. Formally speaking, it supports requests with multipart/form-data content type. This content type is used to submit forms that has the multipart/form-data encoding type, which is used to upload files and is not directly supported by the Servlet Specification.

The class MultipartRequest takes an HttpServletRequest, parses it extracting any parameters and files and exposes them through an API. Notice that the class MultipartRequest supports regular requests as well so that it is possible to process any request using a single API.

File parameters are passed as MultipartRequest.File objects, which encapsulates the file's properties and contents. Regular parameters are passed as String objects.

Notice that the class MultipartRequest supports a simplified version of MIME entity headers, specifically it does not support character escaping, header wrapping, comments nor any extensions. Also, it assumes that parameters are sent using the western (iso-8859-1) character set. Finally, it does not support multipart/mixed parts, which are used to send multiple files as a single parameter, and it assumes that the request is well formed, so no error checking is performed.

Summary

Nested Classes
class MultipartRequest.File The class MultipartRequest.File encapsulates uploaded files. 
Public Constructors
MultipartRequest()
Creates a new, empty MultipartRequest with a default expiration date.
Public Methods
void copyParameters(ContainerStringCollection params)
Copies all parameters from a request to this MultipartRequest.
static MultipartRequest get(int ID)
Gets a MultipartRequest object given its ID.
long getExpiration()
Gets the expiration of this MultipartRequest object.
synchronized String getFile()
Gets the file being uploaded.
MultipartRequest.File getFileParameter(String name)
Convenient method that returns the value of a MultipartRequest.File parameter.
ContainerStringCollection getFormAndQueryStrings()
Returns reqest parameter strings collection
int getID()
Gets the ID of this MultipartRequest.
Object getParameter(String name)
Returns the value of a given parameter, or null if the parameter doesn't exist.
Iterator getParameterNames()
Returns an Iterator that iterates over the names of the parameters contained in this MultipartRequest.
Object[] getParameterValues(String name)
Returns an array of objects containing all of the values the given request parameter has, or null if the parameter does not exist.
synchronized int getProcessed()
Gets the number of bytes of the request's body already processed.
String getStringParameter(String name)
Convenient method that returns the value of a String parameter.
synchronized int getTotal()
Gets the total number of bytes of the request.
void parseRequest(String contentType, InputStream requestStream)
Parses a request, populating this MultipartRequest.
void release()
Releases this MultipartRequest object and all of its parameters.
void setExpiration(long expiration)
Sets the expiration date for this MultipartRequest.
synchronized void setTotal(int total)
Sets the total number of bytes of the request.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public MultipartRequest ()

Creates a new, empty MultipartRequest with a default expiration date.

Public Methods

public void copyParameters (ContainerStringCollection params)

Copies all parameters from a request to this MultipartRequest.

Parameters
params request parameters

public static MultipartRequest get (int ID)

Gets a MultipartRequest object given its ID.

Parameters
ID object ID
Returns
  • the object with the given ID or null if it doesn't exist or if it was released

public long getExpiration ()

Gets the expiration of this MultipartRequest object.

Returns
  • the expiration of this object

public synchronized String getFile ()

Gets the file being uploaded.

Returns
  • the name of the file being uploaded or an empty string if there is no file being uploaded

public MultipartRequest.File getFileParameter (String name)

Convenient method that returns the value of a MultipartRequest.File parameter. If the parameter has multiple values, returns just the first one. Use the method getParameterValues(String) to get all values.

Parameters
name name of the desired parameter
Returns
  • the value of the given parameter, casted to a MultipartRequest.File, or null if the parameter does not exist

public ContainerStringCollection getFormAndQueryStrings ()

Returns reqest parameter strings collection

Returns
  • reqest parameter strings collection

public int getID ()

Gets the ID of this MultipartRequest. Each object is guaranteed to have a unique ID.

Returns
  • the ID of this object

public Object getParameter (String name)

Returns the value of a given parameter, or null if the parameter doesn't exist. The value of the parameter is a String or a MultipartRequest.File object. If the parameter has multiple values, returns just the first one. Use the method getParameterValues(String) to get all values.

Parameters
name name of the desired parameter
Returns
  • the value of the given parameter

public Iterator getParameterNames ()

Returns an Iterator that iterates over the names of the parameters contained in this MultipartRequest. The names of the parameters are String objects.

Returns
  • the names of the parameters, as an Iterator

public Object[] getParameterValues (String name)

Returns an array of objects containing all of the values the given request parameter has, or null if the parameter does not exist. The values of the parameters are String or MultipartRequest.File objects.

Parameters
name name of the parameter desired
Returns
  • the values of the requested parameter

public synchronized int getProcessed ()

Gets the number of bytes of the request's body already processed. This method can be called by another thread.

Returns
  • number of bytes already processed

public String getStringParameter (String name)

Convenient method that returns the value of a String parameter. If the parameter has multiple values, returns just the first one. Use the method getParameterValues(String) to get all values.

Parameters
name name of the desired parameter
Returns
  • the value of the given parameter, casted to a String, or null if the parameter does not exist

public synchronized int getTotal ()

Gets the total number of bytes of the request.

Returns
  • the total number of bytes

public void parseRequest (String contentType, InputStream requestStream)

Parses a request, populating this MultipartRequest. If the content type of the request is multipart/form-data, parses it, extracting any parameters and files, populating this object.

Parameters
contentType content type
requestStream an input stream representing request to parse
Throws
IOException if an error occurs while reading the request, writing to temporary files, or if the pushback buffer is too small

public void release ()

Releases this MultipartRequest object and all of its parameters. This method should be called when this object is not needed anymore. If this object is not explicitly released before its expiration, it will be automatically released when it expires.

Throws
IOException if an error occurs while releasing the temporary files

public void setExpiration (long expiration)

Sets the expiration date for this MultipartRequest. The expiration date is specified using the same base time as the one used by the method System.currentTimeMillis().

Parameters
expiration expiration date

public synchronized void setTotal (int total)

Sets the total number of bytes of the request.

Parameters
total total number of bytes