Class JakartaStreamMultiPartRequest

java.lang.Object
org.apache.struts2.dispatcher.multipart.AbstractMultiPartRequest
org.apache.struts2.dispatcher.multipart.JakartaStreamMultiPartRequest
All Implemented Interfaces:
MultiPartRequest

public class JakartaStreamMultiPartRequest extends AbstractMultiPartRequest
Multipart form data request adapter for Jakarta Commons FileUpload package that leverages the streaming API rather than the traditional non-streaming API.

For more details see WW-3025

Since:
2.3.18
  • Constructor Details

    • JakartaStreamMultiPartRequest

      public JakartaStreamMultiPartRequest()
  • Method Details

    • processUpload

      protected void processUpload(jakarta.servlet.http.HttpServletRequest request, String saveDir) throws IOException
      Processes the upload.
      Specified by:
      processUpload in class AbstractMultiPartRequest
      Parameters:
      request - the servlet request
      saveDir - location of the save dir
      Throws:
      IOException
    • processFileItemAsFormField

      protected void processFileItemAsFormField(org.apache.commons.fileupload2.core.FileItemInput fileItemInput) throws IOException
      Processes a normal form field (non-file) from the multipart request using streaming API.

      This method handles text form fields by:

      1. Validating the field name is not null
      2. Reading the field value from the input stream
      3. Checking if the field value exceeds maximum string length
      4. Adding the value to the parameters collection

      Fields with null names are skipped with a warning log message.

      The streaming approach is more memory-efficient for large form data.

      Parameters:
      fileItemInput - a form field item input from the streaming API
      Throws:
      IOException - if an error occurs reading the input stream
      See Also:
    • actualSizeOfUploadedFiles

      protected Long actualSizeOfUploadedFiles()
      Returns:
      actual size of already uploaded files
    • processFileItemAsFileField

      protected void processFileItemAsFileField(org.apache.commons.fileupload2.core.FileItemInput fileItemInput, Path location) throws IOException
      Processes a file field from the multipart request using streaming API.

      This method handles file uploads by:

      1. Validating the file name and field name are not null/empty
      2. Checking if the upload exceeds maximum file count
      3. Creating a temporary file in the specified location
      4. Streaming the file content directly to disk
      5. Checking if the total size exceeds maximum allowed size
      6. Creating an UploadedFile abstraction or cleaning up on size exceeded

      Files with null names or field names are skipped with appropriate logging.

      The streaming approach is more memory-efficient for large file uploads as it writes directly to disk rather than loading into memory first.

      Parameters:
      fileItemInput - file item representing upload file from streaming API
      location - the directory where temporary files will be created
      Throws:
      IOException - if an error occurs during file processing
      See Also:
    • streamFileToDisk

      protected void streamFileToDisk(org.apache.commons.fileupload2.core.FileItemInput fileItemInput, File file) throws IOException
      Streams the file upload stream to the specified file.
      Parameters:
      fileItemInput - file item input
      file - the file
      Throws:
      IOException
    • createUploadedFile

      protected void createUploadedFile(org.apache.commons.fileupload2.core.FileItemInput fileItemInput, File file)
      Creates an UploadedFile abstraction over an uploaded file.

      This method creates a wrapper around the uploaded file that provides a consistent interface for accessing file information and content. The created UploadedFile instance contains:

      • The original filename as provided by the client
      • The content type (MIME type) if available
      • The form field name that contained the file
      • A reference to the temporary file on disk

      The file is automatically added to the uploaded files collection, grouped by field name to support multiple file uploads per field.

      Parameters:
      fileItemInput - file item stream containing file metadata
      file - the temporary file containing the uploaded content
      See Also: