Remove usage of `HttpStatus` in Web Endpoints

See gh-10350
pull/9839/merge
Vedran Pavic 7 years ago committed by Stephane Nicoll
parent 326290b2c9
commit 6c6ce7221a

@ -22,7 +22,6 @@ import org.springframework.boot.actuate.audit.AuditEventsEndpoint.AuditEventsDes
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
import org.springframework.boot.actuate.endpoint.web.WebEndpointResponse;
import org.springframework.boot.actuate.endpoint.web.annotation.WebEndpointExtension;
import org.springframework.http.HttpStatus;
/**
* {@link WebEndpointExtension} for the {@link AuditEventsEndpoint}.
@ -43,7 +42,7 @@ public class AuditEventsWebEndpointExtension {
public WebEndpointResponse<AuditEventsDescriptor> eventsWithPrincipalDateAfterAndType(
String principal, Date after, String type) {
if (after == null) {
return new WebEndpointResponse<>(HttpStatus.BAD_REQUEST.value());
return new WebEndpointResponse<>(WebEndpointResponse.BAD_REQUEST_STATUS);
}
AuditEventsDescriptor auditEvents = this.delegate
.eventsWithPrincipalDateAfterAndType(principal, after, type);

@ -26,10 +26,36 @@ import org.springframework.boot.actuate.endpoint.web.annotation.WebEndpointExten
* @param <T> the type of the response body
* @author Stephane Nicoll
* @author Andy Wilkinson
* @author Vedran Pavic
* @since 2.0.0
*/
public final class WebEndpointResponse<T> {
/**
* {@code 200 OK}.
*/
public static final int OK_STATUS = 200;
/**
* {@code 400 Bad Request}.
*/
public static final int BAD_REQUEST_STATUS = 400;
/**
* {@code 429 Too Many Requests}.
*/
public static final int TOO_MANY_REQUESTS_STATUS = 429;
/**
* {@code 500 Internal Server Error}.
*/
public static final int INTERNAL_SERVER_ERROR_STATUS = 500;
/**
* {@code 503 Service Unavailable}.
*/
public static final int SERVICE_UNAVAILABLE_STATUS = 503;
private final T body;
private final int status;
@ -56,7 +82,7 @@ public final class WebEndpointResponse<T> {
* @param body the body
*/
public WebEndpointResponse(T body) {
this(body, 200);
this(body, OK_STATUS);
}
/**

@ -20,6 +20,7 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import org.springframework.boot.actuate.endpoint.web.WebEndpointResponse;
import org.springframework.util.Assert;
/**
@ -40,8 +41,9 @@ public class HealthStatusHttpMapper {
}
private void setupDefaultStatusMapping() {
addStatusMapping(Status.DOWN, 503);
addStatusMapping(Status.OUT_OF_SERVICE, 503);
addStatusMapping(Status.DOWN, WebEndpointResponse.SERVICE_UNAVAILABLE_STATUS);
addStatusMapping(Status.OUT_OF_SERVICE,
WebEndpointResponse.SERVICE_UNAVAILABLE_STATUS);
}
/**
@ -102,9 +104,10 @@ public class HealthStatusHttpMapper {
if (code != null) {
return this.statusMapping.keySet().stream()
.filter((key) -> code.equals(getUniformValue(key)))
.map(this.statusMapping::get).findFirst().orElse(200);
.map(this.statusMapping::get).findFirst()
.orElse(WebEndpointResponse.OK_STATUS);
}
return 200;
return WebEndpointResponse.OK_STATUS;
}
private String getUniformValue(String code) {

@ -42,7 +42,6 @@ import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
import org.springframework.boot.actuate.endpoint.web.WebEndpointResponse;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource;
import org.springframework.http.HttpStatus;
import org.springframework.util.ClassUtils;
import org.springframework.util.ReflectionUtils;
@ -89,12 +88,14 @@ public class HeapDumpWebEndpoint {
Thread.currentThread().interrupt();
}
catch (IOException ex) {
return new WebEndpointResponse<>(HttpStatus.INTERNAL_SERVER_ERROR.value());
return new WebEndpointResponse<>(
WebEndpointResponse.INTERNAL_SERVER_ERROR_STATUS);
}
catch (HeapDumperUnavailableException ex) {
return new WebEndpointResponse<>(HttpStatus.SERVICE_UNAVAILABLE.value());
return new WebEndpointResponse<>(
WebEndpointResponse.SERVICE_UNAVAILABLE_STATUS);
}
return new WebEndpointResponse<>(HttpStatus.TOO_MANY_REQUESTS.value());
return new WebEndpointResponse<>(WebEndpointResponse.TOO_MANY_REQUESTS_STATUS);
}
private Resource dumpHeap(boolean live) throws IOException, InterruptedException {

Loading…
Cancel
Save