Spotless
This commit is contained in:
@@ -6,41 +6,40 @@ import java.util.regex.Pattern;
|
|||||||
|
|
||||||
public class HealthCheck {
|
public class HealthCheck {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
try {
|
try {
|
||||||
var port = System.getenv().getOrDefault("SERVER_PORT", "8080");
|
var port = System.getenv().getOrDefault("SERVER_PORT", "8080");
|
||||||
var url = new URL("http://localhost:" + port + "/fhir/metadata");
|
var url = new URL("http://localhost:" + port + "/fhir/metadata");
|
||||||
var conn = (HttpURLConnection) url.openConnection();
|
var conn = (HttpURLConnection) url.openConnection();
|
||||||
conn.setRequestMethod("GET");
|
conn.setRequestMethod("GET");
|
||||||
conn.setRequestProperty("Accept", "application/fhir+json");
|
conn.setRequestProperty("Accept", "application/fhir+json");
|
||||||
conn.setConnectTimeout(10000);
|
conn.setConnectTimeout(10000);
|
||||||
conn.setReadTimeout(10000);
|
conn.setReadTimeout(10000);
|
||||||
|
|
||||||
var status = conn.getResponseCode();
|
var status = conn.getResponseCode();
|
||||||
if (status != 200) {
|
if (status != 200) {
|
||||||
System.err.println("Health check failed: HTTP " + status);
|
System.err.println("Health check failed: HTTP " + status);
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
var body = new StringBuilder();
|
var body = new StringBuilder();
|
||||||
try (var reader =
|
try (var reader = new BufferedReader(new InputStreamReader(conn.getInputStream()))) {
|
||||||
new BufferedReader(new InputStreamReader(conn.getInputStream()))) {
|
String line;
|
||||||
String line;
|
while ((line = reader.readLine()) != null) {
|
||||||
while ((line = reader.readLine()) != null) {
|
body.append(line);
|
||||||
body.append(line);
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
var pattern = Pattern.compile("\"resourceType\"\\s*:\\s*\"CapabilityStatement\"");
|
var pattern = Pattern.compile("\"resourceType\"\\s*:\\s*\"CapabilityStatement\"");
|
||||||
if (pattern.matcher(body.toString()).find()) {
|
if (pattern.matcher(body.toString()).find()) {
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
} else {
|
} else {
|
||||||
System.err.println("Health check failed: CapabilityStatement not found in response");
|
System.err.println("Health check failed: CapabilityStatement not found in response");
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.err.println("Health check failed: " + e.getMessage());
|
System.err.println("Health check failed: " + e.getMessage());
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user