use of org.springframework.boot.actuate.health.Health in project spring-boot by spring-projects.
the class HealthMvcEndpoint method invoke.
@ActuatorGetMapping
@ResponseBody
public Object invoke(HttpServletRequest request, Principal principal) {
if (!getDelegate().isEnabled()) {
// Shouldn't happen because the request mapping should not be registered
return getDisabledResponse();
}
Health health = getHealth(request, principal);
HttpStatus status = getStatus(health);
if (status != null) {
return new ResponseEntity<>(health, status);
}
return health;
}
use of org.springframework.boot.actuate.health.Health in project spring-boot by spring-projects.
the class EndpointAutoConfigurationTests method healthEndpointWithDefaultHealthIndicator.
@Test
public void healthEndpointWithDefaultHealthIndicator() {
load(EndpointAutoConfiguration.class, HealthIndicatorAutoConfiguration.class);
HealthEndpoint bean = this.context.getBean(HealthEndpoint.class);
assertThat(bean).isNotNull();
Health result = bean.invoke();
assertThat(result).isNotNull();
}
use of org.springframework.boot.actuate.health.Health in project spring-boot by spring-projects.
the class HealthMvcEndpointTests method newValueIsReturnedOnceTtlExpires.
@Test
public void newValueIsReturnedOnceTtlExpires() throws InterruptedException {
given(this.endpoint.getTimeToLive()).willReturn(50L);
given(this.endpoint.invoke()).willReturn(new Health.Builder().up().withDetail("foo", "bar").build());
Object result = this.mvc.invoke(this.request, null);
assertThat(result instanceof Health).isTrue();
assertThat(((Health) result).getStatus() == Status.UP).isTrue();
Thread.sleep(100);
given(this.endpoint.invoke()).willReturn(new Health.Builder().down().build());
result = this.mvc.invoke(this.request, null);
@SuppressWarnings("unchecked") Health health = ((ResponseEntity<Health>) result).getBody();
assertThat(health.getStatus() == Status.DOWN).isTrue();
}
use of org.springframework.boot.actuate.health.Health in project camel by apache.
the class CamelHealthTest method shouldHaveHealth.
@Test
public void shouldHaveHealth() throws Exception {
Health health = indicator.health();
assertNotNull(health);
String code = health.getStatus().getCode();
assertEquals("UP", code);
String version = (String) health.getDetails().get("version");
assertEquals(camelContext.getVersion(), version);
}
use of org.springframework.boot.actuate.health.Health in project cas by apereo.
the class StatusController method handleRequestInternal.
/**
* Handle request.
*
* @param request the request
* @param response the response
* @throws Exception the exception
*/
@GetMapping
@ResponseBody
protected void handleRequestInternal(final HttpServletRequest request, final HttpServletResponse response) throws Exception {
ensureEndpointAccessIsAuthorized(request, response);
final StringBuilder sb = new StringBuilder();
final Health health = this.healthEndpoint.invoke();
final Status status = health.getStatus();
if (status.equals(Status.DOWN) || status.equals(Status.OUT_OF_SERVICE)) {
response.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value());
}
sb.append("Health: ").append(status.getCode());
sb.append("\n\nHost:\t\t").append(StringUtils.isBlank(casProperties.getHost().getName()) ? InetAddressUtils.getCasServerHostName() : casProperties.getHost().getName());
sb.append("\nServer:\t\t").append(casProperties.getServer().getName());
sb.append("\nVersion:\t").append(CasVersion.getVersion());
response.setContentType(MediaType.TEXT_PLAIN_VALUE);
try (Writer writer = response.getWriter()) {
IOUtils.copy(new ByteArrayInputStream(sb.toString().getBytes(response.getCharacterEncoding())), writer, StandardCharsets.UTF_8);
writer.flush();
}
}
Aggregations