added custom serializer
This commit is contained in:
parent
6e608191df
commit
af16e3b200
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue