Polishing

This commit is contained in:
Juergen Hoeller
2014-03-11 22:09:46 +01:00
parent 8b2b165777
commit 4d3ca4319e
10 changed files with 72 additions and 67 deletions

View File

@@ -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

View File

@@ -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;
}
}

View File

@@ -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;
}

View File

@@ -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);
}

View File

@@ -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);
}
/**