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.Produces;
|
||||||
import javax.ws.rs.QueryParam;
|
import javax.ws.rs.QueryParam;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
|
import javax.ws.rs.core.Response;
|
||||||
|
|
||||||
import org.eclipse.microprofile.health.HealthCheckResponse;
|
import org.eclipse.microprofile.health.HealthCheckResponse;
|
||||||
import org.gcube.application.geoportal.service.rest.health.GeoportalHealthCheck;
|
import org.gcube.application.geoportal.service.rest.health.GeoportalHealthCheck;
|
||||||
import org.gcube.application.geoportal.service.rest.health.MongoHealthCheck;
|
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;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
@Path("/health")
|
@Path("/health")
|
||||||
|
@ -18,10 +22,13 @@ public class GeoportalHealth {
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("")
|
@Path("")
|
||||||
@Produces({ MediaType.TEXT_HTML, MediaType.APPLICATION_JSON })
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
public HealthCheckResponse serviceCheck() {
|
public String serviceCheck() throws JsonProcessingException {
|
||||||
log.info("serviceCheck called");
|
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
|
@GET
|
||||||
|
@ -36,4 +43,10 @@ public class GeoportalHealth {
|
||||||
return new MongoHealthCheck(context).call();
|
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() {
|
public HealthCheckResponse call() {
|
||||||
log.info(GeoportalHealthCheck.class.getSimpleName() + " call");
|
log.info(GeoportalHealthCheck.class.getSimpleName() + " call");
|
||||||
HealthCheckResponse response = HealthCheckResponse.named(SERVICE_NAME).state(true).withData("serviceStatus", "healthy").build();
|
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;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue