public class ConnectionManager
extends java.lang.Object
implements java.lang.AutoCloseable
Constructor and Description |
---|
ConnectionManager() |
Modifier and Type | Method and Description |
---|---|
void |
close()
Close saved sockets during shutdown.
|
static SocketHandler |
getSocketConnector()
If a socket handler is saved that is not currently in use then return.
|
static SocketHandler |
getSocketHandler(java.lang.String connectionType,
java.net.URL uri,
int callTimeout)
Create and return a socket for making a connection with.
|
static void |
initSSL_Certs(java.lang.String dirPath)
Initialise the trust manager and set the certificates folder.
|
static void |
overrideSSL_Certs()
This overrides the default security certificate situation, so that any response is trusted.
|
static boolean |
ping(java.lang.String ipAddress)
Ping the ip address and return true if it is reachable.
|
static boolean |
pingURL(java.lang.String url,
int timeout)
Pings a HTTP URL.
|
static boolean |
returnSocketConnector(SocketHandler socketHandler)
Return a socket handler back to the connection pool.
|
static java.lang.String |
sendRequest(java.lang.String connectionType,
java.lang.String endpoint,
java.lang.String requestParameters,
int callTimeout)
Sends a web or socket request to a url, assumes the GET method for a web connection.
|
static java.lang.String |
sendWebRequest(java.lang.String method,
java.lang.String endpoint,
java.lang.String requestParameters,
int callTimeout)
Sends an
HttpConst .URLCONN web request. |
static void |
setSSL_Certs()
Reset the trust manager to licas default with keystore and key.
|
public static boolean pingURL(java.lang.String url, int timeout)
true
if the response code is in the 200-399 range.url
- The HTTP URL to be pinged.timeout
- The timeout in millis for both the connection timeout and
the response read timeout. Note that the total timeout is effectively two
times the given timeout.true
if the given HTTP URL has returned response
code 200-399 on a HEAD request within the given timeout, otherwise
false
.
Based on: http://stackoverflow.com/questions/3584210/preferred-java-way-to-ping-an-http-url-for-availability.
public static boolean ping(java.lang.String ipAddress)
ipAddress
- the address to ping.public static void initSSL_Certs(java.lang.String dirPath)
dirPath
- the directory path.public static void setSSL_Certs() throws java.lang.Exception
java.lang.Exception
- any error.public static void overrideSSL_Certs() throws java.lang.Exception
java.lang.Exception
- any error.public static java.lang.String sendRequest(java.lang.String connectionType, java.lang.String endpoint, java.lang.String requestParameters, int callTimeout)
connectionType
- the connection type. Can be HttpConst
.URLCONN
(web/rest)
or HttpConst
.{HTTPCONN} (default licas rpc socket).endpoint
- The URL of the server, .requestParameters
- All the request parameters, .
Note: This method will add the question mark (?) to the request -
DO NOT add it yourself.callTimeout
- the maximum allowed amount of time for the call, in milliseconds.public static java.lang.String sendWebRequest(java.lang.String method, java.lang.String endpoint, java.lang.String requestParameters, int callTimeout)
HttpConst
.URLCONN
web request.method
- the method type. Can be HttpConst
.GET
or HttpConst
.{POST}.endpoint
- The URL of the server, .requestParameters
- All the request parameters, .
Note: This method will add the question mark (?) to the request -
DO NOT add it yourself.callTimeout
- the maximum allowed amount of time for the call, in milliseconds.public static SocketHandler getSocketHandler(java.lang.String connectionType, java.net.URL uri, int callTimeout) throws java.lang.Exception
connectionType
- the connection type. Can be HttpConst.URLCONN or HttpConst.HTTPCONN.uri
- the address to connect to.callTimeout
- the maximum allowed amount of time for the call, in milliseconds.java.lang.Exception
- any error.public static boolean returnSocketConnector(SocketHandler socketHandler)
socketHandler
- the socket handler to return.public static SocketHandler getSocketConnector()
public void close()
close
in interface java.lang.AutoCloseable