Polishing
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2014 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.
|
||||
@@ -47,13 +47,13 @@ final class SimpleStreamingClientHttpRequest extends AbstractClientHttpRequest {
|
||||
private final boolean outputStreaming;
|
||||
|
||||
|
||||
SimpleStreamingClientHttpRequest(HttpURLConnection connection, int chunkSize,
|
||||
boolean outputStreaming) {
|
||||
SimpleStreamingClientHttpRequest(HttpURLConnection connection, int chunkSize, boolean outputStreaming) {
|
||||
this.connection = connection;
|
||||
this.chunkSize = chunkSize;
|
||||
this.outputStreaming = outputStreaming;
|
||||
}
|
||||
|
||||
|
||||
public HttpMethod getMethod() {
|
||||
return HttpMethod.valueOf(this.connection.getRequestMethod());
|
||||
}
|
||||
@@ -70,7 +70,7 @@ final class SimpleStreamingClientHttpRequest extends AbstractClientHttpRequest {
|
||||
@Override
|
||||
protected OutputStream getBodyInternal(HttpHeaders headers) throws IOException {
|
||||
if (this.body == null) {
|
||||
if(this.outputStreaming) {
|
||||
if (this.outputStreaming) {
|
||||
int contentLength = (int) headers.getContentLength();
|
||||
if (contentLength >= 0) {
|
||||
this.connection.setFixedLengthStreamingMode(contentLength);
|
||||
|
||||
@@ -62,12 +62,8 @@ public abstract class AbstractWireFeedHttpMessageConverter<T extends WireFeed> e
|
||||
|
||||
WireFeedInput feedInput = new WireFeedInput();
|
||||
MediaType contentType = inputMessage.getHeaders().getContentType();
|
||||
Charset charset;
|
||||
if (contentType != null && contentType.getCharSet() != null) {
|
||||
charset = contentType.getCharSet();
|
||||
} else {
|
||||
charset = DEFAULT_CHARSET;
|
||||
}
|
||||
Charset charset =
|
||||
(contentType != null && contentType.getCharSet() != null? contentType.getCharSet() : DEFAULT_CHARSET);
|
||||
try {
|
||||
Reader reader = new InputStreamReader(inputMessage.getBody(), charset);
|
||||
return (T) feedInput.build(reader);
|
||||
|
||||
@@ -186,7 +186,8 @@ public class ContentNegotiationManagerFactoryBean
|
||||
PathExtensionContentNegotiationStrategy strategy;
|
||||
if (this.servletContext != null) {
|
||||
strategy = new ServletPathExtensionContentNegotiationStrategy(this.servletContext, this.mediaTypes);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
strategy = new PathExtensionContentNegotiationStrategy(this.mediaTypes);
|
||||
}
|
||||
if (this.useJaf != null) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2014 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.
|
||||
@@ -19,7 +19,6 @@ package org.springframework.web.filter;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.servlet.Filter;
|
||||
import javax.servlet.FilterChain;
|
||||
import javax.servlet.FilterConfig;
|
||||
@@ -28,81 +27,87 @@ import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
|
||||
/**
|
||||
* A generic composite servlet {@link Filter} that just delegates its behaviour to a chain (list) of user supplied
|
||||
* filters, achieving the functionality of a {@link FilterChain}, but conveniently using only {@link Filter} instances.
|
||||
* This is useful for filters that require dependency injection, and can therefore be set up in a Spring application
|
||||
* context. Typically this composite would be used in conjunction with {@link DelegatingFilterProxy}, so that it can be
|
||||
* declared in Spring but applied to a servlet context.
|
||||
* A generic composite servlet {@link Filter} that just delegates its behavior
|
||||
* to a chain (list) of user-supplied filters, achieving the functionality of a
|
||||
* {@link FilterChain}, but conveniently using only {@link Filter} instances.
|
||||
*
|
||||
* @since 3.1
|
||||
* <p>This is useful for filters that require dependency injection, and can
|
||||
* therefore be set up in a Spring application context. Typically, this
|
||||
* composite would be used in conjunction with {@link DelegatingFilterProxy},
|
||||
* so that it can be declared in Spring but applied to a servlet context.
|
||||
*
|
||||
* @author Dave Syer
|
||||
*
|
||||
* @since 3.1
|
||||
*/
|
||||
public class CompositeFilter implements Filter {
|
||||
|
||||
private List<? extends Filter> filters = new ArrayList<Filter>();
|
||||
|
||||
|
||||
public void setFilters(List<? extends Filter> filters) {
|
||||
this.filters = new ArrayList<Filter>(filters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean up all the filters supplied, calling each one's destroy method in turn, but in reverse order.
|
||||
*
|
||||
* @see Filter#init(FilterConfig)
|
||||
*/
|
||||
public void destroy() {
|
||||
for (int i = filters.size(); i-- > 0;) {
|
||||
Filter filter = filters.get(i);
|
||||
filter.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize all the filters, calling each one's init method in turn in the order supplied.
|
||||
*
|
||||
* @see Filter#init(FilterConfig)
|
||||
*/
|
||||
public void init(FilterConfig config) throws ServletException {
|
||||
for (Filter filter : filters) {
|
||||
for (Filter filter : this.filters) {
|
||||
filter.init(config);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Forms a temporary chain from the list of delegate filters supplied ({@link #setFilters(List)}) and executes them
|
||||
* in order. Each filter delegates to the next one in the list, achieving the normal behaviour of a
|
||||
* {@link FilterChain}, despite the fact that this is a {@link Filter}.
|
||||
*
|
||||
* Forms a temporary chain from the list of delegate filters supplied ({@link #setFilters})
|
||||
* and executes them in order. Each filter delegates to the next one in the list, achieving
|
||||
* the normal behavior of a {@link FilterChain}, despite the fact that this is a {@link Filter}.
|
||||
* @see Filter#doFilter(ServletRequest, ServletResponse, FilterChain)
|
||||
*/
|
||||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException,
|
||||
ServletException {
|
||||
new VirtualFilterChain(chain, filters).doFilter(request, response);
|
||||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
|
||||
throws IOException, ServletException {
|
||||
|
||||
new VirtualFilterChain(chain, this.filters).doFilter(request, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean up all the filters supplied, calling each one's destroy method in turn, but in reverse order.
|
||||
* @see Filter#init(FilterConfig)
|
||||
*/
|
||||
public void destroy() {
|
||||
for (int i = this.filters.size(); i-- > 0;) {
|
||||
Filter filter = this.filters.get(i);
|
||||
filter.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static class VirtualFilterChain implements FilterChain {
|
||||
|
||||
private final FilterChain originalChain;
|
||||
|
||||
private final List<? extends Filter> additionalFilters;
|
||||
|
||||
private int currentPosition = 0;
|
||||
|
||||
private VirtualFilterChain(FilterChain chain, List<? extends Filter> additionalFilters) {
|
||||
public VirtualFilterChain(FilterChain chain, List<? extends Filter> additionalFilters) {
|
||||
this.originalChain = chain;
|
||||
this.additionalFilters = additionalFilters;
|
||||
}
|
||||
|
||||
public void doFilter(final ServletRequest request, final ServletResponse response) throws IOException,
|
||||
ServletException {
|
||||
if (currentPosition == additionalFilters.size()) {
|
||||
originalChain.doFilter(request, response);
|
||||
} else {
|
||||
currentPosition++;
|
||||
Filter nextFilter = additionalFilters.get(currentPosition - 1);
|
||||
public void doFilter(final ServletRequest request, final ServletResponse response)
|
||||
throws IOException, ServletException {
|
||||
|
||||
if (this.currentPosition == this.additionalFilters.size()) {
|
||||
this.originalChain.doFilter(request, response);
|
||||
}
|
||||
else {
|
||||
this.currentPosition++;
|
||||
Filter nextFilter = this.additionalFilters.get(this.currentPosition - 1);
|
||||
nextFilter.doFilter(request, response, this);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2014 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,35 +53,74 @@ public class ControllerAdviceBean implements Ordered {
|
||||
* @param beanFactory a BeanFactory that can be used later to resolve the bean
|
||||
*/
|
||||
public ControllerAdviceBean(String beanName, BeanFactory beanFactory) {
|
||||
Assert.hasText(beanName, "'beanName' must not be null");
|
||||
Assert.notNull(beanFactory, "'beanFactory' must not be null");
|
||||
Assert.isTrue(beanFactory.containsBean(beanName),
|
||||
"Bean factory [" + beanFactory + "] does not contain bean " + "with name [" + beanName + "]");
|
||||
Assert.hasText(beanName, "Bean name must not be null");
|
||||
Assert.notNull(beanFactory, "BeanFactory must not be null");
|
||||
|
||||
if (!beanFactory.containsBean(beanName)) {
|
||||
throw new IllegalArgumentException(
|
||||
"BeanFactory [" + beanFactory + "] does not contain bean with name '" + beanName + "'");
|
||||
}
|
||||
|
||||
this.bean = beanName;
|
||||
this.beanFactory = beanFactory;
|
||||
this.order = initOrderFromBeanType(this.beanFactory.getType(beanName));
|
||||
}
|
||||
|
||||
private static int initOrderFromBeanType(Class<?> beanType) {
|
||||
Order annot = AnnotationUtils.findAnnotation(beanType, Order.class);
|
||||
return (annot != null) ? annot.value() : Ordered.LOWEST_PRECEDENCE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance using the given bean instance.
|
||||
* @param bean the bean
|
||||
*/
|
||||
public ControllerAdviceBean(Object bean) {
|
||||
Assert.notNull(bean, "'bean' must not be null");
|
||||
Assert.notNull(bean, "Bean must not be null");
|
||||
this.bean = bean;
|
||||
this.order = initOrderFromBean(bean);
|
||||
this.beanFactory = null;
|
||||
}
|
||||
|
||||
private static int initOrderFromBean(Object bean) {
|
||||
return (bean instanceof Ordered) ? ((Ordered) bean).getOrder() : initOrderFromBeanType(bean.getClass());
|
||||
|
||||
/**
|
||||
* Returns the order value extracted from the {@link ControllerAdvice}
|
||||
* annotation or {@link Ordered#LOWEST_PRECEDENCE} otherwise.
|
||||
*/
|
||||
public int getOrder() {
|
||||
return this.order;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the type of the contained bean.
|
||||
* If the bean type is a CGLIB-generated class, the original, user-defined class is returned.
|
||||
*/
|
||||
public Class<?> getBeanType() {
|
||||
Class<?> clazz = (this.bean instanceof String ?
|
||||
this.beanFactory.getType((String) this.bean) : this.bean.getClass());
|
||||
return ClassUtils.getUserClass(clazz);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a bean instance if necessary resolving the bean name through the BeanFactory.
|
||||
*/
|
||||
public Object resolveBean() {
|
||||
return (this.bean instanceof String ? this.beanFactory.getBean((String) this.bean) : this.bean);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
return (this == other ||
|
||||
(other instanceof ControllerAdviceBean && this.bean.equals(((ControllerAdviceBean) other).bean)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return this.bean.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.bean.toString();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Find the names of beans annotated with
|
||||
* {@linkplain ControllerAdvice @ControllerAdvice} in the given
|
||||
@@ -97,52 +136,13 @@ public class ControllerAdviceBean implements Ordered {
|
||||
return beans;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the order value extracted from the {@link ControllerAdvice}
|
||||
* annotation or {@link Ordered#LOWEST_PRECEDENCE} otherwise.
|
||||
*/
|
||||
public int getOrder() {
|
||||
return this.order;
|
||||
private static int initOrderFromBean(Object bean) {
|
||||
return (bean instanceof Ordered ? ((Ordered) bean).getOrder() : initOrderFromBeanType(bean.getClass()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the type of the contained bean.
|
||||
* If the bean type is a CGLIB-generated class, the original, user-defined class is returned.
|
||||
*/
|
||||
public Class<?> getBeanType() {
|
||||
Class<?> clazz = (this.bean instanceof String)
|
||||
? this.beanFactory.getType((String) this.bean) : this.bean.getClass();
|
||||
|
||||
return ClassUtils.getUserClass(clazz);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a bean instance if necessary resolving the bean name through the BeanFactory.
|
||||
*/
|
||||
public Object resolveBean() {
|
||||
return (this.bean instanceof String) ? this.beanFactory.getBean((String) this.bean) : this.bean;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o != null && o instanceof ControllerAdviceBean) {
|
||||
ControllerAdviceBean other = (ControllerAdviceBean) o;
|
||||
return this.bean.equals(other.bean);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return 31 * this.bean.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return bean.toString();
|
||||
private static int initOrderFromBeanType(Class<?> beanType) {
|
||||
Order ann = AnnotationUtils.findAnnotation(beanType, Order.class);
|
||||
return (ann != null ? ann.value() : Ordered.LOWEST_PRECEDENCE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -147,7 +147,7 @@ public class ExceptionHandlerMethodResolver {
|
||||
*/
|
||||
private Method getMappedMethod(Class<? extends Exception> exceptionType) {
|
||||
List<Class<? extends Throwable>> matches = new ArrayList<Class<? extends Throwable>>();
|
||||
for(Class<? extends Throwable> mappedException : this.mappedMethods.keySet()) {
|
||||
for (Class<? extends Throwable> mappedException : this.mappedMethods.keySet()) {
|
||||
if (mappedException.isAssignableFrom(exceptionType)) {
|
||||
matches.add(mappedException);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2014 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.
|
||||
@@ -20,7 +20,6 @@ import java.beans.PropertyEditor;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
@@ -72,34 +71,35 @@ public class RequestParamMethodArgumentResolver extends AbstractNamedValueMethod
|
||||
|
||||
private final boolean useDefaultResolution;
|
||||
|
||||
|
||||
/**
|
||||
* @param beanFactory a bean factory used for resolving ${...} placeholder
|
||||
* and #{...} SpEL expressions in default values, or {@code null} if default
|
||||
* values are not expected to contain expressions
|
||||
* @param useDefaultResolution in default resolution mode a method argument
|
||||
* that is a simple type, as defined in {@link BeanUtils#isSimpleProperty},
|
||||
* is treated as a request parameter even if it itsn't annotated, the
|
||||
* is treated as a request parameter even if it it isn't annotated, the
|
||||
* request parameter name is derived from the method parameter name.
|
||||
*/
|
||||
public RequestParamMethodArgumentResolver(ConfigurableBeanFactory beanFactory,
|
||||
boolean useDefaultResolution) {
|
||||
public RequestParamMethodArgumentResolver(ConfigurableBeanFactory beanFactory, boolean useDefaultResolution) {
|
||||
super(beanFactory);
|
||||
this.useDefaultResolution = useDefaultResolution;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Supports the following:
|
||||
* <ul>
|
||||
* <li>@RequestParam-annotated method arguments.
|
||||
* This excludes {@link Map} params where the annotation doesn't
|
||||
* specify a name. See {@link RequestParamMapMethodArgumentResolver}
|
||||
* instead for such params.
|
||||
* <li>Arguments of type {@link MultipartFile}
|
||||
* unless annotated with @{@link RequestPart}.
|
||||
* <li>Arguments of type {@code javax.servlet.http.Part}
|
||||
* unless annotated with @{@link RequestPart}.
|
||||
* <li>In default resolution mode, simple type arguments
|
||||
* even if not with @{@link RequestParam}.
|
||||
* <li>@RequestParam-annotated method arguments.
|
||||
* This excludes {@link Map} params where the annotation doesn't
|
||||
* specify a name. See {@link RequestParamMapMethodArgumentResolver}
|
||||
* instead for such params.
|
||||
* <li>Arguments of type {@link MultipartFile}
|
||||
* unless annotated with @{@link RequestPart}.
|
||||
* <li>Arguments of type {@code javax.servlet.http.Part}
|
||||
* unless annotated with @{@link RequestPart}.
|
||||
* <li>In default resolution mode, simple type arguments
|
||||
* even if not with @{@link RequestParam}.
|
||||
* </ul>
|
||||
*/
|
||||
public boolean supportsParameter(MethodParameter parameter) {
|
||||
@@ -139,7 +139,6 @@ public class RequestParamMethodArgumentResolver extends AbstractNamedValueMethod
|
||||
|
||||
@Override
|
||||
protected Object resolveName(String name, MethodParameter parameter, NativeWebRequest webRequest) throws Exception {
|
||||
|
||||
Object arg;
|
||||
|
||||
HttpServletRequest servletRequest = webRequest.getNativeRequest(HttpServletRequest.class);
|
||||
@@ -202,13 +201,14 @@ public class RequestParamMethodArgumentResolver extends AbstractNamedValueMethod
|
||||
throw new MissingServletRequestParameterException(paramName, parameter.getParameterType().getSimpleName());
|
||||
}
|
||||
|
||||
private class RequestParamNamedValueInfo extends NamedValueInfo {
|
||||
|
||||
private RequestParamNamedValueInfo() {
|
||||
private static class RequestParamNamedValueInfo extends NamedValueInfo {
|
||||
|
||||
public RequestParamNamedValueInfo() {
|
||||
super("", false, ValueConstants.DEFAULT_NONE);
|
||||
}
|
||||
|
||||
private RequestParamNamedValueInfo(RequestParam annotation) {
|
||||
public RequestParamNamedValueInfo(RequestParam annotation) {
|
||||
super(annotation.value(), annotation.required(), annotation.defaultValue());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -392,7 +392,7 @@ final class HierarchicalUriComponents extends UriComponents {
|
||||
String path = getPath();
|
||||
if (StringUtils.hasLength(path) && path.charAt(0) != PATH_DELIMITER) {
|
||||
// Only prefix the path delimiter if something exists before it
|
||||
if(getScheme() != null || getUserInfo() != null || getHost() != null || getPort() != -1) {
|
||||
if (getScheme() != null || getUserInfo() != null || getHost() != null || getPort() != -1) {
|
||||
path = PATH_DELIMITER + path;
|
||||
}
|
||||
}
|
||||
@@ -605,7 +605,7 @@ final class HierarchicalUriComponents extends UriComponents {
|
||||
}
|
||||
|
||||
public String getPath() {
|
||||
return path;
|
||||
return this.path;
|
||||
}
|
||||
|
||||
public List<String> getPathSegments() {
|
||||
|
||||
Reference in New Issue
Block a user