Skip to content

Commit 42e01b4

Browse files
committed
Add Simple Java client to check Actuator helath status
1 parent ea4533d commit 42e01b4

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

docker/HealhtCheck.jar

1.64 KB
Binary file not shown.

docker/HealhtCheck.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import java.io.IOException;
2+
import java.net.URI;
3+
import java.net.http.HttpClient;
4+
import java.net.http.HttpRequest;
5+
import java.net.http.HttpResponse.BodyHandlers;
6+
7+
static void main(String[] args) throws IOException, InterruptedException {
8+
final var client = HttpClient.newHttpClient();
9+
final var request = HttpRequest.newBuilder()
10+
.uri(URI.create("http://localhost:8080/actuator/health"))
11+
.header("accept", "application/json")
12+
.build();
13+
14+
final var response = client.send(request, BodyHandlers.ofString());
15+
final var body = response.body();
16+
17+
System.out.print("Status: " + response.statusCode());
18+
System.out.print(" | body: " + body);
19+
System.out.println();
20+
21+
if (response.statusCode() != 200 || !body.contains("UP")) {
22+
System.err.println("Service is not UP!");
23+
System.exit(1);
24+
} else {
25+
System.exit(0);
26+
}
27+
}

0 commit comments

Comments
 (0)