package com.simplerecipemanager.resources;

import java.util.Map;
import java.util.Map.Entry;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.core.Response;

import com.codahale.metrics.health.HealthCheck.Result;
import com.codahale.metrics.health.HealthCheckRegistry;

@Path("/healthcheck")
public class HealthCheckResource {

	private HealthCheckRegistry registry;

	public HealthCheckResource(HealthCheckRegistry hcr) {

	}

	@GET
	public Response returnHealthCheck() {
		Map<String, Result> hcResults = registry.runHealthChecks();
		for (Entry<String, Result> r : hcResults.entrySet()) {
			if (!r.getValue().isHealthy()) {
				return Response.serverError().entity(r.getValue().getMessage())
						.build();
			}
		}
		return Response.ok().build();
	}

}

@@ -160,23 +160,133 @@
 .rs.
-core.Response;%0A
+Produces;%0Aimport javax.ws.rs.core.MediaType;%0Aimport javax.ws.rs.core.Response;%0A%0Aimport com.codahale.metrics.annotation.Timed;
 %0Aimp
@@ -551,18 +551,81 @@
 ) %7B%0A
-%0A%09%7D%0A%0A%09@GET
+%09%09this.registry = hcr;%0A%09%7D%0A%0A%09@GET%0A%09@Produces(MediaType.TEXT_PLAIN)%0A%09@Timed
 %0A%09pu
@@ -722,16 +722,90 @@
 ecks();%0A
+%09%09int fails = 0;%0A%09%09StringBuilder failureMessage = new StringBuilder(); %0A%09%09
 %09%09for (E
@@ -897,45 +897,77 @@
 %09%09%09%09
-return Response.serverError().entity(
+failureMessage.append(String.format(%22%25s message was %25s%22, r.getKey(), 
 r.ge
@@ -992,15 +992,76 @@
 e())
+);
 %0A%09%09%09
-%09%09%09
+%7D%0A%09%09%7D%0A%09%09if (fails == 0) %7B%0A%09%09%09return Response.ok().entity(%22OK%22)
 .bui
@@ -1068,23 +1068,26 @@
 ld();%0A%09%09
-%09%7D%0A%09%09%7D%0A
+%7D else %7B%0A%09
 %09%09return
@@ -1096,19 +1096,62 @@
 esponse.
-ok(
+serverError().entity(failureMessage.toString()
 ).build(
@@ -1153,14 +1153,18 @@
 uild();%0A
+%09%09%7D%0A
 %09%7D%0A%0A%7D%0A

Use better health check details