Polishing
This commit is contained in:
@@ -90,8 +90,7 @@ import org.springframework.util.StringUtils;
|
||||
* operating on pre-resolved bean definition metadata objects.
|
||||
*
|
||||
* <p>Note that readers for specific bean definition formats are typically
|
||||
* implemented separately rather than as bean factory subclasses:
|
||||
* see for example {@link PropertiesBeanDefinitionReader} and
|
||||
* implemented separately rather than as bean factory subclasses: see for example
|
||||
* {@link org.springframework.beans.factory.xml.XmlBeanDefinitionReader}.
|
||||
*
|
||||
* <p>For an alternative implementation of the
|
||||
@@ -179,7 +178,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
|
||||
private volatile String[] frozenBeanDefinitionNames;
|
||||
|
||||
/** Whether bean definition metadata may be cached for all beans */
|
||||
private volatile boolean configurationFrozen = false;
|
||||
private volatile boolean configurationFrozen;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -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");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -53,8 +53,7 @@ public abstract class AbstractValueAdaptingCache implements Cache {
|
||||
|
||||
@Override
|
||||
public ValueWrapper get(Object key) {
|
||||
Object value = lookup(key);
|
||||
return toValueWrapper(value);
|
||||
return toValueWrapper(lookup(key));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -113,5 +112,4 @@ public abstract class AbstractValueAdaptingCache implements Cache {
|
||||
return (storeValue != null ? new SimpleValueWrapper(fromStoreValue(storeValue)) : null);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2020 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.
|
||||
@@ -151,16 +151,15 @@ public class PersistenceExceptionTranslationInterceptor
|
||||
|
||||
/**
|
||||
* Detect all PersistenceExceptionTranslators in the given BeanFactory.
|
||||
* @param beanFactory the ListableBeanFactory to obtaining all
|
||||
* PersistenceExceptionTranslators from
|
||||
* @param bf the ListableBeanFactory to obtain PersistenceExceptionTranslators from
|
||||
* @return a chained PersistenceExceptionTranslator, combining all
|
||||
* PersistenceExceptionTranslators found in the factory
|
||||
* PersistenceExceptionTranslators found in the given bean factory
|
||||
* @see ChainedPersistenceExceptionTranslator
|
||||
*/
|
||||
protected PersistenceExceptionTranslator detectPersistenceExceptionTranslators(ListableBeanFactory beanFactory) {
|
||||
protected PersistenceExceptionTranslator detectPersistenceExceptionTranslators(ListableBeanFactory bf) {
|
||||
// Find all translators, being careful not to activate FactoryBeans.
|
||||
Map<String, PersistenceExceptionTranslator> pets = BeanFactoryUtils.beansOfTypeIncludingAncestors(
|
||||
beanFactory, PersistenceExceptionTranslator.class, false, false);
|
||||
bf, PersistenceExceptionTranslator.class, false, false);
|
||||
ChainedPersistenceExceptionTranslator cpet = new ChainedPersistenceExceptionTranslator();
|
||||
for (PersistenceExceptionTranslator pet : pets.values()) {
|
||||
cpet.addDelegate(pet);
|
||||
|
||||
@@ -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");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -82,7 +82,6 @@ public class MediaType extends MimeType implements Serializable {
|
||||
|
||||
/**
|
||||
* Public constant media type for {@code application/json}.
|
||||
* @see #APPLICATION_JSON_UTF8
|
||||
*/
|
||||
public final static MediaType APPLICATION_JSON;
|
||||
|
||||
@@ -334,7 +333,7 @@ public class MediaType extends MimeType implements Serializable {
|
||||
|
||||
/**
|
||||
* Copy-constructor that copies the type and subtype of the given {@code MediaType},
|
||||
* and allows for different parameter.
|
||||
* and allows for different parameters.
|
||||
* @param other the other media type
|
||||
* @param parameters the parameters, may be {@code null}
|
||||
* @throws IllegalArgumentException if any of the parameters contain illegal characters
|
||||
@@ -381,7 +380,7 @@ public class MediaType extends MimeType implements Serializable {
|
||||
* <p>For instance, {@code text/*} includes {@code text/plain} and {@code text/html},
|
||||
* and {@code application/*+xml} includes {@code application/soap+xml}, etc.
|
||||
* This method is <b>not</b> symmetric.
|
||||
* <p>Simply calls {@link #includes(MimeType)} but declared with a
|
||||
* <p>Simply calls {@link MimeType#includes(MimeType)} but declared with a
|
||||
* {@code MediaType} parameter for binary backwards compatibility.
|
||||
* @param other the reference media type with which to compare
|
||||
* @return {@code true} if this media type includes the given media type;
|
||||
@@ -396,7 +395,7 @@ public class MediaType extends MimeType implements Serializable {
|
||||
* <p>For instance, {@code text/*} is compatible with {@code text/plain},
|
||||
* {@code text/html}, and vice versa. In effect, this method is similar to
|
||||
* {@link #includes}, except that it <b>is</b> symmetric.
|
||||
* <p>Simply calls {@link #isCompatibleWith(MimeType)} but declared with a
|
||||
* <p>Simply calls {@link MimeType#isCompatibleWith(MimeType)} but declared with a
|
||||
* {@code MediaType} parameter for binary backwards compatibility.
|
||||
* @param other the reference media type with which to compare
|
||||
* @return {@code true} if this media type is compatible with the given media type;
|
||||
@@ -470,7 +469,7 @@ public class MediaType extends MimeType implements Serializable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the given comma-separated string into a list of {@code MediaType} objects.
|
||||
* Parse the comma-separated string into a list of {@code MediaType} objects.
|
||||
* <p>This method can be used to parse an Accept or Content-Type header.
|
||||
* @param mediaTypes the string to parse
|
||||
* @return the list of media types
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2020 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.
|
||||
@@ -106,7 +106,7 @@ public class WebRequestDataBinder extends WebDataBinder {
|
||||
* <p>The type of the target property for a multipart file can be Part, MultipartFile,
|
||||
* byte[], or String. The latter two receive the contents of the uploaded file;
|
||||
* all metadata like original file name, content type, etc are lost in those cases.
|
||||
* @param request request with parameters to bind (can be multipart)
|
||||
* @param request the request with parameters to bind (can be multipart)
|
||||
* @see org.springframework.web.multipart.MultipartRequest
|
||||
* @see org.springframework.web.multipart.MultipartFile
|
||||
* @see javax.servlet.http.Part
|
||||
@@ -114,12 +114,12 @@ public class WebRequestDataBinder extends WebDataBinder {
|
||||
*/
|
||||
public void bind(WebRequest request) {
|
||||
MutablePropertyValues mpvs = new MutablePropertyValues(request.getParameterMap());
|
||||
if (isMultipartRequest(request) && request instanceof NativeWebRequest) {
|
||||
if (request instanceof NativeWebRequest) {
|
||||
MultipartRequest multipartRequest = ((NativeWebRequest) request).getNativeRequest(MultipartRequest.class);
|
||||
if (multipartRequest != null) {
|
||||
bindMultipart(multipartRequest.getMultiFileMap(), mpvs);
|
||||
}
|
||||
else if (servlet3Parts) {
|
||||
else if (servlet3Parts && isMultipartRequest(request)) {
|
||||
HttpServletRequest serlvetRequest = ((NativeWebRequest) request).getNativeRequest(HttpServletRequest.class);
|
||||
new Servlet3MultipartHelper(isBindEmptyMultipartFiles()).bindParts(serlvetRequest, mpvs);
|
||||
}
|
||||
@@ -129,11 +129,11 @@ public class WebRequestDataBinder extends WebDataBinder {
|
||||
|
||||
/**
|
||||
* Check if the request is a multipart request (by checking its Content-Type header).
|
||||
* @param request request with parameters to bind
|
||||
* @param request the request with parameters to bind
|
||||
*/
|
||||
private boolean isMultipartRequest(WebRequest request) {
|
||||
String contentType = request.getHeader("Content-Type");
|
||||
return (contentType != null && StringUtils.startsWithIgnoreCase(contentType, "multipart"));
|
||||
return StringUtils.startsWithIgnoreCase(contentType, "multipart/");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2020 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.
|
||||
@@ -85,10 +85,16 @@ public class HandlerExecutionChain {
|
||||
return this.handler;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the given interceptor to the end of this chain.
|
||||
*/
|
||||
public void addInterceptor(HandlerInterceptor interceptor) {
|
||||
initInterceptorList().add(interceptor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the given interceptors to the end of this chain.
|
||||
*/
|
||||
public void addInterceptors(HandlerInterceptor... interceptors) {
|
||||
if (!ObjectUtils.isEmpty(interceptors)) {
|
||||
CollectionUtils.mergeArrayIntoCollection(interceptors, initInterceptorList());
|
||||
@@ -182,13 +188,16 @@ public class HandlerExecutionChain {
|
||||
HandlerInterceptor[] interceptors = getInterceptors();
|
||||
if (!ObjectUtils.isEmpty(interceptors)) {
|
||||
for (int i = interceptors.length - 1; i >= 0; i--) {
|
||||
if (interceptors[i] instanceof AsyncHandlerInterceptor) {
|
||||
HandlerInterceptor interceptor = interceptors[i];
|
||||
if (interceptor instanceof AsyncHandlerInterceptor) {
|
||||
try {
|
||||
AsyncHandlerInterceptor asyncInterceptor = (AsyncHandlerInterceptor) interceptors[i];
|
||||
AsyncHandlerInterceptor asyncInterceptor = (AsyncHandlerInterceptor) interceptor;
|
||||
asyncInterceptor.afterConcurrentHandlingStarted(request, response, this.handler);
|
||||
}
|
||||
catch (Throwable ex) {
|
||||
logger.error("Interceptor [" + interceptors[i] + "] failed in afterConcurrentHandlingStarted", ex);
|
||||
if (logger.isErrorEnabled()) {
|
||||
logger.error("Interceptor [" + interceptor + "] failed in afterConcurrentHandlingStarted", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -197,7 +206,7 @@ public class HandlerExecutionChain {
|
||||
|
||||
|
||||
/**
|
||||
* Delegates to the handler's {@code toString()}.
|
||||
* Delegates to the handler's {@code toString()} implementation.
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
|
||||
@@ -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");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -187,9 +187,8 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport
|
||||
}
|
||||
|
||||
/**
|
||||
* Set "global" CORS configuration based on URL patterns. By default the first
|
||||
* matching URL pattern is combined with the CORS configuration for the
|
||||
* handler, if any.
|
||||
* Set the "global" CORS configurations based on URL patterns. By default the first
|
||||
* matching URL pattern is combined with the CORS configuration for the handler, if any.
|
||||
* @since 4.2
|
||||
*/
|
||||
public void setCorsConfigurations(Map<String, CorsConfiguration> corsConfigurations) {
|
||||
@@ -197,7 +196,7 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the "global" CORS configuration.
|
||||
* Get the "global" CORS configurations.
|
||||
*/
|
||||
public Map<String, CorsConfiguration> getCorsConfigurations() {
|
||||
return this.globalCorsConfigSource.getCorsConfigurations();
|
||||
@@ -261,21 +260,22 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect beans of type {@link MappedInterceptor} and add them to the list of mapped interceptors.
|
||||
* <p>This is called in addition to any {@link MappedInterceptor}s that may have been provided
|
||||
* via {@link #setInterceptors}, by default adding all beans of type {@link MappedInterceptor}
|
||||
* from the current context and its ancestors. Subclasses can override and refine this policy.
|
||||
* @param mappedInterceptors an empty list to add {@link MappedInterceptor} instances to
|
||||
* Detect beans of type {@link MappedInterceptor} and add them to the list
|
||||
* of mapped interceptors.
|
||||
* <p>This is called in addition to any {@link MappedInterceptor}s that may
|
||||
* have been provided via {@link #setInterceptors}, by default adding all
|
||||
* beans of type {@link MappedInterceptor} from the current context and its
|
||||
* ancestors. Subclasses can override and refine this policy.
|
||||
* @param mappedInterceptors an empty list to add to
|
||||
*/
|
||||
protected void detectMappedInterceptors(List<HandlerInterceptor> mappedInterceptors) {
|
||||
mappedInterceptors.addAll(
|
||||
BeanFactoryUtils.beansOfTypeIncludingAncestors(
|
||||
getApplicationContext(), MappedInterceptor.class, true, false).values());
|
||||
mappedInterceptors.addAll(BeanFactoryUtils.beansOfTypeIncludingAncestors(
|
||||
getApplicationContext(), MappedInterceptor.class, true, false).values());
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the specified interceptors, checking for {@link MappedInterceptor}s and
|
||||
* adapting {@link HandlerInterceptor}s and {@link WebRequestInterceptor}s if necessary.
|
||||
* Initialize the specified interceptors adapting
|
||||
* {@link WebRequestInterceptor}s to {@link HandlerInterceptor}.
|
||||
* @see #setInterceptors
|
||||
* @see #adaptInterceptor
|
||||
*/
|
||||
@@ -292,13 +292,13 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport
|
||||
}
|
||||
|
||||
/**
|
||||
* Adapt the given interceptor object to the {@link HandlerInterceptor} interface.
|
||||
* <p>By default, the supported interceptor types are {@link HandlerInterceptor}
|
||||
* and {@link WebRequestInterceptor}. Each given {@link WebRequestInterceptor}
|
||||
* will be wrapped in a {@link WebRequestHandlerInterceptorAdapter}.
|
||||
* Can be overridden in subclasses.
|
||||
* @param interceptor the specified interceptor object
|
||||
* @return the interceptor wrapped as HandlerInterceptor
|
||||
* Adapt the given interceptor object to {@link HandlerInterceptor}.
|
||||
* <p>By default, the supported interceptor types are
|
||||
* {@link HandlerInterceptor} and {@link WebRequestInterceptor}. Each given
|
||||
* {@link WebRequestInterceptor} is wrapped with
|
||||
* {@link WebRequestHandlerInterceptorAdapter}.
|
||||
* @param interceptor the interceptor
|
||||
* @return the interceptor downcast or adapted to HandlerInterceptor
|
||||
* @see org.springframework.web.servlet.HandlerInterceptor
|
||||
* @see org.springframework.web.context.request.WebRequestInterceptor
|
||||
* @see WebRequestHandlerInterceptorAdapter
|
||||
@@ -317,7 +317,8 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport
|
||||
|
||||
/**
|
||||
* Return the adapted interceptors as {@link HandlerInterceptor} array.
|
||||
* @return the array of {@link HandlerInterceptor}s, or {@code null} if none
|
||||
* @return the array of {@link HandlerInterceptor HandlerInterceptor}s,
|
||||
* or {@code null} if none
|
||||
*/
|
||||
protected final HandlerInterceptor[] getAdaptedInterceptors() {
|
||||
int count = this.adaptedInterceptors.size();
|
||||
@@ -394,8 +395,8 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport
|
||||
* Build a {@link HandlerExecutionChain} for the given handler, including
|
||||
* applicable interceptors.
|
||||
* <p>The default implementation builds a standard {@link HandlerExecutionChain}
|
||||
* with the given handler, the handler mapping's common interceptors, and any
|
||||
* {@link MappedInterceptor}s matching to the current request URL. Interceptors
|
||||
* with the given handler, the common interceptors of the handler mapping, and any
|
||||
* {@link MappedInterceptor MappedInterceptors} matching to the current request URL. Interceptors
|
||||
* are added in the order they were registered. Subclasses may override this
|
||||
* in order to extend/rearrange the list of interceptors.
|
||||
* <p><b>NOTE:</b> The passed-in handler object may be a raw handler or a
|
||||
@@ -464,12 +465,12 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport
|
||||
|
||||
if (CorsUtils.isPreFlightRequest(request)) {
|
||||
HandlerInterceptor[] interceptors = chain.getInterceptors();
|
||||
chain = new HandlerExecutionChain(new PreFlightHandler(config), interceptors);
|
||||
return new HandlerExecutionChain(new PreFlightHandler(config), interceptors);
|
||||
}
|
||||
else {
|
||||
chain.addInterceptor(new CorsInterceptor(config));
|
||||
return chain;
|
||||
}
|
||||
return chain;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user