All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.dropwizard.health.conf.response.DefaultHealthServletFactory Maven / Gradle / Ivy

Go to download

Provides a health check implementation that performs ongoing monitoring of an application's dependencies and includes an endpoint that can be called by a load balancer to determine if the application is healthy and thus able to retrieve traffic.

The newest version!
package io.dropwizard.health.conf.response;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeName;
import io.dropwizard.health.core.HealthCheckServlet;
import io.dropwizard.health.core.HealthStatusChecker;

import java.util.concurrent.atomic.AtomicBoolean;

import javax.servlet.http.HttpServlet;
import javax.ws.rs.core.MediaType;

/**
 * The default implementation of {@link HealthServletFactory}, which allows for configuration of the response.
 */
@JsonTypeName("default")
public class DefaultHealthServletFactory implements HealthServletFactory {
    private static final String STATUS_TEMPLATE = "{\"status\": \"%s\"}";

    @JsonProperty
    private boolean cacheControlEnabled = true;

    @JsonProperty
    private String cacheControlValue = "no-store";

    @JsonProperty
    private String contentType = MediaType.APPLICATION_JSON;

    @JsonProperty
    private String healthyValue = String.format(STATUS_TEMPLATE, "healthy");

    @JsonProperty
    private String unhealthyValue = String.format(STATUS_TEMPLATE, "unhealthy");

    public boolean isCacheControlEnabled() {
        return cacheControlEnabled;
    }

    public void setCacheControlEnabled(final boolean cacheControlEnabled) {
        this.cacheControlEnabled = cacheControlEnabled;
    }

    public String getCacheControlValue() {
        return cacheControlValue;
    }

    public void setCacheControlValue(final String cacheControlValue) {
        this.cacheControlValue = cacheControlValue;
    }

    public String getContentType() {
        return contentType;
    }

    public void setContentType(final String contentType) {
        this.contentType = contentType;
    }

    public String getHealthyValue() {
        return healthyValue;
    }

    public void setHealthyValue(final String healthyValue) {
        this.healthyValue = healthyValue;
    }

    public String getUnhealthyValue() {
        return unhealthyValue;
    }

    public void setUnhealthyValue(final String unhealthyValue) {
        this.unhealthyValue = unhealthyValue;
    }

    @Deprecated
    @Override
    public HttpServlet build(AtomicBoolean isHealthy) {
        return new HealthCheckServlet(isHealthy, cacheControlEnabled, cacheControlValue, contentType,
                healthyValue, unhealthyValue);
    }

    @Override
    public HttpServlet build(HealthStatusChecker healthStatusChecker) {
        return new HealthCheckServlet(healthStatusChecker, cacheControlEnabled, cacheControlValue, contentType,
                healthyValue, unhealthyValue);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy