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

@@ -28,7 +28,6 @@ import org.springframework.hateoas.MediaTypes;
import org.springframework.http.MediaType;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.servlet.config.annotation.CorsRegistration;
/**
@@ -565,22 +564,6 @@ public class RepositoryRestConfiguration {
return corsRegistry;
}
/**
* Configures Cross-origin resource sharing given a {@code path}.
*
* @param path path or path pattern, must not be {@literal null} or empty.
* @return the {@link CorsRegistration} to build a CORS configuration.
* @since 2.6
* @see CorsConfiguration
*/
public CorsRegistration addCorsMapping(String path) {
Assert.notNull(path, "Path must not be null!");
Assert.hasText(path, "Path must not be empty!");
return corsRegistry.addMapping(path);
}
/**
* Returns the {@link EntityLookupRegistrar} to create custom {@link EntityLookup} instances registered in the
* configuration.

View File

@@ -26,6 +26,7 @@ import org.junit.Test;
import org.springframework.data.rest.core.config.EnumTranslationConfiguration;
import org.springframework.data.rest.core.config.MetadataConfiguration;
import org.springframework.data.rest.core.config.ProjectionDefinitionConfiguration;
import org.springframework.data.rest.core.config.RepositoryCorsRegistry;
import org.springframework.data.rest.core.config.RepositoryRestConfiguration;
import org.springframework.data.rest.core.domain.Profile;
import org.springframework.data.rest.core.domain.ProfileRepository;
@@ -149,9 +150,10 @@ public class RepositoryRestConfigurationUnitTests {
@Test
public void configuresCorsProcessing() {
configuration.addCorsMapping("/hello").maxAge(1234);
RepositoryCorsRegistry registry = configuration.getCorsRegistry();
registry.addMapping("/hello").maxAge(1234);
Map<String, CorsConfiguration> corsConfigurations = configuration.getCorsRegistry().getCorsConfigurations();
Map<String, CorsConfiguration> corsConfigurations = registry.getCorsConfigurations();
assertThat(corsConfigurations, hasKey("/hello"));
CorsConfiguration corsConfiguration = corsConfigurations.get("/hello");