use of javax.servlet.ServletRequest 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.ServletRequest in project spring-framework by spring-projects.
the class HiddenHttpMethodFilterTests method filterWithParameter.
@Test
public void filterWithParameter() throws IOException, ServletException {
MockHttpServletRequest request = new MockHttpServletRequest("POST", "/hotels");
request.addParameter("_method", "delete");
MockHttpServletResponse response = new MockHttpServletResponse();
FilterChain filterChain = new FilterChain() {
@Override
public void doFilter(ServletRequest filterRequest, ServletResponse filterResponse) throws IOException, ServletException {
assertEquals("Invalid method", "DELETE", ((HttpServletRequest) filterRequest).getMethod());
}
};
filter.doFilter(request, response, filterChain);
}
use of javax.servlet.ServletRequest in project spring-framework by spring-projects.
the class HiddenHttpMethodFilterTests method filterWithNoParameter.
@Test
public void filterWithNoParameter() throws IOException, ServletException {
MockHttpServletRequest request = new MockHttpServletRequest("POST", "/hotels");
MockHttpServletResponse response = new MockHttpServletResponse();
FilterChain filterChain = new FilterChain() {
@Override
public void doFilter(ServletRequest filterRequest, ServletResponse filterResponse) throws IOException, ServletException {
assertEquals("Invalid method", "POST", ((HttpServletRequest) filterRequest).getMethod());
}
};
filter.doFilter(request, response, filterChain);
}
use of javax.servlet.ServletRequest in project spring-boot by spring-projects.
the class ErrorPageFilterTests method responseUncommittedWithoutErrorPage.
@Test
public void responseUncommittedWithoutErrorPage() throws Exception {
this.chain = new MockFilterChain() {
@Override
public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException {
((HttpServletResponse) response).sendError(400, "BAD");
super.doFilter(request, response);
}
};
this.filter.doFilter(this.request, this.response, this.chain);
assertThat(this.chain.getRequest()).isEqualTo(this.request);
assertThat(((HttpServletResponseWrapper) this.chain.getResponse()).getResponse()).isEqualTo(this.response);
assertThat(((HttpServletResponseWrapper) this.chain.getResponse()).getStatus()).isEqualTo(400);
assertThat(this.response.getForwardedUrl()).isNull();
assertThat(this.response.isCommitted()).isTrue();
}
use of javax.servlet.ServletRequest in project spring-boot by spring-projects.
the class ErrorPageFilterTests method errorMessageForRequestWithPathInfo.
@Test
public void errorMessageForRequestWithPathInfo() throws IOException, ServletException {
this.request.setServletPath("/test");
this.request.setPathInfo("/alpha");
this.filter.addErrorPages(new ErrorPage("/error"));
this.chain = new MockFilterChain() {
@Override
public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException {
super.doFilter(request, response);
throw new RuntimeException();
}
};
this.filter.doFilter(this.request, this.response, this.chain);
assertThat(this.output.toString()).contains("request [/test/alpha]");
}
Aggregations