Commit b2f0ebfc authored by Madhura Bhave's avatar Madhura Bhave

Prevent empty json for parameters in trace endpoint

Fixes gh-8883
parent 404bb2d1
......@@ -132,7 +132,7 @@ public class WebRequestTraceFilter extends OncePerRequestFilter implements Order
add(trace, Include.USER_PRINCIPAL, "userPrincipal",
(userPrincipal == null ? null : userPrincipal.getName()));
if (isIncluded(Include.PARAMETERS)) {
trace.put("parameters", request.getParameterMap());
trace.put("parameters", getParameterMap(request));
}
add(trace, Include.QUERY_STRING, "query", request.getQueryString());
add(trace, Include.AUTH_TYPE, "authType", request.getAuthType());
......@@ -170,6 +170,12 @@ public class WebRequestTraceFilter extends OncePerRequestFilter implements Order
return headers;
}
private Map<String, String[]> getParameterMap(HttpServletRequest request) {
Map<String, String[]> map = new LinkedHashMap<String, String[]>();
map.putAll(request.getParameterMap());
return map;
}
/**
* Post process request headers before they are added to the trace.
* @param headers a mutable map containing the request headers to trace
......
......@@ -187,6 +187,22 @@ public class SampleActuatorApplicationTests {
assertThat(map.get("status")).isEqualTo("200");
}
@Test
public void traceWithParameterMap() throws Exception {
this.restTemplate.getForEntity("/health?param1=value1", String.class);
@SuppressWarnings("rawtypes")
ResponseEntity<List> entity = this.restTemplate
.withBasicAuth("user", getPassword()).getForEntity("/trace", List.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
@SuppressWarnings("unchecked")
List<Map<String, Object>> list = entity.getBody();
Map<String, Object> trace = list.get(0);
@SuppressWarnings("unchecked")
Map<String, Object> map = (Map<String, Object>) ((Map<String, Object>)trace
.get("info")).get("parameters");
assertThat(map.get("param1")).isNotNull();
}
@Test
public void testErrorPageDirectAccess() throws Exception {
@SuppressWarnings("rawtypes")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment