com.vaadin.server.communication
Class FileUploadHandler

java.lang.Object
  extended by com.vaadin.server.communication.FileUploadHandler
All Implemented Interfaces:
RequestHandler, java.io.Serializable

public class FileUploadHandler
extends java.lang.Object
implements RequestHandler

Handles a file upload request submitted via an Upload component.

Since:
7.1
Author:
Vaadin Ltd
See Also:
Serialized Form

Nested Class Summary
static class FileUploadHandler.SimpleMultiPartInputStream
          Stream that extracts content from another stream until the boundary string is encountered.
static class FileUploadHandler.UploadInterruptedException
          An UploadInterruptedException will be thrown by an ongoing upload if StreamVariable.isInterrupted() returns true.
 
Field Summary
static int DEFAULT_STREAMING_PROGRESS_EVENT_INTERVAL_MS
           
 
Constructor Summary
FileUploadHandler()
           
 
Method Summary
protected  void doHandleSimpleMultipartFileUpload(VaadinSession session, VaadinRequest request, VaadinResponse response, StreamVariable streamVariable, java.lang.String variableName, ClientConnector owner, java.lang.String boundary)
          Method used to stream content from a multipart request (either from servlet or portlet request) to given StreamVariable.
protected  void doHandleXhrFilePost(VaadinSession session, VaadinRequest request, VaadinResponse response, StreamVariable streamVariable, java.lang.String variableName, ClientConnector owner, long contentLength)
          Used to stream plain file post (aka XHR2.post(File))
protected  int getProgressEventInterval()
          To prevent event storming, streaming progress events are sent in this interval rather than every time the buffer is filled.
 boolean handleRequest(VaadinSession session, VaadinRequest request, VaadinResponse response)
          Called when a request needs to be handled.
protected  void sendUploadResponse(VaadinRequest request, VaadinResponse response)
          TODO document
protected  boolean streamToReceiver(VaadinSession session, java.io.InputStream in, StreamVariable streamVariable, java.lang.String filename, java.lang.String type, long contentLength)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_STREAMING_PROGRESS_EVENT_INTERVAL_MS

public static final int DEFAULT_STREAMING_PROGRESS_EVENT_INTERVAL_MS
See Also:
Constant Field Values
Constructor Detail

FileUploadHandler

public FileUploadHandler()
Method Detail

handleRequest

public boolean handleRequest(VaadinSession session,
                             VaadinRequest request,
                             VaadinResponse response)
                      throws java.io.IOException
Description copied from interface: RequestHandler
Called when a request needs to be handled. If a response is written, this method should return true to indicate that no more request handlers should be invoked for the request.

Note that request handlers by default do not lock the session. If you are using VaadinSession or anything inside the VaadinSession you must ensure the session is locked. This can be done by extending SynchronizedRequestHandler or by using VaadinSession.accessSynchronously(Runnable) or UI.accessSynchronously(Runnable).

Specified by:
handleRequest in interface RequestHandler
Parameters:
session - The session for the request
request - The request to handle
response - The response object to which a response can be written.
Returns:
true if a response has been written and no further request handlers should be called, otherwise false
Throws:
java.io.IOException - If an IO error occurred

doHandleSimpleMultipartFileUpload

protected void doHandleSimpleMultipartFileUpload(VaadinSession session,
                                                 VaadinRequest request,
                                                 VaadinResponse response,
                                                 StreamVariable streamVariable,
                                                 java.lang.String variableName,
                                                 ClientConnector owner,
                                                 java.lang.String boundary)
                                          throws java.io.IOException
Method used to stream content from a multipart request (either from servlet or portlet 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
streamVariable - The destination stream variable
variableName - The name of the destination stream variable
owner - The owner of the stream variable
boundary - The mime boundary used in the upload request
Throws:
java.io.IOException - If there is a problem reading the request or writing the response

doHandleXhrFilePost

protected void doHandleXhrFilePost(VaadinSession session,
                                   VaadinRequest request,
                                   VaadinResponse response,
                                   StreamVariable streamVariable,
                                   java.lang.String variableName,
                                   ClientConnector owner,
                                   long contentLength)
                            throws java.io.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
streamVariable - The destination stream variable
variableName - The name of the destination stream variable
owner - The owner of the stream variable
contentLength - The length of the request content
Throws:
java.io.IOException - If there is a problem reading the request or writing the response

streamToReceiver

protected final boolean streamToReceiver(VaadinSession session,
                                         java.io.InputStream in,
                                         StreamVariable streamVariable,
                                         java.lang.String filename,
                                         java.lang.String type,
                                         long contentLength)
                                  throws UploadException
Parameters:
in -
streamVariable -
filename -
type -
contentLength -
Returns:
true if the streamvariable has informed that the terminal can forget this variable
Throws:
UploadException

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.


sendUploadResponse

protected void sendUploadResponse(VaadinRequest request,
                                  VaadinResponse response)
                           throws java.io.IOException
TODO document

Parameters:
request -
response -
Throws:
java.io.IOException


Copyright © 2000-2014 Vaadin Ltd. All Rights Reserved.