Package edu.ucsb.nceas.metacat.util
Class RequestUtil
java.lang.Object
edu.ucsb.nceas.metacat.util.RequestUtil
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
clearRequestMessages
(javax.servlet.http.HttpServletRequest request) Add a list of general messages to the request.static void
forwardRequest
(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, String destinationUrl, Hashtable<String, String[]> params) Forward a request that was received by this servlet on to another JSP page or servlet to continue handling the request.static void
forwardRequest
(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, Hashtable<String, String[]> params) Forward a request that was received by this servlet on to another JSP page or servlet to continue handling the request.static String
static String
getAttributesAsString
(javax.servlet.http.HttpServletRequest request) Get all the attributes from the request, as a String.static javax.servlet.http.Cookie
Get a cookie from a request by the cookie namegetParameters
(javax.servlet.http.HttpServletRequest request) Get all the parameters from the request, as a Hashtablestatic String
getParametersAsString
(javax.servlet.http.HttpServletRequest request) Get all the parameters from the request, as a String.static SessionData
getSessionData
(javax.servlet.http.HttpServletRequest request) Get the session data from a request.static SessionData
getSessionDataFromToken
(javax.servlet.http.HttpServletRequest request) Get SessionData from the DataONE auth tokenstatic String
Post a request and return the response bodystatic void
setRequestErrors
(javax.servlet.http.HttpServletRequest request, Vector<String> errorVector) Add a list of errors to the request.static void
setRequestFormErrors
(javax.servlet.http.HttpServletRequest request, Vector<String> errorVector) Add a list of form errors to the request.static void
setRequestMessage
(javax.servlet.http.HttpServletRequest request, Vector<String> messageVector) Add a list of general messages to the request.static void
setRequestSuccess
(javax.servlet.http.HttpServletRequest request, Vector<String> successVector) Add a list of success messages to the request.static void
Add the user's login id to the session on this request
-
Field Details
-
ATTR_USER_ID
- See Also:
-
-
Method Details
-
forwardRequest
public static void forwardRequest(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, String destinationUrl, Hashtable<String, String[]> params) throws MetacatUtilExceptionForward a request that was received by this servlet on to another JSP page or servlet to continue handling the request.- Parameters:
request
- to be forwardedresponse
- that can be used for writing output to the clientdestination
- the context-relative URL to which the request is forwardedparams
- the request parameters. these will be added to the request- Throws:
MetacatUtilException
-
forwardRequest
public static void forwardRequest(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, Hashtable<String, String[]> params) throws MetacatUtilExceptionForward a request that was received by this servlet on to another JSP page or servlet to continue handling the request. In this case, the page must be referenced in a paramter named "forwardto". If the qformat is provided, the file will be retrieved from that skin. Otherwise, the file will be retrieved from the system default skin. For more specific file location, use: forwardRequest(request,response, destinationUrl, params)- Parameters:
request
- to be forwardedresponse
- that can be used for writing output to the clientparams
- the request parameters. these will be added to the request.- Throws:
MetacatUtilException
-
post
public static String post(org.apache.http.client.HttpClient httpclient, String url, HashMap<String, String> paramMap) throws IOException, org.apache.http.HttpExceptionPost a request and return the response body- Parameters:
httpClient
- The HttpClient to use in the post. This is passed in because the same client may be used in several postsurl
- the url to post toparamMap
- map of parameters to add to the post- Throws:
IOException
org.apache.http.HttpException
-
get
public static String get(String urlString, Hashtable<String, String[]> params) throws MetacatUtilException- Throws:
MetacatUtilException
-
getCookie
public static javax.servlet.http.Cookie getCookie(javax.servlet.http.HttpServletRequest request, String cookieName) Get a cookie from a request by the cookie name- Parameters:
request
- the request from which to get the cookiecookieName
- the name of the cookie to look for
-
getSessionData
Get the session data from a request. The Scenarios we can run across here: -- the session id parameter was set in the request parameters -- request.getSession returns a new session. There is a chance that the session id was set in a cookie. Check for a JSESSIONID cookie and use that id if provided. -- request.getSession returns a session that is a) preexisting or b) new but without a JSESSIONID cookie. Use the session id from this session- Parameters:
request
- the request from which to get the session data- Returns:
- the session data object representing the active session for this request. If there is no active session, the public session data is returned
-
getSessionDataFromToken
Get SessionData from the DataONE auth token- Parameters:
request
-- Returns:
-
getParameters
public static Hashtable<String,String[]> getParameters(javax.servlet.http.HttpServletRequest request) Get all the parameters from the request, as a Hashtable- Parameters:
request
- the request from which to get the cookie- Returns:
- a Hashtable containing the parameter names and a string array of values for each
-
getParametersAsString
Get all the parameters from the request, as a String. (The parameters are the name-value pairs that are passed as part of the URL, or within a form post.) Note that for a given parameter name (e.g. paramName1), there is an array of associated values - (for example: { paramValue1a, paramValue1b, ...etc. }- Parameters:
request
- the request from which to get the parameters- Returns:
- a String containing the parameter names and all the values for each, formatted
as follows:
paramName1: paramValue1a paramValue1b paramName2: paramValue2a ...etc
If no parameters are found, returns an empty string. Will never return null.
-
getAttributesAsString
Get all the attributes from the request, as a String. The attributes are the name=value pairs that are added to the request object by calls to request.setAttribute(String, Object). Attributes are reset between requests.- Parameters:
request
- the request from which to get the attributes- Returns:
- a String containing the attribute names and the value for each, formatted as follows:
attribName1 = attribValue1 attribName2 = attribValue2 ...etc
If no attributes are found, returns an empty string. Will never return null.
-
setRequestErrors
public static void setRequestErrors(javax.servlet.http.HttpServletRequest request, Vector<String> errorVector) Add a list of errors to the request. The pages will pick up the errors and display them where appropriate.- Parameters:
request
- the request that will get forwardederrorVector
- a list of error strings
-
setRequestFormErrors
public static void setRequestFormErrors(javax.servlet.http.HttpServletRequest request, Vector<String> errorVector) Add a list of form errors to the request. The pages will pick up the errors and display them where appropriate.- Parameters:
request
- the request that will get forwardederrorVector
- a list of form error strings
-
setRequestSuccess
public static void setRequestSuccess(javax.servlet.http.HttpServletRequest request, Vector<String> successVector) Add a list of success messages to the request. The pages will pick up the messages and display them where appropriate.- Parameters:
request
- the request that will get forwardederrorVector
- a list of success message strings
-
setRequestMessage
public static void setRequestMessage(javax.servlet.http.HttpServletRequest request, Vector<String> messageVector) Add a list of general messages to the request. The pages will pick up the messages and display them where appropriate.- Parameters:
request
- the request that will get forwardederrorVector
- a list of general message strings
-
clearRequestMessages
public static void clearRequestMessages(javax.servlet.http.HttpServletRequest request) Add a list of general messages to the request. The pages will pick up the messages and display them where appropriate.- Parameters:
request
- the request that will get forwardederrorVector
- a list of general message strings
-
setUserId
Add the user's login id to the session on this request- Parameters:
request
- the request that will get forwardeduserId
- the user's login id
-