diff --git a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/handler/AbstractUrlHandlerMapping.java b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/handler/AbstractUrlHandlerMapping.java index 75ba08c540..cc874c7145 100644 --- a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/handler/AbstractUrlHandlerMapping.java +++ b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/handler/AbstractUrlHandlerMapping.java @@ -208,7 +208,7 @@ public abstract class AbstractUrlHandlerMapping extends AbstractHandlerMapping { */ protected void validateHandler(Object handler, HttpServletRequest request) throws Exception { } - + /** * Build a handler object for the given raw handler, exposing the actual * handler, the {@link #PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE}, as well as diff --git a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/annotation/AnnotationMethodHandlerAdapter.java b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/annotation/AnnotationMethodHandlerAdapter.java index bcd6d2f28e..20dd1d0744 100644 --- a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/annotation/AnnotationMethodHandlerAdapter.java +++ b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/annotation/AnnotationMethodHandlerAdapter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2011 the original author or authors. + * Copyright 2002-2012 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. @@ -443,7 +443,7 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator /** * This method always returns -1 since an annotated controller can have many methods, * each requiring separate lastModified calculations. Instead, an - * @{@link RequestMapping}-annotated method can calculate the lastModified value, call + * {@link RequestMapping}-annotated method can calculate the lastModified value, call * {@link org.springframework.web.context.request.WebRequest#checkNotModified(long)} * to check it, and return {@code null} if that returns {@code true}. * @see org.springframework.web.context.request.WebRequest#checkNotModified(long) @@ -483,7 +483,7 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator * @return the ServletRequestDataBinder instance to use * @throws Exception in case of invalid state or arguments * @see ServletRequestDataBinder#bind(javax.servlet.ServletRequest) - * @see ServletRequestDataBinder#convertIfNecessary(Object, Class, org.springframework.core.MethodParameter) + * @see ServletRequestDataBinder#convertIfNecessary(Object, Class, org.springframework.core.MethodParameter) */ protected ServletRequestDataBinder createBinder(HttpServletRequest request, Object target, String objectName) throws Exception { return new ServletRequestDataBinder(target, objectName); @@ -588,7 +588,8 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator if (!typeLevelPattern.startsWith("/")) { typeLevelPattern = "/" + typeLevelPattern; } - if (getMatchingPattern(typeLevelPattern, lookupPath) != null) { + boolean useSuffixPattern = useSuffixPattern(request); + if (getMatchingPattern(typeLevelPattern, lookupPath, useSuffixPattern) != null) { if (mappingInfo.matches(request)) { match = true; mappingInfo.addMatchedPattern(typeLevelPattern); @@ -675,6 +676,11 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator return (Boolean) request.getAttribute(HandlerMapping.INTROSPECT_TYPE_LEVEL_MAPPING); } + private boolean useSuffixPattern(HttpServletRequest request) { + Object value = request.getAttribute(DefaultAnnotationHandlerMapping.USE_DEFAULT_SUFFIX_PATTERN); + return (value != null) ? (Boolean) value : Boolean.TRUE; + } + /** * Determines the combined pattern for the given methodLevelPattern and path. *
Uses the following algorithm:
@@ -687,6 +693,7 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator
*
*/
private String getCombinedPattern(String methodLevelPattern, String lookupPath, HttpServletRequest request) {
+ boolean useSuffixPattern = useSuffixPattern(request);
if (useTypeLevelMapping(request)) {
String[] typeLevelPatterns = getTypeLevelMapping().value();
for (String typeLevelPattern : typeLevelPatterns) {
@@ -694,7 +701,7 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator
typeLevelPattern = "/" + typeLevelPattern;
}
String combinedPattern = pathMatcher.combine(typeLevelPattern, methodLevelPattern);
- String matchingPattern = getMatchingPattern(combinedPattern, lookupPath);
+ String matchingPattern = getMatchingPattern(combinedPattern, lookupPath, useSuffixPattern);
if (matchingPattern != null) {
return matchingPattern;
}
@@ -704,20 +711,20 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator
String bestMatchingPattern = (String) request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE);
if (StringUtils.hasText(bestMatchingPattern) && bestMatchingPattern.endsWith("*")) {
String combinedPattern = pathMatcher.combine(bestMatchingPattern, methodLevelPattern);
- String matchingPattern = getMatchingPattern(combinedPattern, lookupPath);
+ String matchingPattern = getMatchingPattern(combinedPattern, lookupPath, useSuffixPattern);
if (matchingPattern != null && !matchingPattern.equals(bestMatchingPattern)) {
return matchingPattern;
}
}
- return getMatchingPattern(methodLevelPattern, lookupPath);
+ return getMatchingPattern(methodLevelPattern, lookupPath, useSuffixPattern);
}
- private String getMatchingPattern(String pattern, String lookupPath) {
+ private String getMatchingPattern(String pattern, String lookupPath, boolean useSuffixPattern) {
if (pattern.equals(lookupPath)) {
return pattern;
}
boolean hasSuffix = pattern.indexOf('.') != -1;
- if (!hasSuffix) {
+ if (useSuffixPattern && !hasSuffix) {
String patternWithSuffix = pattern + ".*";
if (pathMatcher.match(patternWithSuffix, lookupPath)) {
return patternWithSuffix;
@@ -727,7 +734,7 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator
return pattern;
}
boolean endsWithSlash = pattern.endsWith("/");
- if (!endsWithSlash) {
+ if (useSuffixPattern && !endsWithSlash) {
String patternWithSlash = pattern + "/";
if (pathMatcher.match(patternWithSlash, lookupPath)) {
return patternWithSlash;
@@ -1236,7 +1243,7 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator
private int compareAcceptHeaders(RequestMappingInfo info1, RequestMappingInfo info2) {
List