use of org.xipki.common.HealthCheckResult in project xipki by xipki.
the class HealthCheckServlet method service0.
private FullHttpResponse service0(FullHttpRequest request, ServletURI servletUri, SSLSession sslSession) {
HttpVersion version = request.protocolVersion();
HttpMethod method = request.method();
if (method != HttpMethod.GET) {
return createErrorResponse(version, HttpResponseStatus.METHOD_NOT_ALLOWED);
}
try {
if (server == null) {
LOG.error("server in servlet not configured");
return createErrorResponse(version, HttpResponseStatus.INTERNAL_SERVER_ERROR);
}
ResponderAndPath responderAndPath = server.getResponderForPath(servletUri.getPath());
if (responderAndPath == null) {
return createErrorResponse(version, HttpResponseStatus.NOT_FOUND);
}
HealthCheckResult healthResult = server.healthCheck(responderAndPath.getResponder());
HttpResponseStatus status = healthResult.isHealthy() ? HttpResponseStatus.OK : HttpResponseStatus.INTERNAL_SERVER_ERROR;
byte[] respBytes = healthResult.toJsonMessage(true).getBytes();
return createResponse(version, status, HealthCheckServlet.CT_RESPONSE, respBytes);
} catch (Throwable th) {
if (th instanceof EOFException) {
LogUtil.warn(LOG, th, "connection reset by peer");
} else {
LOG.error("Throwable thrown, this should not happen", th);
}
return createErrorResponse(version, HttpResponseStatus.INTERNAL_SERVER_ERROR);
}
}
use of org.xipki.common.HealthCheckResult in project xipki by xipki.
the class HealthCheckServlet method doGet.
@Override
protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {
resp.setHeader("Access-Control-Allow-Origin", "*");
OcspServer server = ServletHelper.getServer();
if (server == null) {
LOG.error("ServletHelper.server not configured");
resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
resp.setContentLength(0);
return;
}
try {
String path = StringUtil.getRelativeRequestUri(req.getServletPath(), req.getRequestURI());
ResponderAndPath responderAndPath = server.getResponderForPath(path);
if (responderAndPath == null) {
resp.setStatus(HttpServletResponse.SC_NOT_FOUND);
resp.setContentLength(0);
return;
}
HealthCheckResult healthResult = server.healthCheck(responderAndPath.getResponder());
int status = healthResult.isHealthy() ? HttpServletResponse.SC_OK : HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
byte[] respBytes = healthResult.toJsonMessage(true).getBytes();
resp.setStatus(status);
resp.setContentType(HealthCheckServlet.CT_RESPONSE);
resp.setContentLength(respBytes.length);
resp.getOutputStream().write(respBytes);
} catch (Throwable th) {
if (th instanceof EOFException) {
LogUtil.warn(LOG, th, "connection reset by peer");
} else {
LOG.error("Throwable thrown, this should not happen", th);
}
resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
resp.setContentLength(0);
} finally {
resp.flushBuffer();
}
}
use of org.xipki.common.HealthCheckResult in project xipki by xipki.
the class X509CaCmpResponderImpl method healthCheck.
public HealthCheckResult healthCheck() {
HealthCheckResult result = getCa().healthCheck();
boolean healthy = result.isHealthy();
boolean responderHealthy = caManager.getResponderWrapper(getResponderName()).getSigner().isHealthy();
healthy &= responderHealthy;
HealthCheckResult responderHealth = new HealthCheckResult("Responder");
responderHealth.setHealthy(responderHealthy);
result.addChildCheck(responderHealth);
result.setHealthy(healthy);
return result;
}
use of org.xipki.common.HealthCheckResult in project xipki by xipki.
the class X509Ca method healthCheck.
// method removeExpirtedCerts
public HealthCheckResult healthCheck() {
HealthCheckResult result = new HealthCheckResult("X509CA");
boolean healthy = true;
ConcurrentContentSigner signer = caInfo.getSigner(null);
if (signer != null) {
boolean caSignerHealthy = signer.isHealthy();
healthy &= caSignerHealthy;
HealthCheckResult signerHealth = new HealthCheckResult("Signer");
signerHealth.setHealthy(caSignerHealthy);
result.addChildCheck(signerHealth);
}
boolean databaseHealthy = certstore.isHealthy();
healthy &= databaseHealthy;
HealthCheckResult databaseHealth = new HealthCheckResult("Database");
databaseHealth.setHealthy(databaseHealthy);
result.addChildCheck(databaseHealth);
X509CrlSignerEntryWrapper crlSigner = getCrlSigner();
if (crlSigner != null && crlSigner.getSigner() != null) {
boolean crlSignerHealthy = crlSigner.getSigner().isHealthy();
healthy &= crlSignerHealthy;
HealthCheckResult crlSignerHealth = new HealthCheckResult("CRLSigner");
crlSignerHealth.setHealthy(crlSignerHealthy);
result.addChildCheck(crlSignerHealth);
}
for (IdentifiedX509CertPublisher publisher : publishers()) {
boolean ph = publisher.isHealthy();
healthy &= ph;
HealthCheckResult publisherHealth = new HealthCheckResult("Publisher");
publisherHealth.setHealthy(publisher.isHealthy());
result.addChildCheck(publisherHealth);
}
result.setHealthy(healthy);
return result;
}
use of org.xipki.common.HealthCheckResult in project xipki by xipki.
the class HealthCheckResultTest method test5.
@Test
public void test5() {
HealthCheckResult result = new HealthCheckResult("mycheck-positive");
result.setHealthy(true);
HealthCheckResult childCheck = new HealthCheckResult("childcheck");
result.addChildCheck(childCheck);
childCheck.setHealthy(false);
HealthCheckResult childCheck2 = new HealthCheckResult("childcheck2");
result.addChildCheck(childCheck2);
childCheck.setHealthy(false);
HealthCheckResult childChildCheck = new HealthCheckResult("childChildCheck");
childCheck.addChildCheck(childChildCheck);
childChildCheck.setHealthy(false);
String noPrettyJson = "{\"healthy\":true,\"checks\":{\"childcheck\":{\"healthy\":false," + "\"checks\":{\"childChildCheck\":{\"healthy\":false}}},\"childcheck2\":" + "{\"healthy\":false}}}";
String prettyJson = "{\n" + " \"healthy\":true,\n" + " \"checks\":{\n" + " \"childcheck\":{\n" + " \"healthy\":false,\n" + " \"checks\":{\n" + " \"childChildCheck\":{\n" + " \"healthy\":false\n" + " }\n" + " }\n" + " },\n" + " \"childcheck2\":{\n" + " \"healthy\":false\n" + " }\n" + " }\n" + "}";
check(result, noPrettyJson, prettyJson);
}
Aggregations