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 Summary
FieldsModifier 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 Summary
Constructors -
Method Summary
Modifier 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_SIZE
public static final int BUFFER_SIZEDefines the internal buffer size used during streaming operations.- See Also:
-
errors
Internal list of raised errors to be passed to the Struts2 framework. -
maxSize
Specifies the maximum size of the entire request. -
maxSizeOfFiles
Specifies the maximum size of all the uploaded files. -
maxFiles
Specifies the maximum number of files in one request. -
maxStringLength
Specifies the maximum length of a string parameter in a multipart request. -
maxFileSize
Specifies the maximum size per a file in the request. -
bufferSize
protected int bufferSizeSpecifies the buffer size to use during streaming. -
defaultEncoding
Defines default encoding to encode data from request used if not provided with request -
uploadedFiles
Map between file fields and file data. -
parameters
Map between non-file fields and values.
-
-
Constructor Details
-
AbstractMultiPartRequest
public 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.
-
processUpload
protected abstract void processUpload(jakarta.servlet.http.HttpServletRequest request, String saveDir) throws IOException Process the request extract file upload data- Parameters:
request- currentHttpServletRequestsaveDir- a temporary directory to store files- Throws:
IOException
-
readCharsetEncoding
- Parameters:
request- multipart request- Returns:
- character encoding from request or
defaultEncoding
-
createJakartaFileUpload
protected 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 requestsaveDir- a temporary folder to store uploaded files (not always needed)
-
prepareServletFileUpload
-
exceedsMaxStringLength
-
parse
public void parse(jakarta.servlet.http.HttpServletRequest request, String saveDir) throws IOException Processes the upload.- Specified by:
parsein interfaceMultiPartRequest- Parameters:
request- the servlet requestsaveDir- location of the save dir- Throws:
IOException
-
buildErrorMessage
protected LocalizedMessage buildErrorMessage(Class<? extends Throwable> exceptionClass, String defaultMessage, Object[] args) Build error message.- Parameters:
exceptionClass- a class of the exceptiondefaultMessage- a default message to useargs- arguments- Returns:
- error message
-
getCanonicalName
- Parameters:
originalFileName- file name- Returns:
- the canonical name based on the supplied filename
-
sanitizeNewlines
-
getErrors
Description 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 interfaceMultiPartRequest- Returns:
- a list of Strings that represent various errors during parsing
-
getFileParameterNames
Description copied from interface:MultiPartRequestReturns an enumeration of the parameter names for uploaded files- Specified by:
getFileParameterNamesin interfaceMultiPartRequest- Returns:
- an enumeration of the parameter names for uploaded files
-
getContentType
Description 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 interfaceMultiPartRequest- 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.
-
getFile
Description copied from interface:MultiPartRequestReturns aUploadedFileobject for the filename specified or null if no files are associated with the given field name.- Specified by:
getFilein interfaceMultiPartRequest- Parameters:
fieldName- input field name- Returns:
- a UploadedFile[] object for files associated with the specified input field name
-
getFileNames
Description copied from interface:MultiPartRequestReturns a String[] of file names for files associated with the specified input field name- Specified by:
getFileNamesin interfaceMultiPartRequest- Parameters:
fieldName- input field name- Returns:
- a String[] of file names for files associated with the specified input field name
-
getFilesystemName
Description 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 interfaceMultiPartRequest- Parameters:
fieldName- input field name- Returns:
- the file system name(s) of files associated with the given field name
-
getParameter
Description copied from interface:MultiPartRequestReturns the specified request parameter.- Specified by:
getParameterin interfaceMultiPartRequest- Parameters:
name- the name of the parameter to get- Returns:
- the parameter or null if it was not found.
-
getParameterNames
Description copied from interface:MultiPartRequestReturns an enumeration of String parameter names.- Specified by:
getParameterNamesin interfaceMultiPartRequest- Returns:
- an enumeration of String parameter names.
-
getParameterValues
Description 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 interfaceMultiPartRequest- Parameters:
name- the name of the parameter.- Returns:
- an array of all values associated with the parameter name.
-
cleanUp
public void cleanUp()Description copied from interface:MultiPartRequestCleans up all uploaded file, should be called at the end of request- Specified by:
cleanUpin interfaceMultiPartRequest
-