Class Connection


  • public class Connection
    extends Object
    Represents and structures connection information. Facilitates HPCC connectivity, provides several convenience methods such as credential encoding, connection URL parsing, and others.
    • Field Detail

      • portDelimiter

        public static final char portDelimiter
        Constant portDelimiter=':'
        See Also:
        Constant Field Values
      • pathDelimiter

        public static final char pathDelimiter
        Constant pathDelimiter='/'
        See Also:
        Constant Field Values
      • firstOptDelimiter

        public static final char firstOptDelimiter
        Constant firstOptDelimiter='?'
        See Also:
        Constant Field Values
      • subsequentOptDelimiter

        public static final char subsequentOptDelimiter
        Constant subsequentOptDelimiter='&'
        See Also:
        Constant Field Values
      • CONNECT_TIMEOUT_PARAM

        public static final String CONNECT_TIMEOUT_PARAM
        Constant CONNECT_TIMEOUT_PARAM="connecttimeoutmillis"
        See Also:
        Constant Field Values
      • READ_TIMEOUT_PARAM

        public static final String READ_TIMEOUT_PARAM
        Constant READ_TIMEOUT_PARAM="readtimeoutmillis"
        See Also:
        Constant Field Values
      • WRITE_TIMEOUT_PARAM

        public static final String WRITE_TIMEOUT_PARAM
        Constant WRITE_TIMEOUT_PARAM="writetimeoutmillis"
        See Also:
        Constant Field Values
      • SOCKET_TIMEOUT_PARAM

        public static final String SOCKET_TIMEOUT_PARAM
        Constant SOCKET_TIMEOUT_PARAM="sockettimeoutmillis"
        See Also:
        Constant Field Values
      • DEFAULT_CONNECT_TIMEOUT_MILLI

        public static final int DEFAULT_CONNECT_TIMEOUT_MILLI
        Constant DEFAULT_CONNECT_TIMEOUT_MILLI=150000
        See Also:
        Constant Field Values
      • DEFAULT_SO_TIMEOUT_MILLI

        public static final int DEFAULT_SO_TIMEOUT_MILLI
        Constant DEFAULT_SO_TIMEOUT_MILLI=150000
        See Also:
        Constant Field Values
      • DEFAULT_WRITE_TIMEOUT_MILLI

        public static final int DEFAULT_WRITE_TIMEOUT_MILLI
        Constant DEFAULT_WRITE_TIMEOUT_MILLI=150000
        See Also:
        Constant Field Values
      • DEFAULT_READ_TIMEOUT_MILLI

        public static final int DEFAULT_READ_TIMEOUT_MILLI
        Constant DEFAULT_READ_TIMEOUT_MILLI=180 * 1000
        See Also:
        Constant Field Values
      • connectTimeoutMilli

        protected int connectTimeoutMilli
      • readTimeoutMilli

        protected int readTimeoutMilli
      • writeTimeoutMilli

        protected int writeTimeoutMilli
      • socketTimeoutMilli

        protected int socketTimeoutMilli
    • Constructor Detail

      • Connection

        public Connection​(boolean ssl,
                          String host,
                          int port)
        Instantiates a new connection.
        Parameters:
        ssl - the ssl
        host - the host
        port - the port
      • Connection

        public Connection​(String protocol,
                          String host,
                          String port)
        Instantiates a new connection.
        Parameters:
        protocol - the protocol
        host - the host
        port - the port
      • Connection

        public Connection​(String protocol,
                          String host,
                          String port,
                          String path)
        Instantiates a new connection.
        Parameters:
        protocol - the protocol
        host - the host
        port - the port
        path - the path
      • Connection

        public Connection​(String protocol_,
                          String host_,
                          String port_,
                          String path_,
                          String[] options_)
        Instantiates a new connection.
        Parameters:
        protocol_ - the protocol
        host_ - the host
        port_ - the port
        path_ - the path
        options_ - the options
    • Method Detail

      • setPreemptiveHTTPAuthenticate

        public void setPreemptiveHTTPAuthenticate​(boolean preemtiveauth)
        Sets option to pre-emptively process HTTP authentication
        Parameters:
        preemtiveauth - Flag determining if pre-emptive HTTP authentication should be processed before connection is challenged
      • getPreemptiveHTTPAuthenticate

        public boolean getPreemptiveHTTPAuthenticate()
        Returns option to pre-emptively process HTTP Authentication
        Returns:
        Flag determining if pre-emptive HTTP authentication should be processed before connection is challenged
      • getProtocol

        public static String getProtocol​(boolean ssl)
        Gets the protocol.
        Parameters:
        ssl - the ssl
        Returns:
        the protocol
      • isSslProtocol

        public static boolean isSslProtocol​(String protocol)
        Checks if is ssl protocol.
        Parameters:
        protocol - the protocol
        Returns:
        true, if is ssl protocol
      • getUrl

        public String getUrl()
        Gets the url.
        Returns:
        the url
      • getBaseUrl

        public String getBaseUrl()
        Gets the base url.
        Returns:
        the base url
      • hasCredentials

        public boolean hasCredentials()
        Checks for credentials.
        Returns:
        true, if successful
      • setEncodedCredentials

        public void setEncodedCredentials​(String encodedcreds)
                                   throws Exception
        Sets the encoded credentials.
        Parameters:
        encodedcreds - the new encoded credentials
        Throws:
        Exception - the exception
      • getBasicAuthString

        public String getBasicAuthString()
        Gets the basic auth string.
        Returns:
        String - "Basic " + encoded credentials, null if no credentials set
      • getHost

        public String getHost()
        Gets the host.
        Returns:
        the host
      • getPort

        public String getPort()
        Gets the port.
        Returns:
        the port
      • getPortInt

        public int getPortInt()
        Gets the port int.
        Returns:
        the port int
      • getUserName

        public String getUserName()
        Gets the user name.
        Returns:
        the user name
      • setUserName

        public void setUserName​(String userName)
        Sets the user name.
        Parameters:
        userName - the new user name
      • getPassword

        public String getPassword()
        Gets the password.
        Returns:
        the password
      • setPassword

        public void setPassword​(String password)
        Sets the password.
        Parameters:
        password - the new password
      • getProtocol

        public String getProtocol()
        Gets the protocol.
        Returns:
        the protocol
      • getIsHttps

        public Boolean getIsHttps()
        Gets the checks if is https.
        Returns:
        the checks if is https
      • getAllowInvalidCerts

        public boolean getAllowInvalidCerts()
        Gets the allow invalid certs.
        Returns:
        the allow invalid certs
      • setAllowInvalidCerts

        public void setAllowInvalidCerts​(boolean allowInvalidCerts)
        Sets the allow invalid certs.
        Parameters:
        allowInvalidCerts - the new allow invalid certs
      • setCredentials

        public void setCredentials​(String username,
                                   String password)
        Sets the credentials.
        Parameters:
        username - the username
        password - the password
      • getCredentials

        public org.hpccsystems.ws.client.utils.Connection.Credentials getCredentials()
        Gets the credentials.
        Returns:
        the credentials
      • createConnection

        public URLConnection createConnection()
                                       throws IOException
        Creates the connection.
        Returns:
        the URL connection
        Throws:
        IOException - Signals that an I/O exception has occurred.
      • createConnection

        public static URLConnection createConnection​(URL url)
                                              throws IOException
        Creates a new java.net.URLConnection object from the specified java.net.URL. This is a convenience method which will set the doInput, doOutput, useCaches and defaultUseCaches fields to the appropriate settings in the correct order.
        Parameters:
        url - the url
        Returns:
        the URL connection
        Throws:
        IOException - Signals that an I/O exception has occurred.
      • buildUrl

        public static String buildUrl​(String protocol,
                                      String host,
                                      String port)
        Builds the url.
        Parameters:
        protocol - the protocol
        host - the host
        port - the port
        Returns:
        the string
      • buildUrl

        public static String buildUrl​(String protocol,
                                      String host,
                                      String port,
                                      String path)
        Builds the url.
        Parameters:
        protocol - the protocol
        host - the host
        port - the port
        path - the path
        Returns:
        the string
      • buildUrl

        public static String buildUrl​(String protocol,
                                      String host,
                                      String port,
                                      String path,
                                      String[] options)
        Builds the url.
        Parameters:
        protocol - the protocol
        host - the host
        port - the port
        path - the path
        options - the options
        Returns:
        the string
      • getConnectTimeoutMilli

        public int getConnectTimeoutMilli()
        Gets the connect timeout milli.
        Returns:
        the connectTimeoutMilli
      • setConnectTimeoutMilli

        public void setConnectTimeoutMilli​(int connectTimeoutMilli)
        Sets the connect timeout milli.
        Parameters:
        connectTimeoutMilli - the connectTimeoutMilli to set
      • getReadTimeoutMilli

        public int getReadTimeoutMilli()
        Gets the read timeout milli.
        Returns:
        the readTimeoutMilli
      • setReadTimeoutMilli

        public void setReadTimeoutMilli​(int readTimeoutMilli)
        Sets the read timeout milli.
        Parameters:
        readTimeoutMilli - the readTimeoutMilli to set
      • getWriteTimeoutMilli

        public int getWriteTimeoutMilli()
        Gets the write timeout milli.
        Returns:
        the writeTimeoutMilli
      • setWriteTimeoutMilli

        public void setWriteTimeoutMilli​(int writeTimeoutMilli)
        Sets the write timeout milli.
        Parameters:
        writeTimeoutMilli - the writeTimeoutMilli to set
      • getSocketTimeoutMilli

        public int getSocketTimeoutMilli()
        Gets the socket timeout milli.
        Returns:
        the socketTimeoutMilli
      • setSocketTimeoutMilli

        public void setSocketTimeoutMilli​(int socketTimeoutMilli)
        Sets the socket timeout milli.
        Parameters:
        socketTimeoutMilli - the socketTimeoutMilli to set
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • sendGetRequest

        public String sendGetRequest​(String uri)
                              throws Exception
        Sends HTTP Get request to connection's URL + uri Returns entire response payload
        Parameters:
        uri - - Appended to connection URL
        Returns:
        a String object.
        Throws:
        Exception - a Exception object.
      • sendHTTPRequest

        public String sendHTTPRequest​(String uri,
                                      String method)
                               throws Exception
        Sends HTTP request to connection's URL + uri Caller specifies the desired HTTP method Returns entire response payload
        Parameters:
        uri - a String object.
        method - - One of GET|POST|HEAD|OPTIONS|PUT|DELETE|TRACE
        Returns:
        a String object.
        Throws:
        Exception - a Exception object.