com.waveset.ui.util
Class RequestTokenizer

java.lang.Object
  extended bycom.waveset.ui.util.RequestTokenizer

public class RequestTokenizer
extends java.lang.Object

This class serially processes an HTTP request input stream, parsing one parameter at a time. This class allows the caller to access the parameter content as a string or as an input stream. Styled after InputStreamTokenizer, which allows the caller to iterate word or number tokens.

Iterating tokens of the HTTP request input stream is a bit less convenient for the caller, but this minimizes the amount of memory required to read request parameters. By comparison, getParameter() and getParameterMap() read the entire request into memory.

Reading parameter content as an input stream enables memory-efficient uploading of large files.

NOTE: this class handles "multipart/mixed" content as described in the HTML 4.01 Specification. Therefore, it will handle a file select control from which multiple files have been selected.

We expect the call pattern to be something like:
 HttpServletRequest request = requestState.getRequest();
 RequestTokenizer rt = new RequestTokenizer(request);
 String parameter = null;
 while (rt.nextParameter()!=null) {
  String parameterName = rt.getName();
  if (PARAMETER_X.equals(parameterName)) {
   _parameterX = rt.getContentString();
  }
  else if (LOAD_FILE.equals(parameterName)) {
   String fileName = rt.getFileName();
   if (fileName!=null && fileName.length()>0) {
    OutputStream os = new FileOutputStream(fileName);
    InputStream is = rt.getContentStream();
    Util.copyFile(is, os);
   }
  }
 } // end while


Field Summary
static java.lang.String code_id
           
protected static java.lang.String COLON
           
protected static java.lang.String CONTENT
           
protected static java.lang.String CONTENT_DISPOSITION
           
protected static java.lang.String CONTENT_TRANSFER_ENCODING
           
protected static java.lang.String CONTENT_TYPE
           
protected static java.lang.String CRLF
           
protected static java.lang.String DASH_DASH
           
protected static java.lang.String EQUALS
           
protected static java.lang.String FILENAME
           
protected static java.lang.String MULTI_PART_FORM_DATA
           
protected static java.lang.String MULTI_PART_MIXED
           
protected static java.lang.String NAME
           
protected static java.lang.String QUOTE
           
protected static java.lang.String SPACE
           
protected static Trace trace
           
 
Constructor Summary
RequestTokenizer(javax.servlet.http.HttpServletRequest request)
           
 
Method Summary
 java.lang.String getContentDisposition()
           
 java.io.InputStream getContentStream()
           
 java.lang.String getContentString()
           
 java.lang.String getContentTransferEncoding()
           
 java.lang.String getContentType()
           
 java.lang.String getFileName()
           
 java.lang.String getName()
           
 java.lang.String nextParameter()
          Advance to the next parameter in the request input stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

code_id

public static final java.lang.String code_id
See Also:
Constant Field Values

trace

protected static Trace trace

MULTI_PART_FORM_DATA

protected static final java.lang.String MULTI_PART_FORM_DATA
See Also:
Constant Field Values

MULTI_PART_MIXED

protected static final java.lang.String MULTI_PART_MIXED
See Also:
Constant Field Values

COLON

protected static final java.lang.String COLON
See Also:
Constant Field Values

EQUALS

protected static final java.lang.String EQUALS
See Also:
Constant Field Values

SPACE

protected static final java.lang.String SPACE
See Also:
Constant Field Values

QUOTE

protected static final java.lang.String QUOTE
See Also:
Constant Field Values

CRLF

protected static final java.lang.String CRLF
See Also:
Constant Field Values

DASH_DASH

protected static final java.lang.String DASH_DASH
See Also:
Constant Field Values

CONTENT

protected static final java.lang.String CONTENT
See Also:
Constant Field Values

CONTENT_DISPOSITION

protected static final java.lang.String CONTENT_DISPOSITION
See Also:
Constant Field Values

CONTENT_TRANSFER_ENCODING

protected static final java.lang.String CONTENT_TRANSFER_ENCODING
See Also:
Constant Field Values

CONTENT_TYPE

protected static final java.lang.String CONTENT_TYPE
See Also:
Constant Field Values

FILENAME

protected static final java.lang.String FILENAME
See Also:
Constant Field Values

NAME

protected static final java.lang.String NAME
See Also:
Constant Field Values
Constructor Detail

RequestTokenizer

public RequestTokenizer(javax.servlet.http.HttpServletRequest request)
Method Detail

getContentType

public java.lang.String getContentType()
Returns:
the content type of the current request parameter.

Before calling nextParameter(), or after nextParameter() returns null, this will return null.

See Also:
nextParameter()

getName

public java.lang.String getName()
Returns:
the name of the current request parameter.

Before calling nextParameter(), or after nextParameter() returns null, this will return null.

See Also:
nextParameter()

getContentDisposition

public java.lang.String getContentDisposition()
Returns:
the content type of the current request parameter.

Before calling nextParameter(), or after nextParameter() returns null, this will return null.

See Also:
nextParameter()

getContentTransferEncoding

public java.lang.String getContentTransferEncoding()
Returns:
the content type of the current request parameter.

If the request parameter does not specify a content transfer encoding (e.g., because it is the default), this method returns null.

Before calling nextParameter(), or after nextParameter() returns null, this method will return null.

See Also:
nextParameter()

getFileName

public java.lang.String getFileName()
Returns:
the filename of the current request parameter if the parameter represents a file; otherwise null.

Before calling nextParameter(), or after nextParameter() returns null, this will return null.

See Also:
nextParameter()

getContentString

public java.lang.String getContentString()
                                  throws IOException
Returns:
the content of the current request parameter as a String.

Throws:
java.lang.IllegalStateException - if this method is called after calling getContentStream() for the same parameter.

java.lang.UnsupportedOperationException - if this method is called on a parameter whose content length exceeds the configured maximum.

This method will return null if nextParameter() has not been called (to advance to the first request parameter) or if nextParameter() returns null (because we have advanced beyond the last parameter).

IOException
See Also:
nextParameter()

getContentStream

public java.io.InputStream getContentStream()
Returns:
the content of the current request parameter as an InputStream.

Throws:
java.lang.IllegalStateException - if this method is called after calling getContentString() for the same parameter.

This method will return null if nextParameter() has not been called (to advance to the first request parameter) or if nextParameter() returns null (because we have advanced beyond the last parameter).

See Also:
nextParameter()

nextParameter

public java.lang.String nextParameter()
                               throws IOException
Advance to the next parameter in the request input stream.

Returns:
the content type of the parameter, or null if none is found.
Throws:
java.lang.IllegalArgumentException - if there is an error parsing the request input stream.
IOException - if there is an error reading the request input stream.

After a call to nextParameter(), the caller may retrieve the parameter's:

  • name by calling getName().
  • Content-Type by calling getContentType().
  • Content-Disposition by calling getContentDisposition().
  • Content-Transfer-Encoding by calling getContentTransferEncoding().
  • content as a String by calling getContentString(), or as an InputStream by calling getContentStream().
  • filename by calling getFileName(). (If the parameter was not a file, the file name will be null.)
See Also:
getContentString(), getContentStream(), getContentType(), getContentDisposition(), getContentTransferEncoding()