public final class NetworkUtils
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
NetworkUtils.HeronSystem |
static class |
NetworkUtils.TunnelConfig |
static class |
NetworkUtils.TunnelType |
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
JSON_TYPE |
static java.lang.String |
URL_ENCODE_TYPE |
Modifier and Type | Method and Description |
---|---|
static boolean |
checkHttpResponseCode(java.net.HttpURLConnection connection,
int expectedCode) |
static Pair<java.net.InetSocketAddress,java.lang.Process> |
establishSSHTunnelIfNeeded(java.net.InetSocketAddress endpoint,
NetworkUtils.TunnelConfig tunnelConfig,
NetworkUtils.TunnelType tunnelType) |
static java.lang.String |
getHostName() |
static java.net.HttpURLConnection |
getHttpConnection(java.lang.String endpoint) |
static java.net.InetSocketAddress |
getInetSocketAddress(java.lang.String endpoint)
Convert an endpoint from String (host:port) to InetSocketAddress
|
static java.net.HttpURLConnection |
getProxiedHttpConnectionIfNeeded(java.net.URL endpoint,
NetworkUtils.TunnelConfig tunnelConfig) |
static boolean |
isLocationReachable(java.net.InetSocketAddress endpoint,
int timeoutMs,
int retryCount,
int retryIntervalMs)
Tests if a network location is reachable.
|
static byte[] |
readHttpRequestBody(com.sun.net.httpserver.HttpExchange exchange)
Read the request body of HTTP request from a given HttpExchange
|
static byte[] |
readHttpResponse(java.net.HttpURLConnection connection)
Read http response from a given http connection
|
static boolean |
sendHttpDeleteRequest(java.net.HttpURLConnection connection) |
static boolean |
sendHttpGetRequest(java.net.HttpURLConnection connection) |
static boolean |
sendHttpPostRequest(java.net.HttpURLConnection connection,
java.lang.String contentType,
byte[] data)
Send Http POST Request to a connection with given data in request body
|
static boolean |
sendHttpResponse(boolean isSuccess,
com.sun.net.httpserver.HttpExchange exchange,
byte[] response)
Send a http response with HTTP_OK return code and response body
|
static boolean |
sendHttpResponse(com.sun.net.httpserver.HttpExchange exchange,
byte[] response) |
public static final java.lang.String JSON_TYPE
public static final java.lang.String URL_ENCODE_TYPE
public static byte[] readHttpRequestBody(com.sun.net.httpserver.HttpExchange exchange)
exchange
- the HttpExchange to read frompublic static boolean sendHttpResponse(boolean isSuccess, com.sun.net.httpserver.HttpExchange exchange, byte[] response)
isSuccess
- send back HTTP_OK if it is true, otherwise send back HTTP_UNAVAILABLEexchange
- the HttpExchange to send responseresponse
- the response the sent back in response bodypublic static boolean sendHttpResponse(com.sun.net.httpserver.HttpExchange exchange, byte[] response)
public static boolean sendHttpPostRequest(java.net.HttpURLConnection connection, java.lang.String contentType, byte[] data)
connection
- the connection to send post request tocontentType
- the type of the content to be sentdata
- the data to send in post request bodypublic static boolean sendHttpGetRequest(java.net.HttpURLConnection connection)
public static boolean sendHttpDeleteRequest(java.net.HttpURLConnection connection)
public static byte[] readHttpResponse(java.net.HttpURLConnection connection)
connection
- the connection to read responsepublic static java.net.HttpURLConnection getHttpConnection(java.lang.String endpoint)
public static java.net.HttpURLConnection getProxiedHttpConnectionIfNeeded(java.net.URL endpoint, NetworkUtils.TunnelConfig tunnelConfig)
public static boolean checkHttpResponseCode(java.net.HttpURLConnection connection, int expectedCode)
public static java.lang.String getHostName()
public static boolean isLocationReachable(java.net.InetSocketAddress endpoint, int timeoutMs, int retryCount, int retryIntervalMs)
endpoint
- the endpoint to connect totimeoutMs
- Open connection will wait for this timeoutMs in ms.retryCount
- In case of connection timeoutMs try retryCount times.retryIntervalMs
- the interval in ms to retryCountpublic static Pair<java.net.InetSocketAddress,java.lang.Process> establishSSHTunnelIfNeeded(java.net.InetSocketAddress endpoint, NetworkUtils.TunnelConfig tunnelConfig, NetworkUtils.TunnelType tunnelType)
public static java.net.InetSocketAddress getInetSocketAddress(java.lang.String endpoint)
endpoint
- a String in (host:port) format