Class HttpTransactionUtils


  • public class HttpTransactionUtils
    extends Object
    HTTP utilites
    • Method Detail

      • formatParameter

        public static String formatParameter​(String name,
                                             String value)
        Format one HTTP parameter
        Parameters:
        name - Parameter name
        value - Parameter value (URLEncoded using default chracter set)
        Returns:
        Parameter text (ampersand+name=url-encoded-value)
      • formatParameter

        public static String formatParameter​(String name,
                                             String value,
                                             String separator,
                                             String cs)
        Format one HTTP parameter
        Parameters:
        name - Parameter name
        value - Parameter value (will be URLEncoded)
        separator - Character to separate parameters
        cs - Character set specification (utf-8, etc)
        Returns:
        Parameter text (separator+name=url-encoded-value)
      • isHttpInfo

        public static boolean isHttpInfo​(int status)
        Informational status?
        Returns:
        true if so
      • isHttpRedirect

        public static boolean isHttpRedirect​(int status)
        HTTP redirect?
        Returns:
        true if so
      • isHttpSuccess

        public static boolean isHttpSuccess​(int status)
        Success status?
        Returns:
        true if so
      • isHttpRequestError

        public static boolean isHttpRequestError​(int status)
        Error in request?
        Returns:
        true if so
      • isHttpServerError

        public static boolean isHttpServerError​(int status)
        Server error?
        Returns:
        true if so
      • isHttpError

        public static boolean isHttpError​(int status)
        General "did an error occur"?
        Returns:
        true if so
      • getAttributesAsMap

        public static Map getAttributesAsMap​(javax.servlet.http.HttpServletRequest request)
        Set up a simple Map of HTTP request parameters (assumes no duplicate names)
        Parameters:
        request - HttpServletRequest object
        Returns:
        Map of name=value pairs
      • formatUrl

        public static String formatUrl​(URL url,
                                       boolean preserveFile)
                                throws MalformedURLException
        Format a base URL string ( protocol://server[:port][/file-specification] )
        Parameters:
        url - URL to format
        preserveFile - Keep the /directory/filename portion of the URL?
        Returns:
        URL string
        Throws:
        MalformedURLException
      • getServer

        public static String getServer​(String url)
        Pull the server [and port] from a URL specification
        Parameters:
        url - URL string
        Returns:
        server[:port]
      • getUrlComponent

        public static String getUrlComponent​(String url,
                                             String component)
                                      throws MalformedURLException
        Fetch a component from a URL string
        Parameters:
        url - URL String
        component - name (one of server, file, parameters, fileandparameters)
        Returns:
        URL component string (null if none)
        Throws:
        MalformedURLException
      • urlEncodeFullUrl

        public static String urlEncodeFullUrl​(String original)
        URLEncode parameter names and values
        Parameters:
        original - Full URL specification (http://example.com/xxx?a=b&c=d)
        Returns:
        Original URL with (possibly) encoded parameters
      • urlEncodeParameters

        public static String urlEncodeParameters​(String original)
        URLEncode parameter names and values
        Parameters:
        original - Original parameter list (?a=b&c=d)
        Returns:
        Possibly encoded parameter list