use of javax.servlet.FilterChain in project spring-framework by spring-projects.
the class ForwardedHeaderFilterTests method doWithFiltersAndGetResponse.
@SuppressWarnings("serial")
private MockHttpServletResponse doWithFiltersAndGetResponse(Filter... filters) throws ServletException, IOException {
MockHttpServletResponse response = new MockHttpServletResponse();
FilterChain filterChain = new MockFilterChain(new HttpServlet() {
}, filters);
filterChain.doFilter(request, response);
return response;
}
use of javax.servlet.FilterChain 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.FilterChain 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.FilterChain in project spring-boot by spring-projects.
the class MetricFilterAutoConfigurationTests method doesNotRecordRolledUpMetricsIfConfigured.
@Test
public void doesNotRecordRolledUpMetricsIfConfigured() throws Exception {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
context.register(Config.class, MetricFilterAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(context, "endpoints.metrics.filter.gauge-submissions=", "endpoints.metrics.filter.counter-submissions=");
context.refresh();
Filter filter = context.getBean(Filter.class);
final MockHttpServletRequest request = new MockHttpServletRequest("PUT", "/test/path");
final MockHttpServletResponse response = new MockHttpServletResponse();
FilterChain chain = mock(FilterChain.class);
willAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
response.setStatus(200);
return null;
}
}).given(chain).doFilter(request, response);
filter.doFilter(request, response, chain);
verify(context.getBean(GaugeService.class), never()).submit(anyString(), anyDouble());
verify(context.getBean(CounterService.class), never()).increment(anyString());
context.close();
}
use of javax.servlet.FilterChain in project spring-boot by spring-projects.
the class MetricFilterAutoConfigurationTests method whenExceptionIsThrownResponseStatusIsUsedWhenResponseHasBeenCommitted.
@Test
public void whenExceptionIsThrownResponseStatusIsUsedWhenResponseHasBeenCommitted() throws Exception {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
context.register(Config.class, MetricFilterAutoConfiguration.class);
context.refresh();
Filter filter = context.getBean(Filter.class);
final MockHttpServletRequest request = new MockHttpServletRequest("GET", "/test/path");
final MockHttpServletResponse response = new MockHttpServletResponse();
FilterChain chain = mock(FilterChain.class);
willAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
response.setStatus(200);
response.setCommitted(true);
throw new IOException();
}
}).given(chain).doFilter(request, response);
try {
filter.doFilter(request, response, chain);
fail();
} catch (IOException ex) {
// Continue
}
verify(context.getBean(CounterService.class)).increment(eq("status.200.test.path"));
context.close();
}
Aggregations