Do not log headers in exception message

Issue: SPR-12984
master
Rossen Stoyanchev 9 years ago
parent bccd59e6c8
commit e843bcc725
  1. 9
      spring-webmvc/src/main/java/org/springframework/web/servlet/NoHandlerFoundException.java
  2. 11
      spring-webmvc/src/test/java/org/springframework/web/servlet/DispatcherServletTests.java

@ -23,9 +23,10 @@ import javax.servlet.http.HttpServletResponse;
import org.springframework.http.HttpHeaders;
/**
* Exception to be thrown if DispatcherServlet is unable to determine a corresponding
* handler for an incoming HTTP request. The DispatcherServlet throws this exception
* only if its "throwExceptionIfNoHandlerFound" property is set to "true".
* By default when the DispatcherServlet can't find a handler for a request it
* sends a 404 response. However if its property "throwExceptionIfNoHandlerFound"
* is set to {@code true} this exception is raised and may be handled with
* a configured HandlerExceptionResolver.
*
* @author Brian Clozel
* @since 4.0
@ -49,7 +50,7 @@ public class NoHandlerFoundException extends ServletException {
* @param headers the HTTP request headers
*/
public NoHandlerFoundException(String httpMethod, String requestURL, HttpHeaders headers) {
super("No handler found for " + httpMethod + " " + requestURL + ", headers=" + headers);
super("No handler found for " + httpMethod + " " + requestURL);
this.httpMethod = httpMethod;
this.requestURL = requestURL;
this.headers = headers;

@ -34,6 +34,7 @@ import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.DummyEnvironment;
import org.springframework.http.HttpHeaders;
import org.springframework.mock.web.test.MockHttpServletRequest;
import org.springframework.mock.web.test.MockHttpServletResponse;
import org.springframework.mock.web.test.MockServletConfig;
@ -574,6 +575,16 @@ public class DispatcherServletTests extends TestCase {
assertTrue("correct error code", response.getStatus() == HttpServletResponse.SC_NOT_FOUND);
}
// SPR-12984
public void testNoHandlerFoundExceptionMessage() {
HttpHeaders headers = new HttpHeaders();
headers.add("foo", "bar");
NoHandlerFoundException ex = new NoHandlerFoundException("GET", "/foo", headers);
assertTrue(!ex.getMessage().contains("bar"));
assertTrue(!ex.toString().contains("bar"));
}
public void testCleanupAfterIncludeWithRemove() throws ServletException, IOException {
MockHttpServletRequest request = new MockHttpServletRequest(getServletContext(), "GET", "/main.do");
MockHttpServletResponse response = new MockHttpServletResponse();

Loading…
Cancel
Save