Class HTTPTool

  • Direct Known Subclasses:
    ServletTool

    public class HTTPTool
    extends java.lang.Object
    HTTP toolbox
    This class only provides static variables and methods
    • Constructor Summary

      Constructors 
      Constructor Description
      HTTPTool()
      Hidden default constructor
    • Method Summary

      All Methods Static Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      static java.lang.String append​(java.lang.String url, java.lang.String params)
      Append GET parameters to URL
      static java.lang.String append​(java.lang.String url, java.lang.String name, java.lang.Object value)
      Append a GET parameter to URL
      static java.lang.String append​(java.lang.String url, java.util.Map<java.lang.String,​java.lang.Object> params)
      Append GET parameters to URL
      static java.lang.String appendURLParameter​(java.lang.String url, java.lang.String params)
      Deprecated.
      Use append
      static java.lang.String appendURLParameter​(java.lang.String url, java.lang.String name, java.lang.Object value)
      Deprecated.
      Use append
      static java.lang.String appendURLParameter​(java.lang.String url, java.util.Map<java.lang.String,​java.lang.Object> params)
      Deprecated.
      Use append
      static java.lang.String baseURL​(java.lang.String url)
      Get base URL without parameters
      static java.lang.String[] call​(java.net.HttpURLConnection conn, java.lang.Object request)
      Call the HTTP request and disconnect
      static java.lang.String[] call​(java.net.HttpURLConnection conn, java.lang.Object request, java.lang.String encoding)
      Call the HTTP request and disconnect
      static int callMultipart​(java.net.HttpURLConnection conn, java.lang.String[] textFields, java.lang.String[] values, java.lang.String[] fileFields, java.lang.String[] filePaths, java.lang.String[] dataFields, byte[][] data)
      Call the HTTP request with multi-part data
      static java.lang.String[] callMultipartWithReturn​(java.net.HttpURLConnection conn, java.lang.String[] textFields, java.lang.String[] values, java.lang.String[] fileFields, java.lang.String[] filePaths, java.lang.String[] dataFields, byte[][] data)
      Call the HTTP request and disconnect with multi-part data
      static java.lang.String cleanURI​(java.lang.String uri)
      Get clean URI
      static java.lang.String decode​(java.lang.Object data)
      URL decode given string using platform encoding
      static java.lang.String decode​(java.lang.Object data, java.lang.String encoding)
      URL decode given string using specified encoding
      static java.lang.String encode​(java.lang.Object data)
      URL encode given string using platform encoding
      static java.lang.String encode​(java.lang.Object data, java.lang.String encoding)
      URL encode given string using specified encoding
      static java.util.Map<java.lang.String,​java.lang.Object> getBasicAuthLoginPassword​(java.lang.String auth)
      Get username and password from a HTTP basic authentication string (base64 encoded).
      static java.lang.String getBasicAuthString​(java.lang.String username, java.lang.String password)
      Get HTTP basic authentication string (base64 encoded) for use in Authorization or Proxy-Authrorization headers
      static int getCacheMaxAge​(Grant g)
      Get configured maximum cache age or default
      static java.lang.String getCookie​(java.net.HttpURLConnection conn)
      Deprecated.
      Use getCookies
      static java.lang.String getCookies​(java.net.HttpURLConnection conn)
      Get a connection's cookies
      static java.lang.String getExtensionFromMedia​(java.lang.String media)
      Get file extension from media type
      static java.lang.String getHeaderField​(java.net.HttpURLConnection conn, java.lang.String name)
      Get a connection header field
      static int getIEVersion​(java.lang.String userAgent)
      Get Internet Explorer major version number (returns -1 if other browser)
      static java.lang.String getMediaFromMimeType​(java.lang.String mime)
      Get media type from MIME type (with or without encoding)
      static java.lang.String getMimeTypeFromMedia​(java.lang.String media)
      Get MIME type with encoding from media type
      static java.lang.String getMimeTypeWithEncoding​(java.lang.String mime)
      Get MIME type with platform encoding
      static java.lang.String getMimeTypeWithEncoding​(java.lang.String mime, java.lang.String encoding)
      Get MIME type with specified encoding
      static java.net.HttpURLConnection initConnection​(java.lang.String url, java.lang.String method, java.lang.String contentType, java.lang.String cookie, java.lang.String user, java.lang.String pwd, boolean proxy, int timeout)
      Get one HTTP connection
      static javax.net.ssl.HttpsURLConnection initConnectionSSL​(java.lang.String url, java.lang.String method, java.lang.String contentType, java.lang.String cookie, java.io.InputStream jks, java.lang.String pwd, int timeout)
      Get one HTTPS connection
      static javax.net.ssl.HttpsURLConnection initConnectionSSL​(java.lang.String url, java.lang.String method, java.lang.String contentType, java.lang.String cookie, java.lang.String user, java.lang.String pwd, boolean proxy, int timeout)
      Get one HTTPS connection
      static boolean isBrowser​(java.lang.String userAgent, java.lang.String browser)
      Checks if user agent is specified browser.
      static boolean isChrome​(java.lang.String userAgent)
      Checks if user agent is Chrome.
      static boolean isEdge​(java.lang.String userAgent)
      Checks if user agent is Edge.
      static boolean isEmpty​(java.lang.String value)
      Check is HTTP value is empty or equals HTTP.NULL
      static boolean isFirefox​(java.lang.String userAgent)
      Checks if user agent is Firefox.
      static boolean isIE​(java.lang.String userAgent)
      Checks if user agent is Internet Explorer < 11.
      static boolean isIE11​(java.lang.String userAgent)
      Checks if user agent is Internet Explorer 11.
      static boolean isIEMaxVersion​(java.lang.String userAgent, int maxVersion)
      Check if browser is Internet Explorer with specified major version number or less
      static boolean isMobileBrowser​(java.lang.String userAgent)
      Checks if user agent is a mobile browser.
      static boolean isMobileWebkit​(java.lang.String userAgent)
      Checks if user agent is a iPhone/iPad/iPod/Android webkit browser.
      static boolean isOpera​(java.lang.String userAgent)
      Checks if user agent is Opera.
      static boolean isSafari​(java.lang.String userAgent)
      Checks if user agent is Safari.
      static boolean isURLAbsolute​(java.lang.String url)
      Checks if URL is absolute
      static java.lang.String paramsToQueryString​(java.util.Map<java.lang.String,​java.lang.Object> params)
      Get a query string from a parameters map
      static java.lang.String paramsToQueryString​(java.util.Map<java.lang.String,​java.lang.Object> params, java.lang.String encoding)
      Get a query string from a parameters map
      static java.util.Map<java.lang.String,​java.lang.Object> queryStringToParams​(java.lang.String queryString)
      Get a parameters map from a query string
      static java.util.Map<java.lang.String,​java.lang.Object> queryStringToParams​(java.lang.String queryString, java.lang.String encoding)
      Get a parameters map from a query string
      static java.lang.String[] split​(java.lang.String uri)
      Split a cleaned URI into parts (removes the context path)
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • MIME_TYPE_FORM

        public static final java.lang.String MIME_TYPE_FORM
        Form URL-encoded MIME type
        See Also:
        Constant Field Values
      • MIME_TYPE_HTML

        public static final java.lang.String MIME_TYPE_HTML
        HTML MIME type
        See Also:
        Constant Field Values
      • MIME_TYPE_JS

        public static final java.lang.String MIME_TYPE_JS
        Javascript MIME type
        See Also:
        Constant Field Values
      • MIME_TYPE_CSS

        public static final java.lang.String MIME_TYPE_CSS
        CSS MIME type
        See Also:
        Constant Field Values
      • MIME_TYPE_XML

        public static final java.lang.String MIME_TYPE_XML
        XML MIME type
        See Also:
        Constant Field Values
      • MIME_TYPE_TXT

        public static final java.lang.String MIME_TYPE_TXT
        Text MIME type
        See Also:
        Constant Field Values
      • MIME_TYPE_CSV

        public static final java.lang.String MIME_TYPE_CSV
        CSV MIME type
        See Also:
        Constant Field Values
      • MIME_TYPE_TSV

        public static final java.lang.String MIME_TYPE_TSV
        TSV MIME type
        See Also:
        Constant Field Values
      • MIME_TYPE_JSON

        public static final java.lang.String MIME_TYPE_JSON
        JSON MIME type
        See Also:
        Constant Field Values
      • MIME_TYPE_YAML

        public static final java.lang.String MIME_TYPE_YAML
        YAML MIME type
        See Also:
        Constant Field Values
      • MIME_TYPE_SQL

        public static final java.lang.String MIME_TYPE_SQL
        SQL MIME type
        See Also:
        Constant Field Values
      • MIME_TYPE_MD

        public static final java.lang.String MIME_TYPE_MD
        Markdown MIME type
        See Also:
        Constant Field Values
      • MIME_TYPE_LOG

        public static final java.lang.String MIME_TYPE_LOG
        Log MIME type
        See Also:
        Constant Field Values
      • MIME_TYPE_XLSX

        public static final java.lang.String MIME_TYPE_XLSX
        XLSX MIME type
        See Also:
        Constant Field Values
      • MIME_TYPE_DOCX

        public static final java.lang.String MIME_TYPE_DOCX
        DOCX MIME type
        See Also:
        Constant Field Values
      • MIME_TYPE_DOC

        public static final java.lang.String MIME_TYPE_DOC
        DOC MIME type
        See Also:
        Constant Field Values
      • MIME_TYPE_RTF

        public static final java.lang.String MIME_TYPE_RTF
        RTF MIME type
        See Also:
        Constant Field Values
      • MIME_TYPE_PPTX

        public static final java.lang.String MIME_TYPE_PPTX
        PPTX MIME type
        See Also:
        Constant Field Values
      • MIME_TYPE_PPT

        public static final java.lang.String MIME_TYPE_PPT
        PPT MIME type
        See Also:
        Constant Field Values
      • MIME_TYPE_PDF

        public static final java.lang.String MIME_TYPE_PDF
        PDF MIME type
        See Also:
        Constant Field Values
      • MIME_TYPE_ZIP

        public static final java.lang.String MIME_TYPE_ZIP
        ZIP MIME type
        See Also:
        Constant Field Values
      • MIME_TYPE_RSS

        public static final java.lang.String MIME_TYPE_RSS
        RSS MIME type
        See Also:
        Constant Field Values
      • MIME_TYPE_PNG

        public static final java.lang.String MIME_TYPE_PNG
        PNG image MIME type
        See Also:
        Constant Field Values
      • MIME_TYPE_JPG

        public static final java.lang.String MIME_TYPE_JPG
        JPEG image MIME type
        See Also:
        Constant Field Values
      • MIME_TYPE_GIF

        public static final java.lang.String MIME_TYPE_GIF
        GIF image MIME type
        See Also:
        Constant Field Values
      • MIME_TYPE_SVG

        public static final java.lang.String MIME_TYPE_SVG
        SVG image MIME type
        See Also:
        Constant Field Values
      • MIME_TYPE_BIN

        public static final java.lang.String MIME_TYPE_BIN
        Binary MIME type
        See Also:
        Constant Field Values
      • MIME_TYPE_DATA

        public static final java.lang.String MIME_TYPE_DATA
        Data MIME type
        See Also:
        Constant Field Values
      • MEDIA_HTML

        public static final java.lang.String MEDIA_HTML
        HTML media type
        See Also:
        Constant Field Values
      • MEDIA_JS

        public static final java.lang.String MEDIA_JS
        Javascript media type
        See Also:
        Constant Field Values
      • MEDIA_CSS

        public static final java.lang.String MEDIA_CSS
        CSS media type
        See Also:
        Constant Field Values
      • MEDIA_XML

        public static final java.lang.String MEDIA_XML
        XML media type
        See Also:
        Constant Field Values
      • MEDIA_TXT

        public static final java.lang.String MEDIA_TXT
        Text media type
        See Also:
        Constant Field Values
      • MEDIA_CSV

        public static final java.lang.String MEDIA_CSV
        CSV media type
        See Also:
        Constant Field Values
      • MEDIA_JSON

        public static final java.lang.String MEDIA_JSON
        JSON media type
        See Also:
        Constant Field Values
      • MEDIA_YAML

        public static final java.lang.String MEDIA_YAML
        YAML media type
        See Also:
        Constant Field Values
      • MEDIA_SQL

        public static final java.lang.String MEDIA_SQL
        SQL media type
        See Also:
        Constant Field Values
      • MEDIA_LOG

        public static final java.lang.String MEDIA_LOG
        Log media type
        See Also:
        Constant Field Values
      • MEDIA_MD

        public static final java.lang.String MEDIA_MD
        Markdown media type
        See Also:
        Constant Field Values
      • MEDIA_XLSX

        public static final java.lang.String MEDIA_XLSX
        XLSX media type
        See Also:
        Constant Field Values
      • MEDIA_XLS

        public static final java.lang.String MEDIA_XLS
        XLS media type
        See Also:
        Constant Field Values
      • MEDIA_DOCX

        public static final java.lang.String MEDIA_DOCX
        DOCX media type
        See Also:
        Constant Field Values
      • MEDIA_DOC

        public static final java.lang.String MEDIA_DOC
        DOC media type
        See Also:
        Constant Field Values
      • MEDIA_PPTX

        public static final java.lang.String MEDIA_PPTX
        PPTX media type
        See Also:
        Constant Field Values
      • MEDIA_PPT

        public static final java.lang.String MEDIA_PPT
        PPT media type
        See Also:
        Constant Field Values
      • MEDIA_PDF

        public static final java.lang.String MEDIA_PDF
        PDF media type
        See Also:
        Constant Field Values
      • MEDIA_ZIP

        public static final java.lang.String MEDIA_ZIP
        ZIP media type
        See Also:
        Constant Field Values
      • MEDIA_ARC

        public static final java.lang.String MEDIA_ARC
        Archive media type
        See Also:
        Constant Field Values
      • DISP_INLINE

        public static final java.lang.String DISP_INLINE
        Inline content disposition
        See Also:
        Constant Field Values
      • DISP_ATTACH

        public static final java.lang.String DISP_ATTACH
        Attachment content disposition
        See Also:
        Constant Field Values
      • AUTH_HEADER

        public static final java.lang.String AUTH_HEADER
        Standard authorization header name
        See Also:
        Constant Field Values
      • X_AUTH_HEADER

        public static final java.lang.String X_AUTH_HEADER
        Simplicite authorization header name
        See Also:
        Constant Field Values
      • X_AUTH_PARAM

        public static final java.lang.String X_AUTH_PARAM
        Simplicite authorization parameter name
      • X_METHOD_HEADER

        public static final java.lang.String X_METHOD_HEADER
        Standard HTTP method override header name
        See Also:
        Constant Field Values
      • X_SESSION_HEADER

        public static final java.lang.String X_SESSION_HEADER
        Simplicite session ID header name
        See Also:
        Constant Field Values
      • BROWSER_IE

        public static final java.lang.String BROWSER_IE
        Microsoft Internet Explorer regular expression
        See Also:
        Constant Field Values
      • BROWSER_IE11

        public static final java.lang.String BROWSER_IE11
        Microsoft Internet Explorer 11 regular expression
        See Also:
        Constant Field Values
      • BROWSER_EDGE

        public static final java.lang.String BROWSER_EDGE
        Microsoft Edge regular expression
        See Also:
        Constant Field Values
      • BROWSER_FIREFOX

        public static final java.lang.String BROWSER_FIREFOX
        Mozilla Firefox regular expression
        See Also:
        Constant Field Values
      • BROWSER_CHROME

        public static final java.lang.String BROWSER_CHROME
        Googe Chrome regular expression
        See Also:
        Constant Field Values
      • BROWSER_SAFARI

        public static final java.lang.String BROWSER_SAFARI
        Apple Safari regular expression
        See Also:
        Constant Field Values
      • BROWSER_SAFARI_IPHONE

        public static final java.lang.String BROWSER_SAFARI_IPHONE
        Apple Safari (iPhone) regular expression
        See Also:
        Constant Field Values
      • BROWSER_SAFARI_IPAD

        public static final java.lang.String BROWSER_SAFARI_IPAD
        Apple Safari (iPad) regular expression
        See Also:
        Constant Field Values
      • BROWSER_SAFARI_ANDROID

        public static final java.lang.String BROWSER_SAFARI_ANDROID
        Apple Safari (Android) regular expression
        See Also:
        Constant Field Values
      • BROWSER_OPERA

        public static final java.lang.String BROWSER_OPERA
        Opera regular expression
        See Also:
        Constant Field Values
    • Constructor Detail

      • HTTPTool

        public HTTPTool()
        Hidden default constructor
    • Method Detail

      • isEmpty

        public static boolean isEmpty​(java.lang.String value)
        Check is HTTP value is empty or equals HTTP.NULL
        Parameters:
        value - Value to check
      • getCacheMaxAge

        public static int getCacheMaxAge​(Grant g)
        Get configured maximum cache age or default
        Parameters:
        g - Grant
        Returns:
        Max cache age in seconds
      • getMimeTypeWithEncoding

        public static java.lang.String getMimeTypeWithEncoding​(java.lang.String mime)
        Get MIME type with platform encoding
        Parameters:
        mime - MIME type (one of MIME_TYPE_*)
        Returns:
        MIME type with encoding
      • getMimeTypeWithEncoding

        public static java.lang.String getMimeTypeWithEncoding​(java.lang.String mime,
                                                               java.lang.String encoding)
        Get MIME type with specified encoding
        Parameters:
        mime - MIME type (one of MIME_TYPE_*)
        encoding - Encoding
        Returns:
        MIME type with encoding
      • getMimeTypeFromMedia

        public static java.lang.String getMimeTypeFromMedia​(java.lang.String media)
        Get MIME type with encoding from media type
        Parameters:
        media - Media type (one of MEDIA_*)
        Returns:
        MIME type with encoding
      • getMediaFromMimeType

        public static java.lang.String getMediaFromMimeType​(java.lang.String mime)
        Get media type from MIME type (with or without encoding)
        Parameters:
        mime - MIME type (one of MIME_TYPE_*)
        Returns:
        Media type (one of MEDIA_*)
      • getExtensionFromMedia

        public static java.lang.String getExtensionFromMedia​(java.lang.String media)
        Get file extension from media type
        Parameters:
        media - Media type (one of MEDIA_*)
        Returns:
        Lowercase file extension
      • isBrowser

        public static boolean isBrowser​(java.lang.String userAgent,
                                        java.lang.String browser)
        Checks if user agent is specified browser.
        Parameters:
        userAgent - User agent string
        browser - Browser's pattern in user agent (user HTTPTool.BROWSER_* constants)
        Returns:
        true if browser matches
      • isIE

        public static boolean isIE​(java.lang.String userAgent)
        Checks if user agent is Internet Explorer < 11.
        Parameters:
        userAgent - User agent string
        Returns:
        true if browser matches
      • isIE11

        public static boolean isIE11​(java.lang.String userAgent)
        Checks if user agent is Internet Explorer 11.
        Parameters:
        userAgent - User agent string
        Returns:
        true if browser matches
      • isEdge

        public static boolean isEdge​(java.lang.String userAgent)
        Checks if user agent is Edge.
        Parameters:
        userAgent - User agent string
        Returns:
        true if browser matches
      • isFirefox

        public static boolean isFirefox​(java.lang.String userAgent)
        Checks if user agent is Firefox.
        Parameters:
        userAgent - User agent string
        Returns:
        true if browser matches
      • isChrome

        public static boolean isChrome​(java.lang.String userAgent)
        Checks if user agent is Chrome.
        Parameters:
        userAgent - User agent string
        Returns:
        true if browser matches
      • isOpera

        public static boolean isOpera​(java.lang.String userAgent)
        Checks if user agent is Opera.
        Parameters:
        userAgent - User agent string
        Returns:
        true if browser matches
      • isSafari

        public static boolean isSafari​(java.lang.String userAgent)
        Checks if user agent is Safari.
        Parameters:
        userAgent - User agent string
        Returns:
        true if browser matches
      • getIEVersion

        public static int getIEVersion​(java.lang.String userAgent)
        Get Internet Explorer major version number (returns -1 if other browser)
        Parameters:
        userAgent - User agent string
        Returns:
        Internet Explorer major version number
      • isIEMaxVersion

        public static boolean isIEMaxVersion​(java.lang.String userAgent,
                                             int maxVersion)
        Check if browser is Internet Explorer with specified major version number or less
        Parameters:
        userAgent - User agent string
        maxVersion - Maximum version to check if browser version is less or equals to it
        Returns:
        true if browser is Internet Explorer and if major version matches
      • isMobileWebkit

        public static boolean isMobileWebkit​(java.lang.String userAgent)
        Checks if user agent is a iPhone/iPad/iPod/Android webkit browser.
        Parameters:
        userAgent - User agent string
        Returns:
        true if browser matches
      • isMobileBrowser

        public static boolean isMobileBrowser​(java.lang.String userAgent)
        Checks if user agent is a mobile browser.
        Parameters:
        userAgent - User agent string
        Returns:
        true if browser matches
      • baseURL

        public static java.lang.String baseURL​(java.lang.String url)
        Get base URL without parameters
        Parameters:
        url - URL to extract base URL from
        Returns:
        Base URL
      • isURLAbsolute

        public static boolean isURLAbsolute​(java.lang.String url)
        Checks if URL is absolute
        Parameters:
        url - URL
        Returns:
        True if URL is absolute
      • encode

        public static java.lang.String encode​(java.lang.Object data)
        URL encode given string using platform encoding
        Parameters:
        data - Data to URL encode (if not a String then toString() is applied to Object)
        Returns:
        URL-encoded string
      • encode

        public static java.lang.String encode​(java.lang.Object data,
                                              java.lang.String encoding)
        URL encode given string using specified encoding
        Parameters:
        data - Data to URL encode (if not a String then toString() is applied to Object)
        encoding - encoding
        Returns:
        Encoded string
      • decode

        public static java.lang.String decode​(java.lang.Object data)
        URL decode given string using platform encoding
        Parameters:
        data - Data to URL decode (if not a String then toString() is applied to Object)
        Returns:
        Decoded string
      • decode

        public static java.lang.String decode​(java.lang.Object data,
                                              java.lang.String encoding)
        URL decode given string using specified encoding
        Parameters:
        data - Data to URL decode (if not a String then toString() is applied to Object)
        encoding - encoding
        Returns:
        Decoded string
      • appendURLParameter

        @Deprecated
        public static java.lang.String appendURLParameter​(java.lang.String url,
                                                          java.lang.String params)
        Deprecated.
        Use append
      • append

        public static java.lang.String append​(java.lang.String url,
                                              java.lang.String params)
        Append GET parameters to URL
        Parameters:
        url - URL
        params - URL-encoded parameters (in the form name=value[&name=value[...]]
        Returns:
        URL with parameters appended as GET parameters
      • appendURLParameter

        @Deprecated
        public static java.lang.String appendURLParameter​(java.lang.String url,
                                                          java.lang.String name,
                                                          java.lang.Object value)
        Deprecated.
        Use append
      • append

        public static java.lang.String append​(java.lang.String url,
                                              java.lang.String name,
                                              java.lang.Object value)
        Append a GET parameter to URL
        Parameters:
        url - URL
        name - Name
        value - Non URL encoded value
        Returns:
        URL with parameter appended as GET parameter
      • appendURLParameter

        @Deprecated
        public static java.lang.String appendURLParameter​(java.lang.String url,
                                                          java.util.Map<java.lang.String,​java.lang.Object> params)
        Deprecated.
        Use append
      • append

        public static java.lang.String append​(java.lang.String url,
                                              java.util.Map<java.lang.String,​java.lang.Object> params)
        Append GET parameters to URL
        Parameters:
        url - URL
        params - Map of name and non URL encoded values
        Returns:
        URL with parameters appended as GET parameters
      • queryStringToParams

        public static java.util.Map<java.lang.String,​java.lang.Object> queryStringToParams​(java.lang.String queryString)
        Get a parameters map from a query string
        Parameters:
        queryString - Query string
        Returns:
        Parameters map
      • queryStringToParams

        public static java.util.Map<java.lang.String,​java.lang.Object> queryStringToParams​(java.lang.String queryString,
                                                                                                 java.lang.String encoding)
        Get a parameters map from a query string
        Parameters:
        queryString - Query string
        encoding - Encoding
        Returns:
        Parameters map
      • paramsToQueryString

        public static java.lang.String paramsToQueryString​(java.util.Map<java.lang.String,​java.lang.Object> params)
        Get a query string from a parameters map
        Parameters:
        params - Parameters map
        Returns:
        Query string
      • paramsToQueryString

        public static java.lang.String paramsToQueryString​(java.util.Map<java.lang.String,​java.lang.Object> params,
                                                           java.lang.String encoding)
        Get a query string from a parameters map
        Parameters:
        encoding - Encoding
        params - Parameters map
        Returns:
        Query string
      • getBasicAuthString

        public static java.lang.String getBasicAuthString​(java.lang.String username,
                                                          java.lang.String password)
        Get HTTP basic authentication string (base64 encoded) for use in Authorization or Proxy-Authrorization headers
        Parameters:
        username - User name
        password - Password
        Returns:
        HTTP basic authentication string
      • getBasicAuthLoginPassword

        public static java.util.Map<java.lang.String,​java.lang.Object> getBasicAuthLoginPassword​(java.lang.String auth)
                                                                                                throws ParamsException
        Get username and password from a HTTP basic authentication string (base64 encoded).
        Parameters:
        auth - Auth string with keys "login" and "password"
        Returns:
        Username and password as map
        Throws:
        ParamsException
      • initConnection

        public static java.net.HttpURLConnection initConnection​(java.lang.String url,
                                                                java.lang.String method,
                                                                java.lang.String contentType,
                                                                java.lang.String cookie,
                                                                java.lang.String user,
                                                                java.lang.String pwd,
                                                                boolean proxy,
                                                                int timeout)
                                                         throws java.io.IOException
        Get one HTTP connection
        Parameters:
        url - Full URL
        method - GET or POST
        contentType - Content-Type header
        cookie - Cookies
        user - Optional user for HTTP basic authentication
        pwd - Optional password for HTTP basic authentication
        proxy - true to use user and pwd in the Proxy-Authorization header instead of the Authorization header
        timeout - timeout value in milliseconds, 0 is interpreted as an infinite timeout
        Returns:
        HTTP connection
        Throws:
        java.io.IOException
      • initConnectionSSL

        public static javax.net.ssl.HttpsURLConnection initConnectionSSL​(java.lang.String url,
                                                                         java.lang.String method,
                                                                         java.lang.String contentType,
                                                                         java.lang.String cookie,
                                                                         java.lang.String user,
                                                                         java.lang.String pwd,
                                                                         boolean proxy,
                                                                         int timeout)
                                                                  throws java.io.IOException
        Get one HTTPS connection
        Parameters:
        url - Full URL
        method - GET or POST
        contentType - Content-Type header
        cookie - Cookies
        user - Optional user for HTTP basic authentication
        pwd - Optional password for HTTP basic authentication
        proxy - true to use user and pwd in the Proxy-Authorization header instead of the Authorization header
        timeout - timeout value in milliseconds, 0 is interpreted as an infinite timeout
        Returns:
        HTTP connection
        Throws:
        An - exception if JKS certificate is incorrect
        java.io.IOException
      • initConnectionSSL

        public static javax.net.ssl.HttpsURLConnection initConnectionSSL​(java.lang.String url,
                                                                         java.lang.String method,
                                                                         java.lang.String contentType,
                                                                         java.lang.String cookie,
                                                                         java.io.InputStream jks,
                                                                         java.lang.String pwd,
                                                                         int timeout)
                                                                  throws java.io.IOException
        Get one HTTPS connection
        Parameters:
        url - Full URL
        method - GET or POST
        contentType - Content-Type header
        cookie - Cookies
        jks - Optional JKS key store (as stream) for certificate based authentication
        pwd - Optional password for certificate based authentication
        timeout - timeout value in milliseconds, 0 is interpreted as an infinite timeout
        Returns:
        HTTP connection
        Throws:
        An - exception if JKS certificate is incorrect
        java.io.IOException
      • call

        public static java.lang.String[] call​(java.net.HttpURLConnection conn,
                                              java.lang.Object request)
                                       throws java.io.IOException,
                                              HTTPException
        Call the HTTP request and disconnect
        Parameters:
        conn - HTTP connection
        request - Message to send
        Returns:
        Array with the response and the full cookie
        Throws:
        An - exception when status not equals to HTTP 20x
        java.io.IOException
        HTTPException
      • call

        public static java.lang.String[] call​(java.net.HttpURLConnection conn,
                                              java.lang.Object request,
                                              java.lang.String encoding)
                                       throws java.io.IOException,
                                              HTTPException
        Call the HTTP request and disconnect
        Parameters:
        conn - HTTP connection
        request - Message to send
        encoding - Encoding (used to encode request to and to decode response from)
        Returns:
        Array with the string response and the full cookie
        Throws:
        an - exception when status not equals to HTTP 20x
        java.io.IOException
        HTTPException
      • callMultipart

        public static int callMultipart​(java.net.HttpURLConnection conn,
                                        java.lang.String[] textFields,
                                        java.lang.String[] values,
                                        java.lang.String[] fileFields,
                                        java.lang.String[] filePaths,
                                        java.lang.String[] dataFields,
                                        byte[][] data)
                                 throws java.io.IOException
        Call the HTTP request with multi-part data
        Parameters:
        conn - HTTP connection
        textFields - field names to send
        values - field values
        fileFields - file names to send
        filePaths - file local paths
        dataFields - data names to send (format: name[;file name]
        data - bytes to send
        Returns:
        HTTP response code
        Throws:
        java.io.IOException
      • callMultipartWithReturn

        public static java.lang.String[] callMultipartWithReturn​(java.net.HttpURLConnection conn,
                                                                 java.lang.String[] textFields,
                                                                 java.lang.String[] values,
                                                                 java.lang.String[] fileFields,
                                                                 java.lang.String[] filePaths,
                                                                 java.lang.String[] dataFields,
                                                                 byte[][] data)
                                                          throws java.io.IOException,
                                                                 HTTPException
        Call the HTTP request and disconnect with multi-part data
        Parameters:
        conn - HTTP connection
        textFields - field names to send
        values - field values
        fileFields - file names to send
        filePaths - file local paths
        dataFields - data names to send
        data - bytes to send
        Returns:
        Array with the response and the full cookie
        Throws:
        an - exception when status not equals to HTTP 20x
        java.io.IOException
        HTTPException
      • getHeaderField

        public static java.lang.String getHeaderField​(java.net.HttpURLConnection conn,
                                                      java.lang.String name)
        Get a connection header field
        Parameters:
        conn - HTTP connection
        name - Header field name
        Returns:
        field value or null if not found
      • getCookie

        @Deprecated
        public static java.lang.String getCookie​(java.net.HttpURLConnection conn)
        Deprecated.
        Use getCookies
      • getCookies

        public static java.lang.String getCookies​(java.net.HttpURLConnection conn)
        Get a connection's cookies
        Parameters:
        conn - HTTP connection
        Returns:
        cookie value or null
      • cleanURI

        public static java.lang.String cleanURI​(java.lang.String uri)
        Get clean URI
        Parameters:
        uri - URI to clean
      • split

        public static java.lang.String[] split​(java.lang.String uri)
        Split a cleaned URI into parts (removes the context path)
        Parameters:
        uri - URI to split