Class MultipartRequest
- java.lang.Object
-
- com.microstrategy.web.platform.MultipartRequest
-
public class MultipartRequest extends java.lang.Object
The classMultipartRequest
allows servlets to process file uploads. Formally speaking, it supports requests withmultipart/form-data
content type. This content type is used to submit forms that has themultipart/form-data
encoding type, which is used to upload files and is not directly supported by the Servlet Specification.The class
MultipartRequest
takes anHttpServletRequest
, parses it extracting any parameters and files and exposes them through an API. Notice that the classMultipartRequest
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 asString
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 supportmultipart/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.- Since:
- MicroStrategy Web 7.3.1 or earlier
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
MultipartRequest.File
The classMultipartRequest.File
encapsulates uploaded files.
-
Constructor Summary
Constructors Constructor Description MultipartRequest()
Creates a new, emptyMultipartRequest
with a default expiration date.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
copyParameters(ContainerStringCollection params)
Copies all parameters from a request to thisMultipartRequest
.static MultipartRequest
get(int ID)
Gets aMultipartRequest
object given itsID
.long
getExpiration()
Gets the expiration of thisMultipartRequest
object.java.lang.String
getFile()
Gets the file being uploaded.MultipartRequest.File
getFileParameter(java.lang.String name)
Convenient method that returns the value of aMultipartRequest.File
parameter.ContainerStringCollection
getFormAndQueryStrings()
Returns reqest parameter strings collectionint
getID()
Gets theID
of thisMultipartRequest
.java.lang.Object
getParameter(java.lang.String name)
Returns the value of a given parameter, ornull
if the parameter doesn't exist.java.util.Iterator
getParameterNames()
Returns anIterator
that 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, ornull
if the parameter does not exist.int
getProcessed()
Gets the number of bytes of the request's body already processed.java.lang.String
getStringParameter(java.lang.String name)
Convenient method that returns the value of aString
parameter.int
getTotal()
Gets the total number of bytes of the request.void
parseRequest(java.lang.String contentType, java.io.InputStream requestStream)
Parses a request, populating thisMultipartRequest
.void
release()
Releases thisMultipartRequest
object and all of its parameters.void
setExpiration(long expiration)
Sets the expiration date for thisMultipartRequest
.void
setTotal(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.IOException
Parses 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 aMultipartRequest
object given itsID
.- Parameters:
ID
- objectID
- Returns:
- the object with the given
ID
ornull
if it doesn't exist or if it was released
-
getExpiration
public long getExpiration()
Gets the expiration of thisMultipartRequest
object.- 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.File
parameter. 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
, ornull
if the parameter does not exist
-
getID
public int getID()
Gets theID
of thisMultipartRequest
. Each object is guaranteed to have a uniqueID
.- Returns:
- the
ID
of this object
-
getParameter
public java.lang.Object getParameter(java.lang.String name)
Returns the value of a given parameter, ornull
if the parameter doesn't exist. The value of the parameter is aString
or aMultipartRequest.File
object. 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 anIterator
that iterates over the names of the parameters contained in thisMultipartRequest
. The names of the parameters areString
objects.- 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, ornull
if the parameter does not exist. The values of the parameters areString
orMultipartRequest.File
objects.- 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 aString
parameter. 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
, ornull
if 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.IOException
Releases thisMultipartRequest
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:
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
-
-