javac HealthCheck.java
java HealthCheck
import java.io.IOException; | |
import java.net.URI; | |
import java.net.http.HttpClient; | |
import java.net.http.HttpRequest; | |
import java.net.http.HttpResponse; | |
public class HealthCheck { | |
public static void main(String[] args) { | |
HttpClient client = HttpClient.newHttpClient(); | |
HttpRequest request = HttpRequest.newBuilder() | |
.uri(URI.create("http://localhost:8080/")) | |
.GET() | |
.build(); | |
try { | |
HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString()); | |
if (response.statusCode() != 200) { | |
System.out.println("Status : " + response.statusCode()); | |
System.out.println("Headers : " + response.headers()); | |
System.out.println("Body : " + response.body()); | |
System.exit(1); | |
} | |
} catch (IOException | InterruptedException e) { | |
e.printStackTrace(); | |
System.exit(1); | |
} | |
} | |
} |