Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.core.MediaType;

import java.io.IOException;

@WebServlet(urlPatterns = {"${health.servlet.uri}"}, name = "HealthServlet")
Expand All @@ -39,13 +41,21 @@ public class HealthCheckServlet extends HttpServlet {

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
Jsonb jsonb = JsonbBuilder.newBuilder().build();
resp.setContentType(MediaType.APPLICATION_JSON);
HealthCheckModel healthCheckModel = healthCheckManager.performHealthChecks();
if (healthCheckModel.getOutcome().equalsIgnoreCase(HealthCheckResponse.State.UP.name())) {
resp.setStatus(200);
} else {
resp.setStatus(503);
}
jsonb.toJson(healthCheckModel, resp.getOutputStream());
try (Jsonb jsonb = JsonbBuilder.newBuilder().build()) {
jsonb.toJson(healthCheckModel, resp.getOutputStream());
} catch (IOException ex) {
// Re-throw IOException specifically to maintain existing functionality
throw ex;
} catch (Exception ex) {
// Convert other exceptions thrown by close() into a runtime exception
throw new RuntimeException(ex);
}
}
}