Class AbstractMultiPartRequest
java.lang.Object
org.apache.struts2.dispatcher.multipart.AbstractMultiPartRequest
- All Implemented Interfaces:
- MultiPartRequest
- Direct Known Subclasses:
- JakartaMultiPartRequest,- JakartaStreamMultiPartRequest
Abstract class with some helper methods, it should be used
 when starting development of another implementation of 
MultiPartRequest- 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic final intDefines the internal buffer size used during streaming operations.protected intSpecifies the buffer size to use during streaming.protected StringDefines default encoding to encode data from request used if not provided with requestprotected List<LocalizedMessage>Internal list of raised errors to be passed to the Struts2 framework.protected LongSpecifies the maximum number of files in one request.protected LongSpecifies the maximum size per a file in the request.protected LongSpecifies the maximum size of the entire request.protected LongSpecifies the maximum size of all the uploaded files.protected LongSpecifies the maximum length of a string parameter in a multipart request.Map between non-file fields and values.protected static final Stringprotected Map<String,List<UploadedFile>> Map between file fields and file data.
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionprotected LocalizedMessagebuildErrorMessage(Class<? extends Throwable> exceptionClass, String defaultMessage, Object[] args) Build error message.voidcleanUp()Cleans up all uploaded file, should be called at the end of requestprotected abstract org.apache.commons.fileupload2.jakarta.servlet6.JakartaServletDiskFileUploadcreateJakartaFileUpload(Charset charset, Path saveDir) Creates an instance ofJakartaServletDiskFileUploadused by the parser to extract uploaded filesprotected booleanexceedsMaxStringLength(String fieldName, String fieldValue) protected StringgetCanonicalName(String originalFileName) String[]getContentType(String fieldName) Returns the content type(s) of the file(s) associated with the specified field name (as supplied by the client browser), or null if no files are associated with the given field name.Returns a list of error messages that may have occurred while processing the request.Returns aUploadedFileobject for the filename specified or null if no files are associated with the given field name.String[]getFileNames(String fieldName) Returns a String[] of file names for files associated with the specified input field nameReturns an enumeration of the parameter names for uploaded filesString[]getFilesystemName(String fieldName) Returns the file system name(s) of files associated with the given field name or null if no files are associated with the given field name.getParameter(String name) Returns the specified request parameter.Returns an enumeration of String parameter names.String[]getParameterValues(String name) Returns a list of all parameter values associated with a parameter name.voidProcesses the upload.protected org.apache.commons.fileupload2.jakarta.servlet6.JakartaServletDiskFileUploadprepareServletFileUpload(Charset charset, Path saveDir) protected abstract voidprocessUpload(jakarta.servlet.http.HttpServletRequest request, String saveDir) Process the request extract file upload dataprotected CharsetreadCharsetEncoding(jakarta.servlet.http.HttpServletRequest request) protected StringsanitizeNewlines(String before) voidsetBufferSize(String bufferSize) voidsetDefaultEncoding(String enc) voidsetMaxFiles(String maxFiles) voidsetMaxFileSize(String maxFileSize) voidsetMaxSize(String maxSize) voidsetMaxSizeOfFiles(String maxSizeOfFiles) voidsetMaxStringLength(String maxStringLength) 
- 
Field Details- 
STRUTS_MESSAGES_UPLOAD_ERROR_PARAMETER_TOO_LONG_KEY- See Also:
 
- 
BUFFER_SIZEpublic static final int BUFFER_SIZEDefines the internal buffer size used during streaming operations.- See Also:
 
- 
errorsInternal list of raised errors to be passed to the Struts2 framework.
- 
maxSizeSpecifies the maximum size of the entire request.
- 
maxSizeOfFilesSpecifies the maximum size of all the uploaded files.
- 
maxFilesSpecifies the maximum number of files in one request.
- 
maxStringLengthSpecifies the maximum length of a string parameter in a multipart request.
- 
maxFileSizeSpecifies the maximum size per a file in the request.
- 
bufferSizeprotected int bufferSizeSpecifies the buffer size to use during streaming.
- 
defaultEncodingDefines default encoding to encode data from request used if not provided with request
- 
uploadedFilesMap between file fields and file data.
- 
parametersMap between non-file fields and values.
 
- 
- 
Constructor Details- 
AbstractMultiPartRequestpublic AbstractMultiPartRequest()
 
- 
- 
Method Details- 
setBufferSize- Parameters:
- bufferSize- Sets the buffer size to be used.
 
- 
setDefaultEncoding
- 
setMaxSize- Parameters:
- maxSize- Injects the Struts multipart request maximum size.
 
- 
setMaxSizeOfFiles- Parameters:
- maxSizeOfFiles- Injects the Struts maximum size of all uploaded files.
 
- 
setMaxFiles- Parameters:
- maxFiles- Injects the Struts maximum size of an individual file uploaded.
 
- 
setMaxFileSize- Parameters:
- maxFileSize- Injects the Struts maximum number of files, which can be uploaded.
 
- 
setMaxStringLength- Parameters:
- maxStringLength- Injects the Struts maximum size of single form field.
 
- 
processUploadprotected abstract void processUpload(jakarta.servlet.http.HttpServletRequest request, String saveDir) throws IOException Process the request extract file upload data- Parameters:
- request- current- HttpServletRequest
- saveDir- a temporary directory to store files
- Throws:
- IOException
 
- 
readCharsetEncoding- Parameters:
- request- multipart request
- Returns:
- character encoding from request or defaultEncoding
 
- 
createJakartaFileUploadprotected abstract org.apache.commons.fileupload2.jakarta.servlet6.JakartaServletDiskFileUpload createJakartaFileUpload(Charset charset, Path saveDir) Creates an instance ofJakartaServletDiskFileUploadused by the parser to extract uploaded files- Parameters:
- charset- used charset from incoming request
- saveDir- a temporary folder to store uploaded files (not always needed)
 
- 
prepareServletFileUpload
- 
exceedsMaxStringLength
- 
parsepublic void parse(jakarta.servlet.http.HttpServletRequest request, String saveDir) throws IOException Processes the upload.- Specified by:
- parsein interface- MultiPartRequest
- Parameters:
- request- the servlet request
- saveDir- location of the save dir
- Throws:
- IOException
 
- 
buildErrorMessageprotected LocalizedMessage buildErrorMessage(Class<? extends Throwable> exceptionClass, String defaultMessage, Object[] args) Build error message.- Parameters:
- exceptionClass- a class of the exception
- defaultMessage- a default message to use
- args- arguments
- Returns:
- error message
 
- 
getCanonicalName- Parameters:
- originalFileName- file name
- Returns:
- the canonical name based on the supplied filename
 
- 
sanitizeNewlines
- 
getErrorsDescription copied from interface:MultiPartRequestReturns a list of error messages that may have occurred while processing the request. If there are no errors, an empty list is returned. If the underlying implementation (ie: cos, jakarta, etc) cannot support providing these errors, an empty list is also returned. This list of errors is reported back to theMultiPartRequestWrapper's errors field.- Specified by:
- getErrorsin interface- MultiPartRequest
- Returns:
- a list of Strings that represent various errors during parsing
 
- 
getFileParameterNamesDescription copied from interface:MultiPartRequestReturns an enumeration of the parameter names for uploaded files- Specified by:
- getFileParameterNamesin interface- MultiPartRequest
- Returns:
- an enumeration of the parameter names for uploaded files
 
- 
getContentTypeDescription copied from interface:MultiPartRequestReturns the content type(s) of the file(s) associated with the specified field name (as supplied by the client browser), or null if no files are associated with the given field name.- Specified by:
- getContentTypein interface- MultiPartRequest
- Parameters:
- fieldName- input field name
- Returns:
- an array of content encoding for the specified input field name or null if no content type was specified.
 
- 
getFileDescription copied from interface:MultiPartRequestReturns aUploadedFileobject for the filename specified or null if no files are associated with the given field name.- Specified by:
- getFilein interface- MultiPartRequest
- Parameters:
- fieldName- input field name
- Returns:
- a UploadedFile[] object for files associated with the specified input field name
 
- 
getFileNamesDescription copied from interface:MultiPartRequestReturns a String[] of file names for files associated with the specified input field name- Specified by:
- getFileNamesin interface- MultiPartRequest
- Parameters:
- fieldName- input field name
- Returns:
- a String[] of file names for files associated with the specified input field name
 
- 
getFilesystemNameDescription copied from interface:MultiPartRequestReturns the file system name(s) of files associated with the given field name or null if no files are associated with the given field name.- Specified by:
- getFilesystemNamein interface- MultiPartRequest
- Parameters:
- fieldName- input field name
- Returns:
- the file system name(s) of files associated with the given field name
 
- 
getParameterDescription copied from interface:MultiPartRequestReturns the specified request parameter.- Specified by:
- getParameterin interface- MultiPartRequest
- Parameters:
- name- the name of the parameter to get
- Returns:
- the parameter or null if it was not found.
 
- 
getParameterNamesDescription copied from interface:MultiPartRequestReturns an enumeration of String parameter names.- Specified by:
- getParameterNamesin interface- MultiPartRequest
- Returns:
- an enumeration of String parameter names.
 
- 
getParameterValuesDescription copied from interface:MultiPartRequestReturns a list of all parameter values associated with a parameter name. If there is only one parameter value per name the resulting array will be of length 1. If the parameter doesn't exist, null should be returned instead of empty array.- Specified by:
- getParameterValuesin interface- MultiPartRequest
- Parameters:
- name- the name of the parameter.
- Returns:
- an array of all values associated with the parameter name.
 
- 
cleanUppublic void cleanUp()Description copied from interface:MultiPartRequestCleans up all uploaded file, should be called at the end of request- Specified by:
- cleanUpin interface- MultiPartRequest
 
 
-