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 String
CONNECT_TIMEOUT_PARAM
ConstantCONNECT_TIMEOUT_PARAM="connecttimeoutmillis"
protected int
connectTimeoutMilli
static int
DEFAULT_CONNECT_TIMEOUT_MILLI
ConstantDEFAULT_CONNECT_TIMEOUT_MILLI=150000
static int
DEFAULT_READ_TIMEOUT_MILLI
ConstantDEFAULT_READ_TIMEOUT_MILLI=180 * 1000
static int
DEFAULT_SO_TIMEOUT_MILLI
ConstantDEFAULT_SO_TIMEOUT_MILLI=150000
static int
DEFAULT_WRITE_TIMEOUT_MILLI
ConstantDEFAULT_WRITE_TIMEOUT_MILLI=150000
static char
firstOptDelimiter
ConstantfirstOptDelimiter='?'
static char
pathDelimiter
ConstantpathDelimiter='/'
static char
portDelimiter
ConstantportDelimiter=':'
static String
protDelimiter
ConstantprotDelimiter="://"
static String
protHttp
ConstantprotHttp="http"
static String
protHttps
ConstantprotHttps="https"
static String
READ_TIMEOUT_PARAM
ConstantREAD_TIMEOUT_PARAM="readtimeoutmillis"
protected int
readTimeoutMilli
static String
SOCKET_TIMEOUT_PARAM
ConstantSOCKET_TIMEOUT_PARAM="sockettimeoutmillis"
protected int
socketTimeoutMilli
static char
subsequentOptDelimiter
ConstantsubsequentOptDelimiter='&'
static String
WRITE_TIMEOUT_PARAM
ConstantWRITE_TIMEOUT_PARAM="writetimeoutmillis"
protected int
writeTimeoutMilli
-
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 String
buildUrl(String protocol, String host, String port)
Builds the url.static String
buildUrl(String protocol, String host, String port, String path)
Builds the url.static String
buildUrl(String protocol, String host, String port, String path, String[] options)
Builds the url.URLConnection
createConnection()
Creates the connection.static URLConnection
createConnection(URL url)
Creates a newjava.net.URLConnection
object from the specifiedjava.net.URL
.boolean
equals(Object aThat)
boolean
getAllowInvalidCerts()
Gets the allow invalid certs.String
getBaseUrl()
Gets the base url.String
getBasicAuthString()
Gets the basic auth string.int
getConnectTimeoutMilli()
Gets the connect timeout milli.org.hpccsystems.ws.client.utils.Connection.Credentials
getCredentials()
Gets the credentials.String
getHost()
Gets the host.Boolean
getIsHttps()
Gets the checks if is https.String
getPassword()
Gets the password.String
getPort()
Gets the port.int
getPortInt()
Gets the port int.boolean
getPreemptiveHTTPAuthenticate()
Returns option to pre-emptively process HTTP AuthenticationString
getProtocol()
Gets the protocol.static String
getProtocol(boolean ssl)
Gets the protocol.int
getReadTimeoutMilli()
Gets the read timeout milli.int
getSocketTimeoutMilli()
Gets the socket timeout milli.String
getUrl()
Gets the url.String
getUserName()
Gets the user name.int
getWriteTimeoutMilli()
Gets the write timeout milli.boolean
hasCredentials()
Checks for credentials.int
hashCode()
static boolean
isSslProtocol(String protocol)
Checks if is ssl protocol.String
sendGetRequest(String uri)
Sends HTTP Get request to connection's URL + uri Returns entire response payloadString
sendHTTPRequest(String uri, String method)
Sends HTTP request to connection's URL + uri Caller specifies the desired HTTP method Returns entire response payloadvoid
setAllowInvalidCerts(boolean allowInvalidCerts)
Sets the allow invalid certs.void
setConnectTimeoutMilli(int connectTimeoutMilli)
Sets the connect timeout milli.void
setCredentials(String username, String password)
Sets the credentials.void
setEncodedCredentials(String encodedcreds)
Sets the encoded credentials.void
setPassword(String password)
Sets the password.void
setPreemptiveHTTPAuthenticate(boolean preemtiveauth)
Sets option to pre-emptively process HTTP authenticationvoid
setReadTimeoutMilli(int readTimeoutMilli)
Sets the read timeout milli.void
setSocketTimeoutMilli(int socketTimeoutMilli)
Sets the socket timeout milli.void
setUserName(String userName)
Sets the user name.void
setWriteTimeoutMilli(int writeTimeoutMilli)
Sets the write timeout milli.String
toString()
-
-
-
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.URLConnection
object from the specifiedjava.net.URL
. This is a convenience method which will set thedoInput
,doOutput
,useCaches
anddefaultUseCaches
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 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
-
-