Package org.apache.juneau.rest.util
Class RestUtils
java.lang.Object
org.apache.juneau.rest.util.RestUtils
Various reusable utility methods.
 
See Also:
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionstatic StringfixMethodPath(String path) Normalizes theRestOp.path()value.static StringgetHttpResponseText(int rc) Returns readable text for an HTTP response code.static StringgetPathInfoUndecoded(jakarta.servlet.http.HttpServletRequest req) Identical toHttpServletRequest.getPathInfo()but doesn't decode encoded characters.static booleanisValidContextPath(String value) Returnstrue if the specified value is a valid context path.static booleanisValidPathInfo(String value) Returnstrue if the specified value is a valid path-info path.static booleanisValidServletPath(String value) Returnstrue if the specified value is a valid servlet path.static ObjectParses a string that can consist of a simple string or JSON object/array.static String[]Parses HTTP header.static String[]Parses key/value pairs separated by either : or =parseQuery(Object qs) Parses a URL query string or form-data content.parseQuery(Object qs, Map<String, String[]> map) Same asparseQuery(Object)but allows you to specify the map to insert values into.static StringConverts the specified path segment to a valid context path.static StringtrimContextPath(String contextPath, String path) If the specified path-info starts with the specified context path, trims the context path from the path info.static StringBuffertrimPathInfo(StringBuffer requestURI, String contextPath, String servletPath) Efficiently trims the path info part from a request URI.static voidvalidateContextPath(String value) Throws aRuntimeExceptionif the methodisValidContextPath(String)returnsfalse for the specified value.static voidvalidatePathInfo(String value) Throws aRuntimeExceptionif the methodisValidPathInfo(String)returnsfalse for the specified value.static voidvalidateServletPath(String value) Throws aRuntimeExceptionif the methodisValidServletPath(String)returnsfalse for the specified value.
- 
Constructor Details- 
RestUtilspublic RestUtils()
 
- 
- 
Method Details- 
getHttpResponseTextReturns readable text for an HTTP response code.- Parameters:
- rc- The HTTP response code.
- Returns:
- Readable text for an HTTP response code, or null if it's an invalid code.
 
- 
getPathInfoUndecodedIdentical toHttpServletRequest.getPathInfo()but doesn't decode encoded characters.- Parameters:
- req- The HTTP request
- Returns:
- The un-decoded path info.
 
- 
trimPathInfopublic static StringBuffer trimPathInfo(StringBuffer requestURI, String contextPath, String servletPath) Efficiently trims the path info part from a request URI.The result is the URI of the servlet itself. - Parameters:
- requestURI- The value returned by- HttpServletRequest.getRequestURL()
- contextPath- The value returned by- HttpServletRequest.getContextPath()
- servletPath- The value returned by- HttpServletRequest.getServletPath()
- Returns:
- The same StringBuilder with remainder trimmed.
 
- 
parseHeaderParses HTTP header.- Parameters:
- s- The string to parse.
- Returns:
- The parsed string.
 
- 
parseKeyValuePairParses key/value pairs separated by either : or =- Parameters:
- s- The string to parse.
- Returns:
- The parsed string.
 
- 
parseQueryParses a URL query string or form-data content.- Parameters:
- qs- A reader or string containing the query string to parse.
- Returns:
- A new map containing the parsed query.
 
- 
parseQuerySame asparseQuery(Object)but allows you to specify the map to insert values into.- Parameters:
- qs- A reader containing the query string to parse.
- map- The map to pass the values into.
- Returns:
- The same map passed in, or a new map if it was null .
 
- 
parseAnythingParses a string that can consist of a simple string or JSON object/array.- Parameters:
- s- The string to parse.
- Returns:
- The parsed value, or null if the input is null.
- Throws:
- ParseException- Invalid JSON in string.
 
- 
trimContextPathIf the specified path-info starts with the specified context path, trims the context path from the path info.- Parameters:
- contextPath- The context path.
- path- The URL path.
- Returns:
- The path following the context path, or the original path.
 
- 
fixMethodPathNormalizes theRestOp.path()value.- Parameters:
- path- The path to normalize.
- Returns:
- The normalized path.
 
- 
isValidContextPathReturnstrue if the specified value is a valid context path. The path must start with a "/" character but not end with a "/" character. For servlets in the default (root) context, the value should be "".- Parameters:
- value- The value to test.
- Returns:
- true if the specified value is a valid context path.
 
- 
toValidContextPathConverts the specified path segment to a valid context path.- nulls and- "/" are converted to empty strings.
- Trailing slashes are trimmed.
- Leading slash is added if needed.
 - Parameters:
- s- The value to convert.
- Returns:
- The converted path.
 
- 
validateContextPathThrows aRuntimeExceptionif the methodisValidContextPath(String)returnsfalse for the specified value.- Parameters:
- value- The value to test.
 
- 
isValidServletPathReturnstrue if the specified value is a valid servlet path. This path must with a "/" character and includes either the servlet name or a path to the servlet, but does not include any extra path information or a query string. Should be an empty string ("") if the servlet used to process this request was matched using the "/*" pattern.- Parameters:
- value- The value to test.
- Returns:
- true if the specified value is a valid servlet path.
 
- 
validateServletPathThrows aRuntimeExceptionif the methodisValidServletPath(String)returnsfalse for the specified value.- Parameters:
- value- The value to test.
 
- 
isValidPathInfoReturnstrue if the specified value is a valid path-info path. The extra path information follows the servlet path but precedes the query string and will start with a "/" character. The value should be null if there was no extra path information.- Parameters:
- value- The value to test.
- Returns:
- true if the specified value is a valid path-info path.
 
- 
validatePathInfoThrows aRuntimeExceptionif the methodisValidPathInfo(String)returnsfalse for the specified value.- Parameters:
- value- The value to test.
 
 
-