use of org.springframework.web.servlet.HandlerExecutionChain in project spring-framework by spring-projects.
the class PathMatchingUrlHandlerMappingTests method mappingExposedInRequest.
@Test
public void mappingExposedInRequest() throws Exception {
Object bean = wac.getBean("mainController");
MockHttpServletRequest req = new MockHttpServletRequest("GET", "/show.html");
HandlerExecutionChain hec = getHandler(req);
assertTrue("Handler is correct bean", hec != null && hec.getHandler() == bean);
assertEquals("Mapping not exposed", "show.html", req.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE));
}
use of org.springframework.web.servlet.HandlerExecutionChain 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.HandlerExecutionChain in project spring-framework by spring-projects.
the class CrossOriginTests method classLevel.
@Test
public void classLevel() throws Exception {
this.handlerMapping.registerHandler(new ClassLevelController());
this.request.setRequestURI("/foo");
HandlerExecutionChain chain = this.handlerMapping.getHandler(request);
CorsConfiguration config = getCorsConfiguration(chain, false);
assertNotNull(config);
assertArrayEquals(new String[] { "GET" }, config.getAllowedMethods().toArray());
assertArrayEquals(new String[] { "*" }, config.getAllowedOrigins().toArray());
assertFalse(config.getAllowCredentials());
this.request.setRequestURI("/bar");
chain = this.handlerMapping.getHandler(request);
config = getCorsConfiguration(chain, false);
assertNotNull(config);
assertArrayEquals(new String[] { "GET" }, config.getAllowedMethods().toArray());
assertArrayEquals(new String[] { "*" }, config.getAllowedOrigins().toArray());
assertFalse(config.getAllowCredentials());
this.request.setRequestURI("/baz");
chain = this.handlerMapping.getHandler(request);
config = getCorsConfiguration(chain, false);
assertNotNull(config);
assertArrayEquals(new String[] { "GET" }, config.getAllowedMethods().toArray());
assertArrayEquals(new String[] { "*" }, config.getAllowedOrigins().toArray());
assertTrue(config.getAllowCredentials());
}
use of org.springframework.web.servlet.HandlerExecutionChain in project spring-framework by spring-projects.
the class CrossOriginTests method ambiguousHeaderPreFlightRequest.
@Test
public void ambiguousHeaderPreFlightRequest() throws Exception {
this.handlerMapping.registerHandler(new MethodLevelController());
this.request.setMethod("OPTIONS");
this.request.addHeader(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET");
this.request.addHeader(HttpHeaders.ACCESS_CONTROL_REQUEST_HEADERS, "header1");
this.request.setRequestURI("/ambiguous-header");
HandlerExecutionChain chain = this.handlerMapping.getHandler(request);
CorsConfiguration config = getCorsConfiguration(chain, true);
assertNotNull(config);
assertArrayEquals(new String[] { "*" }, config.getAllowedMethods().toArray());
assertArrayEquals(new String[] { "*" }, config.getAllowedOrigins().toArray());
assertArrayEquals(new String[] { "*" }, config.getAllowedHeaders().toArray());
assertTrue(config.getAllowCredentials());
assertTrue(CollectionUtils.isEmpty(config.getExposedHeaders()));
assertNull(config.getMaxAge());
}
use of org.springframework.web.servlet.HandlerExecutionChain in project spring-framework by spring-projects.
the class CrossOriginTests method noAnnotationPostWithOrigin.
// SPR-12931
@Test
public void noAnnotationPostWithOrigin() throws Exception {
this.handlerMapping.registerHandler(new MethodLevelController());
this.request.setMethod("POST");
this.request.setRequestURI("/no");
HandlerExecutionChain chain = this.handlerMapping.getHandler(request);
assertNull(getCorsConfiguration(chain, false));
}
Aggregations