public class RequestUtils extends Object
| Modifier and Type | Class and Description |
|---|---|
static class |
RequestUtils.ShortestStringLastComparator
Comparator which puts the longest strings first and the shortest last
|
| Modifier and Type | Field and Description |
|---|---|
static Map<String,String> |
extensionsToFormat
A map from extensions to format constants
|
static Map<String,String> |
formatToMimeType
A map from format constants to mimetypes
|
static String[] |
ignoreForSearch |
static Map<String,String> |
mimeTypeToFormat
A map from mimetypes to format constants
|
| Constructor and Description |
|---|
RequestUtils() |
| Modifier and Type | Method and Description |
|---|---|
static String |
findAndHandleFormat(HttpServletRequest req,
HttpServletResponse res,
String defaultFormat)
This method will correctly extract the format constant from a request
(extension first and then Accepts header) and then set it in the response
as the correct return type, if none is found then the default will be used
|
static String |
getServletContext(HttpServletRequest req)
This finds the correct servlet path or returns the default one,
will not return "" or null
|
static void |
handleURLRedirect(String redirectURL,
boolean forward,
HttpServletRequest req,
HttpServletResponse res)
Handles the redirect to a URL from the current location,
the URL should be relative for a forward, otherwise it will be a redirect
NOTE: You should perform no actions after call this method, you should simply pass control back to the handler |
static boolean |
isRequestOutput(HttpServletRequest req,
EntityView view)
Gets the correct info out of the request method and places it into the entity view and
identifies if this is an output (read) or input (write) request
|
static Search |
makeSearchFromRequestParams(Map<String,Object> params)
This looks at request parameters and returns anything it finds in the
request parameters that can be put into the search,
supports the page params and sorting params
|
static void |
setResponseEncoding(String format,
HttpServletResponse res)
This will set the response mime type correctly based on the format constant,
also sets the response encoding to UTF_8
|
public static Map<String,String> mimeTypeToFormat
public static Map<String,String> formatToMimeType
public static Map<String,String> extensionsToFormat
public static String[] ignoreForSearch
public static void handleURLRedirect(String redirectURL, boolean forward, HttpServletRequest req, HttpServletResponse res)
redirectURL - the URL to redirect to (relative or absolute)forward - if false, use redirect (this should be the default),
if true use forward, note that we can only forward from your webapp back to your servlets and
a check will be performed to see if this is the case, if it is not
(anything with a "http", a non-matching prefix, and anything with a query string) will be switched to redirect automaticallyreq - the current requestres - the current responseIllegalArgumentException - is the params are invalidpublic static boolean isRequestOutput(HttpServletRequest req, EntityView view)
req - the requestview - the entity view to updateEntityException - if the request has problemspublic static String findAndHandleFormat(HttpServletRequest req, HttpServletResponse res, String defaultFormat)
req - the Servlet requestres - the Servlet responsedefaultFormat - (OPTIONAL) if this is set then it will be the default format assigned when none can be found,
otherwise the default format is Formats.HTMLFormats.XMLpublic static Search makeSearchFromRequestParams(Map<String,Object> params)
params - the request params from a request (do not include headers)public static void setResponseEncoding(String format, HttpServletResponse res)
format - the format constant, example Formats.XMLres - the current outgoing responsepublic static String getServletContext(HttpServletRequest req)
req - the incoming requestCopyright © 2007-2014 CARET, University of Cambridge. All Rights Reserved.