com.vaadin.flow.server.communication.
Class StreamReceiverHandler
- java.lang.Object
-
- com.vaadin.flow.server.communication.StreamReceiverHandler
-
All Implemented Interfaces:
public class StreamReceiverHandler extends Object implements Serializable
Handles
StreamReceiver
instances registered inVaadinSession
.For internal use only. May be renamed or removed in a future release.
Since:
1.0
Author:
Vaadin Ltd
See Also:
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
StreamReceiverHandler.UploadInterruptedException
An UploadInterruptedException will be thrown by an ongoing upload if
StreamVariable.isInterrupted()
returnstrue
.
-
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_STREAMING_PROGRESS_EVENT_INTERVAL_MS
-
Constructor Summary
Constructors Constructor Description StreamReceiverHandler()
-
Method Summary
All Methods Modifier and Type Method Description protected 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 long
getContentLength(VaadinRequest request)
Deprecated.
useVaadinRequest.getContentLengthLong()
insteadprotected org.apache.commons.fileupload.FileItemIterator
getItemIterator(VaadinRequest request)
protected Collection<javax.servlet.http.Part>
getParts(VaadinRequest request)
protected int
getProgressEventInterval()
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.
-
-
-
Method Detail
-
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 idThrows:
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 streamThrows:
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 contentThrows:
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 streamReturns:
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 toThrows:
IOException
- exception when writing to stream
-
getContentLength
@Deprecated protected long getContentLength(VaadinRequest request)
Deprecated.useVaadinRequest.getContentLengthLong()
insteadThe request.getContentLength() is limited to "int" by the Servlet specification. To support larger file uploads manually evaluate the Content-Length header which can contain long values.
-
isMultipartUpload
protected boolean isMultipartUpload(VaadinRequest request)
-
getParts
protected Collection<javax.servlet.http.Part> getParts(VaadinRequest request) throws Exception
Throws:
-
getItemIterator
protected org.apache.commons.fileupload.FileItemIterator getItemIterator(VaadinRequest request) throws org.apache.commons.fileupload.FileUploadException, IOException
Throws:
org.apache.commons.fileupload.FileUploadException
-
-