DATAREST-573 - Polishing.

Removed RepositoryRestConfiguration.addCorsMapping(…) as we currently don't have any other shortcut methods for configuration like this.

Tweaked the setup of (now Repository)CorsConfigurationAccessor to be created earlier so that we avoid recreation for every lookup. Introduced a NoOpStringValueResolver to be used by default so that we don't need to deal with the case of the resolver being null at the end of the call chain. Replaced constructor of RepositoryCorsConfigurationAccessor with corresponding Lombok annotation.

Updated reference documentation accordingly.

Original pull request: #233.
This commit is contained in:
Oliver Gierke
2016-10-28 13:31:09 +02:00
parent a3870ca528
commit 40bb8e8e6c
8 changed files with 89 additions and 88 deletions

View File

@@ -15,14 +15,17 @@
*/
package org.springframework.data.rest.webmvc.jpa;
import static org.springframework.web.bind.annotation.RequestMethod.*;
import org.springframework.data.repository.CrudRepository;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMethod;
/**
* @author Oliver Gierke
* @author Mark Paluch
*/
@CrossOrigin(origins = "http://not.so.far.away", allowCredentials = "true",
methods = { RequestMethod.GET, RequestMethod.PATCH }, maxAge = 1234)
@CrossOrigin(origins = "http://not.so.far.away", //
allowCredentials = "true", //
methods = { GET, PATCH }, //
maxAge = 1234)
public interface AuthorRepository extends CrudRepository<Author, Long> {}

View File

@@ -15,11 +15,9 @@
*/
package org.springframework.data.rest.webmvc.jpa;
import static org.hamcrest.Matchers.containsString;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.options;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import static org.hamcrest.Matchers.*;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
import org.junit.Test;
import org.springframework.context.annotation.Bean;
@@ -58,7 +56,7 @@ public class CorsIntegrationTests extends AbstractWebIntegrationTests {
@Override
public void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) {
config.addCorsMapping("/books/**") //
config.getCorsRegistry().addMapping("/books/**") //
.allowedMethods("GET", "PUT", "POST") //
.allowedOrigins("http://far.far.away");
}
@@ -79,7 +77,8 @@ public class CorsIntegrationTests extends AbstractWebIntegrationTests {
.header(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "POST")) //
.andExpect(status().isOk()) //
.andExpect(header().string(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN, "http://far.far.away")) //
.andExpect(header().string(HttpHeaders.ACCESS_CONTROL_ALLOW_METHODS, "GET,HEAD,POST,PUT,PATCH,DELETE,OPTIONS,TRACE"));
.andExpect(
header().string(HttpHeaders.ACCESS_CONTROL_ALLOW_METHODS, "GET,HEAD,POST,PUT,PATCH,DELETE,OPTIONS,TRACE"));
}
/**