Class HttpServletUtils


  • public class HttpServletUtils
    extends Object
    Package of small useful methods
    Author:
    Mike Douglass
    • Constructor Summary

      Constructors 
      Constructor Description
      HttpServletUtils()
      Had to have this because it's subclassed.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void dumpHeaders​(javax.servlet.http.HttpServletRequest req)
      Print all the headers
      static String getBrowserType​(javax.servlet.http.HttpServletRequest request)
      Return the browser type for the given request.
      static String getContext​(javax.servlet.http.HttpServletRequest request)
      Returns the context path.
      static String getHeaders​(javax.servlet.http.HttpServletRequest req)
      Return a concatenated string of all the headers
      static Collection<Locale> getLocales​(javax.servlet.http.HttpServletRequest req)
      If there is no Accept-Language header returns null, otherwise returns a collection of Locales ordered with preferred first.
      static String getReqLine​(javax.servlet.http.HttpServletRequest req)  
      static String getUrl​(javax.servlet.http.HttpServletRequest request)
      Returns the String url from the request.
      static String getURLPrefix​(javax.servlet.http.HttpServletRequest request)
      Returns the scheme + host + port part of the url together with the path up to the servlet path.
      static String getURLshp​(javax.servlet.http.HttpServletRequest request)
      Returns the scheme + host + port part of the url.
      static String remoteUser​(javax.servlet.http.HttpServletRequest request)
      Use environment variable BEDEWORK_MIXEDCASE_ACCOUNTS=true to allow mixed case account names.
    • Constructor Detail

      • HttpServletUtils

        public HttpServletUtils()
                         throws Exception
        Had to have this because it's subclassed.
        Throws:
        Exception
    • Method Detail

      • remoteUser

        public static String remoteUser​(javax.servlet.http.HttpServletRequest request)
        Use environment variable BEDEWORK_MIXEDCASE_ACCOUNTS=true to allow mixed case account names.
        Parameters:
        request - to extract remote user
        Returns:
        null for none or possibly lowercased version
      • getBrowserType

        public static String getBrowserType​(javax.servlet.http.HttpServletRequest request)
        Return the browser type for the given request. We attempt to reduce the set of browsers to a more manageable number. The returned value is one of:
        • opera The opera browser
        • MSIE Microsoft Internet Explorer compatible
        • Netscape6 Netscape 6.x
        • Mozilla Mozilla
        • Netscape4 Netscape 4.x compatible
        • default none of the above
        Parameters:
        request - Incoming HttpServletRequest object
        Returns:
        String browser type
      • getReqLine

        public static String getReqLine​(javax.servlet.http.HttpServletRequest req)
        Parameters:
        req -
        Returns:
        reconstructed request
      • getUrl

        public static String getUrl​(javax.servlet.http.HttpServletRequest request)
        Returns the String url from the request.
        Parameters:
        request - incoming request
        Returns:
        String url from the request
      • getURLshp

        public static String getURLshp​(javax.servlet.http.HttpServletRequest request)
        Returns the scheme + host + port part of the url. This allows us to link to services on the same machine.

        For example, a URL of http://myhost.com:8080/myapp/doit.do will get a result "http://myhost.com:8080"

        Parameters:
        request -
        Returns:
        scheme + host + port
      • getURLPrefix

        public static String getURLPrefix​(javax.servlet.http.HttpServletRequest request)
        Returns the scheme + host + port part of the url together with the path up to the servlet path. This allows us to append a new action to the end.

        For example, a URL of http://myhost.com:8080/myapp/doit.do will get a result "http://myhost.com:8080/myapp"

        Parameters:
        request -
        Returns:
        scheme + host + port + path
      • getContext

        public static String getContext​(javax.servlet.http.HttpServletRequest request)
        Returns the context path.

        For example, a URL of http://myhost.com:8080/myapp/doit.do will get a result "/myapp"

        Note: do we have to deal with MultipartRequestWrapper?

        Parameters:
        request -
        Returns:
        context path
      • getHeaders

        public static String getHeaders​(javax.servlet.http.HttpServletRequest req)
        Return a concatenated string of all the headers
        Parameters:
        req - Incoming HttpServletRequest object
        Returns:
        header values
      • dumpHeaders

        public static void dumpHeaders​(javax.servlet.http.HttpServletRequest req)
        Print all the headers
        Parameters:
        req - Incoming HttpServletRequest object
      • getLocales

        public static Collection<Locale> getLocales​(javax.servlet.http.HttpServletRequest req)
        If there is no Accept-Language header returns null, otherwise returns a collection of Locales ordered with preferred first.
        Parameters:
        req -
        Returns:
        Collection of locales or null