Constructor and Description |
---|
RestUtils() |
Modifier and Type | Method and Description |
---|---|
static String |
fixMethodPath(String path)
Normalizes the
RestMethod.path() value. |
static String |
getHttpResponseText(int rc)
Returns readable text for an HTTP response code.
|
static String |
getPathInfoUndecoded(HttpServletRequest req)
Identical to
HttpServletRequest.getPathInfo() but doesn't decode encoded characters. |
static boolean |
isValidContextPath(String value)
Returns
|
static boolean |
isValidPathInfo(String value)
Returns
|
static boolean |
isValidServletPath(String value)
Returns
|
static Object[] |
merge(Object[] fromParent,
Object[] fromChild)
Merges the specified parent and child arrays.
|
static Object |
parseAnything(String s)
Parses a string that can consist of a simple string or JSON object/array.
|
static String[] |
parseHeader(String s)
Parses HTTP header.
|
static String[] |
parseKeyValuePair(String s)
Parses key/value pairs separated by either : or =
|
static Map<String,String[]> |
parseQuery(Object qs)
Parses a URL query string or form-data body.
|
static Map<String,String[]> |
parseQuery(Object qs,
Map<String,String[]> map)
Same as
parseQuery(Object) but allows you to specify the map to insert values into. |
static String |
trimContextPath(String contextPath,
String path)
If the specified path-info starts with the specified context path, trims the context path from the path info.
|
static StringBuffer |
trimPathInfo(StringBuffer requestURI,
String contextPath,
String servletPath)
Efficiently trims the path info part from a request URI.
|
static void |
validateContextPath(String value)
Throws a
RuntimeException if the method isValidContextPath(String) returns |
static void |
validatePathInfo(String value)
Throws a
RuntimeException if the method isValidPathInfo(String) returns |
static void |
validateServletPath(String value)
Throws a
RuntimeException if the method isValidServletPath(String) returns |
public RestUtils()
public static String getHttpResponseText(int rc)
rc
- The HTTP response code.public static String getPathInfoUndecoded(HttpServletRequest req)
HttpServletRequest.getPathInfo()
but doesn't decode encoded characters.req
- The HTTP requestpublic static StringBuffer trimPathInfo(StringBuffer requestURI, String contextPath, String servletPath)
The result is the URI of the servlet itself.
requestURI
- The value returned by HttpServletRequest.getRequestURL()
contextPath
- The value returned by HttpServletRequest.getContextPath()
servletPath
- The value returned by HttpServletRequest.getServletPath()
public static String[] parseHeader(String s)
s
- The string to parse.public static String[] parseKeyValuePair(String s)
s
- The string to parse.public static Map<String,String[]> parseQuery(Object qs)
qs
- A reader or string containing the query string to parse.public static Map<String,String[]> parseQuery(Object qs, Map<String,String[]> map)
parseQuery(Object)
but allows you to specify the map to insert values into.qs
- A reader containing the query string to parse.map
- The map to pass the values into.public static Object parseAnything(String s) throws ParseException
s
- The string to parse.ParseException
- Invalid JSON in string.public static Object[] merge(Object[] fromParent, Object[] fromChild)
The general concept is to allow child values to override parent values.
The rules are:
None
, then an empty array is always returned.
Inherit
, then the contents of the parent array are inserted into the position of the Inherit
entry.
fromParent
- The parent array.fromChild
- The child array.public static String trimContextPath(String contextPath, String path)
contextPath
- The context path.path
- The URL path.public static String fixMethodPath(String path)
RestMethod.path()
value.path
- The path to normalize.public static boolean isValidContextPath(String value)
value
- The value to test.public static void validateContextPath(String value)
RuntimeException
if the method isValidContextPath(String)
returns value
- The value to test.public static boolean isValidServletPath(String value)
value
- The value to test.public static void validateServletPath(String value)
RuntimeException
if the method isValidServletPath(String)
returns value
- The value to test.public static boolean isValidPathInfo(String value)
value
- The value to test.public static void validatePathInfo(String value)
RuntimeException
if the method isValidPathInfo(String)
returns value
- The value to test.Copyright © 2016–2020 The Apache Software Foundation. All rights reserved.