Dropwizard: configure address and health check format

Is it possible to configure the output of Healthwatch Dropwizrd so that: /healthfor healthchecks instead of /healthchecksome output, for example {"status": 200}.

I understand that I can just write a new resource that does what I need, I just wonder if there is a more standard way to do this.

+4
source share
2 answers

From what I read in the 0.7.1 source code, unfortunately, it is not possible to change the resource URI for healthchecks, I very much doubt that you can change the healthcheck format. I also remember how people complained about the impossibility of adding REST resources to the admin page, only servlets. Perhaps at 0.8.0?

, . , , - .

AdminServlet, , , URI .

this.healthcheckUri = getParam(config.getInitParameter(HEALTHCHECK_URI_PARAM_KEY), DEFAULT_HEALTHCHECK_URI);

dropwizard AbstractServerFactory.

handler.addServlet(new NonblockingServletHolder(new AdminServlet()), "/*");

NonblockingServletHolder - , AdminServlet, AbstractServerFactory .

ServletHolder Environment Application.run, , run.

environment.getAdminContext().getServletHandler().getServlets()[0].setInitParameter("healthcheck-uri", "/health");
+4

- run() URI :

environment.servlets().addServlet(
      "HealthCheckServlet", 
      new HealthCheckServlet(environment.healthChecks())
 ).addMapping("/health");

, , . , , .

+1

All Articles