use of javax.servlet.FilterChain in project spring-boot by spring-projects.
the class WebRequestTraceFilterTests method filterHas500ResponseStatusWhenExceptionIsThrown.
@Test
@SuppressWarnings("unchecked")
public void filterHas500ResponseStatusWhenExceptionIsThrown() throws ServletException, IOException {
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo");
MockHttpServletResponse response = new MockHttpServletResponse();
try {
this.filter.doFilterInternal(request, response, new FilterChain() {
@Override
public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException {
throw new RuntimeException();
}
});
fail("Exception was swallowed");
} catch (RuntimeException ex) {
Map<String, Object> headers = (Map<String, Object>) this.repository.findAll().iterator().next().getInfo().get("headers");
Map<String, Object> responseHeaders = (Map<String, Object>) headers.get("response");
assertThat((String) responseHeaders.get("status")).isEqualTo("500");
}
}
use of javax.servlet.FilterChain in project spring-boot by spring-projects.
the class WebRequestTraceFilterTests method filterDoesNotAddAuthorizationHeaderWithoutAuthorizationHeaderInclude.
@Test
@SuppressWarnings({ "unchecked" })
public void filterDoesNotAddAuthorizationHeaderWithoutAuthorizationHeaderInclude() throws ServletException, IOException {
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo");
request.addHeader("Authorization", "my-auth-header");
MockHttpServletResponse response = new MockHttpServletResponse();
this.filter.doFilterInternal(request, response, new FilterChain() {
@Override
public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException {
}
});
Map<String, Object> info = this.repository.findAll().iterator().next().getInfo();
Map<String, Object> headers = (Map<String, Object>) info.get("headers");
assertThat(((Map<Object, Object>) headers.get("request"))).hasSize(0);
}
use of javax.servlet.FilterChain in project spring-boot by spring-projects.
the class WebRequestTraceFilterTests method filterDoesNotAddResponseHeadersWithoutResponseHeadersInclude.
@Test
@SuppressWarnings({ "unchecked" })
public void filterDoesNotAddResponseHeadersWithoutResponseHeadersInclude() throws ServletException, IOException {
this.properties.setInclude(Collections.singleton(Include.REQUEST_HEADERS));
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo");
MockHttpServletResponse response = new MockHttpServletResponse();
response.addHeader("Content-Type", "application/json");
this.filter.doFilterInternal(request, response, new FilterChain() {
@Override
public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException {
}
});
Map<String, Object> info = this.repository.findAll().iterator().next().getInfo();
Map<String, Object> headers = (Map<String, Object>) info.get("headers");
assertThat(headers.get("response") == null).isTrue();
}
use of javax.servlet.FilterChain in project spring-framework by spring-projects.
the class RequestLoggingFilterTests method noQueryStringAvailable.
@Test
public void noQueryStringAvailable() throws Exception {
filter.setIncludeQueryString(true);
MockHttpServletRequest request = new MockHttpServletRequest("POST", "/hotels");
MockHttpServletResponse response = new MockHttpServletResponse();
FilterChain filterChain = new NoOpFilterChain();
filter.doFilter(request, response, filterChain);
assertNotNull(filter.beforeRequestMessage);
assertTrue(filter.beforeRequestMessage.contains("[uri=/hotels]"));
assertNotNull(filter.afterRequestMessage);
assertTrue(filter.afterRequestMessage.contains("[uri=/hotels]"));
}
use of javax.servlet.FilterChain in project spring-framework by spring-projects.
the class RequestLoggingFilterTests method queryStringIncluded.
@Test
public void queryStringIncluded() throws Exception {
filter.setIncludeQueryString(true);
MockHttpServletRequest request = new MockHttpServletRequest("POST", "/hotels");
MockHttpServletResponse response = new MockHttpServletResponse();
request.setQueryString("booking=42");
FilterChain filterChain = new NoOpFilterChain();
filter.doFilter(request, response, filterChain);
assertNotNull(filter.beforeRequestMessage);
assertTrue(filter.beforeRequestMessage.contains("[uri=/hotels?booking=42]"));
assertNotNull(filter.afterRequestMessage);
assertTrue(filter.afterRequestMessage.contains("[uri=/hotels?booking=42]"));
}
Aggregations