Class MultipartRequest
- java.lang.Object
-
- com.microstrategy.web.platform.MultipartRequest
-
public class MultipartRequest extends java.lang.ObjectThe classMultipartRequestallows servlets to process file uploads. Formally speaking, it supports requests withmultipart/form-datacontent type. This content type is used to submit forms that has themultipart/form-dataencoding type, which is used to upload files and is not directly supported by the Servlet Specification.The class
MultipartRequesttakes anHttpServletRequest, parses it extracting any parameters and files and exposes them through an API. Notice that the classMultipartRequestsupports regular requests as well so that it is possible to process any request using a single API.File parameters are passed as
MultipartRequest.Fileobjects, which encapsulates the file's properties and contents. Regular parameters are passed asStringobjects.Notice that the class
MultipartRequestsupports 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 supportmultipart/mixedparts, 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.- Since:
- MicroStrategy Web 7.3.1 or earlier
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classMultipartRequest.FileThe classMultipartRequest.Fileencapsulates uploaded files.
-
Constructor Summary
Constructors Constructor Description MultipartRequest()Creates a new, emptyMultipartRequestwith a default expiration date.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcopyParameters(ContainerStringCollection params)Copies all parameters from a request to thisMultipartRequest.static MultipartRequestget(int ID)Gets aMultipartRequestobject given itsID.longgetExpiration()Gets the expiration of thisMultipartRequestobject.java.lang.StringgetFile()Gets the file being uploaded.MultipartRequest.FilegetFileParameter(java.lang.String name)Convenient method that returns the value of aMultipartRequest.Fileparameter.ContainerStringCollectiongetFormAndQueryStrings()Returns reqest parameter strings collectionintgetID()Gets theIDof thisMultipartRequest.java.lang.ObjectgetParameter(java.lang.String name)Returns the value of a given parameter, ornullif the parameter doesn't exist.java.util.IteratorgetParameterNames()Returns anIteratorthat iterates over the names of the parameters contained in thisMultipartRequest.java.lang.Object[]getParameterValues(java.lang.String name)Returns an array of objects containing all of the values the given request parameter has, ornullif the parameter does not exist.intgetProcessed()Gets the number of bytes of the request's body already processed.java.lang.StringgetStringParameter(java.lang.String name)Convenient method that returns the value of aStringparameter.intgetTotal()Gets the total number of bytes of the request.voidparseRequest(java.lang.String contentType, java.io.InputStream requestStream)Parses a request, populating thisMultipartRequest.voidrelease()Releases thisMultipartRequestobject and all of its parameters.voidsetExpiration(long expiration)Sets the expiration date for thisMultipartRequest.voidsetTotal(int total)Sets the total number of bytes of the request.
-
-
-
Method Detail
-
copyParameters
public void copyParameters(ContainerStringCollection params)
Copies all parameters from a request to thisMultipartRequest.- Parameters:
params- request parameters
-
parseRequest
public void parseRequest(java.lang.String contentType, java.io.InputStream requestStream) throws java.io.IOExceptionParses a request, populating thisMultipartRequest. If the content type of the request ismultipart/form-data, parses it, extracting any parameters and files, populating this object.- Parameters:
contentType- content typerequestStream- an input stream representing request to parse- Throws:
java.io.IOException- if an error occurs while reading the request, writing to temporary files, or if the pushback buffer is too small
-
setTotal
public void setTotal(int total)
Sets the total number of bytes of the request.- Parameters:
total- total number of bytes
-
get
public static MultipartRequest get(int ID)
Gets aMultipartRequestobject given itsID.- Parameters:
ID- objectID- Returns:
- the object with the given
IDornullif it doesn't exist or if it was released
-
getExpiration
public long getExpiration()
Gets the expiration of thisMultipartRequestobject.- Returns:
- the expiration of this object
-
getFile
public java.lang.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
-
getFileParameter
public MultipartRequest.File getFileParameter(java.lang.String name)
Convenient method that returns the value of aMultipartRequest.Fileparameter. If the parameter has multiple values, returns just the first one. Use the methodgetParameterValues(String)to get all values.- Parameters:
name- name of the desired parameter- Returns:
- the value of the given parameter, casted to a
MultipartRequest.File, ornullif the parameter does not exist
-
getID
public int getID()
Gets theIDof thisMultipartRequest. Each object is guaranteed to have a uniqueID.- Returns:
- the
IDof this object
-
getParameter
public java.lang.Object getParameter(java.lang.String name)
Returns the value of a given parameter, ornullif the parameter doesn't exist. The value of the parameter is aStringor aMultipartRequest.Fileobject. If the parameter has multiple values, returns just the first one. Use the methodgetParameterValues(String)to get all values.- Parameters:
name- name of the desired parameter- Returns:
- the value of the given parameter
-
getParameterNames
public java.util.Iterator getParameterNames()
Returns anIteratorthat iterates over the names of the parameters contained in thisMultipartRequest. The names of the parameters areStringobjects.- Returns:
- the names of the parameters, as an
Iterator
-
getParameterValues
public java.lang.Object[] getParameterValues(java.lang.String name)
Returns an array of objects containing all of the values the given request parameter has, ornullif the parameter does not exist. The values of the parameters areStringorMultipartRequest.Fileobjects.- Parameters:
name- name of the parameter desired- Returns:
- the values of the requested parameter
-
getProcessed
public 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
-
getStringParameter
public java.lang.String getStringParameter(java.lang.String name)
Convenient method that returns the value of aStringparameter. If the parameter has multiple values, returns just the first one. Use the methodgetParameterValues(String)to get all values.- Parameters:
name- name of the desired parameter- Returns:
- the value of the given parameter, casted to a
String, ornullif the parameter does not exist
-
getTotal
public int getTotal()
Gets the total number of bytes of the request.- Returns:
- the total number of bytes
-
release
public void release() throws java.io.IOExceptionReleases thisMultipartRequestobject 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:
java.io.IOException- if an error occurs while releasing the temporary files
-
setExpiration
public void setExpiration(long expiration)
Sets the expiration date for thisMultipartRequest. The expiration date is specified using the same base time as the one used by the methodSystem.currentTimeMillis().- Parameters:
expiration- expiration date
-
getFormAndQueryStrings
public ContainerStringCollection getFormAndQueryStrings()
Returns reqest parameter strings collection- Returns:
- reqest parameter strings collection
-
-