Skip to content

Commit b2f0ebf

Browse files
committed
Prevent empty json for parameters in trace endpoint
Fixes gh-8883
1 parent 404bb2d commit b2f0ebf

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

spring-boot-actuator/src/main/java/org/springframework/boot/actuate/trace/WebRequestTraceFilter.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ protected Map<String, Object> getTrace(HttpServletRequest request) {
132132
add(trace, Include.USER_PRINCIPAL, "userPrincipal",
133133
(userPrincipal == null ? null : userPrincipal.getName()));
134134
if (isIncluded(Include.PARAMETERS)) {
135-
trace.put("parameters", request.getParameterMap());
135+
trace.put("parameters", getParameterMap(request));
136136
}
137137
add(trace, Include.QUERY_STRING, "query", request.getQueryString());
138138
add(trace, Include.AUTH_TYPE, "authType", request.getAuthType());
@@ -170,6 +170,12 @@ else if (values.isEmpty()) {
170170
return headers;
171171
}
172172

173+
private Map<String, String[]> getParameterMap(HttpServletRequest request) {
174+
Map<String, String[]> map = new LinkedHashMap<String, String[]>();
175+
map.putAll(request.getParameterMap());
176+
return map;
177+
}
178+
173179
/**
174180
* Post process request headers before they are added to the trace.
175181
* @param headers a mutable map containing the request headers to trace

spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/SampleActuatorApplicationTests.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,22 @@ public void testTrace() throws Exception {
187187
assertThat(map.get("status")).isEqualTo("200");
188188
}
189189

190+
@Test
191+
public void traceWithParameterMap() throws Exception {
192+
this.restTemplate.getForEntity("/health?param1=value1", String.class);
193+
@SuppressWarnings("rawtypes")
194+
ResponseEntity<List> entity = this.restTemplate
195+
.withBasicAuth("user", getPassword()).getForEntity("/trace", List.class);
196+
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
197+
@SuppressWarnings("unchecked")
198+
List<Map<String, Object>> list = entity.getBody();
199+
Map<String, Object> trace = list.get(0);
200+
@SuppressWarnings("unchecked")
201+
Map<String, Object> map = (Map<String, Object>) ((Map<String, Object>)trace
202+
.get("info")).get("parameters");
203+
assertThat(map.get("param1")).isNotNull();
204+
}
205+
190206
@Test
191207
public void testErrorPageDirectAccess() throws Exception {
192208
@SuppressWarnings("rawtypes")

0 commit comments

Comments
 (0)