Nitido Inc.

com.nitido.nimbox.http
Class MultipartRequestParser

java.lang.Object
  extended by com.nitido.nimbox.http.MultipartRequestParser
All Implemented Interfaces:
RequestParser

public class MultipartRequestParser
extends java.lang.Object
implements RequestParser

This class is used to interpret HttpServletRequests whose content type indicate a multipart/form-data request. The implementation of this class reads any incoming files which are then saved directly to disk to a location that you can set.

This class can receive arbitrarily large files (up to an artificial limit that can be configured). It cannot handle nested data (multipart content within multipart content). It can also handle internationalized content (such as non Latin-1 filenames).

To avoid collisions and have fine control over file placement, the init method of the class can include a reference to a FileRenamePolicy implementation. A particular policy can choose to rename or change the location of the file before it's written.


Field Summary
static java.lang.String BUFFERED
          Key used to retrieve from the initialization settings the flag indicating weather this parser should do internal buffering or let the server handle the buffering.
static java.lang.String CHAR_ENCODING
          Key used to retrieve from the initialization settings the encoding for the response.
static java.lang.String FILE_RENAME_POLICY
          Key used to retrieve from the initialization settings the file rename policy to be used by the parseRequest() method before saving the file to disk.
static java.lang.String LIMIT_LENGTH
          Key used to retrieve from the initialization settings the flag indicating that the parseRequest() method needs to filter the request's input stream to prevent trying to read past the end of the stream.
static java.lang.String MAX_POST_SIZE
          Key used to retrieve from the initialization settings the max post size allowed.
static java.lang.String SAVE_DIRECTORY
          Key used to retrieve from the initialization settings the directory location where uploaded files are cached.
 
Constructor Summary
MultipartRequestParser()
          Class constructor.
 
Method Summary
 void init(java.util.HashMap settings)
          This method is used to initialize this request parser.
 java.util.HashMap parseRequest(javax.servlet.http.HttpServletRequest request)
          This method parses an Http request that has the following content type: multipart/form-data.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SAVE_DIRECTORY

public static final java.lang.String SAVE_DIRECTORY
Key used to retrieve from the initialization settings the directory location where uploaded files are cached.

See Also:
Constant Field Values

CHAR_ENCODING

public static final java.lang.String CHAR_ENCODING
Key used to retrieve from the initialization settings the encoding for the response.

See Also:
Constant Field Values

MAX_POST_SIZE

public static final java.lang.String MAX_POST_SIZE
Key used to retrieve from the initialization settings the max post size allowed.

See Also:
Constant Field Values

BUFFERED

public static final java.lang.String BUFFERED
Key used to retrieve from the initialization settings the flag indicating weather this parser should do internal buffering or let the server handle the buffering.

See Also:
Constant Field Values

LIMIT_LENGTH

public static final java.lang.String LIMIT_LENGTH
Key used to retrieve from the initialization settings the flag indicating that the parseRequest() method needs to filter the request's input stream to prevent trying to read past the end of the stream.

See Also:
Constant Field Values

FILE_RENAME_POLICY

public static final java.lang.String FILE_RENAME_POLICY
Key used to retrieve from the initialization settings the file rename policy to be used by the parseRequest() method before saving the file to disk.

See Also:
Constant Field Values
Constructor Detail

MultipartRequestParser

public MultipartRequestParser()
Class constructor.

Method Detail

init

public void init(java.util.HashMap settings)
This method is used to initialize this request parser.

Specified by:
init in interface RequestParser
Parameters:
settings - A HashMap containing the initialization parameters for this parser: This implementation requires the following initialization parameters:
  • MultipartRequestParser.SAVE_DIRECTORY: The directory location where uploaded files are placed. This parameters is a mandatory settings and an IllegalArgumentException is thrown if this parameter is not available.
  • MultipartRequestParser.CHAR_ENCODING: The encoding of the response, such as "ISO-8859-1". If this parameter is not in the settings a default encoding is used ("ISO-8859-1").
  • MultipartRequestParser.MAX_POST_SIZE: The max post size accepted for the request. If this parameter is not set, a default max post size of 1Mb is used.
  • MultipartRequestParser.BUFFERED: A boolean flag indicating weather this parser should handle internal buffering or let the server handle the buffering. If this parameter is not set, the flag is set to true.
  • MultipartRequestParser.LIMIT_LENGTH: A boolean flag indicating that this parser needs to filter the request's input stream to prevent trying to read past the end of the stream. If this parameter is not set, the flag is set to true.
  • MultipartRequestParser.FILE_RENAME_POLICY: The rename policy implementation to use. If this parameter is not set, the DefaultFileRenamePolicy implementation is used. The default rename policy object will append a number to the filename before the file is stored in the file system.
Throws:
java.lang.IllegalArgumentException - If any of the initialization settings are not valid.

parseRequest

public java.util.HashMap parseRequest(javax.servlet.http.HttpServletRequest request)
                               throws java.io.IOException
This method parses an Http request that has the following content type: multipart/form-data. Any uploaded files are written to a given location in the file system.

Specified by:
parseRequest in interface RequestParser
Parameters:
request - Reference to the HttpServletRequest to be parsed.
Returns:
A HashMap with all the parameters of the requests. References to all uploaded files are placed in a HashMap that is stored under the NimletInput.UPLOADED_FILES key of the returned HashMap.
Throws:
java.io.IOException - If unable to:
  • read from the ServletInputStream or,
  • write file to given location.
java.lang.IllegalArgumentException - If the given request parameter is null

Nitido NiM 2.5 Java API

These JavaDoc pages are generated for release/nim_2_5-2.5.44

Copyright © 1999-2009 Nitido Inc.    Proprietary and Confidential.    All Rights Reserved.