Apache Tomcat 6.0.53

org.apache.catalina.util
Class RequestUtil

java.lang.Object
  extended by org.apache.catalina.util.RequestUtil

public final class RequestUtil
extends java.lang.Object

General purpose request parsing and encoding utility methods.

Author:
Craig R. McClanahan, Tim Tye

Constructor Summary
RequestUtil()
           
 
Method Summary
static java.lang.String filter(java.lang.String message)
          Filter the specified message string for characters that are sensitive in HTML.
static java.lang.String normalize(java.lang.String path)
          Normalize a relative URI path that may have relative values ("/./", "/../", and so on ) it it.
static java.lang.String normalize(java.lang.String path, boolean replaceBackSlash)
          Normalize a relative URI path that may have relative values ("/./", "/../", and so on ) it it.
static void parseParameters(java.util.Map map, byte[] data, java.lang.String encoding)
          Append request parameters from the specified String to the specified Map.
static void parseParameters(java.util.Map map, java.lang.String data, java.lang.String encoding)
          Append request parameters from the specified String to the specified Map.
static java.lang.String URLDecode(byte[] bytes)
          Decode and return the specified URL-encoded byte array.
static java.lang.String URLDecode(byte[] bytes, java.lang.String enc)
          Decode and return the specified URL-encoded byte array.
static java.lang.String URLDecode(byte[] bytes, java.lang.String enc, boolean isQuery)
          Decode and return the specified URL-encoded byte array.
static java.lang.String URLDecode(java.lang.String str)
          Decode and return the specified URL-encoded String.
static java.lang.String URLDecode(java.lang.String str, java.lang.String enc)
          Decode and return the specified URL-encoded String.
static java.lang.String URLDecode(java.lang.String str, java.lang.String enc, boolean isQuery)
          Decode and return the specified URL-encoded String.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RequestUtil

public RequestUtil()
Method Detail

filter

public static java.lang.String filter(java.lang.String message)
Filter the specified message string for characters that are sensitive in HTML. This avoids potential attacks caused by including JavaScript codes in the request URL that is often reported in error messages.

Parameters:
message - The message string to be filtered

normalize

public static java.lang.String normalize(java.lang.String path)
Normalize a relative URI path that may have relative values ("/./", "/../", and so on ) it it. WARNING - This method is useful only for normalizing application-generated paths. It does not try to perform security checks for malicious input.

Parameters:
path - Relative path to be normalized
Returns:
The normalized path or null if the path cannot be normalized

normalize

public static java.lang.String normalize(java.lang.String path,
                                         boolean replaceBackSlash)
Normalize a relative URI path that may have relative values ("/./", "/../", and so on ) it it. WARNING - This method is useful only for normalizing application-generated paths. It does not try to perform security checks for malicious input.

Parameters:
path - Relative path to be normalized
replaceBackSlash - Should '\\' be replaced with '/'
Returns:
The normalized path or null if the path cannot be normalized

parseParameters

public static void parseParameters(java.util.Map map,
                                   java.lang.String data,
                                   java.lang.String encoding)
                            throws java.io.UnsupportedEncodingException
Append request parameters from the specified String to the specified Map. It is presumed that the specified Map is not accessed from any other thread, so no synchronization is performed.

IMPLEMENTATION NOTE: URL decoding is performed individually on the parsed name and value elements, rather than on the entire query string ahead of time, to properly deal with the case where the name or value includes an encoded "=" or "&" character that would otherwise be interpreted as a delimiter.

Parameters:
map - Map that accumulates the resulting parameters
data - Input string containing request parameters
Throws:
java.lang.IllegalArgumentException - if the data is malformed
java.io.UnsupportedEncodingException

URLDecode

public static java.lang.String URLDecode(java.lang.String str)
Decode and return the specified URL-encoded String. When the byte array is converted to a string, the system default character encoding is used... This may be different than some other servers. It is assumed the string is not a query string.

Parameters:
str - The url-encoded string
Throws:
java.lang.IllegalArgumentException - if a '%' character is not followed by a valid 2-digit hexadecimal number

URLDecode

public static java.lang.String URLDecode(java.lang.String str,
                                         java.lang.String enc)
Decode and return the specified URL-encoded String. It is assumed the string is not a query string.

Parameters:
str - The url-encoded string
enc - The encoding to use; if null, the default encoding is used
Throws:
java.lang.IllegalArgumentException - if a '%' character is not followed by a valid 2-digit hexadecimal number

URLDecode

public static java.lang.String URLDecode(java.lang.String str,
                                         java.lang.String enc,
                                         boolean isQuery)
Decode and return the specified URL-encoded String.

Parameters:
str - The url-encoded string
enc - The encoding to use; if null, the default encoding is used
isQuery - Is this a query string being processed
Throws:
java.lang.IllegalArgumentException - if a '%' character is not followed by a valid 2-digit hexadecimal number

URLDecode

public static java.lang.String URLDecode(byte[] bytes)
Decode and return the specified URL-encoded byte array. It is assumed the string is not a query string.

Parameters:
bytes - The url-encoded byte array
Throws:
java.lang.IllegalArgumentException - if a '%' character is not followed by a valid 2-digit hexadecimal number

URLDecode

public static java.lang.String URLDecode(byte[] bytes,
                                         java.lang.String enc)
Decode and return the specified URL-encoded byte array. It is assumed the string is not a query string.

Parameters:
bytes - The url-encoded byte array
enc - The encoding to use; if null, the default encoding is used
Throws:
java.lang.IllegalArgumentException - if a '%' character is not followed by a valid 2-digit hexadecimal number

URLDecode

public static java.lang.String URLDecode(byte[] bytes,
                                         java.lang.String enc,
                                         boolean isQuery)
Decode and return the specified URL-encoded byte array.

Parameters:
bytes - The url-encoded byte array
enc - The encoding to use; if null, the default encoding is used
isQuery - Is this a query string being processed
Throws:
java.lang.IllegalArgumentException - if a '%' character is not followed by a valid 2-digit hexadecimal number

parseParameters

public static void parseParameters(java.util.Map map,
                                   byte[] data,
                                   java.lang.String encoding)
                            throws java.io.UnsupportedEncodingException
Append request parameters from the specified String to the specified Map. It is presumed that the specified Map is not accessed from any other thread, so no synchronization is performed.

IMPLEMENTATION NOTE: URL decoding is performed individually on the parsed name and value elements, rather than on the entire query string ahead of time, to properly deal with the case where the name or value includes an encoded "=" or "&" character that would otherwise be interpreted as a delimiter. NOTE: byte array data is modified by this method. Caller beware.

Parameters:
map - Map that accumulates the resulting parameters
data - Input string containing request parameters
encoding - Encoding to use for converting hex
Throws:
java.io.UnsupportedEncodingException - if the data is malformed

Apache Tomcat 6.0.53

Copyright © 2000-2017 Apache Software Foundation. All Rights Reserved.