Class RequestUtil

java.lang.Object
edu.ucsb.nceas.metacat.util.RequestUtil

public class RequestUtil extends Object
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static 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
    get(String urlString, Hashtable<String,String[]> params)
     
    static String
    getAttributesAsString(javax.servlet.http.HttpServletRequest request)
    Get all the attributes from the request, as a String.
    static javax.servlet.http.Cookie
    getCookie(javax.servlet.http.HttpServletRequest request, String cookieName)
    Get a cookie from a request by the cookie name
    getParameters(javax.servlet.http.HttpServletRequest request)
    Get all the parameters from the request, as a Hashtable
    static String
    getParametersAsString(javax.servlet.http.HttpServletRequest request)
    Get all the parameters from the request, as a String.
    getSessionData(javax.servlet.http.HttpServletRequest request)
    Get the session data from a request.
    getSessionDataFromToken(javax.servlet.http.HttpServletRequest request)
    Get SessionData from the DataONE auth token
    static String
    post(org.apache.http.client.HttpClient httpclient, String url, HashMap<String,String> paramMap)
    Post a request and return the response body
    static 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
    setUserId(javax.servlet.http.HttpServletRequest request, String userId)
    Add the user's login id to the session on this request

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Method Details

    • forwardRequest

      public static void forwardRequest(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, String destinationUrl, Hashtable<String,String[]> params) throws MetacatUtilException
      Forward a request that was received by this servlet on to another JSP page or servlet to continue handling the request.
      Parameters:
      request - to be forwarded
      response - that can be used for writing output to the client
      destination - the context-relative URL to which the request is forwarded
      params - 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 MetacatUtilException
      Forward 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 forwarded
      response - that can be used for writing output to the client
      params - 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.HttpException
      Post 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 posts
      url - the url to post to
      paramMap - 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 cookie
      cookieName - the name of the cookie to look for
    • getSessionData

      public static SessionData getSessionData(javax.servlet.http.HttpServletRequest request)
      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

      public static SessionData getSessionDataFromToken(javax.servlet.http.HttpServletRequest request)
      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

      public static String getParametersAsString(javax.servlet.http.HttpServletRequest request)
      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

      public static String getAttributesAsString(javax.servlet.http.HttpServletRequest request)
      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 forwarded
      errorVector - 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 forwarded
      errorVector - 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 forwarded
      errorVector - 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 forwarded
      errorVector - 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 forwarded
      errorVector - a list of general message strings
    • setUserId

      public static void setUserId(javax.servlet.http.HttpServletRequest request, String userId)
      Add the user's login id to the session on this request
      Parameters:
      request - the request that will get forwarded
      userId - the user's login id