Search in sources :

Example 56 with HandlerExecutionChain

use of org.springframework.web.servlet.HandlerExecutionChain in project spring-framework by spring-projects.

the class CrossOriginTests method noAnnotationWithOrigin.

// SPR-12931
@Test
public void noAnnotationWithOrigin() throws Exception {
    this.handlerMapping.registerHandler(new MethodLevelController());
    this.request.setRequestURI("/no");
    HandlerExecutionChain chain = this.handlerMapping.getHandler(request);
    assertNull(getCorsConfiguration(chain, false));
}
Also used : HandlerExecutionChain(org.springframework.web.servlet.HandlerExecutionChain) Test(org.junit.Test)

Example 57 with HandlerExecutionChain

use of org.springframework.web.servlet.HandlerExecutionChain in project spring-framework by spring-projects.

the class CrossOriginTests method customized.

@Test
public void customized() throws Exception {
    this.handlerMapping.registerHandler(new MethodLevelController());
    this.request.setRequestURI("/customized");
    HandlerExecutionChain chain = this.handlerMapping.getHandler(request);
    CorsConfiguration config = getCorsConfiguration(chain, false);
    assertNotNull(config);
    assertArrayEquals(new String[] { "DELETE" }, config.getAllowedMethods().toArray());
    assertArrayEquals(new String[] { "http://site1.com", "http://site2.com" }, config.getAllowedOrigins().toArray());
    assertArrayEquals(new String[] { "header1", "header2" }, config.getAllowedHeaders().toArray());
    assertArrayEquals(new String[] { "header3", "header4" }, config.getExposedHeaders().toArray());
    assertEquals(new Long(123), config.getMaxAge());
    assertFalse(config.getAllowCredentials());
}
Also used : CorsConfiguration(org.springframework.web.cors.CorsConfiguration) HandlerExecutionChain(org.springframework.web.servlet.HandlerExecutionChain) Test(org.junit.Test)

Example 58 with HandlerExecutionChain

use of org.springframework.web.servlet.HandlerExecutionChain in project spring-framework by spring-projects.

the class CrossOriginTests method defaultAnnotation.

@Test
public void defaultAnnotation() throws Exception {
    this.handlerMapping.registerHandler(new MethodLevelController());
    this.request.setRequestURI("/default");
    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());
    assertTrue(config.getAllowCredentials());
    assertArrayEquals(new String[] { "*" }, config.getAllowedHeaders().toArray());
    assertTrue(CollectionUtils.isEmpty(config.getExposedHeaders()));
    assertEquals(new Long(1800), config.getMaxAge());
}
Also used : CorsConfiguration(org.springframework.web.cors.CorsConfiguration) HandlerExecutionChain(org.springframework.web.servlet.HandlerExecutionChain) Test(org.junit.Test)

Example 59 with HandlerExecutionChain

use of org.springframework.web.servlet.HandlerExecutionChain in project spring-framework by spring-projects.

the class CrossOriginTests method classLevelComposedAnnotation.

// SPR-13468
@Test
public void classLevelComposedAnnotation() throws Exception {
    this.handlerMapping.registerHandler(new ClassLevelMappingWithComposedAnnotation());
    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[] { "http://foo.com" }, config.getAllowedOrigins().toArray());
    assertTrue(config.getAllowCredentials());
}
Also used : CorsConfiguration(org.springframework.web.cors.CorsConfiguration) HandlerExecutionChain(org.springframework.web.servlet.HandlerExecutionChain) Test(org.junit.Test)

Example 60 with HandlerExecutionChain

use of org.springframework.web.servlet.HandlerExecutionChain in project spring-framework by spring-projects.

the class CrossOriginTests method noAnnotationWithoutOrigin.

@Test
public void noAnnotationWithoutOrigin() throws Exception {
    this.handlerMapping.registerHandler(new MethodLevelController());
    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/no");
    HandlerExecutionChain chain = this.handlerMapping.getHandler(request);
    assertNull(getCorsConfiguration(chain, false));
}
Also used : HandlerExecutionChain(org.springframework.web.servlet.HandlerExecutionChain) MockHttpServletRequest(org.springframework.mock.web.test.MockHttpServletRequest) Test(org.junit.Test)

Aggregations

HandlerExecutionChain (org.springframework.web.servlet.HandlerExecutionChain)61 Test (org.junit.Test)47 MockHttpServletRequest (org.springframework.mock.web.test.MockHttpServletRequest)28 CorsConfiguration (org.springframework.web.cors.CorsConfiguration)16 RequestMappingHandlerMapping (org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping)11 HandlerInterceptor (org.springframework.web.servlet.HandlerInterceptor)9 MockHttpServletResponse (org.springframework.mock.web.test.MockHttpServletResponse)8 ConversionServiceExposingInterceptor (org.springframework.web.servlet.handler.ConversionServiceExposingInterceptor)7 SimpleUrlHandlerMapping (org.springframework.web.servlet.handler.SimpleUrlHandlerMapping)7 HandlerMethod (org.springframework.web.method.HandlerMethod)6 ModelAndView (org.springframework.web.servlet.ModelAndView)6 LocaleChangeInterceptor (org.springframework.web.servlet.i18n.LocaleChangeInterceptor)5 ThemeChangeInterceptor (org.springframework.web.servlet.theme.ThemeChangeInterceptor)5 Mock (org.jmock.Mock)4 ContentNegotiationManager (org.springframework.web.accept.ContentNegotiationManager)3 NativeWebRequest (org.springframework.web.context.request.NativeWebRequest)3 ServletWebRequest (org.springframework.web.context.request.ServletWebRequest)3 HttpRequestHandlerAdapter (org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ApplicationContext (org.springframework.context.ApplicationContext)2