Merge branch '1.3.x'

pull/4284/merge
Andy Wilkinson 9 years ago
commit 11c9068d53

@ -45,6 +45,7 @@ import org.springframework.web.filter.OncePerRequestFilter;
* *
* @author Dave Syer * @author Dave Syer
* @author Wallace Wadge * @author Wallace Wadge
* @author Andy Wilkinson
*/ */
public class WebRequestTraceFilter extends OncePerRequestFilter implements Ordered { public class WebRequestTraceFilter extends OncePerRequestFilter implements Ordered {
@ -124,7 +125,9 @@ public class WebRequestTraceFilter extends OncePerRequestFilter implements Order
add(trace, Include.CONTEXT_PATH, "contextPath", request.getContextPath()); add(trace, Include.CONTEXT_PATH, "contextPath", request.getContextPath());
add(trace, Include.USER_PRINCIPAL, "userPrincipal", add(trace, Include.USER_PRINCIPAL, "userPrincipal",
(userPrincipal == null ? null : userPrincipal.getName())); (userPrincipal == null ? null : userPrincipal.getName()));
add(trace, Include.PARAMETERS, "parameters", request.getParameterMap()); if (isIncluded(Include.PARAMETERS)) {
trace.put("parameters", request.getParameterMap());
}
add(trace, Include.QUERY_STRING, "query", request.getQueryString()); add(trace, Include.QUERY_STRING, "query", request.getQueryString());
add(trace, Include.AUTH_TYPE, "authType", request.getAuthType()); add(trace, Include.AUTH_TYPE, "authType", request.getAuthType());
add(trace, Include.REMOTE_ADDRESS, "remoteAddress", request.getRemoteAddr()); add(trace, Include.REMOTE_ADDRESS, "remoteAddress", request.getRemoteAddr());

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2015 the original author or authors. * Copyright 2012-2016 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -38,6 +38,9 @@ import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse; import org.springframework.mock.web.MockHttpServletResponse;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
/** /**
* Tests for {@link WebRequestTraceFilter}. * Tests for {@link WebRequestTraceFilter}.
@ -45,6 +48,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Dave Syer * @author Dave Syer
* @author Wallace Wadge * @author Wallace Wadge
* @author Phillip Webb * @author Phillip Webb
* @author Andy Wilkinson
*/ */
public class WebRequestTraceFilterTests { public class WebRequestTraceFilterTests {
@ -58,13 +62,14 @@ public class WebRequestTraceFilterTests {
@Test @Test
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void filterAddsTraceWithDefaultIncludes() { public void filterAddsTraceWithDefaultIncludes() {
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo"); MockHttpServletRequest request = spy(new MockHttpServletRequest("GET", "/foo"));
request.addHeader("Accept", "application/json"); request.addHeader("Accept", "application/json");
Map<String, Object> trace = this.filter.getTrace(request); Map<String, Object> trace = this.filter.getTrace(request);
assertThat(trace.get("method")).isEqualTo("GET"); assertThat(trace.get("method")).isEqualTo("GET");
assertThat(trace.get("path")).isEqualTo("/foo"); assertThat(trace.get("path")).isEqualTo("/foo");
Map<String, Object> map = (Map<String, Object>) trace.get("headers"); Map<String, Object> map = (Map<String, Object>) trace.get("headers");
assertThat(map.get("request").toString()).isEqualTo("{Accept=application/json}"); assertThat(map.get("request").toString()).isEqualTo("{Accept=application/json}");
verify(request, times(0)).getParameterMap();
} }
@Test @Test

Loading…
Cancel
Save