Class StreamReceiverHandler

java.lang.Object
com.vaadin.flow.server.communication.StreamReceiverHandler
All Implemented Interfaces:
Serializable

public class StreamReceiverHandler extends Object implements Serializable
Handles StreamReceiver instances registered in VaadinSession.

For internal use only. May be renamed or removed in a future release.

Since:
1.0
Author:
Vaadin Ltd
See Also:
  • Field Details

    • DEFAULT_STREAMING_PROGRESS_EVENT_INTERVAL_MS

      public static final int DEFAULT_STREAMING_PROGRESS_EVENT_INTERVAL_MS
      See Also:
  • Constructor Details

    • StreamReceiverHandler

      public StreamReceiverHandler()
  • Method Details

    • handleRequest

      public void handleRequest(VaadinSession session, VaadinRequest request, VaadinResponse response, StreamReceiver streamReceiver, String uiId, String securityKey) throws IOException
      Handle reception of incoming stream from the client.
      Parameters:
      session - The session for the request
      request - The request to handle
      response - The response object to which a response can be written.
      streamReceiver - the receiver containing the destination stream variable
      uiId - id of the targeted ui
      securityKey - security from the request that should match registered stream receiver id
      Throws:
      IOException - if an IO error occurred
    • doHandleMultipartFileUpload

      protected void doHandleMultipartFileUpload(VaadinSession session, VaadinRequest request, VaadinResponse response, StreamReceiver streamReceiver, StateNode owner) throws IOException
      Streams content from a multipart request to given StreamVariable.

      This method takes care of locking the session as needed and does not assume the caller has locked the session. This allows the session to be locked only when needed and not when handling the upload data.

      Parameters:
      session - The session containing the stream variable
      request - The upload request
      response - The upload response
      streamReceiver - the receiver containing the destination stream variable
      owner - The owner of the stream
      Throws:
      IOException - If there is a problem reading the request or writing the response
    • doHandleXhrFilePost

      protected void doHandleXhrFilePost(VaadinSession session, VaadinRequest request, VaadinResponse response, StreamReceiver streamReceiver, StateNode owner, long contentLength) throws IOException
      Used to stream plain file post (aka XHR2.post(File))

      This method takes care of locking the session as needed and does not assume the caller has locked the session. This allows the session to be locked only when needed and not when handling the upload data.

      Parameters:
      session - The session containing the stream variable
      request - The upload request
      response - The upload response
      streamReceiver - the receiver containing the destination stream variable
      owner - The owner of the stream
      contentLength - The length of the request content
      Throws:
      IOException - If there is a problem reading the request or writing the response
    • handleFileUploadValidationAndData

      protected boolean handleFileUploadValidationAndData(VaadinSession session, InputStream inputStream, StreamReceiver streamReceiver, String filename, String mimeType, long contentLength, StateNode node) throws UploadException
      Validate that stream target is in a valid state for receiving data and send stream to receiver. Handles cleanup and error in reading stream
      Parameters:
      session - The session containing the stream variable
      inputStream - the request content input stream
      streamReceiver - the receiver containing the destination stream variable
      filename - name of the streamed file
      mimeType - file mime type
      contentLength - The length of the request content
      node - The owner of the stream
      Returns:
      true if upload successful, else false
      Throws:
      UploadException - Thrown for illegal target node state
    • getProgressEventInterval

      protected int getProgressEventInterval()
      To prevent event storming, streaming progress events are sent in this interval rather than every time the buffer is filled. This fixes #13155. To adjust this value override the method, and register your own handler in VaadinService.createRequestHandlers(). The default is 500ms, and setting it to 0 effectively restores the old behavior.
      Returns:
      the minimum interval to be used for streaming progress events
    • sendUploadResponse

      protected void sendUploadResponse(VaadinResponse response, boolean success) throws IOException
      Build response for handled download.
      Parameters:
      response - response to write to
      Throws:
      IOException - exception when writing to stream
    • isMultipartUpload

      protected boolean isMultipartUpload(VaadinRequest request)
    • getParts

      protected Collection<jakarta.servlet.http.Part> getParts(VaadinRequest request) throws Exception
      Throws:
      Exception
    • getItemIterator

      protected org.apache.commons.fileupload2.core.FileItemInputIterator getItemIterator(VaadinRequest request) throws org.apache.commons.fileupload2.core.FileUploadException, IOException
      Throws:
      org.apache.commons.fileupload2.core.FileUploadException
      IOException
    • setRequestSizeMax

      public void setRequestSizeMax(long requestSizeMax)
    • setFileSizeMax

      public void setFileSizeMax(long fileSizeMax)
    • setFileCountMax

      public void setFileCountMax(long fileCountMax)