public class JkUtilsNet
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
JkUtilsNet.BasicHttpResponse |
Constructor and Description |
---|
JkUtilsNet() |
Modifier and Type | Method and Description |
---|---|
static void |
assertResponseOk(java.net.HttpURLConnection con,
java.lang.String body) |
static boolean |
checkPortOpen(java.lang.String hostAndPort,
int millis)
Checks if a port is open on a specified host.
|
static boolean |
checkPortOpen(java.lang.String host,
int port,
int timeoutMillis)
Checks if a port is open on a specified host.
|
static void |
checkUntilOk(java.lang.String url,
int timeoutMillis,
int sleepMillis)
Weak implementation of heath checker, but maybe good enough for certain scenario.
|
static void |
downloadFile(java.lang.String fileURL,
java.nio.file.Path saveFilePath)
Downloads the specified url file at the specified file.
|
static int |
findFreePort(int from,
int to)
Finds a free port within the specified range.
|
static boolean |
isAvailableAndOk(java.lang.String url,
boolean log) |
static boolean |
isStatusOk(java.lang.String url,
boolean log) |
static JkUtilsNet.BasicHttpResponse |
sendHttpRequest(java.lang.String url,
java.lang.String method,
java.util.Map<java.lang.String,java.lang.String> headers,
java.lang.String requestBody)
Sends an HTTP request to the specified URL using the specified method and parameters.
|
static JkUtilsNet.BasicHttpResponse |
sendHttpRequest(java.lang.String url,
java.lang.String method,
java.lang.String requestBody) |
public static void assertResponseOk(java.net.HttpURLConnection con, java.lang.String body) throws java.io.IOException
java.io.IOException
public static void checkUntilOk(java.lang.String url, int timeoutMillis, int sleepMillis)
public static boolean isStatusOk(java.lang.String url, boolean log)
public static boolean isAvailableAndOk(java.lang.String url, boolean log)
public static boolean checkPortOpen(java.lang.String hostAndPort, int millis)
hostAndPort
- A string representing the host and port in the format "host:port"millis
- The timeout value in millisecondspublic static boolean checkPortOpen(java.lang.String host, int port, int timeoutMillis)
public static int findFreePort(int from, int to)
public static JkUtilsNet.BasicHttpResponse sendHttpRequest(java.lang.String url, java.lang.String method, java.util.Map<java.lang.String,java.lang.String> headers, java.lang.String requestBody)
url
- The URL to send the request tomethod
- The HTTP method to use (e.g., "GET", "POST", etc.)requestBody
- The parameters to include in the request bodyjava.io.UncheckedIOException
- If an I/O error occurs while sending the request or receiving the responsepublic static JkUtilsNet.BasicHttpResponse sendHttpRequest(java.lang.String url, java.lang.String method, java.lang.String requestBody)
public static void downloadFile(java.lang.String fileURL, java.nio.file.Path saveFilePath)
fileURL
- the file tu dowloadsaveFilePath
- The filesytem location to get the file once downloaded