From a075f731625db4a790d567de4da7d018c3696131 Mon Sep 17 00:00:00 2001 From: Jakub Lidke Date: Wed, 2 Aug 2023 15:19:38 +0200 Subject: feat: add Dockerfile for build within docker environment and run application within a container. --- HealthCheck.java | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 HealthCheck.java (limited to 'HealthCheck.java') diff --git a/HealthCheck.java b/HealthCheck.java new file mode 100644 index 0000000..0aac2a6 --- /dev/null +++ b/HealthCheck.java @@ -0,0 +1,20 @@ +import java.io.IOException; +import java.net.URI; +import java.net.http.HttpClient; +import java.net.http.HttpRequest; +import java.net.http.HttpResponse.BodyHandlers; + +public class HealthCheck { + + public static void main(String[] args) throws InterruptedException, IOException { + var client = HttpClient.newHttpClient(); + var request = HttpRequest.newBuilder() + .uri(URI.create("http://localhost:8001/actuator/health")) + .header("accept", "application/json") + .build(); + var response = client.send(request, BodyHandlers.ofString()); + if (response.statusCode() != 200 || !response.body().contains("UP")) { + throw new RuntimeException("Healthcheck failed"); + } + } +} \ No newline at end of file -- cgit v1.2.3