nextapp.eftl.jakarta.commons.fileupload
Class JakartaCommonsFileUploadProvider

java.lang.Object
  extended by nextapp.eftl.jakarta.commons.fileupload.JakartaCommonsFileUploadProvider
All Implemented Interfaces:
java.lang.Cloneable, EchoServer.MultipartRequestWrapper, MultipartUploadSPI

public class JakartaCommonsFileUploadProvider
extends java.lang.Object
implements MultipartUploadSPI, java.lang.Cloneable

Implementation of MultipartUploadSPI that uses the Jakarta Commons FileUpload library to perform the parsing of multipart HttpServletRequests.


Constructor Summary
JakartaCommonsFileUploadProvider()
           
 
Method Summary
 MultipartUploadSPI copy()
          Returns a new instance of the implementation configured identically to the current instance.
 javax.servlet.http.HttpServletRequest getWrappedRequest(javax.servlet.http.HttpServletRequest request)
          Returns a replacement HttpServletRequest object that may be used to handle a multipart/form-data encoded HTTP request.
 boolean operative()
          Implementations return whether they are able to handle calls to wrapRequest() and updateComponent().
 void setDiskCacheLocation(java.io.File directory)
          Sets the directory to be used for storing file uploads that exceed the memory cache threshold.
 void setFileUploadSizeLimit(int bytes)
          Sets the maximum size, in bytes, of file uploads to be accepted.
 void setMemoryCacheThreshold(int bytes)
          Sets the size, in bytes, that the file upload must exceed before being cached to disk.
 boolean supportsDiskCaching()
          Implementations return true if they support caching the uploaded file to disk.
 boolean supportsFileUploadSizeLimit()
          Implementations return true if they support limiting the size of the upload.
 void updateComponent(Connection conn, UploadSelect uploadSelect)
          Implementations use the information from the HttpServletRequest in the Connection to call the fileUpload() method of the UploadSelect component.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JakartaCommonsFileUploadProvider

public JakartaCommonsFileUploadProvider()
Method Detail

operative

public boolean operative()
Description copied from interface: MultipartUploadSPI
Implementations return whether they are able to handle calls to wrapRequest() and updateComponent(). This allows an implementation to determine whether its supporting libraries are available.

Specified by:
operative in interface MultipartUploadSPI
Returns:
true if the implementation is able to parse requests
See Also:
MultipartUploadSPI.operative()

supportsDiskCaching

public boolean supportsDiskCaching()
Description copied from interface: MultipartUploadSPI
Implementations return true if they support caching the uploaded file to disk. Implementations that return true must not throw UnsupportedOperationExceptions for the methods setMemoryCacheThreshold() and setDiskCacheLocation().

Specified by:
supportsDiskCaching in interface MultipartUploadSPI
Returns:
true if the implementation is able to conserve memory by storing the uploaded file to disk
See Also:
MultipartUploadSPI.supportsDiskCaching()

supportsFileUploadSizeLimit

public boolean supportsFileUploadSizeLimit()
Description copied from interface: MultipartUploadSPI
Implementations return true if they support limiting the size of the upload. Implementations that return true must not throw an UnsupportedOperationException for the method setFileUploadSizeLimit().

Specified by:
supportsFileUploadSizeLimit in interface MultipartUploadSPI
Returns:
true if the implmentation is able to terminate uploads larger than a specified size
See Also:
MultipartUploadSPI.supportsFileUploadSizeLimit()

updateComponent

public void updateComponent(Connection conn,
                            UploadSelect uploadSelect)
                     throws java.io.IOException,
                            javax.servlet.ServletException
Description copied from interface: MultipartUploadSPI
Implementations use the information from the HttpServletRequest in the Connection to call the fileUpload() method of the UploadSelect component.

Specified by:
updateComponent in interface MultipartUploadSPI
Parameters:
conn - provides access to the HttpServletRequest
uploadSelect - component to be updated with the file upload information
Throws:
java.io.IOException - if the Connection or the HttpServletRequest throws an IOException during the operation
javax.servlet.ServletException - if Connection or the HttpServletRequest throws an IOException during the operation
See Also:
MultipartUploadSPI.updateComponent(nextapp.echoservlet.Connection, nextapp.echo.filetransfer.UploadSelect)

setMemoryCacheThreshold

public void setMemoryCacheThreshold(int bytes)
                             throws java.lang.UnsupportedOperationException
Description copied from interface: MultipartUploadSPI
Sets the size, in bytes, that the file upload must exceed before being cached to disk. Some implementations that support disk caching may not support the storing of small uploads in memory. Such implementations should ignore calls to this method and not throw an UnsupportedOperationException.

Specified by:
setMemoryCacheThreshold in interface MultipartUploadSPI
Parameters:
bytes - maximum size of the file upload before it will be cached to disk
Throws:
java.lang.UnsupportedOperationException - if this implementation does not support disk caching
See Also:
MultipartUploadSPI.setMemoryCacheThreshold(int)

setDiskCacheLocation

public void setDiskCacheLocation(java.io.File directory)
                          throws java.io.IOException
Description copied from interface: MultipartUploadSPI
Sets the directory to be used for storing file uploads that exceed the memory cache threshold.

Specified by:
setDiskCacheLocation in interface MultipartUploadSPI
Parameters:
directory - location to store uploaded files
Throws:
java.io.IOException - if the directory does not exist or the File throws an IOException during this operation
See Also:
MultipartUploadSPI.setDiskCacheLocation(java.io.File)

setFileUploadSizeLimit

public void setFileUploadSizeLimit(int bytes)
                            throws java.lang.UnsupportedOperationException
Description copied from interface: MultipartUploadSPI
Sets the maximum size, in bytes, of file uploads to be accepted. Uploads that exceed the specified size are terminated or handled in a manner that minimizes the risk of a Denial of Service attack against the application.

Specified by:
setFileUploadSizeLimit in interface MultipartUploadSPI
Parameters:
bytes - the size threshold after which a file upload is rejected
Throws:
java.lang.UnsupportedOperationException - if this implementation does not support limiting file upload sizes
See Also:
MultipartUploadSPI.setFileUploadSizeLimit(int)

copy

public MultipartUploadSPI copy()
Description copied from interface: MultipartUploadSPI
Returns a new instance of the implementation configured identically to the current instance. It is very important that the object returned is not this, but rather a newly instantiated object.

Specified by:
copy in interface MultipartUploadSPI
Returns:
a clone of this object
See Also:
MultipartUploadSPI.copy()

getWrappedRequest

public javax.servlet.http.HttpServletRequest getWrappedRequest(javax.servlet.http.HttpServletRequest request)
                                                        throws java.io.IOException,
                                                               javax.servlet.ServletException
Description copied from interface: EchoServer.MultipartRequestWrapper
Returns a replacement HttpServletRequest object that may be used to handle a multipart/form-data encoded HTTP request.

Specified by:
getWrappedRequest in interface EchoServer.MultipartRequestWrapper
Parameters:
request - The HTTP request provided from the servlet container that has multipart/form-data encoding.
Returns:
An HTTP request that is capable of handling multipart/form-data encoding.
Throws:
java.io.IOException
javax.servlet.ServletException
See Also:
EchoServer.MultipartRequestWrapper.getWrappedRequest(javax.servlet.http.HttpServletRequest)