From b2f0ebfcb80b60dc0e87c0e285036a1f4c0ab66f Mon Sep 17 00:00:00 2001 From: Madhura Bhave Date: Tue, 11 Apr 2017 15:08:17 -0700 Subject: [PATCH] Prevent empty json for parameters in trace endpoint Fixes gh-8883 --- .../actuate/trace/WebRequestTraceFilter.java | 8 +++++++- .../actuator/SampleActuatorApplicationTests.java | 16 ++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/trace/WebRequestTraceFilter.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/trace/WebRequestTraceFilter.java index dfaa375bea..ae00f07385 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/trace/WebRequestTraceFilter.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/trace/WebRequestTraceFilter.java @@ -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 getParameterMap(HttpServletRequest request) { + Map map = new LinkedHashMap(); + 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 diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/SampleActuatorApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/SampleActuatorApplicationTests.java index a001628434..22ba59fe5e 100644 --- a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/SampleActuatorApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/SampleActuatorApplicationTests.java @@ -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 entity = this.restTemplate + .withBasicAuth("user", getPassword()).getForEntity("/trace", List.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + @SuppressWarnings("unchecked") + List> list = entity.getBody(); + Map trace = list.get(0); + @SuppressWarnings("unchecked") + Map map = (Map) ((Map)trace + .get("info")).get("parameters"); + assertThat(map.get("param1")).isNotNull(); + } + @Test public void testErrorPageDirectAccess() throws Exception { @SuppressWarnings("rawtypes")