File tree Expand file tree Collapse file tree 4 files changed +45
-11
lines changed
spring-boot-actuator/src/main/java/org/springframework/boot/actuate Expand file tree Collapse file tree 4 files changed +45
-11
lines changed Original file line number Diff line number Diff line change 22
22
import org .springframework .boot .actuate .endpoint .annotation .ReadOperation ;
23
23
import org .springframework .boot .actuate .endpoint .web .WebEndpointResponse ;
24
24
import org .springframework .boot .actuate .endpoint .web .annotation .WebEndpointExtension ;
25
- import org .springframework .http .HttpStatus ;
26
25
27
26
/**
28
27
* {@link WebEndpointExtension} for the {@link AuditEventsEndpoint}.
@@ -43,7 +42,7 @@ public AuditEventsWebEndpointExtension(AuditEventsEndpoint delegate) {
43
42
public WebEndpointResponse <AuditEventsDescriptor > eventsWithPrincipalDateAfterAndType (
44
43
String principal , Date after , String type ) {
45
44
if (after == null ) {
46
- return new WebEndpointResponse <>(HttpStatus . BAD_REQUEST . value () );
45
+ return new WebEndpointResponse <>(WebEndpointResponse . STATUS_BAD_REQUEST );
47
46
}
48
47
AuditEventsDescriptor auditEvents = this .delegate
49
48
.eventsWithPrincipalDateAfterAndType (principal , after , type );
Original file line number Diff line number Diff line change 26
26
* @param <T> the type of the response body
27
27
* @author Stephane Nicoll
28
28
* @author Andy Wilkinson
29
+ * @author Vedran Pavic
29
30
* @since 2.0.0
30
31
*/
31
32
public final class WebEndpointResponse <T > {
32
33
34
+ /**
35
+ * {@code 200 OK}.
36
+ */
37
+ public static final int STATUS_OK = 200 ;
38
+
39
+ /**
40
+ * {@code 400 Bad Request}.
41
+ */
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 ;
48
+
49
+ /**
50
+ * {@code 429 Too Many Requests}.
51
+ */
52
+ public static final int STATUS_TOO_MANY_REQUESTS = 429 ;
53
+
54
+ /**
55
+ * {@code 500 Internal Server Error}.
56
+ */
57
+ public static final int STATUS_INTERNAL_SERVER_ERROR = 500 ;
58
+
59
+ /**
60
+ * {@code 503 Service Unavailable}.
61
+ */
62
+ public static final int STATUS_SERVICE_UNAVAILABLE = 503 ;
63
+
33
64
private final T body ;
34
65
35
66
private final int status ;
@@ -56,7 +87,7 @@ public WebEndpointResponse(int status) {
56
87
* @param body the body
57
88
*/
58
89
public WebEndpointResponse (T body ) {
59
- this (body , 200 );
90
+ this (body , STATUS_OK );
60
91
}
61
92
62
93
/**
Original file line number Diff line number Diff line change 20
20
import java .util .HashMap ;
21
21
import java .util .Map ;
22
22
23
+ import org .springframework .boot .actuate .endpoint .web .WebEndpointResponse ;
23
24
import org .springframework .util .Assert ;
24
25
25
26
/**
@@ -40,8 +41,9 @@ public HealthStatusHttpMapper() {
40
41
}
41
42
42
43
private void setupDefaultStatusMapping () {
43
- addStatusMapping (Status .DOWN , 503 );
44
- addStatusMapping (Status .OUT_OF_SERVICE , 503 );
44
+ addStatusMapping (Status .DOWN , WebEndpointResponse .STATUS_SERVICE_UNAVAILABLE );
45
+ addStatusMapping (Status .OUT_OF_SERVICE ,
46
+ WebEndpointResponse .STATUS_SERVICE_UNAVAILABLE );
45
47
}
46
48
47
49
/**
@@ -102,9 +104,10 @@ public int mapStatus(Status status) {
102
104
if (code != null ) {
103
105
return this .statusMapping .keySet ().stream ()
104
106
.filter ((key ) -> code .equals (getUniformValue (key )))
105
- .map (this .statusMapping ::get ).findFirst ().orElse (200 );
107
+ .map (this .statusMapping ::get ).findFirst ()
108
+ .orElse (WebEndpointResponse .STATUS_OK );
106
109
}
107
- return 200 ;
110
+ return WebEndpointResponse . STATUS_OK ;
108
111
}
109
112
110
113
private String getUniformValue (String code ) {
Original file line number Diff line number Diff line change 42
42
import org .springframework .boot .actuate .endpoint .web .WebEndpointResponse ;
43
43
import org .springframework .core .io .FileSystemResource ;
44
44
import org .springframework .core .io .Resource ;
45
- import org .springframework .http .HttpStatus ;
46
45
import org .springframework .util .ClassUtils ;
47
46
import org .springframework .util .ReflectionUtils ;
48
47
@@ -89,12 +88,14 @@ public WebEndpointResponse<Resource> heapDump(Boolean live) {
89
88
Thread .currentThread ().interrupt ();
90
89
}
91
90
catch (IOException ex ) {
92
- return new WebEndpointResponse <>(HttpStatus .INTERNAL_SERVER_ERROR .value ());
91
+ return new WebEndpointResponse <>(
92
+ WebEndpointResponse .STATUS_INTERNAL_SERVER_ERROR );
93
93
}
94
94
catch (HeapDumperUnavailableException ex ) {
95
- return new WebEndpointResponse <>(HttpStatus .SERVICE_UNAVAILABLE .value ());
95
+ return new WebEndpointResponse <>(
96
+ WebEndpointResponse .STATUS_SERVICE_UNAVAILABLE );
96
97
}
97
- return new WebEndpointResponse <>(HttpStatus . TOO_MANY_REQUESTS . value () );
98
+ return new WebEndpointResponse <>(WebEndpointResponse . STATUS_TOO_MANY_REQUESTS );
98
99
}
99
100
100
101
private Resource dumpHeap (boolean live ) throws IOException , InterruptedException {
You can’t perform that action at this time.
0 commit comments