From acb9433e5cad2f668a5d1edf8320fadfcdaf0706 Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Thu, 21 Apr 2011 11:40:24 +0000 Subject: [PATCH] SPR-8247 review changes --- .../handler/AbstractHandlerMethodMapping.java | 84 ++++++------ .../RequestMappingHandlerMethodMapping.java | 90 +++++++------ ...appingKey.java => RequestMappingInfo.java} | 45 +++---- .../method/condition/RequestCondition.java | 2 +- .../handler/HandlerMethodMappingTests.java | 6 +- .../annotation/RequestKeyComparatorTests.java | 58 ++++---- .../method/annotation/RequestKeyTests.java | 124 +++++++++--------- ...questMappingHandlerMethodMappingTests.java | 2 +- 8 files changed, 199 insertions(+), 212 deletions(-) rename org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/{RequestMappingKey.java => RequestMappingInfo.java} (83%) diff --git a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMethodMapping.java b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMethodMapping.java index a1d8ddb6bb..b7baf8e5f0 100644 --- a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMethodMapping.java +++ b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMethodMapping.java @@ -41,7 +41,7 @@ import org.springframework.web.util.UrlPathHelper; * Abstract base class for {@link org.springframework.web.servlet.HandlerMapping HandlerMapping} implementations that * support mapping requests to {@link HandlerMethod}s rather than to handlers. * - * @param Represents a mapping key with conditions for mapping a request to a {@link HandlerMethod}. + * @param A type containing request mapping conditions required to match a request to a {@link HandlerMethod}. * * @author Arjen Poutsma * @author Rossen Stoyanchev @@ -106,7 +106,7 @@ public abstract class AbstractHandlerMethodMapping extends AbstractHandlerMap /** * Register handler methods found in beans of the current ApplicationContext. - *

The actual mapping for a handler is up to the concrete {@link #getMappingKeyForMethod(String, Method)} + *

The actual mapping for a handler is up to the concrete {@link #getMappingForMethod(String, Method)} * implementation. */ protected void initHandlerMethods() { @@ -135,57 +135,57 @@ public abstract class AbstractHandlerMethodMapping extends AbstractHandlerMap Set methods = HandlerMethodSelector.selectMethods(handlerType, new MethodFilter() { public boolean matches(Method method) { - return getMappingKeyForMethod(beanName, method) != null; + return getMappingForMethod(beanName, method) != null; } }); for (Method method : methods) { HandlerMethod handlerMethod = new HandlerMethod(beanName, getApplicationContext(), method); - T mapping = getMappingKeyForMethod(beanName, method); + T mapping = getMappingForMethod(beanName, method); Set paths = getMappingPaths(mapping); registerHandlerMethod(paths, mapping, handlerMethod); } } /** - * Provides a mapping key for the given bean method. A method for which no mapping can be determined is - * not considered a handler method. + * Provides a request mapping for the given bean method. A method for which no request mapping can be determined + * is not considered a handler method. * * @param beanName the name of the bean the method belongs to * @param method the method to create a mapping for - * @return the mapping key, or {@code null} if the method is not mapped + * @return the mapping, or {@code null} if the method is not mapped */ - protected abstract T getMappingKeyForMethod(String beanName, Method method); + protected abstract T getMappingForMethod(String beanName, Method method); /** * Registers a {@link HandlerMethod} with the given mapping. * * @param paths URL paths mapped to this method - * @param mappingKey the mapping key for the method + * @param mapping the mapping for the method * @param handlerMethod the handler method to register * @throws IllegalStateException if another method was already register under the same mapping */ - protected void registerHandlerMethod(Set paths, T mappingKey, HandlerMethod handlerMethod) { - Assert.notNull(mappingKey, "'mapping' must not be null"); + protected void registerHandlerMethod(Set paths, T mapping, HandlerMethod handlerMethod) { + Assert.notNull(mapping, "'mapping' must not be null"); Assert.notNull(handlerMethod, "'handlerMethod' must not be null"); - HandlerMethod mappedHandlerMethod = handlerMethods.get(mappingKey); + HandlerMethod mappedHandlerMethod = handlerMethods.get(mapping); if (mappedHandlerMethod != null && !mappedHandlerMethod.equals(handlerMethod)) { throw new IllegalStateException("Ambiguous mapping found. Cannot map '" + handlerMethod.getBean() - + "' bean method \n" + handlerMethod + "\nto " + mappingKey + ": There is already '" + + "' bean method \n" + handlerMethod + "\nto " + mapping + ": There is already '" + mappedHandlerMethod.getBean() + "' bean method\n" + mappedHandlerMethod + " mapped."); } - handlerMethods.put(mappingKey, handlerMethod); + handlerMethods.put(mapping, handlerMethod); if (logger.isInfoEnabled()) { - logger.info("Mapped \"" + mappingKey + "\" onto " + handlerMethod); + logger.info("Mapped \"" + mapping + "\" onto " + handlerMethod); } for (String path : paths) { - urlMap.add(path, mappingKey); + urlMap.add(path, mapping); } } /** * Get the URL paths for the given mapping. */ - protected abstract Set getMappingPaths(T mappingKey); + protected abstract Set getMappingPaths(T mapping); @Override protected HandlerMethod getHandlerInternal(HttpServletRequest request) throws Exception { @@ -211,32 +211,32 @@ public abstract class AbstractHandlerMethodMapping extends AbstractHandlerMap /** * Looks up the best-matching {@link HandlerMethod} for the given request. * - *

This implementation iterators through all handler methods, calls {@link #getMatchingKey(Object, - * HttpServletRequest)} for each of them, {@linkplain #getKeyComparator(HttpServletRequest) sorts} all matches, and - * returns the 1st entry, if any. If no matches are found, {@link #handleNoMatch(Set, HttpServletRequest)} is - * invoked. + *

This implementation iterators through all handler methods, calls + * {@link #getMatchingMapping(Object, String, HttpServletRequest)} for each of them, + * sorts all matches via {@linkplain #getMappingComparator(String, HttpServletRequest)} , and returns the + * top match, if any. If no matches are found, {@link #handleNoMatch(Set, HttpServletRequest)} is invoked. * * @param lookupPath mapping lookup path within the current servlet mapping if applicable * @param request the current HTTP servlet request * @return the best-matching handler method, or {@code null} if there is no match */ protected HandlerMethod lookupHandlerMethod(String lookupPath, HttpServletRequest request) throws Exception { - List keys = urlMap.get(lookupPath); - if (keys == null) { - keys = new ArrayList(handlerMethods.keySet()); + List mappings = urlMap.get(lookupPath); + if (mappings == null) { + mappings = new ArrayList(handlerMethods.keySet()); } List matches = new ArrayList(); - for (T key : keys) { - T match = getMatchingMappingKey(key, lookupPath, request); + for (T mapping : mappings) { + T match = getMatchingMapping(mapping, lookupPath, request); if (match != null) { - matches.add(new Match(match, handlerMethods.get(key))); + matches.add(new Match(match, handlerMethods.get(mapping))); } } if (!matches.isEmpty()) { - Comparator comparator = new MatchComparator(getMappingKeyComparator(lookupPath, request)); + Comparator comparator = new MatchComparator(getMappingComparator(lookupPath, request)); Collections.sort(matches, comparator); if (logger.isTraceEnabled()) { @@ -255,7 +255,7 @@ public abstract class AbstractHandlerMethodMapping extends AbstractHandlerMap } } - handleMatch(bestMatch.mappingKey, lookupPath, request); + handleMatch(bestMatch.mapping, lookupPath, request); return bestMatch.handlerMethod; } else { @@ -266,12 +266,12 @@ public abstract class AbstractHandlerMethodMapping extends AbstractHandlerMap /** * Invoked when a request has been matched to a mapping. * - * @param mappingKey the mapping selected for the request returned by - * {@link #getMatchingMappingKey(Object, String, HttpServletRequest)}. + * @param mapping the mapping selected for the request returned by + * {@link #getMatchingMapping(Object, String, HttpServletRequest)}. * @param lookupPath mapping lookup path within the current servlet mapping if applicable * @param request the current request */ - protected void handleMatch(T mappingKey, String lookupPath, HttpServletRequest request) { + protected void handleMatch(T mapping, String lookupPath, HttpServletRequest request) { } /** @@ -279,49 +279,49 @@ public abstract class AbstractHandlerMethodMapping extends AbstractHandlerMap * relevant to the current request (for example a mapping may have several HTTP methods, the matching mapping * will contain only 1). * - * @param mappingKey the mapping key to get a match for + * @param mapping the mapping to get a match for * @param lookupPath mapping lookup path within the current servlet mapping if applicable * @param request the current HTTP servlet request * @return a matching mapping, or {@code null} if the given mapping does not match the request */ - protected abstract T getMatchingMappingKey(T mappingKey, String lookupPath, HttpServletRequest request); + protected abstract T getMatchingMapping(T mapping, String lookupPath, HttpServletRequest request); /** - * Returns a comparator to sort mapping keys with. The returned comparator should sort 'better' matches higher. + * Returns a comparator to sort request mappings with. The returned comparator should sort 'better' matches higher. * * @param lookupPath mapping lookup path within the current servlet mapping if applicable * @param request the current HTTP servlet request * @return the comparator */ - protected abstract Comparator getMappingKeyComparator(String lookupPath, HttpServletRequest request); + protected abstract Comparator getMappingComparator(String lookupPath, HttpServletRequest request); /** * Invoked when no match was found. Default implementation returns {@code null}. * - * @param mappingKeys all registered mappings + * @param mappings all registered request mappings * @param lookupPath mapping lookup path within the current servlet mapping if applicable * @param request the current HTTP request * @throws ServletException in case of errors */ - protected HandlerMethod handleNoMatch(Set mappingKeys, String lookupPath, HttpServletRequest request) + protected HandlerMethod handleNoMatch(Set mappings, String lookupPath, HttpServletRequest request) throws Exception { return null; } private class Match { - private final T mappingKey; + private final T mapping; private final HandlerMethod handlerMethod; private Match(T mapping, HandlerMethod handlerMethod) { - this.mappingKey = mapping; + this.mapping = mapping; this.handlerMethod = handlerMethod; } @Override public String toString() { - return mappingKey.toString(); + return mapping.toString(); } } @@ -334,7 +334,7 @@ public abstract class AbstractHandlerMethodMapping extends AbstractHandlerMap } public int compare(Match match1, Match match2) { - return comparator.compare(match1.mappingKey, match2.mappingKey); + return comparator.compare(match1.mapping, match2.mapping); } } diff --git a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerMethodMapping.java b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerMethodMapping.java index aeb1d7e7d9..6ef6afc1e7 100644 --- a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerMethodMapping.java +++ b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerMethodMapping.java @@ -46,14 +46,14 @@ import org.springframework.web.servlet.handler.MappedInterceptors; import org.springframework.web.servlet.mvc.method.condition.RequestConditionFactory; /** - * An {@link AbstractHandlerMethodMapping} variant that uses {@link RequestMappingKey}s for the registration and + * An {@link AbstractHandlerMethodMapping} variant that uses {@link RequestMappingInfo}s for the registration and * the lookup of {@link HandlerMethod}s. * * @author Arjen Poutsma * @author Rossen Stoyanchev * @since 3.1.0 */ -public class RequestMappingHandlerMethodMapping extends AbstractHandlerMethodMapping { +public class RequestMappingHandlerMethodMapping extends AbstractHandlerMethodMapping { private PathMatcher pathMatcher = new AntPathMatcher(); @@ -97,28 +97,28 @@ public class RequestMappingHandlerMethodMapping extends AbstractHandlerMethodMap } /** - * Provides a {@link RequestMappingKey} for the given method. + * Provides a {@link RequestMappingInfo} for the given method. *

Only {@link RequestMapping @RequestMapping}-annotated methods are considered. * Type-level {@link RequestMapping @RequestMapping} annotations are also detected and their * attributes combined with method-level {@link RequestMapping @RequestMapping} attributes. * * @param beanName the name of the bean the method belongs to - * @param method the method to create a key for - * @return the key, or {@code null} - * @see RequestMappingKey#combine(RequestMappingKey, PathMatcher) + * @param method the method to create a mapping for + * @return the mapping, or {@code null} + * @see RequestMappingInfo#combine(RequestMappingInfo, PathMatcher) */ @Override - protected RequestMappingKey getMappingKeyForMethod(String beanName, Method method) { + protected RequestMappingInfo getMappingForMethod(String beanName, Method method) { RequestMapping annotation = AnnotationUtils.findAnnotation(method, RequestMapping.class); if (annotation != null) { - RequestMappingKey methodKey = createFromRequestMapping(annotation); + RequestMappingInfo methodMapping = createFromRequestMapping(annotation); RequestMapping typeAnnot = getApplicationContext().findAnnotationOnBean(beanName, RequestMapping.class); if (typeAnnot != null) { - RequestMappingKey typeKey = createFromRequestMapping(typeAnnot); - return typeKey.combine(methodKey, pathMatcher); + RequestMappingInfo typeMapping = createFromRequestMapping(typeAnnot); + return typeMapping.combine(methodMapping, pathMatcher); } else { - return methodKey; + return methodMapping; } } else { @@ -126,55 +126,53 @@ public class RequestMappingHandlerMethodMapping extends AbstractHandlerMethodMap } } - private static RequestMappingKey createFromRequestMapping(RequestMapping annotation) { - return new RequestMappingKey(Arrays.asList(annotation.value()), Arrays.asList(annotation.method()), + private static RequestMappingInfo createFromRequestMapping(RequestMapping annotation) { + return new RequestMappingInfo(Arrays.asList(annotation.value()), Arrays.asList(annotation.method()), RequestConditionFactory.parseParams(annotation.params()), - RequestConditionFactory.parseHeaders(annotation.headers()), - RequestConditionFactory.parseConsumes(annotation.consumes()) - ); + RequestConditionFactory.parseHeaders(annotation.headers())); } @Override - protected Set getMappingPaths(RequestMappingKey key) { - return key.getPatterns(); + protected Set getMappingPaths(RequestMappingInfo mapping) { + return mapping.getPatterns(); } /** - * Returns a new {@link RequestMappingKey} with attributes matching to the current request or {@code null}. - * @see RequestMappingKey#getMatchingKey(String, HttpServletRequest, PathMatcher) + * Returns a new {@link RequestMappingInfo} with attributes matching to the current request or {@code null}. + * @see RequestMappingInfo#getMatchingRequestMapping(String, HttpServletRequest, PathMatcher) */ @Override - protected RequestMappingKey getMatchingMappingKey(RequestMappingKey key, String lookupPath, HttpServletRequest request) { - return key.getMatchingKey(lookupPath, request, pathMatcher); + protected RequestMappingInfo getMatchingMapping(RequestMappingInfo mapping, String lookupPath, HttpServletRequest request) { + return mapping.getMatchingRequestMapping(lookupPath, request, pathMatcher); } /** - * Returns a {@link Comparator} that can be used to sort and select the best matching {@link RequestMappingKey}. + * Returns a {@link Comparator} that can be used to sort and select the best matching {@link RequestMappingInfo}. */ @Override - protected Comparator getMappingKeyComparator(String lookupPath, HttpServletRequest request) { - return new RequestKeyComparator(lookupPath, request); + protected Comparator getMappingComparator(String lookupPath, HttpServletRequest request) { + return new RequestMappingInfoComparator(lookupPath, request); } @Override - protected void handleMatch(RequestMappingKey key, String lookupPath, HttpServletRequest request) { - String pattern = key.getPatterns().iterator().next(); + protected void handleMatch(RequestMappingInfo mapping, String lookupPath, HttpServletRequest request) { + String pattern = mapping.getPatterns().iterator().next(); Map uriTemplateVariables = pathMatcher.extractUriTemplateVariables(pattern, lookupPath); request.setAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, uriTemplateVariables); } /** - * Iterates all {@link RequestMappingKey}s looking for keys that match by URL but not by HTTP method. + * Iterates all {@link RequestMappingInfo}s looking for mappings that match by URL but not by HTTP method. * @exception HttpRequestMethodNotSupportedException if there are matches by URL but not by HTTP method */ @Override - protected HandlerMethod handleNoMatch(Set requestKeys, String lookupPath, HttpServletRequest request) + protected HandlerMethod handleNoMatch(Set requestMappingInfos, String lookupPath, HttpServletRequest request) throws HttpRequestMethodNotSupportedException { Set allowedMethods = new HashSet(6); - for (RequestMappingKey requestKey : requestKeys) { - for (String pattern : requestKey.getPatterns()) { + for (RequestMappingInfo info : requestMappingInfos) { + for (String pattern : info.getPatterns()) { if (pathMatcher.match(pattern, lookupPath)) { - for (RequestMethod method : requestKey.getMethods()) { + for (RequestMethod method : info.getMethods()) { allowedMethods.add(method.name()); } } @@ -206,50 +204,50 @@ public class RequestMappingHandlerMethodMapping extends AbstractHandlerMethodMap } /** - * A comparator for {@link RequestMappingKey}s. Effective comparison can only be done in the context of a - * specific request. For example not all {@link RequestMappingKey} patterns may apply to the current request. + * A comparator for {@link RequestMappingInfo}s. Effective comparison can only be done in the context of a + * specific request. For example not all {@link RequestMappingInfo} patterns may apply to the current request. * Therefore an HttpServletRequest is required as input. * - *

Furthermore, the following assumptions are made about the input RequestKeys: - *

  • Each RequestKey has been fully matched to the request
  • The RequestKey contains matched - * patterns only
  • Patterns are ordered with the best matching pattern at the top
+ *

Furthermore, the following assumptions are made about the input RequestMappings: + *

  • Each RequestMappingInfo has been fully matched to the request
  • The RequestMappingInfo contains + * matched patterns only
  • Patterns are ordered with the best matching pattern at the top
* - * @see RequestMappingHandlerMethodMapping#getMatchingKey(RequestMappingKey, HttpServletRequest) + * @see RequestMappingHandlerMethodMapping#getMatchingMapping(RequestMappingInfo, String, HttpServletRequest) */ - private class RequestKeyComparator implements Comparator { + private class RequestMappingInfoComparator implements Comparator { private Comparator patternComparator; private List requestAcceptHeader; - public RequestKeyComparator(String lookupPath, HttpServletRequest request) { + public RequestMappingInfoComparator(String lookupPath, HttpServletRequest request) { this.patternComparator = pathMatcher.getPatternComparator(lookupPath); String acceptHeader = request.getHeader("Accept"); this.requestAcceptHeader = MediaType.parseMediaTypes(acceptHeader); MediaType.sortByQualityValue(this.requestAcceptHeader); } - public int compare(RequestMappingKey key, RequestMappingKey otherKey) { - int result = comparePatterns(key.getPatterns(), otherKey.getPatterns()); + public int compare(RequestMappingInfo mapping, RequestMappingInfo otherMapping) { + int result = comparePatterns(mapping.getPatterns(), otherMapping.getPatterns()); if (result != 0) { return result; } - result = key.getParams().compareTo(otherKey.getParams()); + result = mapping.getParams().compareTo(otherMapping.getParams()); if (result != 0) { return result; } - result = key.getHeaders().compareTo(otherKey.getHeaders()); + result = mapping.getHeaders().compareTo(otherMapping.getHeaders()); if (result != 0) { return result; } /* TODO: fix - result = compareAcceptHeaders(key.getAcceptHeaderMediaTypes(), otherKey.getAcceptHeaderMediaTypes()); + result = compareAcceptHeaders(mapping.getAcceptHeaderMediaTypes(), otherMapping.getAcceptHeaderMediaTypes()); if (result != 0) { return result; } */ - result = otherKey.getMethods().size() - key.getMethods().size(); + result = otherMapping.getMethods().size() - mapping.getMethods().size(); if (result != 0) { return result; } diff --git a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingKey.java b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingInfo.java similarity index 83% rename from org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingKey.java rename to org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingInfo.java index e46bab7470..22b6963f88 100644 --- a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingKey.java +++ b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingInfo.java @@ -32,20 +32,18 @@ import org.springframework.web.servlet.mvc.method.condition.RequestCondition; import org.springframework.web.servlet.mvc.method.condition.RequestConditionFactory; /** - * Contains a set of conditions to match to a given request such as URL patterns, HTTP methods, request - * parameters and headers. + * Contains a set of conditions to match to a given request such as URL patterns, HTTP methods, request parameters + * and headers. * - *

A {@link RequestMappingKey} can be combined with another {@link RequestMappingKey} resulting in a new {@link RequestMappingKey} - * with conditions from both (see {@link #combine(RequestMappingKey, PathMatcher)}). - * - *

A {@link RequestMappingKey} can be matched to a request resulting in a new {@link RequestMappingKey} with the subset of - * conditions relevant to the request (see {@link #getMatchingKey(String, HttpServletRequest, PathMatcher)}). + *

Two {@link RequestMappingInfo}s can be combined resulting in a new {@link RequestMappingInfo} with conditions + * from both. A {@link RequestMappingInfo} can also match itself to an HTTP request resulting in a new + * {@link RequestMappingInfo} with the subset of conditions relevant to the request. * * @author Arjen Poutsma * @author Rossen Stoyanchev * @since 3.1 */ -public final class RequestMappingKey { +public final class RequestMappingInfo { private final Set patterns; @@ -55,8 +53,6 @@ public final class RequestMappingKey { private final RequestCondition headersCondition; - private final RequestCondition consumesCondition; - private int hash; /** @@ -64,23 +60,21 @@ public final class RequestMappingKey { * *

Package protected for testing purposes. */ - RequestMappingKey(Collection patterns, Collection methods) { - this(patterns, methods, null, null, null); + RequestMappingInfo(Collection patterns, Collection methods) { + this(patterns, methods, null, null); } /** * Creates a new {@code RequestKey} instance with a full set of conditions. */ - public RequestMappingKey(Collection patterns, + public RequestMappingInfo(Collection patterns, Collection methods, RequestCondition paramsCondition, - RequestCondition headersCondition, - RequestCondition consumesCondition) { + RequestCondition headersCondition) { this.patterns = asUnmodifiableSet(prependLeadingSlash(patterns)); this.methods = asUnmodifiableSet(methods); this.paramsCondition = paramsCondition != null ? paramsCondition : RequestConditionFactory.trueCondition(); this.headersCondition = headersCondition != null ? headersCondition : RequestConditionFactory.trueCondition(); - this.consumesCondition = consumesCondition != null ? consumesCondition : RequestConditionFactory.trueCondition(); } private static Set prependLeadingSlash(Collection patterns) { @@ -145,20 +139,18 @@ public final class RequestMappingKey { *

  • HTTP methods are combined as union of all HTTP methods listed in both keys. *
  • Request parameter are combined into a logical AND. *
  • Request header are combined into a logical AND. - *
  • Consumes .. TODO * * @param methodKey the key to combine with * @param pathMatcher to {@linkplain PathMatcher#combine(String, String) combine} the patterns * @return a new request key containing conditions from both keys */ - public RequestMappingKey combine(RequestMappingKey methodKey, PathMatcher pathMatcher) { + public RequestMappingInfo combine(RequestMappingInfo methodKey, PathMatcher pathMatcher) { Set patterns = combinePatterns(this.patterns, methodKey.patterns, pathMatcher); Set methods = union(this.methods, methodKey.methods); RequestCondition params = RequestConditionFactory.and(this.paramsCondition, methodKey.paramsCondition); RequestCondition headers = RequestConditionFactory.and(this.headersCondition, methodKey.headersCondition); - RequestCondition consumes = RequestConditionFactory.mostSpecific(methodKey.consumesCondition, this.consumesCondition); - return new RequestMappingKey(patterns, methods, params, headers, consumes); + return new RequestMappingInfo(patterns, methods, params, headers); } private static Set combinePatterns(Collection typePatterns, @@ -204,17 +196,15 @@ public final class RequestMappingKey { * @param pathMatcher to check for matching patterns * @return a new request key that contains all matching attributes, or {@code null} if not all conditions match */ - public RequestMappingKey getMatchingKey(String lookupPath, HttpServletRequest request, PathMatcher pathMatcher) { - if (!checkMethod(request) || !paramsCondition.match(request) || !headersCondition.match(request) || - !consumesCondition.match(request)) { + public RequestMappingInfo getMatchingRequestMapping(String lookupPath, HttpServletRequest request, PathMatcher pathMatcher) { + if (!checkMethod(request) || !paramsCondition.match(request) || !headersCondition.match(request)) { return null; } else { List matchingPatterns = getMatchingPatterns(lookupPath, request, pathMatcher); if (!matchingPatterns.isEmpty()) { Set matchingMethods = getMatchingMethod(request); - return new RequestMappingKey(matchingPatterns, matchingMethods, this.paramsCondition, this.headersCondition, - this.consumesCondition); + return new RequestMappingInfo(matchingPatterns, matchingMethods, this.paramsCondition, this.headersCondition); } else { return null; @@ -275,8 +265,8 @@ public final class RequestMappingKey { if (this == obj) { return true; } - if (obj != null && obj instanceof RequestMappingKey) { - RequestMappingKey other = (RequestMappingKey) obj; + if (obj != null && obj instanceof RequestMappingInfo) { + RequestMappingInfo other = (RequestMappingInfo) obj; return (this.patterns.equals(other.patterns) && this.methods.equals(other.methods) && this.paramsCondition.equals(other.paramsCondition) && this.headersCondition.equals(other.headersCondition)); @@ -307,7 +297,6 @@ public final class RequestMappingKey { } builder.append(",params=").append(paramsCondition.toString()); builder.append(",headers=").append(headersCondition.toString()); - builder.append(",consumes=").append(consumesCondition.toString()); builder.append('}'); return builder.toString(); } diff --git a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/condition/RequestCondition.java b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/condition/RequestCondition.java index 26fa888098..ada88f4575 100644 --- a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/condition/RequestCondition.java +++ b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/condition/RequestCondition.java @@ -20,7 +20,7 @@ import javax.servlet.http.HttpServletRequest; /** * Defines the contract for conditions that must be met before an incoming request matches a {@link - * org.springframework.web.servlet.mvc.method.annotation.RequestMappingKey RequestKey}. + * org.springframework.web.servlet.mvc.method.annotation.RequestMappingInfo RequestKey}. * *

    Implementations of this interface are created by the {@link RequestConditionFactory}. * diff --git a/org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/handler/HandlerMethodMappingTests.java b/org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/handler/HandlerMethodMappingTests.java index c4de71a484..788e8eb414 100644 --- a/org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/handler/HandlerMethodMappingTests.java +++ b/org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/handler/HandlerMethodMappingTests.java @@ -90,18 +90,18 @@ public class HandlerMethodMappingTests { private PathMatcher pathMatcher = new AntPathMatcher(); @Override - protected String getMatchingMappingKey(String pattern, String lookupPath, HttpServletRequest request) { + protected String getMatchingMapping(String pattern, String lookupPath, HttpServletRequest request) { return pathMatcher.match(pattern, lookupPath) ? pattern : null; } @Override - protected String getMappingKeyForMethod(String beanName, Method method) { + protected String getMappingForMethod(String beanName, Method method) { String methodName = method.getName(); return methodName.startsWith("handler") ? methodName : null; } @Override - protected Comparator getMappingKeyComparator(String lookupPath, HttpServletRequest request) { + protected Comparator getMappingComparator(String lookupPath, HttpServletRequest request) { return pathMatcher.getPatternComparator(lookupPath); } diff --git a/org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestKeyComparatorTests.java b/org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestKeyComparatorTests.java index 555a820cba..1d199f02d1 100644 --- a/org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestKeyComparatorTests.java +++ b/org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestKeyComparatorTests.java @@ -33,7 +33,7 @@ import static java.util.Arrays.*; import static org.junit.Assert.*; /** - * Test fixture with {@link RequestMappingHandlerMethodMapping} testing its {@link RequestMappingKey} comparator. + * Test fixture with {@link RequestMappingHandlerMethodMapping} testing its {@link RequestMappingInfo} comparator. * * @author Arjen Poutsma * @author Rossen Stoyanchev @@ -54,9 +54,9 @@ public class RequestKeyComparatorTests { public void moreSpecificPatternWins() { request.setRequestURI("/foo"); String lookupPath = new UrlPathHelper().getLookupPathForRequest(request); - Comparator comparator = handlerMapping.getMappingKeyComparator(lookupPath, request); - RequestMappingKey key1 = new RequestMappingKey(asList("/fo*"), null); - RequestMappingKey key2 = new RequestMappingKey(asList("/foo"), null); + Comparator comparator = handlerMapping.getMappingComparator(lookupPath, request); + RequestMappingInfo key1 = new RequestMappingInfo(asList("/fo*"), null); + RequestMappingInfo key2 = new RequestMappingInfo(asList("/foo"), null); assertEquals(1, comparator.compare(key1, key2)); } @@ -65,9 +65,9 @@ public class RequestKeyComparatorTests { public void equalPatterns() { request.setRequestURI("/foo"); String lookupPath = new UrlPathHelper().getLookupPathForRequest(request); - Comparator comparator = handlerMapping.getMappingKeyComparator(lookupPath, request); - RequestMappingKey key1 = new RequestMappingKey(asList("/foo*"), null); - RequestMappingKey key2 = new RequestMappingKey(asList("/foo*"), null); + Comparator comparator = handlerMapping.getMappingComparator(lookupPath, request); + RequestMappingInfo key1 = new RequestMappingInfo(asList("/foo*"), null); + RequestMappingInfo key2 = new RequestMappingInfo(asList("/foo*"), null); assertEquals(0, comparator.compare(key1, key2)); } @@ -76,34 +76,34 @@ public class RequestKeyComparatorTests { public void greaterNumberOfMatchingPatternsWins() throws Exception { request.setRequestURI("/foo.html"); String lookupPath = new UrlPathHelper().getLookupPathForRequest(request); - RequestMappingKey key1 = new RequestMappingKey(asList("/foo", "*.jpeg"), null); - RequestMappingKey key2 = new RequestMappingKey(asList("/foo", "*.html"), null); - RequestMappingKey match1 = handlerMapping.getMatchingMappingKey(key1, lookupPath, request); - RequestMappingKey match2 = handlerMapping.getMatchingMappingKey(key2, lookupPath, request); - List matches = asList(match1, match2); - Collections.sort(matches, handlerMapping.getMappingKeyComparator(lookupPath, request)); + RequestMappingInfo key1 = new RequestMappingInfo(asList("/foo", "*.jpeg"), null); + RequestMappingInfo key2 = new RequestMappingInfo(asList("/foo", "*.html"), null); + RequestMappingInfo match1 = handlerMapping.getMatchingMapping(key1, lookupPath, request); + RequestMappingInfo match2 = handlerMapping.getMatchingMapping(key2, lookupPath, request); + List matches = asList(match1, match2); + Collections.sort(matches, handlerMapping.getMappingComparator(lookupPath, request)); assertSame(match2.getPatterns(), matches.get(0).getPatterns()); } @Test public void oneMethodWinsOverNone() { - Comparator comparator = handlerMapping.getMappingKeyComparator("", request); - RequestMappingKey key1 = new RequestMappingKey(null, null); - RequestMappingKey key2 = new RequestMappingKey(null, asList(RequestMethod.GET)); + Comparator comparator = handlerMapping.getMappingComparator("", request); + RequestMappingInfo key1 = new RequestMappingInfo(null, null); + RequestMappingInfo key2 = new RequestMappingInfo(null, asList(RequestMethod.GET)); assertEquals(1, comparator.compare(key1, key2)); } @Test public void methodsAndParams() { - RequestMappingKey empty = new RequestMappingKey(null, null); - RequestMappingKey oneMethod = new RequestMappingKey(null, asList(RequestMethod.GET)); - RequestMappingKey oneMethodOneParam = - new RequestMappingKey(null, asList(RequestMethod.GET), RequestConditionFactory.parseParams("foo"), null, null); - List list = asList(empty, oneMethod, oneMethodOneParam); + RequestMappingInfo empty = new RequestMappingInfo(null, null); + RequestMappingInfo oneMethod = new RequestMappingInfo(null, asList(RequestMethod.GET)); + RequestMappingInfo oneMethodOneParam = + new RequestMappingInfo(null, asList(RequestMethod.GET), RequestConditionFactory.parseParams("foo"), null); + List list = asList(empty, oneMethod, oneMethodOneParam); Collections.shuffle(list); - Collections.sort(list, handlerMapping.getMappingKeyComparator("", request)); + Collections.sort(list, handlerMapping.getMappingComparator("", request)); assertEquals(oneMethodOneParam, list.get(0)); assertEquals(oneMethod, list.get(1)); @@ -113,12 +113,12 @@ public class RequestKeyComparatorTests { @Test @Ignore // TODO : remove ignore public void acceptHeaders() { - RequestMappingKey html = new RequestMappingKey(null, null, null, RequestConditionFactory.parseHeaders("accept=text/html"), null); - RequestMappingKey xml = new RequestMappingKey(null, null, null, RequestConditionFactory.parseHeaders("accept=application/xml"), null); - RequestMappingKey none = new RequestMappingKey(null, null); + RequestMappingInfo html = new RequestMappingInfo(null, null, null, RequestConditionFactory.parseHeaders("accept=text/html")); + RequestMappingInfo xml = new RequestMappingInfo(null, null, null, RequestConditionFactory.parseHeaders("accept=application/xml")); + RequestMappingInfo none = new RequestMappingInfo(null, null); request.addHeader("Accept", "application/xml, text/html"); - Comparator comparator = handlerMapping.getMappingKeyComparator("", request); + Comparator comparator = handlerMapping.getMappingComparator("", request); assertTrue(comparator.compare(html, xml) > 0); assertTrue(comparator.compare(xml, html) < 0); @@ -129,14 +129,14 @@ public class RequestKeyComparatorTests { request = new MockHttpServletRequest(); request.addHeader("Accept", "application/xml, text/*"); - comparator = handlerMapping.getMappingKeyComparator("", request); + comparator = handlerMapping.getMappingComparator("", request); assertTrue(comparator.compare(html, xml) > 0); assertTrue(comparator.compare(xml, html) < 0); request = new MockHttpServletRequest(); request.addHeader("Accept", "application/pdf"); - comparator = handlerMapping.getMappingKeyComparator("", request); + comparator = handlerMapping.getMappingComparator("", request); assertTrue(comparator.compare(html, xml) == 0); assertTrue(comparator.compare(xml, html) == 0); @@ -144,7 +144,7 @@ public class RequestKeyComparatorTests { // See SPR-7000 request = new MockHttpServletRequest(); request.addHeader("Accept", "text/html;q=0.9,application/xml"); - comparator = handlerMapping.getMappingKeyComparator("", request); + comparator = handlerMapping.getMappingComparator("", request); assertTrue(comparator.compare(html, xml) > 0); assertTrue(comparator.compare(xml, html) < 0); diff --git a/org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestKeyTests.java b/org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestKeyTests.java index 73f941fdff..2d9654ecc3 100644 --- a/org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestKeyTests.java +++ b/org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestKeyTests.java @@ -32,7 +32,7 @@ import org.springframework.web.servlet.mvc.method.condition.RequestConditionFact import org.springframework.web.util.UrlPathHelper; /** - * Test fixture for {@link RequestMappingKey} tests. + * Test fixture for {@link RequestMappingInfo} tests. * * @author Arjen Poutsma * @author Rossen Stoyanchev @@ -41,8 +41,8 @@ public class RequestKeyTests { @Test public void equals() { - RequestMappingKey key1 = new RequestMappingKey(singleton("/foo"), singleton(GET)); - RequestMappingKey key2 = new RequestMappingKey(singleton("/foo"), singleton(GET)); + RequestMappingInfo key1 = new RequestMappingInfo(singleton("/foo"), singleton(GET)); + RequestMappingInfo key2 = new RequestMappingInfo(singleton("/foo"), singleton(GET)); assertEquals(key1, key2); assertEquals(key1.hashCode(), key2.hashCode()); @@ -50,8 +50,8 @@ public class RequestKeyTests { @Test public void equalsPrependSlash() { - RequestMappingKey key1 = new RequestMappingKey(singleton("/foo"), singleton(GET)); - RequestMappingKey key2 = new RequestMappingKey(singleton("foo"), singleton(GET)); + RequestMappingInfo key1 = new RequestMappingInfo(singleton("/foo"), singleton(GET)); + RequestMappingInfo key2 = new RequestMappingInfo(singleton("foo"), singleton(GET)); assertEquals(key1, key2); assertEquals(key1.hashCode(), key2.hashCode()); @@ -61,9 +61,9 @@ public class RequestKeyTests { public void combinePatterns() { AntPathMatcher pathMatcher = new AntPathMatcher(); - RequestMappingKey key1 = createKeyFromPatterns("/t1", "/t2"); - RequestMappingKey key2 = createKeyFromPatterns("/m1", "/m2"); - RequestMappingKey key3 = createKeyFromPatterns("/t1/m1", "/t1/m2", "/t2/m1", "/t2/m2"); + RequestMappingInfo key1 = createKeyFromPatterns("/t1", "/t2"); + RequestMappingInfo key2 = createKeyFromPatterns("/m1", "/m2"); + RequestMappingInfo key3 = createKeyFromPatterns("/t1/m1", "/t1/m2", "/t2/m1", "/t2/m2"); assertEquals(key3.getPatterns(), key1.combine(key2, pathMatcher).getPatterns()); key1 = createKeyFromPatterns("/t1"); @@ -93,40 +93,40 @@ public class RequestKeyTests { PathMatcher pathMatcher = new AntPathMatcher(); MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo"); - RequestMappingKey key = new RequestMappingKey(singleton("/foo"), null); - RequestMappingKey match = key.getMatchingKey(pathHelper.getLookupPathForRequest(request), request, pathMatcher); + RequestMappingInfo key = new RequestMappingInfo(singleton("/foo"), null); + RequestMappingInfo match = key.getMatchingRequestMapping(pathHelper.getLookupPathForRequest(request), request, pathMatcher); assertNotNull(match); request = new MockHttpServletRequest("GET", "/foo/bar"); - key = new RequestMappingKey(singleton("/foo/*"), null); - match = key.getMatchingKey(pathHelper.getLookupPathForRequest(request), request, pathMatcher); + key = new RequestMappingInfo(singleton("/foo/*"), null); + match = key.getMatchingRequestMapping(pathHelper.getLookupPathForRequest(request), request, pathMatcher); assertNotNull("Pattern match", match); request = new MockHttpServletRequest("GET", "/foo.html"); - key = new RequestMappingKey(singleton("/foo"), null); - match = key.getMatchingKey(pathHelper.getLookupPathForRequest(request), request, pathMatcher); + key = new RequestMappingInfo(singleton("/foo"), null); + match = key.getMatchingRequestMapping(pathHelper.getLookupPathForRequest(request), request, pathMatcher); assertNotNull("Implicit match by extension", match); assertEquals("Contains matched pattern", "/foo.*", match.getPatterns().iterator().next()); request = new MockHttpServletRequest("GET", "/foo/"); - key = new RequestMappingKey(singleton("/foo"), null); - match = key.getMatchingKey(pathHelper.getLookupPathForRequest(request), request, pathMatcher); + key = new RequestMappingInfo(singleton("/foo"), null); + match = key.getMatchingRequestMapping(pathHelper.getLookupPathForRequest(request), request, pathMatcher); assertNotNull("Implicit match by trailing slash", match); assertEquals("Contains matched pattern", "/foo/", match.getPatterns().iterator().next()); request = new MockHttpServletRequest("GET", "/foo.html"); - key = new RequestMappingKey(singleton("/foo.jpg"), null); - match = key.getMatchingKey(pathHelper.getLookupPathForRequest(request), request, pathMatcher); + key = new RequestMappingInfo(singleton("/foo.jpg"), null); + match = key.getMatchingRequestMapping(pathHelper.getLookupPathForRequest(request), request, pathMatcher); assertNull("Implicit match ignored if pattern has extension", match); request = new MockHttpServletRequest("GET", "/foo.html"); - key = new RequestMappingKey(singleton("/foo.jpg"), null); - match = key.getMatchingKey(pathHelper.getLookupPathForRequest(request), request, pathMatcher); + key = new RequestMappingInfo(singleton("/foo.jpg"), null); + match = key.getMatchingRequestMapping(pathHelper.getLookupPathForRequest(request), request, pathMatcher); assertNull("Implicit match ignored on pattern with trailing slash", match); } @@ -137,18 +137,18 @@ public class RequestKeyTests { MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo"); String lookupPath = new UrlPathHelper().getLookupPathForRequest(request); - RequestMappingKey key = new RequestMappingKey(singleton("/foo"), null); - RequestMappingKey match = key.getMatchingKey(lookupPath, request, pathMatcher); + RequestMappingInfo key = new RequestMappingInfo(singleton("/foo"), null); + RequestMappingInfo match = key.getMatchingRequestMapping(lookupPath, request, pathMatcher); assertNotNull("No method matches any method", match); - key = new RequestMappingKey(singleton("/foo"), singleton(GET)); - match = key.getMatchingKey(lookupPath, request, pathMatcher); + key = new RequestMappingInfo(singleton("/foo"), singleton(GET)); + match = key.getMatchingRequestMapping(lookupPath, request, pathMatcher); assertNotNull("Exact match", match); - key = new RequestMappingKey(singleton("/foo"), singleton(POST)); - match = key.getMatchingKey(lookupPath, request, pathMatcher); + key = new RequestMappingInfo(singleton("/foo"), singleton(POST)); + match = key.getMatchingRequestMapping(lookupPath, request, pathMatcher); assertNull("No match", match); } @@ -159,15 +159,15 @@ public class RequestKeyTests { MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo"); String lookupPath = new UrlPathHelper().getLookupPathForRequest(request); - RequestMappingKey key = new RequestMappingKey(asList("/foo*", "/bar"), asList(GET, POST)); - RequestMappingKey match = key.getMatchingKey(lookupPath, request, pathMatcher); - RequestMappingKey expected = new RequestMappingKey(singleton("/foo*"), singleton(GET)); + RequestMappingInfo key = new RequestMappingInfo(asList("/foo*", "/bar"), asList(GET, POST)); + RequestMappingInfo match = key.getMatchingRequestMapping(lookupPath, request, pathMatcher); + RequestMappingInfo expected = new RequestMappingInfo(singleton("/foo*"), singleton(GET)); assertEquals("Matching RequestKey contains matched patterns and methods only", expected, match); - key = new RequestMappingKey(asList("/**", "/foo*", "/foo"), null); - match = key.getMatchingKey(lookupPath, request, pathMatcher); - expected = new RequestMappingKey(asList("/foo", "/foo*", "/**"), null); + key = new RequestMappingInfo(asList("/**", "/foo*", "/foo"), null); + match = key.getMatchingRequestMapping(lookupPath, request, pathMatcher); + expected = new RequestMappingInfo(asList("/foo", "/foo*", "/**"), null); assertEquals("Matched patterns are sorted with best match at the top", expected, match); } @@ -179,13 +179,13 @@ public class RequestKeyTests { request.setParameter("foo", "bar"); String lookupPath = new UrlPathHelper().getLookupPathForRequest(request); - RequestMappingKey key = new RequestMappingKey(asList("/foo"), null, RequestConditionFactory.parseParams("foo=bar"), null, null); - RequestMappingKey match = key.getMatchingKey(lookupPath, request, pathMatcher); + RequestMappingInfo key = new RequestMappingInfo(asList("/foo"), null, RequestConditionFactory.parseParams("foo=bar"), null); + RequestMappingInfo match = key.getMatchingRequestMapping(lookupPath, request, pathMatcher); assertNotNull(match); - key = new RequestMappingKey(singleton("/foo"), null, RequestConditionFactory.parseParams("foo!=bar"), null, null); - match = key.getMatchingKey(lookupPath, request, pathMatcher); + key = new RequestMappingInfo(singleton("/foo"), null, RequestConditionFactory.parseParams("foo!=bar"), null); + match = key.getMatchingRequestMapping(lookupPath, request, pathMatcher); assertNull(match); } @@ -197,39 +197,39 @@ public class RequestKeyTests { request.addHeader("foo", "bar"); String lookupPath = new UrlPathHelper().getLookupPathForRequest(request); - RequestMappingKey key = new RequestMappingKey(singleton("/foo"), null, null, RequestConditionFactory.parseHeaders("foo=bar"), null); - RequestMappingKey match = key.getMatchingKey(lookupPath, request, pathMatcher); + RequestMappingInfo key = new RequestMappingInfo(singleton("/foo"), null, null, RequestConditionFactory.parseHeaders("foo=bar")); + RequestMappingInfo match = key.getMatchingRequestMapping(lookupPath, request, pathMatcher); assertNotNull(match); - key = new RequestMappingKey(singleton("/foo"), null, null, RequestConditionFactory.parseHeaders("foo!=bar"), null); - match = key.getMatchingKey(lookupPath, request, pathMatcher); + key = new RequestMappingInfo(singleton("/foo"), null, null, RequestConditionFactory.parseHeaders("foo!=bar")); + match = key.getMatchingRequestMapping(lookupPath, request, pathMatcher); assertNull(match); } - @Test - public void consumesCondition() { - PathMatcher pathMatcher = new AntPathMatcher(); - MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo"); - request.setContentType("text/plain"); - String lookupPath = new UrlPathHelper().getLookupPathForRequest(request); - - RequestMappingKey key = new RequestMappingKey(singleton("/foo"), null, null, null, RequestConditionFactory.parseConsumes( - "text/plain")); - RequestMappingKey match = key.getMatchingKey(lookupPath, request, pathMatcher); - - assertNotNull(match); - - key = new RequestMappingKey(singleton("/foo"), null, null, null, RequestConditionFactory.parseConsumes( - "application/xml")); - match = key.getMatchingKey(lookupPath, request, pathMatcher); - - assertNull(match); - } - - private RequestMappingKey createKeyFromPatterns(String... patterns) { - return new RequestMappingKey(asList(patterns), null); +// @Test +// public void consumesCondition() { +// PathMatcher pathMatcher = new AntPathMatcher(); +// MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo"); +// request.setContentType("text/plain"); +// String lookupPath = new UrlPathHelper().getLookupPathForRequest(request); +// +// RequestMappingInfo key = new RequestMappingInfo(singleton("/foo"), null, null, null, RequestConditionFactory.parseConsumes( +// "text/plain")); +// RequestMappingInfo match = key.getMatchingKey(lookupPath, request, pathMatcher); +// +// assertNotNull(match); +// +// key = new RequestMappingInfo(singleton("/foo"), null, null, null, RequestConditionFactory.parseConsumes( +// "application/xml")); +// match = key.getMatchingKey(lookupPath, request, pathMatcher); +// +// assertNull(match); +// } + + private RequestMappingInfo createKeyFromPatterns(String... patterns) { + return new RequestMappingInfo(asList(patterns), null); } } \ No newline at end of file diff --git a/org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerMethodMappingTests.java b/org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerMethodMappingTests.java index bb8254b82e..231993699f 100644 --- a/org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerMethodMappingTests.java +++ b/org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerMethodMappingTests.java @@ -124,7 +124,7 @@ public class RequestMappingHandlerMethodMappingTests { @Test public void uriTemplateVariables() { - RequestMappingKey key = new RequestMappingKey(Arrays.asList("/{path1}/{path2}"), null); + RequestMappingInfo key = new RequestMappingInfo(Arrays.asList("/{path1}/{path2}"), null); MockHttpServletRequest request = new MockHttpServletRequest("GET", "/1/2"); String lookupPath = new UrlPathHelper().getLookupPathForRequest(request);