Class DefaultUploadService
- All Implemented Interfaces:
org.apache.avalon.framework.activity.Initializable
,org.apache.avalon.framework.configuration.Configurable
,org.apache.avalon.framework.context.Contextualizable
,org.apache.avalon.framework.logger.LogEnabled
,UploadService
This class is an implementation of UploadService
.
Files will be stored in temporary disk storage on in memory, depending on request size,
and will be available from the
org.apache.fulcrum.util.parser.ParameterParser
as
org.apache.commons.fileupload.FileItem
objects.
This implementation of UploadService
handles multiple files per single html
form, sent using multipart/form-data encoding type, as specified by RFC 1867. Use
org.apache.fulcrum.parser.ParameterParser#getFileItems(String)
to acquire
an array of org.apache.commons.fileupload.FileItem
objects associated with
given html form.
- Version:
- $Id$
- Author:
- Rafal Krzewski, Daniel Rall, Jason van Zyl
-
Field Summary
Fields inherited from interface org.apache.fulcrum.upload.UploadService
CONTENT_DISPOSITION, CONTENT_TYPE, FORM_DATA, HEADER_ENCODING_DEFAULT, HEADER_ENCODING_KEY, MIXED, MULTIPART, MULTIPART_FORM_DATA, MULTIPART_MIXED, REPOSITORY_DEFAULT, REPOSITORY_KEY, REPOSITORY_PARAMETER, ROLE, SIZE_MAX_DEFAULT, SIZE_MAX_KEY, SIZE_THRESHOLD_DEFAULT, SIZE_THRESHOLD_KEY
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
configure
(org.apache.avalon.framework.configuration.Configuration conf) Avalon component lifecycle methodvoid
contextualize
(org.apache.avalon.framework.context.Context context) Avalon component lifecycle methodorg.apache.commons.fileupload2.jakarta.servlet6.JakartaServletFileUpload
getDefaultFileUpload
(jakarta.servlet.http.HttpServletRequest req, org.apache.commons.fileupload2.core.DiskFileItemFactory factory) Follows RFC 1867long
The maximum number of files allowed per request.long
The maximum allowed size of a sinlge file uploadRetrieves the value of theheaderEncoding
property ofUploadService
.org.apache.commons.fileupload2.core.FileItemInputIterator
getItemIterator
(jakarta.servlet.http.HttpServletRequest req) Processes an RFC 1867 compliantmultipart/form-data
stream.The location used to temporarily store files that are larger than the size threshold.long
The maximum allowed upload sizelong
The threshold beyond which files are written directly to disk.void
Avalon component lifecycle method Initializes the service.boolean
isMultipart
(jakarta.servlet.http.HttpServletRequest req) Utility method that determines whether the request contains multipart content.List
<org.apache.commons.fileupload2.core.FileItem> parseRequest
(jakarta.servlet.http.HttpServletRequest req) Parses a RFC 1867 compliantmultipart/form-data
stream.List
<org.apache.commons.fileupload2.core.FileItem> parseRequest
(jakarta.servlet.http.HttpServletRequest req, int sizeThreshold, int sizeMax, String path) Parses a RFC 1867 compliantmultipart/form-data
stream.protected List
<org.apache.commons.fileupload2.core.FileItem> parseRequest
(jakarta.servlet.http.HttpServletRequest req, int sizeMax, org.apache.commons.fileupload2.core.DiskFileItemFactory factory) Parses a RFC 1867 compliantmultipart/form-data
stream.List
<org.apache.commons.fileupload2.core.FileItem> parseRequest
(jakarta.servlet.http.HttpServletRequest req, String path) Parses a RFC 1867 compliantmultipart/form-data
stream.void
setFileCountMax
(int fileCountMax) void
setFileSizeMax
(long fileSizeMax) Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
-
Constructor Details
-
DefaultUploadService
public DefaultUploadService()
-
-
Method Details
-
getSizeMax
public long getSizeMax()The maximum allowed upload size- Specified by:
getSizeMax
in interfaceUploadService
- Returns:
- The maximum upload size.
-
getSizeThreshold
public long getSizeThreshold()The threshold beyond which files are written directly to disk.- Specified by:
getSizeThreshold
in interfaceUploadService
- Returns:
- The threshold beyond which files are written directly to disk.
-
getRepository
The location used to temporarily store files that are larger than the size threshold.- Specified by:
getRepository
in interfaceUploadService
- Returns:
- The repository.
-
getHeaderEncoding
Description copied from interface:UploadService
Retrieves the value of the
headerEncoding
property ofUploadService
.- Specified by:
getHeaderEncoding
in interfaceUploadService
- Returns:
- Returns the headerEncoding.
-
getDefaultFileUpload
public org.apache.commons.fileupload2.jakarta.servlet6.JakartaServletFileUpload getDefaultFileUpload(jakarta.servlet.http.HttpServletRequest req, org.apache.commons.fileupload2.core.DiskFileItemFactory factory) Follows RFC 1867- Parameters:
req
-factory
-- Returns:
- a spec compliant servlet
- Throws:
org.apache.avalon.framework.service.ServiceException
-
parseRequest
public List<org.apache.commons.fileupload2.core.FileItem> parseRequest(jakarta.servlet.http.HttpServletRequest req) throws org.apache.avalon.framework.service.ServiceException Parses a RFC 1867 compliant
multipart/form-data
stream.- Specified by:
parseRequest
in interfaceUploadService
- Parameters:
req
- The servlet request to be parsed.- Returns:
- list of file items
- Throws:
org.apache.avalon.framework.service.ServiceException
- Problems reading/parsing the request or storing the uploaded file(s).
-
parseRequest
public List<org.apache.commons.fileupload2.core.FileItem> parseRequest(jakarta.servlet.http.HttpServletRequest req, String path) throws org.apache.avalon.framework.service.ServiceException Parses a RFC 1867 compliant
multipart/form-data
stream.- Specified by:
parseRequest
in interfaceUploadService
- Parameters:
req
- The servlet request to be parsed.path
- The location where the files should be stored.- Returns:
- List of FileItem parts
- Throws:
org.apache.avalon.framework.service.ServiceException
- Problems reading/parsing the request or storing the uploaded file(s).
-
parseRequest
public List<org.apache.commons.fileupload2.core.FileItem> parseRequest(jakarta.servlet.http.HttpServletRequest req, int sizeThreshold, int sizeMax, String path) throws org.apache.avalon.framework.service.ServiceException Parses a RFC 1867 compliant
multipart/form-data
stream.- Specified by:
parseRequest
in interfaceUploadService
- Parameters:
req
- The servlet request to be parsed.sizeThreshold
- the max size in bytes to be stored in memorysizeMax
- the maximum allowed upload size in bytespath
- The location where the files should be stored.- Returns:
- list of file items
- Throws:
org.apache.avalon.framework.service.ServiceException
- Problems reading/parsing the request or storing the uploaded file(s).
-
parseRequest
protected List<org.apache.commons.fileupload2.core.FileItem> parseRequest(jakarta.servlet.http.HttpServletRequest req, int sizeMax, org.apache.commons.fileupload2.core.DiskFileItemFactory factory) throws org.apache.avalon.framework.service.ServiceException Parses a RFC 1867 compliant
multipart/form-data
stream.- Parameters:
req
- The servlet request to be parsed.sizeMax
- the maximum allowed upload size in bytesfactory
- the file item factory to use- Returns:
- list of file items
- Throws:
org.apache.avalon.framework.service.ServiceException
- Problems reading/parsing the request or storing the uploaded file(s).
-
getItemIterator
public org.apache.commons.fileupload2.core.FileItemInputIterator getItemIterator(jakarta.servlet.http.HttpServletRequest req) throws org.apache.avalon.framework.service.ServiceException Processes an RFC 1867 compliantmultipart/form-data
stream.- Specified by:
getItemIterator
in interfaceUploadService
- Parameters:
req
- The servlet request to be parsed.- Returns:
- An iterator to instances of
FileItemStream
parsed from the request, in the order that they were transmitted. - Throws:
org.apache.avalon.framework.service.ServiceException
- if there are problems reading/parsing the request or storing files. This may also be a network error while communicating with the client or a problem while storing the uploaded content.
-
isMultipart
public boolean isMultipart(jakarta.servlet.http.HttpServletRequest req) Utility method that determines whether the request contains multipart content.- Specified by:
isMultipart
in interfaceUploadService
- Parameters:
req
- The servlet request to be evaluated. Must be non-null.- Returns:
true
if the request is multipart;false
otherwise.
-
configure
public void configure(org.apache.avalon.framework.configuration.Configuration conf) Avalon component lifecycle method- Specified by:
configure
in interfaceorg.apache.avalon.framework.configuration.Configurable
-
initialize
Avalon component lifecycle method Initializes the service. This method processes the repository path, to make it relative to the web application root, if necessary- Specified by:
initialize
in interfaceorg.apache.avalon.framework.activity.Initializable
- Throws:
Exception
-
contextualize
public void contextualize(org.apache.avalon.framework.context.Context context) throws org.apache.avalon.framework.context.ContextException Avalon component lifecycle method- Specified by:
contextualize
in interfaceorg.apache.avalon.framework.context.Contextualizable
- Throws:
org.apache.avalon.framework.context.ContextException
-
getFileSizeMax
public long getFileSizeMax()The maximum allowed size of a sinlge file upload- Specified by:
getFileSizeMax
in interfaceUploadService
- Returns:
- the maximum size
-
setFileSizeMax
public void setFileSizeMax(long fileSizeMax) -
getFileCountMax
public long getFileCountMax()The maximum number of files allowed per request.- Returns:
- maximum number of files allowed per request
-
setFileCountMax
public void setFileCountMax(int fileCountMax)
-