use of org.springframework.web.servlet.HandlerInterceptor in project spring-framework by spring-projects.
the class HandlerMappingTests method orderedInterceptors.
@Test
public void orderedInterceptors() throws Exception {
MappedInterceptor firstMappedInterceptor = new MappedInterceptor(new String[] { "/**" }, Mockito.mock(HandlerInterceptor.class));
HandlerInterceptor secondHandlerInterceptor = Mockito.mock(HandlerInterceptor.class);
MappedInterceptor thirdMappedInterceptor = new MappedInterceptor(new String[] { "/**" }, Mockito.mock(HandlerInterceptor.class));
HandlerInterceptor fourthHandlerInterceptor = Mockito.mock(HandlerInterceptor.class);
this.handlerMapping.setInterceptors(new Object[] { firstMappedInterceptor, secondHandlerInterceptor, thirdMappedInterceptor, fourthHandlerInterceptor });
this.handlerMapping.setApplicationContext(this.context);
HandlerExecutionChain chain = this.handlerMapping.getHandlerExecutionChain(new SimpleHandler(), this.request);
Assert.assertThat(chain.getInterceptors(), Matchers.arrayContaining(firstMappedInterceptor.getInterceptor(), secondHandlerInterceptor, thirdMappedInterceptor.getInterceptor(), fourthHandlerInterceptor));
}
use of org.springframework.web.servlet.HandlerInterceptor in project spring-framework by spring-projects.
the class PathMatchingUrlHandlerMappingTests method getHandler.
private HandlerExecutionChain getHandler(MockHttpServletRequest req) throws Exception {
HandlerExecutionChain hec = hm.getHandler(req);
HandlerInterceptor[] interceptors = hec.getInterceptors();
if (interceptors != null) {
for (HandlerInterceptor interceptor : interceptors) {
interceptor.preHandle(req, null, hec.getHandler());
}
}
return hec;
}
use of org.springframework.web.servlet.HandlerInterceptor in project spring-framework by spring-projects.
the class SimpleUrlHandlerMappingTests method getHandler.
private HandlerExecutionChain getHandler(HandlerMapping hm, MockHttpServletRequest req) throws Exception {
HandlerExecutionChain hec = hm.getHandler(req);
HandlerInterceptor[] interceptors = hec.getInterceptors();
if (interceptors != null) {
for (HandlerInterceptor interceptor : interceptors) {
interceptor.preHandle(req, null, hec.getHandler());
}
}
return hec;
}
use of org.springframework.web.servlet.HandlerInterceptor in project spring-integration by spring-projects.
the class CrossOriginTests method getCorsConfiguration.
private CorsConfiguration getCorsConfiguration(HandlerExecutionChain chain, boolean isPreFlightRequest) {
if (isPreFlightRequest) {
Object handler = chain.getHandler();
assertTrue(handler.getClass().getSimpleName().equals("PreFlightHandler"));
return TestUtils.getPropertyValue(handler, "config", CorsConfiguration.class);
} else {
HandlerInterceptor[] interceptors = chain.getInterceptors();
if (interceptors != null) {
for (HandlerInterceptor interceptor : interceptors) {
if (interceptor.getClass().getSimpleName().equals("CorsInterceptor")) {
return TestUtils.getPropertyValue(interceptor, "config", CorsConfiguration.class);
}
}
}
}
return null;
}
use of org.springframework.web.servlet.HandlerInterceptor in project spring-integration by spring-projects.
the class IntegrationGraphControllerTests method testIntegrationGraphControllerParser.
@Test
public void testIntegrationGraphControllerParser() throws Exception {
ConfigurableApplicationContext context = new ClassPathXmlApplicationContext("IntegrationGraphControllerParserTests-context.xml", getClass());
HandlerMapping handlerMapping = context.getBean(RequestMappingHandlerMapping.class.getName(), HandlerMapping.class);
HandlerAdapter handlerAdapter = context.getBean(RequestMappingHandlerAdapter.class);
MockHttpServletRequest request = new MockHttpServletRequest();
request.setMethod("GET");
request.setRequestURI("/foo");
request.addHeader(HttpHeaders.ORIGIN, "http://foo.bar.com");
MockHttpServletResponse response = new MockHttpServletResponse();
HandlerExecutionChain executionChain = handlerMapping.getHandler(request);
assertNotNull(executionChain);
Object handler = executionChain.getHandler();
for (HandlerInterceptor handlerInterceptor : executionChain.getInterceptors()) {
// Assert the CORS config
assertTrue(handlerInterceptor.preHandle(request, response, handler));
}
handlerAdapter.handle(request, response, handler);
assertEquals(HttpStatus.OK.value(), response.getStatus());
assertThat(response.getContentAsString(), containsString("\"name\":\"nullChannel\","));
assertThat(response.getContentAsString(), not(containsString("\"name\":\"myChannel\",")));
context.getBeanFactory().registerSingleton("myChannel", new DirectChannel());
request = new MockHttpServletRequest();
request.setMethod("GET");
request.setRequestURI("/foo/refresh");
response = new MockHttpServletResponse();
executionChain = handlerMapping.getHandler(request);
assertNotNull(executionChain);
handler = executionChain.getHandler();
for (HandlerInterceptor handlerInterceptor : executionChain.getInterceptors()) {
// Assert the CORS config
assertTrue(handlerInterceptor.preHandle(request, response, handler));
}
handlerAdapter.handle(request, response, handler);
assertEquals(HttpStatus.OK.value(), response.getStatus());
assertThat(response.getContentAsString(), containsString("\"name\":\"myChannel\","));
context.close();
}
Aggregations