Polishing
This commit is contained in:
@@ -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.
|
||||
@@ -27,6 +27,10 @@ import org.springframework.util.ObjectUtils;
|
||||
* {@link Comparator} implementation for {@link Ordered} objects, sorting
|
||||
* by order value ascending, respectively by priority descending.
|
||||
*
|
||||
* <h3>{@code PriorityOrdered} Objects</h3>
|
||||
* <p>{@link PriorityOrdered} objects will be sorted with higher priority than
|
||||
* <em>plain</em> {@code Ordered} objects.
|
||||
*
|
||||
* <h3>Same Order Objects</h3>
|
||||
* <p>Objects that have the same order value will be sorted with arbitrary
|
||||
* ordering with respect to other objects with the same order value.
|
||||
@@ -41,6 +45,7 @@ import org.springframework.util.ObjectUtils;
|
||||
* @author Sam Brannen
|
||||
* @since 07.04.2003
|
||||
* @see Ordered
|
||||
* @see PriorityOrdered
|
||||
* @see org.springframework.core.annotation.AnnotationAwareOrderComparator
|
||||
* @see java.util.List#sort(java.util.Comparator)
|
||||
* @see java.util.Arrays#sort(Object[], java.util.Comparator)
|
||||
@@ -96,8 +101,7 @@ public class OrderComparator implements Comparator<Object> {
|
||||
Object orderSource = sourceProvider.getOrderSource(obj);
|
||||
if (orderSource != null) {
|
||||
if (orderSource.getClass().isArray()) {
|
||||
Object[] sources = ObjectUtils.toObjectArray(orderSource);
|
||||
for (Object source : sources) {
|
||||
for (Object source : ObjectUtils.toObjectArray(orderSource)) {
|
||||
order = findOrder(source);
|
||||
if (order != null) {
|
||||
break;
|
||||
|
||||
@@ -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.
|
||||
@@ -149,8 +149,9 @@ public abstract class AbstractNamedValueMethodArgumentResolver implements Handle
|
||||
if (info.name.isEmpty()) {
|
||||
name = parameter.getParameterName();
|
||||
if (name == null) {
|
||||
throw new IllegalArgumentException("Name for argument type [" + parameter.getParameterType().getName() +
|
||||
"] not available, and parameter name information not found in class file either.");
|
||||
throw new IllegalArgumentException(
|
||||
"Name for argument of type [" + parameter.getNestedParameterType().getName() +
|
||||
"] not specified, and parameter name information not found in class file either.");
|
||||
}
|
||||
}
|
||||
String defaultValue = (ValueConstants.DEFAULT_NONE.equals(info.defaultValue) ? null : info.defaultValue);
|
||||
|
||||
@@ -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.
|
||||
@@ -78,6 +78,7 @@ public abstract class AbstractNamedValueMethodArgumentResolver implements Handle
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new {@link AbstractNamedValueMethodArgumentResolver} instance.
|
||||
* @param beanFactory a bean factory to use for resolving ${...} placeholder
|
||||
* and #{...} SpEL expressions in default values, or {@code null} if default
|
||||
* values are not expected to contain expressions
|
||||
@@ -129,7 +130,6 @@ public abstract class AbstractNamedValueMethodArgumentResolver implements Handle
|
||||
catch (TypeMismatchException ex) {
|
||||
throw new MethodArgumentTypeMismatchException(arg, ex.getRequiredType(),
|
||||
namedValueInfo.name, parameter, ex.getCause());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -168,8 +168,8 @@ public abstract class AbstractNamedValueMethodArgumentResolver implements Handle
|
||||
name = parameter.getParameterName();
|
||||
if (name == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Name for argument type [" + parameter.getNestedParameterType().getName() +
|
||||
"] not available, and parameter name information not found in class file either.");
|
||||
"Name for argument of type [" + parameter.getNestedParameterType().getName() +
|
||||
"] not specified, and parameter name information not found in class file either.");
|
||||
}
|
||||
}
|
||||
String defaultValue = (ValueConstants.DEFAULT_NONE.equals(info.defaultValue) ? null : info.defaultValue);
|
||||
@@ -182,12 +182,12 @@ public abstract class AbstractNamedValueMethodArgumentResolver implements Handle
|
||||
*/
|
||||
@Nullable
|
||||
private Object resolveStringValue(String value) {
|
||||
if (this.configurableBeanFactory == null) {
|
||||
if (this.configurableBeanFactory == null || this.expressionContext == null) {
|
||||
return value;
|
||||
}
|
||||
String placeholdersResolved = this.configurableBeanFactory.resolveEmbeddedValue(value);
|
||||
BeanExpressionResolver exprResolver = this.configurableBeanFactory.getBeanExpressionResolver();
|
||||
if (exprResolver == null || this.expressionContext == null) {
|
||||
if (exprResolver == null) {
|
||||
return value;
|
||||
}
|
||||
return exprResolver.evaluate(placeholdersResolved, this.expressionContext);
|
||||
|
||||
@@ -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.
|
||||
@@ -48,13 +48,13 @@ import org.springframework.web.method.HandlerMethod;
|
||||
*/
|
||||
public class InvocableHandlerMethod extends HandlerMethod {
|
||||
|
||||
@Nullable
|
||||
private WebDataBinderFactory dataBinderFactory;
|
||||
|
||||
private HandlerMethodArgumentResolverComposite argumentResolvers = new HandlerMethodArgumentResolverComposite();
|
||||
private HandlerMethodArgumentResolverComposite resolvers = new HandlerMethodArgumentResolverComposite();
|
||||
|
||||
private ParameterNameDiscoverer parameterNameDiscoverer = new DefaultParameterNameDiscoverer();
|
||||
|
||||
@Nullable
|
||||
private WebDataBinderFactory dataBinderFactory;
|
||||
|
||||
|
||||
/**
|
||||
* Create an instance from a {@code HandlerMethod}.
|
||||
@@ -84,20 +84,11 @@ public class InvocableHandlerMethod extends HandlerMethod {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the {@link WebDataBinderFactory} to be passed to argument resolvers allowing them to create
|
||||
* a {@link WebDataBinder} for data binding and type conversion purposes.
|
||||
* @param dataBinderFactory the data binder factory.
|
||||
*/
|
||||
public void setDataBinderFactory(WebDataBinderFactory dataBinderFactory) {
|
||||
this.dataBinderFactory = dataBinderFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set {@link HandlerMethodArgumentResolver}s to use to use for resolving method argument values.
|
||||
*/
|
||||
public void setHandlerMethodArgumentResolvers(HandlerMethodArgumentResolverComposite argumentResolvers) {
|
||||
this.argumentResolvers = argumentResolvers;
|
||||
this.resolvers = argumentResolvers;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -109,6 +100,14 @@ public class InvocableHandlerMethod extends HandlerMethod {
|
||||
this.parameterNameDiscoverer = parameterNameDiscoverer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the {@link WebDataBinderFactory} to be passed to argument resolvers allowing them
|
||||
* to create a {@link WebDataBinder} for data binding and type conversion purposes.
|
||||
*/
|
||||
public void setDataBinderFactory(WebDataBinderFactory dataBinderFactory) {
|
||||
this.dataBinderFactory = dataBinderFactory;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Invoke the method after resolving its argument values in the context of the given request.
|
||||
@@ -156,9 +155,9 @@ public class InvocableHandlerMethod extends HandlerMethod {
|
||||
if (args[i] != null) {
|
||||
continue;
|
||||
}
|
||||
if (this.argumentResolvers.supportsParameter(parameter)) {
|
||||
if (this.resolvers.supportsParameter(parameter)) {
|
||||
try {
|
||||
args[i] = this.argumentResolvers.resolveArgument(
|
||||
args[i] = this.resolvers.resolveArgument(
|
||||
parameter, mavContainer, request, this.dataBinderFactory);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
@@ -26,7 +26,7 @@ import org.springframework.web.multipart.MultipartResolver;
|
||||
*
|
||||
* <p>This may be because the request is not a multipart/form-data request,
|
||||
* because the part is not present in the request, or because the web
|
||||
* application is not configured correctly for processing multipart requests,
|
||||
* application is not configured correctly for processing multipart requests,
|
||||
* e.g. no {@link MultipartResolver}.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
@@ -35,17 +35,24 @@ import org.springframework.web.multipart.MultipartResolver;
|
||||
@SuppressWarnings("serial")
|
||||
public class MissingServletRequestPartException extends ServletException {
|
||||
|
||||
private final String partName;
|
||||
private final String requestPartName;
|
||||
|
||||
|
||||
public MissingServletRequestPartException(String partName) {
|
||||
super("Required request part '" + partName + "' is not present");
|
||||
this.partName = partName;
|
||||
/**
|
||||
* Constructor for MissingServletRequestPartException.
|
||||
* @param requestPartName the name of the missing part of the multipart request
|
||||
*/
|
||||
public MissingServletRequestPartException(String requestPartName) {
|
||||
super("Required request part '" + requestPartName + "' is not present");
|
||||
this.requestPartName = requestPartName;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the name of the offending part of the multipart request.
|
||||
*/
|
||||
public String getRequestPartName() {
|
||||
return this.partName;
|
||||
return this.requestPartName;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
@@ -21,6 +21,7 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.Charset;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.Part;
|
||||
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
@@ -45,59 +46,65 @@ public class RequestPartServletServerHttpRequest extends ServletServerHttpReques
|
||||
|
||||
private final MultipartHttpServletRequest multipartRequest;
|
||||
|
||||
private final String partName;
|
||||
private final String requestPartName;
|
||||
|
||||
private final HttpHeaders headers;
|
||||
private final HttpHeaders multipartHeaders;
|
||||
|
||||
|
||||
/**
|
||||
* Create a new {@code RequestPartServletServerHttpRequest} instance.
|
||||
* @param request the current servlet request
|
||||
* @param partName the name of the part to adapt to the {@link ServerHttpRequest} contract
|
||||
* @param requestPartName the name of the part to adapt to the {@link ServerHttpRequest} contract
|
||||
* @throws MissingServletRequestPartException if the request part cannot be found
|
||||
* @throws MultipartException if MultipartHttpServletRequest cannot be initialized
|
||||
*/
|
||||
public RequestPartServletServerHttpRequest(HttpServletRequest request, String partName)
|
||||
public RequestPartServletServerHttpRequest(HttpServletRequest request, String requestPartName)
|
||||
throws MissingServletRequestPartException {
|
||||
|
||||
super(request);
|
||||
|
||||
this.multipartRequest = MultipartResolutionDelegate.asMultipartHttpServletRequest(request);
|
||||
this.partName = partName;
|
||||
this.requestPartName = requestPartName;
|
||||
|
||||
HttpHeaders headers = this.multipartRequest.getMultipartHeaders(this.partName);
|
||||
if (headers == null) {
|
||||
throw new MissingServletRequestPartException(partName);
|
||||
HttpHeaders multipartHeaders = this.multipartRequest.getMultipartHeaders(requestPartName);
|
||||
if (multipartHeaders == null) {
|
||||
throw new MissingServletRequestPartException(requestPartName);
|
||||
}
|
||||
this.headers = headers;
|
||||
this.multipartHeaders = multipartHeaders;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public HttpHeaders getHeaders() {
|
||||
return this.headers;
|
||||
return this.multipartHeaders;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getBody() throws IOException {
|
||||
// Prefer Servlet Part resolution to cover file as well as parameter streams
|
||||
if (this.multipartRequest instanceof StandardMultipartHttpServletRequest) {
|
||||
try {
|
||||
return this.multipartRequest.getPart(this.partName).getInputStream();
|
||||
Part part = this.multipartRequest.getPart(this.requestPartName);
|
||||
if (part != null) {
|
||||
return part.getInputStream();
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw new MultipartException("Could not parse multipart servlet request", ex);
|
||||
throw new MultipartException("Failed to retrieve request part '" + this.requestPartName + "'", ex);
|
||||
}
|
||||
}
|
||||
else {
|
||||
MultipartFile file = this.multipartRequest.getFile(this.partName);
|
||||
if (file != null) {
|
||||
return file.getInputStream();
|
||||
}
|
||||
else {
|
||||
String paramValue = this.multipartRequest.getParameter(this.partName);
|
||||
return new ByteArrayInputStream(paramValue.getBytes(determineCharset()));
|
||||
}
|
||||
|
||||
// Spring-style distinction between MultipartFile and String parameters
|
||||
MultipartFile file = this.multipartRequest.getFile(this.requestPartName);
|
||||
if (file != null) {
|
||||
return file.getInputStream();
|
||||
}
|
||||
String paramValue = this.multipartRequest.getParameter(this.requestPartName);
|
||||
if (paramValue != null) {
|
||||
return new ByteArrayInputStream(paramValue.getBytes(determineCharset()));
|
||||
}
|
||||
|
||||
throw new IllegalStateException("No body available for request part '" + this.requestPartName + "'");
|
||||
}
|
||||
|
||||
private Charset determineCharset() {
|
||||
|
||||
@@ -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");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -62,17 +62,23 @@ public class InvocableHandlerMethod extends HandlerMethod {
|
||||
private static final Object NO_ARG_VALUE = new Object();
|
||||
|
||||
|
||||
private List<HandlerMethodArgumentResolver> resolvers = new ArrayList<>();
|
||||
private final List<HandlerMethodArgumentResolver> resolvers = new ArrayList<>();
|
||||
|
||||
private ParameterNameDiscoverer parameterNameDiscoverer = new DefaultParameterNameDiscoverer();
|
||||
|
||||
private ReactiveAdapterRegistry reactiveAdapterRegistry = ReactiveAdapterRegistry.getSharedInstance();
|
||||
|
||||
|
||||
/**
|
||||
* Create an instance from a {@code HandlerMethod}.
|
||||
*/
|
||||
public InvocableHandlerMethod(HandlerMethod handlerMethod) {
|
||||
super(handlerMethod);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance from a bean instance and a method.
|
||||
*/
|
||||
public InvocableHandlerMethod(Object bean, Method method) {
|
||||
super(bean, method);
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
@@ -70,14 +70,15 @@ public abstract class AbstractNamedValueArgumentResolver extends HandlerMethodAr
|
||||
|
||||
|
||||
/**
|
||||
* @param factory a bean factory to use for resolving ${...} placeholder
|
||||
* and #{...} SpEL expressions in default values, or {@code null} if default
|
||||
* Create a new {@link AbstractNamedValueArgumentResolver} instance.
|
||||
* @param factory a bean factory to use for resolving {@code ${...}} placeholder
|
||||
* and {@code #{...}} SpEL expressions in default values, or {@code null} if default
|
||||
* values are not expected to contain expressions
|
||||
* @param registry for checking reactive type wrappers
|
||||
*/
|
||||
public AbstractNamedValueArgumentResolver(@Nullable ConfigurableBeanFactory factory,
|
||||
ReactiveAdapterRegistry registry) {
|
||||
|
||||
|
||||
super(registry);
|
||||
this.configurableBeanFactory = factory;
|
||||
this.expressionContext = (factory != null ? new BeanExpressionContext(factory, null) : null);
|
||||
@@ -143,9 +144,9 @@ public abstract class AbstractNamedValueArgumentResolver extends HandlerMethodAr
|
||||
if (info.name.isEmpty()) {
|
||||
name = parameter.getParameterName();
|
||||
if (name == null) {
|
||||
String type = parameter.getNestedParameterType().getName();
|
||||
throw new IllegalArgumentException("Name for argument type [" + type + "] not " +
|
||||
"available, and parameter name information not found in class file either.");
|
||||
throw new IllegalArgumentException(
|
||||
"Name for argument of type [" + parameter.getNestedParameterType().getName() +
|
||||
"] not specified, and parameter name information not found in class file either.");
|
||||
}
|
||||
}
|
||||
String defaultValue = (ValueConstants.DEFAULT_NONE.equals(info.defaultValue) ? null : info.defaultValue);
|
||||
|
||||
Reference in New Issue
Block a user