Package org.hpccsystems.ws.client.utils
Class Connection
- java.lang.Object
-
- org.hpccsystems.ws.client.utils.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 Summary
Fields Modifier and Type Field Description static StringCONNECT_TIMEOUT_PARAMConstantCONNECT_TIMEOUT_PARAM="connecttimeoutmillis"protected intconnectTimeoutMillistatic intDEFAULT_CONNECT_TIMEOUT_MILLIConstantDEFAULT_CONNECT_TIMEOUT_MILLI=150000static intDEFAULT_READ_TIMEOUT_MILLIConstantDEFAULT_READ_TIMEOUT_MILLI=180 * 1000static intDEFAULT_SO_TIMEOUT_MILLIConstantDEFAULT_SO_TIMEOUT_MILLI=150000static intDEFAULT_WRITE_TIMEOUT_MILLIConstantDEFAULT_WRITE_TIMEOUT_MILLI=150000static charfirstOptDelimiterConstantfirstOptDelimiter='?'static charpathDelimiterConstantpathDelimiter='/'static charportDelimiterConstantportDelimiter=':'static StringprotDelimiterConstantprotDelimiter="://"static StringprotHttpConstantprotHttp="http"static StringprotHttpsConstantprotHttps="https"static StringREAD_TIMEOUT_PARAMConstantREAD_TIMEOUT_PARAM="readtimeoutmillis"protected intreadTimeoutMillistatic StringSOCKET_TIMEOUT_PARAMConstantSOCKET_TIMEOUT_PARAM="sockettimeoutmillis"protected intsocketTimeoutMillistatic charsubsequentOptDelimiterConstantsubsequentOptDelimiter='&'static StringWRITE_TIMEOUT_PARAMConstantWRITE_TIMEOUT_PARAM="writetimeoutmillis"protected intwriteTimeoutMilli
-
Constructor Summary
Constructors Constructor Description Connection(boolean ssl, String host, int port)Instantiates a new connection.Connection(String connectionstring)Instantiates a new connection.Connection(String protocol, String host, String port)Instantiates a new connection.Connection(String protocol, String host, String port, String path)Instantiates a new connection.Connection(String protocol_, String host_, String port_, String path_, String[] options_)Instantiates a new connection.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static StringbuildUrl(String protocol, String host, String port)Builds the url.static StringbuildUrl(String protocol, String host, String port, String path)Builds the url.static StringbuildUrl(String protocol, String host, String port, String path, String[] options)Builds the url.URLConnectioncreateConnection()Creates the connection.static URLConnectioncreateConnection(URL url)Creates a newjava.net.URLConnectionobject from the specifiedjava.net.URL.booleanequals(Object aThat)booleangetAllowInvalidCerts()Gets the allow invalid certs.StringgetBaseUrl()Gets the base url.StringgetBasicAuthString()Gets the basic auth string.intgetConnectTimeoutMilli()Gets the connect timeout milli.org.hpccsystems.ws.client.utils.Connection.CredentialsgetCredentials()Gets the credentials.StringgetHost()Gets the host.BooleangetIsHttps()Gets the checks if is https.StringgetPassword()Gets the password.StringgetPort()Gets the port.intgetPortInt()Gets the port int.booleangetPreemptiveHTTPAuthenticate()Returns option to pre-emptively process HTTP AuthenticationStringgetProtocol()Gets the protocol.static StringgetProtocol(boolean ssl)Gets the protocol.intgetReadTimeoutMilli()Gets the read timeout milli.intgetSocketTimeoutMilli()Gets the socket timeout milli.StringgetUrl()Gets the url.StringgetUserName()Gets the user name.intgetWriteTimeoutMilli()Gets the write timeout milli.booleanhasCredentials()Checks for credentials.inthashCode()static booleanisSslProtocol(String protocol)Checks if is ssl protocol.StringsendGetRequest(String uri)Sends HTTP Get request to connection's URL + uri Returns entire response payloadStringsendHTTPRequest(String uri, String method)Sends HTTP request to connection's URL + uri Caller specifies the desired HTTP method Returns entire response payloadvoidsetAllowInvalidCerts(boolean allowInvalidCerts)Sets the allow invalid certs.voidsetConnectTimeoutMilli(int connectTimeoutMilli)Sets the connect timeout milli.voidsetCredentials(String username, String password)Sets the credentials.voidsetEncodedCredentials(String encodedcreds)Sets the encoded credentials.voidsetPassword(String password)Sets the password.voidsetPreemptiveHTTPAuthenticate(boolean preemtiveauth)Sets option to pre-emptively process HTTP authenticationvoidsetReadTimeoutMilli(int readTimeoutMilli)Sets the read timeout milli.voidsetSocketTimeoutMilli(int socketTimeoutMilli)Sets the socket timeout milli.voidsetUserName(String userName)Sets the user name.voidsetWriteTimeoutMilli(int writeTimeoutMilli)Sets the write timeout milli.StringtoString()
-
-
-
Field Detail
-
protDelimiter
public static final String protDelimiter
ConstantprotDelimiter="://"- See Also:
- Constant Field Values
-
portDelimiter
public static final char portDelimiter
ConstantportDelimiter=':'- See Also:
- Constant Field Values
-
pathDelimiter
public static final char pathDelimiter
ConstantpathDelimiter='/'- See Also:
- Constant Field Values
-
firstOptDelimiter
public static final char firstOptDelimiter
ConstantfirstOptDelimiter='?'- See Also:
- Constant Field Values
-
subsequentOptDelimiter
public static final char subsequentOptDelimiter
ConstantsubsequentOptDelimiter='&'- See Also:
- Constant Field Values
-
protHttp
public static final String protHttp
ConstantprotHttp="http"- See Also:
- Constant Field Values
-
protHttps
public static final String protHttps
ConstantprotHttps="https"- See Also:
- Constant Field Values
-
CONNECT_TIMEOUT_PARAM
public static final String CONNECT_TIMEOUT_PARAM
ConstantCONNECT_TIMEOUT_PARAM="connecttimeoutmillis"- See Also:
- Constant Field Values
-
READ_TIMEOUT_PARAM
public static final String READ_TIMEOUT_PARAM
ConstantREAD_TIMEOUT_PARAM="readtimeoutmillis"- See Also:
- Constant Field Values
-
WRITE_TIMEOUT_PARAM
public static final String WRITE_TIMEOUT_PARAM
ConstantWRITE_TIMEOUT_PARAM="writetimeoutmillis"- See Also:
- Constant Field Values
-
SOCKET_TIMEOUT_PARAM
public static final String SOCKET_TIMEOUT_PARAM
ConstantSOCKET_TIMEOUT_PARAM="sockettimeoutmillis"- See Also:
- Constant Field Values
-
DEFAULT_CONNECT_TIMEOUT_MILLI
public static final int DEFAULT_CONNECT_TIMEOUT_MILLI
ConstantDEFAULT_CONNECT_TIMEOUT_MILLI=150000- See Also:
- Constant Field Values
-
DEFAULT_SO_TIMEOUT_MILLI
public static final int DEFAULT_SO_TIMEOUT_MILLI
ConstantDEFAULT_SO_TIMEOUT_MILLI=150000- See Also:
- Constant Field Values
-
DEFAULT_WRITE_TIMEOUT_MILLI
public static final int DEFAULT_WRITE_TIMEOUT_MILLI
ConstantDEFAULT_WRITE_TIMEOUT_MILLI=150000- See Also:
- Constant Field Values
-
DEFAULT_READ_TIMEOUT_MILLI
public static final int DEFAULT_READ_TIMEOUT_MILLI
ConstantDEFAULT_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(String connectionstring) throws MalformedURLException
Instantiates a new connection.- Parameters:
connectionstring- as defined by java.net.URL- Throws:
MalformedURLException- the malformed URL exception
-
Connection
public Connection(boolean ssl, String host, int port)Instantiates a new connection.- Parameters:
ssl- the sslhost- the hostport- the port
-
Connection
public Connection(String protocol, String host, String port)
Instantiates a new connection.- Parameters:
protocol- the protocolhost- the hostport- the port
-
Connection
public Connection(String protocol, String host, String port, String path)
Instantiates a new connection.- Parameters:
protocol- the protocolhost- the hostport- the portpath- the path
-
-
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 usernamepassword- 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 newjava.net.URLConnectionobject from the specifiedjava.net.URL. This is a convenience method which will set thedoInput,doOutput,useCachesanddefaultUseCachesfields 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 protocolhost- the hostport- the port- Returns:
- the string
-
buildUrl
public static String buildUrl(String protocol, String host, String port, String path)
Builds the url.- Parameters:
protocol- the protocolhost- the hostport- the portpath- 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 protocolhost- the hostport- the portpath- the pathoptions- 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
-
sendGetRequest
public String sendGetRequest(String uri) throws Exception
Sends HTTP Get request to connection's URL + uri Returns entire response payload
-
-