public final class RequestUtil extends Object
| Constructor and Description |
|---|
RequestUtil() |
| Modifier and Type | Method and Description |
|---|---|
static String |
createSessionVersionString(Map<String,String> sessionVersions)
Creates the string representation for the given context path to
session version mappings.
|
static String |
encodeCookie(javax.servlet.http.Cookie cookie)
Encode a cookie as per RFC 2109.
|
static Charset |
lookupCharset(String enc)
This is a convenient API which wraps around the one in Grizzly and throws
checked java.io.UnsupportedEncodingException instead of
unchecked java.nio.charset.UnsupportedCharsetException.
|
static String |
normalize(String path)
Normalize a relative URI path that may have relative values ("/./",
"/../", and so on ) it it.
|
static String |
normalize(String path,
boolean replaceBackSlash)
Normalize a relative URI path that may have relative values ("/./",
"/../", and so on ) it it.
|
static String |
parseCharacterEncoding(String contentType)
Parse the character encoding from the specified content type header.
|
static javax.servlet.http.Cookie[] |
parseCookieHeader(String header)
Parse a cookie header into an array of cookies according to RFC 2109.
|
static void |
parseParameters(Map<String,String[]> map,
byte[] data,
String encoding)
Append request parameters from the specified String to the specified
Map.
|
static void |
parseParameters(Map<String,String[]> map,
String data,
String encoding)
Append request parameters from the specified String to the specified
Map.
|
static HashMap<String,String> |
parseSessionVersionString(String sessionVersion)
Parses the given session version string into its components.
|
static String |
urlDecode(byte[] bytes)
Decode and return the specified URL-encoded byte array.
|
static String |
urlDecode(byte[] bytes,
String enc)
Decode and return the specified URL-encoded byte array.
|
static String |
urlDecode(org.glassfish.grizzly.http.util.ByteChunk bc,
boolean toString)
Decode (in place) the specified URL-encoded byte chunk, and optionally
return the decoded result as a String
|
static String |
urlDecode(String str)
Decode and return the specified URL-encoded String.
|
static String |
urlDecode(String str,
String enc)
Decode and return the specified URL-encoded String.
|
public static String encodeCookie(javax.servlet.http.Cookie cookie)
Set-Cookie header.cookie - The cookie to encode.public static String normalize(String path)
path - Relative path to be normalizedpublic static String normalize(String path, boolean replaceBackSlash)
path - Relative path to be normalizedreplaceBackSlash - Should '\\' be replaced with '/'public static String parseCharacterEncoding(String contentType)
null is returned.contentType - a content type headerpublic static javax.servlet.http.Cookie[] parseCookieHeader(String header)
header - Value of an HTTP "Cookie" headerpublic static void parseParameters(Map<String,String[]> map, String data, String encoding) throws UnsupportedEncodingException
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.
map - Map that accumulates the resulting parametersdata - Input string containing request parametersencoding - The name of a supported charset used to encodeIllegalArgumentException - if the data is malformedUnsupportedEncodingExceptionpublic static String urlDecode(String str)
str - The url-encoded stringIllegalArgumentException - if a '%' character is not followed
by a valid 2-digit hexadecimal numberpublic static String urlDecode(String str, String enc)
str - The url-encoded stringenc - The encoding to use; if null, the default encoding is usedIllegalArgumentException - if a '%' character is not followed
by a valid 2-digit hexadecimal numberpublic static String urlDecode(byte[] bytes)
bytes - The url-encoded byte arrayIllegalArgumentException - if a '%' character is not followed
by a valid 2-digit hexadecimal numberpublic static String urlDecode(byte[] bytes, String enc)
bytes - The url-encoded byte arrayenc - The encoding to use; if null, the default encoding is usedIllegalArgumentException - if a '%' character is not followed
by a valid 2-digit hexadecimal numberpublic static String urlDecode(org.glassfish.grizzly.http.util.ByteChunk bc, boolean toString)
bc - The URL-encoded byte chunk to be decoded in placetoString - true if the decoded result is to be returned as a
String, false otherwisetoString
is true, or null otherwiseIllegalArgumentException - if a '%' character is not followed
by a valid 2-digit hexadecimal numberpublic static void parseParameters(Map<String,String[]> map, byte[] data, String encoding) throws UnsupportedEncodingException
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.
map - Map that accumulates the resulting parametersdata - Input string containing request parametersencoding - Encoding to use for converting hexUnsupportedEncodingException - if the data is malformedpublic static final HashMap<String,String> parseSessionVersionString(String sessionVersion)
sessionVersion - The session version string to parsepublic static String createSessionVersionString(Map<String,String> sessionVersions)
The returned string will be used as the value of a JSESSIONIDVERSION cookie or jsessionidversion URI parameter, depending on the configured session tracking mode.
sessionVersions - Context path to session version mappingspublic static Charset lookupCharset(String enc) throws UnsupportedEncodingException
UnsupportedEncodingExceptionCopyright © 2019. All rights reserved.