Polishing

This commit is contained in:
Juergen Hoeller
2017-02-21 22:41:40 +01:00
parent f219680d42
commit d2cc97af47
16 changed files with 83 additions and 80 deletions

View File

@@ -16,7 +16,6 @@
package org.springframework.web.servlet.config.annotation;
import java.util.ArrayList;
import java.util.Arrays;
import org.springframework.web.cors.CorsConfiguration;
@@ -45,7 +44,6 @@ public class CorsRegistration {
* Create a new {@link CorsRegistration} that allows all origins, headers, and
* credentials for {@code GET}, {@code HEAD}, and {@code POST} requests with
* max age set to 1800 seconds (30 minutes) for the specified path.
*
* @param pathPattern the path that the CORS configuration should apply to;
* exact path mapping URIs (such as {@code "/admin"}) are supported as well
* as Ant-style path patterns (such as {@code "/admin/**"}).
@@ -56,13 +54,14 @@ public class CorsRegistration {
this.config = new CorsConfiguration().applyPermitDefaultValues();
}
/**
* Set the origins to allow, e.g. {@code "http://domain1.com"}.
* <p>The special value {@code "*"} allows all domains.
* <p>By default, all origins are allowed.
*/
public CorsRegistration allowedOrigins(String... origins) {
this.config.setAllowedOrigins(new ArrayList<>(Arrays.asList(origins)));
this.config.setAllowedOrigins(Arrays.asList(origins));
return this;
}
@@ -74,7 +73,7 @@ public class CorsRegistration {
* are allowed.
*/
public CorsRegistration allowedMethods(String... methods) {
this.config.setAllowedMethods(new ArrayList<>(Arrays.asList(methods)));
this.config.setAllowedMethods(Arrays.asList(methods));
return this;
}
@@ -88,7 +87,7 @@ public class CorsRegistration {
* <p>By default all headers are allowed.
*/
public CorsRegistration allowedHeaders(String... headers) {
this.config.setAllowedHeaders(new ArrayList<>(Arrays.asList(headers)));
this.config.setAllowedHeaders(Arrays.asList(headers));
return this;
}
@@ -101,7 +100,7 @@ public class CorsRegistration {
* <p>By default this is not set.
*/
public CorsRegistration exposedHeaders(String... headers) {
this.config.setExposedHeaders(new ArrayList<>(Arrays.asList(headers)));
this.config.setExposedHeaders(Arrays.asList(headers));
return this;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -37,14 +37,15 @@ public class CorsRegistry {
/**
* Enable cross origin request handling for the specified path pattern.
*
* Enable cross-origin request handling for the specified path pattern.
* <p>Exact path mapping URIs (such as {@code "/admin"}) are supported as
* well as Ant-style path patterns (such as {@code "/admin/**"}).
*
* <p>By default, all origins, all headers, credentials and {@code GET},
* {@code HEAD}, and {@code POST} methods are allowed, and the max age
* is set to 30 minutes.
* @param pathPattern the path pattern to enable CORS handling for
* @return CorsRegistration the corresponding registration object,
* allowing for further fine-tuning
*/
public CorsRegistration addMapping(String pathPattern) {
CorsRegistration registration = new CorsRegistration(pathPattern);
@@ -52,6 +53,10 @@ public class CorsRegistry {
return registration;
}
/**
* Return the registered {@link CorsConfiguration} objects,
* keyed by path pattern.
*/
protected Map<String, CorsConfiguration> getCorsConfigurations() {
Map<String, CorsConfiguration> configs = new LinkedHashMap<>(this.registrations.size());
for (CorsRegistration registration : this.registrations) {

View File

@@ -22,7 +22,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
@@ -629,12 +628,9 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv
String className = "org.springframework.validation.beanvalidation.OptionalValidatorFactoryBean";
clazz = ClassUtils.forName(className, WebMvcConfigurationSupport.class.getClassLoader());
}
catch (ClassNotFoundException ex) {
catch (ClassNotFoundException | LinkageError ex) {
throw new BeanInitializationException("Could not find default validator class", ex);
}
catch (LinkageError ex) {
throw new BeanInitializationException("Could not load default validator class", ex);
}
validator = (Validator) BeanUtils.instantiateClass(clazz);
}
else {
@@ -961,6 +957,8 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv
}
/**
* Return the registered {@link CorsConfiguration} objects,
* keyed by path pattern.
* @since 4.2
*/
protected final Map<String, CorsConfiguration> getCorsConfigurations() {