Polishing

This commit is contained in:
Juergen Hoeller 2020-07-17 17:48:33 +02:00
parent 30bf870810
commit e9898f7d52
10 changed files with 42 additions and 40 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2018 the original author or authors. * Copyright 2002-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -49,8 +49,9 @@ abstract class AbstractJndiLocatingBeanDefinitionParser extends AbstractSimpleBe
@Override @Override
protected boolean isEligibleAttribute(String attributeName) { protected boolean isEligibleAttribute(String attributeName) {
return (super.isEligibleAttribute(attributeName) && !ENVIRONMENT_REF.equals(attributeName) && !LAZY_INIT_ATTRIBUTE return (super.isEligibleAttribute(attributeName) &&
.equals(attributeName)); !ENVIRONMENT_REF.equals(attributeName) &&
!LAZY_INIT_ATTRIBUTE.equals(attributeName));
} }
@Override @Override

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -42,8 +42,9 @@ public class JeeNamespaceHandlerTests {
private ConfigurableListableBeanFactory beanFactory; private ConfigurableListableBeanFactory beanFactory;
@BeforeEach @BeforeEach
public void setUp() throws Exception { public void setup() {
GenericApplicationContext ctx = new GenericApplicationContext(); GenericApplicationContext ctx = new GenericApplicationContext();
new XmlBeanDefinitionReader(ctx).loadBeanDefinitions( new XmlBeanDefinitionReader(ctx).loadBeanDefinitions(
new ClassPathResource("jeeNamespaceHandlerTests.xml", getClass())); new ClassPathResource("jeeNamespaceHandlerTests.xml", getClass()));
@ -52,8 +53,9 @@ public class JeeNamespaceHandlerTests {
this.beanFactory.getBeanNamesForType(ITestBean.class); this.beanFactory.getBeanNamesForType(ITestBean.class);
} }
@Test @Test
public void testSimpleDefinition() throws Exception { public void testSimpleDefinition() {
BeanDefinition beanDefinition = this.beanFactory.getMergedBeanDefinition("simple"); BeanDefinition beanDefinition = this.beanFactory.getMergedBeanDefinition("simple");
assertThat(beanDefinition.getBeanClassName()).isEqualTo(JndiObjectFactoryBean.class.getName()); assertThat(beanDefinition.getBeanClassName()).isEqualTo(JndiObjectFactoryBean.class.getName());
assertPropertyValue(beanDefinition, "jndiName", "jdbc/MyDataSource"); assertPropertyValue(beanDefinition, "jndiName", "jdbc/MyDataSource");
@ -61,7 +63,7 @@ public class JeeNamespaceHandlerTests {
} }
@Test @Test
public void testComplexDefinition() throws Exception { public void testComplexDefinition() {
BeanDefinition beanDefinition = this.beanFactory.getMergedBeanDefinition("complex"); BeanDefinition beanDefinition = this.beanFactory.getMergedBeanDefinition("complex");
assertThat(beanDefinition.getBeanClassName()).isEqualTo(JndiObjectFactoryBean.class.getName()); assertThat(beanDefinition.getBeanClassName()).isEqualTo(JndiObjectFactoryBean.class.getName());
assertPropertyValue(beanDefinition, "jndiName", "jdbc/MyDataSource"); assertPropertyValue(beanDefinition, "jndiName", "jdbc/MyDataSource");
@ -75,21 +77,21 @@ public class JeeNamespaceHandlerTests {
} }
@Test @Test
public void testWithEnvironment() throws Exception { public void testWithEnvironment() {
BeanDefinition beanDefinition = this.beanFactory.getMergedBeanDefinition("withEnvironment"); BeanDefinition beanDefinition = this.beanFactory.getMergedBeanDefinition("withEnvironment");
assertPropertyValue(beanDefinition, "jndiEnvironment", "foo=bar"); assertPropertyValue(beanDefinition, "jndiEnvironment", "foo=bar");
assertPropertyValue(beanDefinition, "defaultObject", new RuntimeBeanReference("myBean")); assertPropertyValue(beanDefinition, "defaultObject", new RuntimeBeanReference("myBean"));
} }
@Test @Test
public void testWithReferencedEnvironment() throws Exception { public void testWithReferencedEnvironment() {
BeanDefinition beanDefinition = this.beanFactory.getMergedBeanDefinition("withReferencedEnvironment"); BeanDefinition beanDefinition = this.beanFactory.getMergedBeanDefinition("withReferencedEnvironment");
assertPropertyValue(beanDefinition, "jndiEnvironment", new RuntimeBeanReference("myEnvironment")); assertPropertyValue(beanDefinition, "jndiEnvironment", new RuntimeBeanReference("myEnvironment"));
assertThat(beanDefinition.getPropertyValues().contains("environmentRef")).isFalse(); assertThat(beanDefinition.getPropertyValues().contains("environmentRef")).isFalse();
} }
@Test @Test
public void testSimpleLocalSlsb() throws Exception { public void testSimpleLocalSlsb() {
BeanDefinition beanDefinition = this.beanFactory.getMergedBeanDefinition("simpleLocalEjb"); BeanDefinition beanDefinition = this.beanFactory.getMergedBeanDefinition("simpleLocalEjb");
assertThat(beanDefinition.getBeanClassName()).isEqualTo(LocalStatelessSessionProxyFactoryBean.class.getName()); assertThat(beanDefinition.getBeanClassName()).isEqualTo(LocalStatelessSessionProxyFactoryBean.class.getName());
assertPropertyValue(beanDefinition, "businessInterface", ITestBean.class.getName()); assertPropertyValue(beanDefinition, "businessInterface", ITestBean.class.getName());
@ -97,7 +99,7 @@ public class JeeNamespaceHandlerTests {
} }
@Test @Test
public void testSimpleRemoteSlsb() throws Exception { public void testSimpleRemoteSlsb() {
BeanDefinition beanDefinition = this.beanFactory.getMergedBeanDefinition("simpleRemoteEjb"); BeanDefinition beanDefinition = this.beanFactory.getMergedBeanDefinition("simpleRemoteEjb");
assertThat(beanDefinition.getBeanClassName()).isEqualTo(SimpleRemoteStatelessSessionProxyFactoryBean.class.getName()); assertThat(beanDefinition.getBeanClassName()).isEqualTo(SimpleRemoteStatelessSessionProxyFactoryBean.class.getName());
assertPropertyValue(beanDefinition, "businessInterface", ITestBean.class.getName()); assertPropertyValue(beanDefinition, "businessInterface", ITestBean.class.getName());
@ -105,7 +107,7 @@ public class JeeNamespaceHandlerTests {
} }
@Test @Test
public void testComplexLocalSlsb() throws Exception { public void testComplexLocalSlsb() {
BeanDefinition beanDefinition = this.beanFactory.getMergedBeanDefinition("complexLocalEjb"); BeanDefinition beanDefinition = this.beanFactory.getMergedBeanDefinition("complexLocalEjb");
assertThat(beanDefinition.getBeanClassName()).isEqualTo(LocalStatelessSessionProxyFactoryBean.class.getName()); assertThat(beanDefinition.getBeanClassName()).isEqualTo(LocalStatelessSessionProxyFactoryBean.class.getName());
assertPropertyValue(beanDefinition, "businessInterface", ITestBean.class.getName()); assertPropertyValue(beanDefinition, "businessInterface", ITestBean.class.getName());
@ -117,7 +119,7 @@ public class JeeNamespaceHandlerTests {
} }
@Test @Test
public void testComplexRemoteSlsb() throws Exception { public void testComplexRemoteSlsb() {
BeanDefinition beanDefinition = this.beanFactory.getMergedBeanDefinition("complexRemoteEjb"); BeanDefinition beanDefinition = this.beanFactory.getMergedBeanDefinition("complexRemoteEjb");
assertThat(beanDefinition.getBeanClassName()).isEqualTo(SimpleRemoteStatelessSessionProxyFactoryBean.class.getName()); assertThat(beanDefinition.getBeanClassName()).isEqualTo(SimpleRemoteStatelessSessionProxyFactoryBean.class.getName());
assertPropertyValue(beanDefinition, "businessInterface", ITestBean.class.getName()); assertPropertyValue(beanDefinition, "businessInterface", ITestBean.class.getName());
@ -132,7 +134,7 @@ public class JeeNamespaceHandlerTests {
} }
@Test @Test
public void testLazyInitJndiLookup() throws Exception { public void testLazyInitJndiLookup() {
BeanDefinition definition = this.beanFactory.getMergedBeanDefinition("lazyDataSource"); BeanDefinition definition = this.beanFactory.getMergedBeanDefinition("lazyDataSource");
assertThat(definition.isLazyInit()).isTrue(); assertThat(definition.isLazyInit()).isTrue();
definition = this.beanFactory.getMergedBeanDefinition("lazyLocalBean"); definition = this.beanFactory.getMergedBeanDefinition("lazyLocalBean");

View File

@ -202,7 +202,7 @@ public @interface RequestMapping {
* produces = "text/plain;charset=UTF-8" * produces = "text/plain;charset=UTF-8"
* </pre> * </pre>
* <p>If a declared media type contains a parameter (e.g. "charset=UTF-8", * <p>If a declared media type contains a parameter (e.g. "charset=UTF-8",
* "type=feed", type="entry") and if a compatible media type from the request * "type=feed", "type=entry") and if a compatible media type from the request
* has that parameter too, then the parameter values must match. Otherwise * has that parameter too, then the parameter values must match. Otherwise
* if the media type from the request does not contain the parameter, it is * if the media type from the request does not contain the parameter, it is
* assumed the client accepts any value. * assumed the client accepts any value.
@ -212,7 +212,6 @@ public @interface RequestMapping {
* If specified at both levels, the method level produces condition overrides * If specified at both levels, the method level produces condition overrides
* the type level condition. * the type level condition.
* @see org.springframework.http.MediaType * @see org.springframework.http.MediaType
* @see org.springframework.http.MediaType
*/ */
String[] produces() default {}; String[] produces() default {};

View File

@ -16,7 +16,6 @@
package org.springframework.web.reactive.config; package org.springframework.web.reactive.config;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import org.springframework.web.cors.CorsConfiguration; import org.springframework.web.cors.CorsConfiguration;
@ -28,6 +27,7 @@ import org.springframework.web.cors.CorsConfiguration;
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
* @since 5.0 * @since 5.0
* @see CorsConfiguration
* @see CorsRegistry * @see CorsRegistry
*/ */
public class CorsRegistration { public class CorsRegistration {
@ -39,6 +39,7 @@ public class CorsRegistration {
public CorsRegistration(String pathPattern) { public CorsRegistration(String pathPattern) {
this.pathPattern = pathPattern; this.pathPattern = pathPattern;
// Same implicit default values as the @CrossOrigin annotation + allows simple methods
this.config = new CorsConfiguration().applyPermitDefaultValues(); this.config = new CorsConfiguration().applyPermitDefaultValues();
} }
@ -58,7 +59,7 @@ public class CorsRegistration {
* See the Spring Framework reference for more on this filter. * See the Spring Framework reference for more on this filter.
*/ */
public CorsRegistration allowedOrigins(String... origins) { public CorsRegistration allowedOrigins(String... origins) {
this.config.setAllowedOrigins(new ArrayList<>(Arrays.asList(origins))); this.config.setAllowedOrigins(Arrays.asList(origins));
return this; return this;
} }
@ -69,7 +70,7 @@ public class CorsRegistration {
* are allowed. * are allowed.
*/ */
public CorsRegistration allowedMethods(String... methods) { public CorsRegistration allowedMethods(String... methods) {
this.config.setAllowedMethods(new ArrayList<>(Arrays.asList(methods))); this.config.setAllowedMethods(Arrays.asList(methods));
return this; return this;
} }
@ -83,7 +84,7 @@ public class CorsRegistration {
* <p>By default all headers are allowed. * <p>By default all headers are allowed.
*/ */
public CorsRegistration allowedHeaders(String... headers) { public CorsRegistration allowedHeaders(String... headers) {
this.config.setAllowedHeaders(new ArrayList<>(Arrays.asList(headers))); this.config.setAllowedHeaders(Arrays.asList(headers));
return this; return this;
} }
@ -96,7 +97,7 @@ public class CorsRegistration {
* <p>By default this is not set. * <p>By default this is not set.
*/ */
public CorsRegistration exposedHeaders(String... headers) { public CorsRegistration exposedHeaders(String... headers) {
this.config.setExposedHeaders(new ArrayList<>(Arrays.asList(headers))); this.config.setExposedHeaders(Arrays.asList(headers));
return this; return this;
} }

View File

@ -37,11 +37,9 @@ 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 * <p>Exact path mapping URIs (such as {@code "/admin"}) are supported as
* well as Ant-style path patterns (such as {@code "/admin/**"}). * well as Ant-style path patterns (such as {@code "/admin/**"}).
*
* <p>By default, the {@code CorsConfiguration} for this mapping is * <p>By default, the {@code CorsConfiguration} for this mapping is
* initialized with default values as described in * initialized with default values as described in
* {@link CorsConfiguration#applyPermitDefaultValues()}. * {@link CorsConfiguration#applyPermitDefaultValues()}.
@ -52,6 +50,10 @@ public class CorsRegistry {
return registration; return registration;
} }
/**
* Return the registered {@link CorsConfiguration} objects,
* keyed by path pattern.
*/
protected Map<String, CorsConfiguration> getCorsConfigurations() { protected Map<String, CorsConfiguration> getCorsConfigurations() {
Map<String, CorsConfiguration> configs = new LinkedHashMap<>(this.registrations.size()); Map<String, CorsConfiguration> configs = new LinkedHashMap<>(this.registrations.size());
for (CorsRegistration registration : this.registrations) { for (CorsRegistration registration : this.registrations) {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -169,7 +169,7 @@ class ControllerMethodResolver {
boolean requestMappingMethod = !readers.isEmpty() && supportDataBinding; boolean requestMappingMethod = !readers.isEmpty() && supportDataBinding;
// Annotation-based... // Annotation-based...
List<HandlerMethodArgumentResolver> result = new ArrayList<>(); List<HandlerMethodArgumentResolver> result = new ArrayList<>(30);
result.add(new RequestParamMethodArgumentResolver(beanFactory, adapterRegistry, false)); result.add(new RequestParamMethodArgumentResolver(beanFactory, adapterRegistry, false));
result.add(new RequestParamMapMethodArgumentResolver(adapterRegistry)); result.add(new RequestParamMapMethodArgumentResolver(adapterRegistry));
result.add(new PathVariableMethodArgumentResolver(beanFactory, adapterRegistry)); result.add(new PathVariableMethodArgumentResolver(beanFactory, adapterRegistry));

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2018 the original author or authors. * Copyright 2002-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -38,7 +38,6 @@ import org.springframework.web.server.ServerWebInputException;
*/ */
public class RequestAttributeMethodArgumentResolver extends AbstractNamedValueSyncArgumentResolver { public class RequestAttributeMethodArgumentResolver extends AbstractNamedValueSyncArgumentResolver {
/** /**
* Create a new {@link RequestAttributeMethodArgumentResolver} instance. * Create a new {@link RequestAttributeMethodArgumentResolver} instance.
* @param factory a bean factory to use for resolving {@code ${...}} * @param factory a bean factory to use for resolving {@code ${...}}

View File

@ -67,9 +67,9 @@ public class CorsRegistration {
/** /**
* Set the HTTP methods to allow, e.g. {@code "GET"}, {@code "POST"}, etc. * Set the HTTP methods to allow, e.g. {@code "GET"}, {@code "POST"}, etc.
* The special value {@code "*"} allows all methods. * <p>The special value {@code "*"} allows all methods.
* <p>By default "simple" methods, i.e. {@code GET}, {@code HEAD}, and * <p>By default "simple" methods {@code GET}, {@code HEAD}, and {@code POST}
* {@code POST} are allowed. * are allowed.
*/ */
public CorsRegistration allowedMethods(String... methods) { public CorsRegistration allowedMethods(String... methods) {
this.config.setAllowedMethods(Arrays.asList(methods)); this.config.setAllowedMethods(Arrays.asList(methods));
@ -77,9 +77,9 @@ public class CorsRegistration {
} }
/** /**
* Set the list of headers that a preflight request can list as allowed * Set the list of headers that a pre-flight request can list as allowed
* for use during an actual request. The special value {@code "*"} may be * for use during an actual request.
* used to allow all headers. * <p>The special value {@code "*"} may be used to allow all headers.
* <p>A header name is not required to be listed if it is one of: * <p>A header name is not required to be listed if it is one of:
* {@code Cache-Control}, {@code Content-Language}, {@code Expires}, * {@code Cache-Control}, {@code Content-Language}, {@code Expires},
* {@code Last-Modified}, or {@code Pragma} as per the CORS spec. * {@code Last-Modified}, or {@code Pragma} as per the CORS spec.

View File

@ -39,10 +39,8 @@ 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 * <p>Exact path mapping URIs (such as {@code "/admin"}) are supported as
* well as Ant-style path patterns (such as {@code "/admin/**"}). * well as Ant-style path patterns (such as {@code "/admin/**"}).
*
* <p>By default, the {@code CorsConfiguration} for this mapping is * <p>By default, the {@code CorsConfiguration} for this mapping is
* initialized with default values as described in * initialized with default values as described in
* {@link CorsConfiguration#applyPermitDefaultValues()}. * {@link CorsConfiguration#applyPermitDefaultValues()}.

View File

@ -151,7 +151,7 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter
private List<HttpMessageConverter<?>> messageConverters; private List<HttpMessageConverter<?>> messageConverters;
private List<Object> requestResponseBodyAdvice = new ArrayList<>(); private final List<Object> requestResponseBodyAdvice = new ArrayList<>();
@Nullable @Nullable
private WebBindingInitializer webBindingInitializer; private WebBindingInitializer webBindingInitializer;
@ -632,7 +632,7 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter
* and custom resolvers provided via {@link #setCustomArgumentResolvers}. * and custom resolvers provided via {@link #setCustomArgumentResolvers}.
*/ */
private List<HandlerMethodArgumentResolver> getDefaultArgumentResolvers() { private List<HandlerMethodArgumentResolver> getDefaultArgumentResolvers() {
List<HandlerMethodArgumentResolver> resolvers = new ArrayList<>(); List<HandlerMethodArgumentResolver> resolvers = new ArrayList<>(30);
// Annotation-based argument resolution // Annotation-based argument resolution
resolvers.add(new RequestParamMethodArgumentResolver(getBeanFactory(), false)); resolvers.add(new RequestParamMethodArgumentResolver(getBeanFactory(), false));
@ -679,7 +679,7 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter
* methods including built-in and custom resolvers. * methods including built-in and custom resolvers.
*/ */
private List<HandlerMethodArgumentResolver> getDefaultInitBinderArgumentResolvers() { private List<HandlerMethodArgumentResolver> getDefaultInitBinderArgumentResolvers() {
List<HandlerMethodArgumentResolver> resolvers = new ArrayList<>(); List<HandlerMethodArgumentResolver> resolvers = new ArrayList<>(20);
// Annotation-based argument resolution // Annotation-based argument resolution
resolvers.add(new RequestParamMethodArgumentResolver(getBeanFactory(), false)); resolvers.add(new RequestParamMethodArgumentResolver(getBeanFactory(), false));
@ -712,7 +712,7 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter
* custom handlers provided via {@link #setReturnValueHandlers}. * custom handlers provided via {@link #setReturnValueHandlers}.
*/ */
private List<HandlerMethodReturnValueHandler> getDefaultReturnValueHandlers() { private List<HandlerMethodReturnValueHandler> getDefaultReturnValueHandlers() {
List<HandlerMethodReturnValueHandler> handlers = new ArrayList<>(); List<HandlerMethodReturnValueHandler> handlers = new ArrayList<>(20);
// Single-purpose return value types // Single-purpose return value types
handlers.add(new ModelAndViewMethodReturnValueHandler()); handlers.add(new ModelAndViewMethodReturnValueHandler());