Skip to content

Commit f43aa94

Browse files
committed
Polish "Remove usage of HttpStatus in Web Endpoints"
Closes gh-10350
1 parent 6c6ce72 commit f43aa94

File tree

4 files changed

+19
-14
lines changed

4 files changed

+19
-14
lines changed

spring-boot-actuator/src/main/java/org/springframework/boot/actuate/audit/AuditEventsWebEndpointExtension.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public AuditEventsWebEndpointExtension(AuditEventsEndpoint delegate) {
4242
public WebEndpointResponse<AuditEventsDescriptor> eventsWithPrincipalDateAfterAndType(
4343
String principal, Date after, String type) {
4444
if (after == null) {
45-
return new WebEndpointResponse<>(WebEndpointResponse.BAD_REQUEST_STATUS);
45+
return new WebEndpointResponse<>(WebEndpointResponse.STATUS_BAD_REQUEST);
4646
}
4747
AuditEventsDescriptor auditEvents = this.delegate
4848
.eventsWithPrincipalDateAfterAndType(principal, after, type);

spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/WebEndpointResponse.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,27 +34,32 @@ public final class WebEndpointResponse<T> {
3434
/**
3535
* {@code 200 OK}.
3636
*/
37-
public static final int OK_STATUS = 200;
37+
public static final int STATUS_OK = 200;
3838

3939
/**
4040
* {@code 400 Bad Request}.
4141
*/
42-
public static final int BAD_REQUEST_STATUS = 400;
42+
public static final int STATUS_BAD_REQUEST = 400;
43+
44+
/**
45+
* {@code 404 Not Found}.
46+
*/
47+
public static final int STATUS_NOT_FOUND = 404;
4348

4449
/**
4550
* {@code 429 Too Many Requests}.
4651
*/
47-
public static final int TOO_MANY_REQUESTS_STATUS = 429;
52+
public static final int STATUS_TOO_MANY_REQUESTS = 429;
4853

4954
/**
5055
* {@code 500 Internal Server Error}.
5156
*/
52-
public static final int INTERNAL_SERVER_ERROR_STATUS = 500;
57+
public static final int STATUS_INTERNAL_SERVER_ERROR = 500;
5358

5459
/**
5560
* {@code 503 Service Unavailable}.
5661
*/
57-
public static final int SERVICE_UNAVAILABLE_STATUS = 503;
62+
public static final int STATUS_SERVICE_UNAVAILABLE = 503;
5863

5964
private final T body;
6065

@@ -82,7 +87,7 @@ public WebEndpointResponse(int status) {
8287
* @param body the body
8388
*/
8489
public WebEndpointResponse(T body) {
85-
this(body, OK_STATUS);
90+
this(body, STATUS_OK);
8691
}
8792

8893
/**

spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/HealthStatusHttpMapper.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ public HealthStatusHttpMapper() {
4141
}
4242

4343
private void setupDefaultStatusMapping() {
44-
addStatusMapping(Status.DOWN, WebEndpointResponse.SERVICE_UNAVAILABLE_STATUS);
44+
addStatusMapping(Status.DOWN, WebEndpointResponse.STATUS_SERVICE_UNAVAILABLE);
4545
addStatusMapping(Status.OUT_OF_SERVICE,
46-
WebEndpointResponse.SERVICE_UNAVAILABLE_STATUS);
46+
WebEndpointResponse.STATUS_SERVICE_UNAVAILABLE);
4747
}
4848

4949
/**
@@ -105,9 +105,9 @@ public int mapStatus(Status status) {
105105
return this.statusMapping.keySet().stream()
106106
.filter((key) -> code.equals(getUniformValue(key)))
107107
.map(this.statusMapping::get).findFirst()
108-
.orElse(WebEndpointResponse.OK_STATUS);
108+
.orElse(WebEndpointResponse.STATUS_OK);
109109
}
110-
return WebEndpointResponse.OK_STATUS;
110+
return WebEndpointResponse.STATUS_OK;
111111
}
112112

113113
private String getUniformValue(String code) {

spring-boot-actuator/src/main/java/org/springframework/boot/actuate/management/HeapDumpWebEndpoint.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,13 @@ public WebEndpointResponse<Resource> heapDump(Boolean live) {
8989
}
9090
catch (IOException ex) {
9191
return new WebEndpointResponse<>(
92-
WebEndpointResponse.INTERNAL_SERVER_ERROR_STATUS);
92+
WebEndpointResponse.STATUS_INTERNAL_SERVER_ERROR);
9393
}
9494
catch (HeapDumperUnavailableException ex) {
9595
return new WebEndpointResponse<>(
96-
WebEndpointResponse.SERVICE_UNAVAILABLE_STATUS);
96+
WebEndpointResponse.STATUS_SERVICE_UNAVAILABLE);
9797
}
98-
return new WebEndpointResponse<>(WebEndpointResponse.TOO_MANY_REQUESTS_STATUS);
98+
return new WebEndpointResponse<>(WebEndpointResponse.STATUS_TOO_MANY_REQUESTS);
9999
}
100100

101101
private Resource dumpHeap(boolean live) throws IOException, InterruptedException {

0 commit comments

Comments
 (0)