Class StreamReceiverHandler
java.lang.Object
com.vaadin.flow.server.communication.StreamReceiverHandler
- All Implemented Interfaces:
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:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
An UploadInterruptedException will be thrown by an ongoing upload ifStreamVariable.isInterrupted()
returnstrue
. -
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
doHandleMultipartFileUpload
(VaadinSession session, VaadinRequest request, VaadinResponse response, StreamReceiver streamReceiver, StateNode owner) Streams content from a multipart request to given StreamVariable.protected void
doHandleXhrFilePost
(VaadinSession session, VaadinRequest request, VaadinResponse response, StreamReceiver streamReceiver, StateNode owner, long contentLength) Used to stream plain file post (aka XHR2.post(File))protected org.apache.commons.fileupload2.core.FileItemInputIterator
getItemIterator
(VaadinRequest request) protected Collection<jakarta.servlet.http.Part>
getParts
(VaadinRequest request) protected int
To prevent event storming, streaming progress events are sent in this interval rather than every time the buffer is filled.protected boolean
handleFileUploadValidationAndData
(VaadinSession session, InputStream inputStream, StreamReceiver streamReceiver, String filename, String mimeType, long contentLength, StateNode node) Validate that stream target is in a valid state for receiving data and send stream to receiver.void
handleRequest
(VaadinSession session, VaadinRequest request, VaadinResponse response, StreamReceiver streamReceiver, String uiId, String securityKey) Handle reception of incoming stream from the client.protected boolean
isMultipartUpload
(VaadinRequest request) protected void
sendUploadResponse
(VaadinResponse response, boolean success) Build response for handled download.void
setFileCountMax
(long fileCountMax) void
setFileSizeMax
(long fileSizeMax) void
setRequestSizeMax
(long requestSizeMax)
-
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 requestrequest
- The request to handleresponse
- The response object to which a response can be written.streamReceiver
- the receiver containing the destination stream variableuiId
- id of the targeted uisecurityKey
- 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 variablerequest
- The upload requestresponse
- The upload responsestreamReceiver
- the receiver containing the destination stream variableowner
- 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 variablerequest
- The upload requestresponse
- The upload responsestreamReceiver
- the receiver containing the destination stream variableowner
- The owner of the streamcontentLength
- 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 variableinputStream
- the request content input streamstreamReceiver
- the receiver containing the destination stream variablefilename
- name of the streamed filemimeType
- file mime typecontentLength
- The length of the request contentnode
- 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
Build response for handled download.- Parameters:
response
- response to write to- Throws:
IOException
- exception when writing to stream
-
isMultipartUpload
-
getParts
- 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)
-