diff --git a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/GeoportalHealth.java b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/GeoportalHealth.java index c04fdc6..11cf4ca 100644 --- a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/GeoportalHealth.java +++ b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/GeoportalHealth.java @@ -5,11 +5,15 @@ import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; import org.eclipse.microprofile.health.HealthCheckResponse; import org.gcube.application.geoportal.service.rest.health.GeoportalHealthCheck; import org.gcube.application.geoportal.service.rest.health.MongoHealthCheck; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; + import lombok.extern.slf4j.Slf4j; @Path("/health") @@ -18,10 +22,13 @@ public class GeoportalHealth { @GET @Path("") - @Produces({ MediaType.TEXT_HTML, MediaType.APPLICATION_JSON }) - public HealthCheckResponse serviceCheck() { + @Produces({ MediaType.APPLICATION_JSON }) + public String serviceCheck() throws JsonProcessingException { log.info("serviceCheck called"); - return new GeoportalHealthCheck().call(); + HealthCheckResponse response = new GeoportalHealthCheck().call(); + String json = healthCheckSerializer(response); + log.info("serviceCheck response is {}", json); + return json; } @GET @@ -36,4 +43,10 @@ public class GeoportalHealth { return new MongoHealthCheck(context).call(); } + private String healthCheckSerializer(HealthCheckResponse response) throws JsonProcessingException { + ObjectMapper mapper = new ObjectMapper(); + // Serializes HealthCheckResponse in JSON + return mapper.writeValueAsString(response); + } + } diff --git a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/health/GeoportalHealthCheck.java b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/health/GeoportalHealthCheck.java index d08f6da..466d2fe 100644 --- a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/health/GeoportalHealthCheck.java +++ b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/health/GeoportalHealthCheck.java @@ -19,8 +19,6 @@ public class GeoportalHealthCheck implements HealthCheck { public HealthCheckResponse call() { log.info(GeoportalHealthCheck.class.getSimpleName() + " call"); HealthCheckResponse response = HealthCheckResponse.named(SERVICE_NAME).state(true).withData("serviceStatus", "healthy").build(); - log.info("Generated HealthCheckResponse: " + response.toString()); - log.info("Generated HealthCheckResponse map: " + response.getData()!=null?response.getData().toString():""); return response; }