import org.springframework.context.annotation.*;
import java.io.IOException;
import java.net.HttpURLConnection;
+import java.net.Socket;
import java.net.URL;
-import static org.iotivity.cloud.util.HealthCheck.checkSocket;
-
/**
* The type Policy witout cloud test.
*
return false;
}
+ public static boolean checkSocket(String socket) {
+ LOG.info("health check "+socket+"...");
+ String host="";
+ String port="";
+ int hasParts = socket.indexOf(":");
+ if (hasParts > -1) {
+ String[] parts = socket.split(":");
+ host = parts[0];
+ port = parts[1];
+ }
+ else {
+ LOG.info("socket has an incorrect format...");
+ return false;
+ }
+ try (Socket s = new Socket(host, Integer.valueOf(port))) {
+ LOG.info("health check was successful");
+ return true;
+ } catch (IOException ex) {
+ LOG.info(socket+" not available...");
+ return false;
+ }
+ }
+
private static void checkHost(String host) {
while (!checkSocket(host)) {
sleep();