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
Modifier and TypeFieldDescriptionstatic final int
Defines the internal buffer size used during streaming operations.protected int
Specifies the buffer size to use during streaming.protected String
Defines 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 Long
Specifies the maximum number of files in one request.protected Long
Specifies the maximum size per a file in the request.protected Long
Specifies the maximum size of the entire request.protected Long
Specifies the maximum size of all the uploaded files.protected Long
Specifies the maximum length of a string parameter in a multipart request.Map between non-file fields and values.protected static final String
protected Map<String,
List<UploadedFile>> Map between file fields and file data. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected LocalizedMessage
buildErrorMessage
(Class<? extends Throwable> exceptionClass, String defaultMessage, Object[] args) Build error message.void
cleanUp()
Cleans up all uploaded file, should be called at the end of requestprotected abstract org.apache.commons.fileupload2.jakarta.servlet6.JakartaServletDiskFileUpload
createJakartaFileUpload
(Charset charset, Path saveDir) Creates an instance ofJakartaServletDiskFileUpload
used by the parser to extract uploaded filesprotected boolean
exceedsMaxStringLength
(String fieldName, String fieldValue) protected String
getCanonicalName
(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 aUploadedFile
object 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.void
Processes the upload.protected org.apache.commons.fileupload2.jakarta.servlet6.JakartaServletDiskFileUpload
prepareServletFileUpload
(Charset charset, Path saveDir) protected abstract void
processUpload
(jakarta.servlet.http.HttpServletRequest request, String saveDir) Process the request extract file upload dataprotected Charset
readCharsetEncoding
(jakarta.servlet.http.HttpServletRequest request) protected String
sanitizeNewlines
(String before) void
setBufferSize
(String bufferSize) void
setDefaultEncoding
(String enc) void
setMaxFiles
(String maxFiles) void
setMaxFileSize
(String maxFileSize) void
setMaxSize
(String maxSize) void
setMaxSizeOfFiles
(String maxSizeOfFiles) void
setMaxStringLength
(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
- currentHttpServletRequest
saveDir
- 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 ofJakartaServletDiskFileUpload
used 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:
parse
in 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:MultiPartRequest
Returns 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:
getErrors
in interfaceMultiPartRequest
- Returns:
- a list of Strings that represent various errors during parsing
-
getFileParameterNames
Description copied from interface:MultiPartRequest
Returns an enumeration of the parameter names for uploaded files- Specified by:
getFileParameterNames
in interfaceMultiPartRequest
- Returns:
- an enumeration of the parameter names for uploaded files
-
getContentType
Description copied from interface:MultiPartRequest
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.- Specified by:
getContentType
in 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:MultiPartRequest
Returns aUploadedFile
object for the filename specified or null if no files are associated with the given field name.- Specified by:
getFile
in interfaceMultiPartRequest
- Parameters:
fieldName
- input field name- Returns:
- a UploadedFile[] object for files associated with the specified input field name
-
getFileNames
Description copied from interface:MultiPartRequest
Returns a String[] of file names for files associated with the specified input field name- Specified by:
getFileNames
in 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:MultiPartRequest
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.- Specified by:
getFilesystemName
in 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:MultiPartRequest
Returns the specified request parameter.- Specified by:
getParameter
in 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:MultiPartRequest
Returns an enumeration of String parameter names.- Specified by:
getParameterNames
in interfaceMultiPartRequest
- Returns:
- an enumeration of String parameter names.
-
getParameterValues
Description copied from interface:MultiPartRequest
Returns 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:
getParameterValues
in 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:MultiPartRequest
Cleans up all uploaded file, should be called at the end of request- Specified by:
cleanUp
in interfaceMultiPartRequest
-