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.
|
||||
@@ -18,15 +18,18 @@ package org.springframework.expression;
|
||||
|
||||
|
||||
/**
|
||||
* A property accessor is able to read (and possibly write) to object properties. The
|
||||
* interface places no restrictions and so implementors are free to access properties
|
||||
* directly as fields or through getters or in any other way they see as appropriate. A
|
||||
* resolver can optionally specify an array of target classes for which it should be
|
||||
* called - but if it returns null from getSpecificTargetClasses() then it will be called
|
||||
* for all property references and given a chance to determine if it can read or write
|
||||
* them. Property resolvers are considered to be ordered and each will be called in turn.
|
||||
* A property accessor is able to read from (and possibly write to) an object's properties.
|
||||
* This interface places no restrictions, and so implementors are free to access properties
|
||||
* directly as fields or through getters or in any other way they see as appropriate.
|
||||
*
|
||||
* <p>A resolver can optionally specify an array of target classes for which it should be
|
||||
* called. However, if it returns {@code null} from {@link #getSpecificTargetClasses()},
|
||||
* it will be called for all property references and given a chance to determine if it
|
||||
* can read or write them.
|
||||
*
|
||||
* <p>Property resolvers are considered to be ordered and each will be called in turn.
|
||||
* The only rule that affects the call order is that any naming the target class directly
|
||||
* in getSpecifiedTargetClasses() will be called first, before the general resolvers.
|
||||
* in {@link #getSpecificTargetClasses()} will be called first, before the general resolvers.
|
||||
*
|
||||
* @author Andy Clement
|
||||
* @since 3.0
|
||||
@@ -34,11 +37,11 @@ package org.springframework.expression;
|
||||
public interface PropertyAccessor {
|
||||
|
||||
/**
|
||||
* Return an array of classes for which this resolver should be called. Returning null
|
||||
* indicates this is a general resolver that can be called in an attempt to resolve a
|
||||
* property on any type.
|
||||
* @return an array of classes that this resolver is suitable for (or null if a
|
||||
* general resolver)
|
||||
* Return an array of classes for which this resolver should be called.
|
||||
* <p>>Returning {@code null} indicates this is a general resolver that
|
||||
* can be called in an attempt to resolve a property on any type.
|
||||
* @return an array of classes that this resolver is suitable for
|
||||
* (or {@code null} if a general resolver)
|
||||
*/
|
||||
Class<?>[] getSpecificTargetClasses();
|
||||
|
||||
@@ -49,13 +52,13 @@ public interface PropertyAccessor {
|
||||
* @param target the target object upon which the property is being accessed
|
||||
* @param name the name of the property being accessed
|
||||
* @return true if this resolver is able to read the property
|
||||
* @throws AccessException if there is any problem determining whether the property
|
||||
* can be read
|
||||
* @throws AccessException if there is any problem determining whether the property can be read
|
||||
*/
|
||||
boolean canRead(EvaluationContext context, Object target, String name) throws AccessException;
|
||||
|
||||
/**
|
||||
* Called to read a property from a specified target object
|
||||
* Called to read a property from a specified target object.
|
||||
* Should only succeed if {@link #canRead} also returns {@code true}.
|
||||
* @param context the evaluation context in which the access is being attempted
|
||||
* @param target the target object upon which the property is being accessed
|
||||
* @param name the name of the property being accessed
|
||||
@@ -65,20 +68,20 @@ public interface PropertyAccessor {
|
||||
TypedValue read(EvaluationContext context, Object target, String name) throws AccessException;
|
||||
|
||||
/**
|
||||
* Called to determine if a resolver instance is able to write to a specified property
|
||||
* on a specified target object.
|
||||
* Called to determine if a resolver instance is able to write to a specified
|
||||
* property on a specified target object.
|
||||
* @param context the evaluation context in which the access is being attempted
|
||||
* @param target the target object upon which the property is being accessed
|
||||
* @param name the name of the property being accessed
|
||||
* @return true if this resolver is able to write to the property
|
||||
* @throws AccessException if there is any problem determining whether the property
|
||||
* can be written to
|
||||
* @throws AccessException if there is any problem determining whether the
|
||||
* property can be written to
|
||||
*/
|
||||
boolean canWrite(EvaluationContext context, Object target, String name) throws AccessException;
|
||||
|
||||
/**
|
||||
* Called to write to a property on a specified target object. Should only succeed if
|
||||
* canWrite() also returns true.
|
||||
* Called to write to a property on a specified target object.
|
||||
* Should only succeed if {@link #canWrite} also returns {@code true}.
|
||||
* @param context the evaluation context in which the access is being attempted
|
||||
* @param target the target object upon which the property is being accessed
|
||||
* @param name the name of the property being accessed
|
||||
|
||||
@@ -31,6 +31,7 @@ import org.springframework.util.Assert;
|
||||
* that use JAXB2. Creates {@link JAXBContext} object lazily.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 3.0
|
||||
*/
|
||||
public abstract class AbstractJaxb2HttpMessageConverter<T> extends AbstractXmlHttpMessageConverter<T> {
|
||||
@@ -61,8 +62,8 @@ public abstract class AbstractJaxb2HttpMessageConverter<T> extends AbstractXmlHt
|
||||
* Customize the {@link Marshaller} created by this
|
||||
* message converter before using it to write the object to the output.
|
||||
* @param marshaller the marshaller to customize
|
||||
* @see #createMarshaller(Class)
|
||||
* @since 4.0.3
|
||||
* @see #createMarshaller(Class)
|
||||
*/
|
||||
protected void customizeMarshaller(Marshaller marshaller) {
|
||||
}
|
||||
@@ -90,8 +91,8 @@ public abstract class AbstractJaxb2HttpMessageConverter<T> extends AbstractXmlHt
|
||||
* Customize the {@link Unmarshaller} created by this
|
||||
* message converter before using it to read the object from the input.
|
||||
* @param unmarshaller the unmarshaller to customize
|
||||
* @see #createUnmarshaller(Class)
|
||||
* @since 4.0.3
|
||||
* @see #createUnmarshaller(Class)
|
||||
*/
|
||||
protected void customizeUnmarshaller(Unmarshaller unmarshaller) {
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
@@ -22,7 +22,6 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.springframework.http.HttpHeaders;
|
||||
@@ -116,11 +115,12 @@ public class ServletServerHttpResponse implements ServerHttpResponse {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extends HttpHeaders with the ability to look up headers already present in
|
||||
* the underlying HttpServletResponse.
|
||||
*
|
||||
* The intent is merely to expose what is available through the HttpServletResponse
|
||||
* <p>The intent is merely to expose what is available through the HttpServletResponse
|
||||
* i.e. the ability to look up specific header values by name. All other
|
||||
* map-related operations (e.g. iteration, removal, etc) apply only to values
|
||||
* added directly through HttpHeaders methods.
|
||||
@@ -144,8 +144,8 @@ public class ServletServerHttpResponse implements ServerHttpResponse {
|
||||
|
||||
@Override
|
||||
public List<String> get(Object key) {
|
||||
Assert.isInstanceOf(String.class, key, "Key must be a String-based header name");
|
||||
|
||||
Assert.isInstanceOf(String.class, key, "key must be a String-based header name");
|
||||
Collection<String> values1 = servletResponse.getHeaders((String) key);
|
||||
boolean isEmpty1 = CollectionUtils.isEmpty(values1);
|
||||
|
||||
|
||||
@@ -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.
|
||||
@@ -277,7 +277,7 @@ public abstract class WebUtils {
|
||||
* @throws IllegalStateException if the session attribute could not be found
|
||||
*/
|
||||
public static Object getRequiredSessionAttribute(HttpServletRequest request, String name)
|
||||
throws IllegalStateException {
|
||||
throws IllegalStateException {
|
||||
|
||||
Object attr = getSessionAttribute(request, name);
|
||||
if (attr == 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.
|
||||
@@ -25,7 +25,6 @@ import javax.servlet.http.HttpServletResponse;
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 3.1
|
||||
*
|
||||
* @see FlashMap
|
||||
*/
|
||||
public interface FlashMapManager {
|
||||
@@ -46,7 +45,7 @@ public interface FlashMapManager {
|
||||
/**
|
||||
* Save the given FlashMap, in some underlying storage and set the start
|
||||
* of its expiration period.
|
||||
* <p><strong>Note:</strong> Invoke this method prior to a redirect in order
|
||||
* <p><strong>NOTE:</strong> Invoke this method prior to a redirect in order
|
||||
* to allow saving the FlashMap in the HTTP session or in a response
|
||||
* cookie before the response is committed.
|
||||
* @param flashMap the FlashMap to save
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.servlet.config.annotation;
|
||||
|
||||
import org.springframework.util.PathMatcher;
|
||||
@@ -29,11 +30,16 @@ import org.springframework.web.util.UrlPathHelper;
|
||||
public class PathMatchConfigurer {
|
||||
|
||||
private Boolean useSuffixPatternMatch;
|
||||
|
||||
private Boolean useTrailingSlashMatch;
|
||||
|
||||
private Boolean useRegisteredSuffixPatternMatch;
|
||||
|
||||
private UrlPathHelper urlPathHelper;
|
||||
|
||||
private PathMatcher pathMatcher;
|
||||
|
||||
|
||||
/**
|
||||
* Whether to use suffix pattern match (".*") when matching patterns to
|
||||
* requests. If enabled a method mapped to "/users" also matches to "/users.*".
|
||||
@@ -95,23 +101,25 @@ public class PathMatchConfigurer {
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public Boolean isUseSuffixPatternMatch() {
|
||||
return useSuffixPatternMatch;
|
||||
return this.useSuffixPatternMatch;
|
||||
}
|
||||
|
||||
public Boolean isUseTrailingSlashMatch() {
|
||||
return useTrailingSlashMatch;
|
||||
return this.useTrailingSlashMatch;
|
||||
}
|
||||
|
||||
public Boolean isUseRegisteredSuffixPatternMatch() {
|
||||
return useRegisteredSuffixPatternMatch;
|
||||
return this.useRegisteredSuffixPatternMatch;
|
||||
}
|
||||
|
||||
public UrlPathHelper getUrlPathHelper() {
|
||||
return urlPathHelper;
|
||||
return this.urlPathHelper;
|
||||
}
|
||||
|
||||
public PathMatcher getPathMatcher() {
|
||||
return pathMatcher;
|
||||
return this.pathMatcher;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
@@ -26,7 +26,6 @@ import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
@@ -114,8 +113,8 @@ import org.springframework.web.util.WebUtils;
|
||||
* @see HandlerMethodArgumentResolver
|
||||
* @see HandlerMethodReturnValueHandler
|
||||
*/
|
||||
public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter implements BeanFactoryAware,
|
||||
InitializingBean {
|
||||
public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter
|
||||
implements BeanFactoryAware, InitializingBean {
|
||||
|
||||
private List<HandlerMethodArgumentResolver> customArgumentResolvers;
|
||||
|
||||
@@ -698,7 +697,7 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter i
|
||||
Class<?> handlerType = handlerMethod.getBeanType();
|
||||
SessionAttributesHandler sessionAttrHandler = this.sessionAttributesHandlerCache.get(handlerType);
|
||||
if (sessionAttrHandler == null) {
|
||||
synchronized(this.sessionAttributesHandlerCache) {
|
||||
synchronized (this.sessionAttributesHandlerCache) {
|
||||
sessionAttrHandler = this.sessionAttributesHandlerCache.get(handlerType);
|
||||
if (sessionAttrHandler == null) {
|
||||
sessionAttrHandler = new SessionAttributesHandler(handlerType, sessionAttributeStore);
|
||||
@@ -710,7 +709,8 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter i
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoke the {@link RequestMapping} handler method preparing a {@link ModelAndView} if view resolution is required.
|
||||
* Invoke the {@link RequestMapping} handler method preparing a {@link ModelAndView}
|
||||
* if view resolution is required.
|
||||
*/
|
||||
private ModelAndView invokeHandleMethod(HttpServletRequest request,
|
||||
HttpServletResponse response, HandlerMethod handlerMethod) throws Exception {
|
||||
@@ -778,7 +778,7 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter i
|
||||
List<InvocableHandlerMethod> attrMethods = new ArrayList<InvocableHandlerMethod>();
|
||||
// Global methods first
|
||||
for (Entry<ControllerAdviceBean, Set<Method>> entry : this.modelAttributeAdviceCache.entrySet()) {
|
||||
if(entry.getKey().isApplicableToBeanType(handlerType)) {
|
||||
if (entry.getKey().isApplicableToBeanType(handlerType)) {
|
||||
Object bean = entry.getKey().resolveBean();
|
||||
for (Method method : entry.getValue()) {
|
||||
attrMethods.add(createModelAttributeMethod(binderFactory, bean, method));
|
||||
@@ -810,7 +810,7 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter i
|
||||
List<InvocableHandlerMethod> initBinderMethods = new ArrayList<InvocableHandlerMethod>();
|
||||
// Global methods first
|
||||
for (Entry<ControllerAdviceBean, Set<Method>> entry : this.initBinderAdviceCache .entrySet()) {
|
||||
if(entry.getKey().isApplicableToBeanType(handlerType)) {
|
||||
if (entry.getKey().isApplicableToBeanType(handlerType)) {
|
||||
Object bean = entry.getKey().resolveBean();
|
||||
for (Method method : entry.getValue()) {
|
||||
initBinderMethods.add(createInitBinderMethod(bean, method));
|
||||
@@ -850,7 +850,6 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter i
|
||||
ModelFactory modelFactory, NativeWebRequest webRequest) throws Exception {
|
||||
|
||||
modelFactory.updateModel(webRequest, mavContainer);
|
||||
|
||||
if (mavContainer.isRequestHandled()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -20,12 +20,12 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
@@ -43,13 +43,14 @@ import org.springframework.web.util.UrlPathHelper;
|
||||
*/
|
||||
public abstract class AbstractFlashMapManager implements FlashMapManager {
|
||||
|
||||
private static final Object writeLock = new Object();
|
||||
|
||||
protected final Log logger = LogFactory.getLog(getClass());
|
||||
|
||||
private int flashMapTimeout = 180;
|
||||
|
||||
private UrlPathHelper urlPathHelper = new UrlPathHelper();
|
||||
|
||||
private static final Object writeLock = new Object();
|
||||
|
||||
/**
|
||||
* Set the amount of time in seconds after a {@link FlashMap} is saved
|
||||
@@ -82,17 +83,17 @@ public abstract class AbstractFlashMapManager implements FlashMapManager {
|
||||
return this.urlPathHelper;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public final FlashMap retrieveAndUpdate(HttpServletRequest request, HttpServletResponse response) {
|
||||
|
||||
List<FlashMap> maps = retrieveFlashMaps(request);
|
||||
if (CollectionUtils.isEmpty(maps)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Retrieved FlashMap(s): " + maps);
|
||||
}
|
||||
|
||||
List<FlashMap> mapsToRemove = getExpiredFlashMaps(maps);
|
||||
|
||||
FlashMap match = getMatchingFlashMap(maps, request);
|
||||
@@ -163,8 +164,7 @@ public abstract class AbstractFlashMapManager implements FlashMapManager {
|
||||
String expectedPath = flashMap.getTargetRequestPath();
|
||||
if (expectedPath != null) {
|
||||
String requestUri = this.urlPathHelper.getOriginatingRequestUri(request);
|
||||
if (!requestUri.equals(expectedPath)
|
||||
&& !requestUri.equals(expectedPath + "/")) {
|
||||
if (!requestUri.equals(expectedPath) && !requestUri.equals(expectedPath + "/")) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -187,18 +187,16 @@ public abstract class AbstractFlashMapManager implements FlashMapManager {
|
||||
|
||||
String path = decodeAndNormalizePath(flashMap.getTargetRequestPath(), request);
|
||||
flashMap.setTargetRequestPath(path);
|
||||
|
||||
decodeParameters(flashMap.getTargetRequestParams(), request);
|
||||
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Saving FlashMap=" + flashMap);
|
||||
}
|
||||
|
||||
flashMap.startExpirationPeriod(this.flashMapTimeout);
|
||||
|
||||
synchronized (writeLock) {
|
||||
List<FlashMap> allMaps = retrieveFlashMaps(request);
|
||||
allMaps = (allMaps == null) ? new CopyOnWriteArrayList<FlashMap>() : allMaps;
|
||||
allMaps = (allMaps != null ? allMaps : new CopyOnWriteArrayList<FlashMap>());
|
||||
allMaps.add(flashMap);
|
||||
updateFlashMaps(allMaps, request, response);
|
||||
}
|
||||
@@ -232,7 +230,7 @@ public abstract class AbstractFlashMapManager implements FlashMapManager {
|
||||
* @param request the current request
|
||||
* @param response the current response
|
||||
*/
|
||||
protected abstract void updateFlashMaps(List<FlashMap> flashMaps, HttpServletRequest request,
|
||||
HttpServletResponse response);
|
||||
protected abstract void updateFlashMaps(
|
||||
List<FlashMap> flashMaps, HttpServletRequest request, HttpServletResponse response);
|
||||
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
@@ -17,7 +17,6 @@
|
||||
package org.springframework.web.servlet.support;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
@@ -30,10 +29,11 @@ import org.springframework.web.servlet.FlashMap;
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 3.1.1
|
||||
*/
|
||||
public class SessionFlashMapManager extends AbstractFlashMapManager{
|
||||
public class SessionFlashMapManager extends AbstractFlashMapManager {
|
||||
|
||||
private static final String FLASH_MAPS_SESSION_ATTRIBUTE = SessionFlashMapManager.class.getName() + ".FLASH_MAPS";
|
||||
|
||||
|
||||
/**
|
||||
* Retrieve saved FlashMap instances from the HTTP Session.
|
||||
* <p>Does not cause an HTTP session to be created but may update it if a
|
||||
@@ -44,7 +44,7 @@ public class SessionFlashMapManager extends AbstractFlashMapManager{
|
||||
@SuppressWarnings("unchecked")
|
||||
protected List<FlashMap> retrieveFlashMaps(HttpServletRequest request) {
|
||||
HttpSession session = request.getSession(false);
|
||||
return (session != null) ? (List<FlashMap>) session.getAttribute(FLASH_MAPS_SESSION_ATTRIBUTE) : null;
|
||||
return (session != null ? (List<FlashMap>) session.getAttribute(FLASH_MAPS_SESSION_ATTRIBUTE) : null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -16,12 +16,10 @@
|
||||
|
||||
package org.springframework.web.servlet.support;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
@@ -305,8 +303,7 @@ public class FlashMapManagerTests {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateFlashMaps(List<FlashMap> flashMaps, HttpServletRequest request,
|
||||
HttpServletResponse response) {
|
||||
protected void updateFlashMaps(List<FlashMap> flashMaps, HttpServletRequest request, HttpServletResponse response) {
|
||||
this.flashMaps = flashMaps;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user