Browse Source

Do not use ParsingPathMatcher by default in Spring MVC

pull/1293/head
Brian Clozel 9 years ago
parent
commit
47ac3379ea
  1. 5
      spring-web/src/main/java/org/springframework/web/cors/UrlBasedCorsConfigurationSource.java
  2. 5
      spring-webmvc/src/main/java/org/springframework/web/servlet/ResourceServlet.java
  3. 7
      spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupport.java
  4. 5
      spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMapping.java
  5. 5
      spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/WebContentInterceptor.java
  6. 5
      spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/PatternsRequestCondition.java
  7. 5
      spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/MvcUriComponentsBuilder.java
  8. 5
      spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceUrlProvider.java
  9. 8
      spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/InterceptorRegistryTests.java
  10. 4
      spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupportTests.java
  11. 9
      spring-webmvc/src/test/java/org/springframework/web/servlet/handler/HandlerMethodMappingTests.java
  12. 10
      spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/UrlFilenameViewControllerTests.java

5
spring-web/src/main/java/org/springframework/web/cors/UrlBasedCorsConfigurationSource.java

@ -19,11 +19,12 @@ package org.springframework.web.cors; @@ -19,11 +19,12 @@ package org.springframework.web.cors;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.springframework.util.AntPathMatcher;
import org.springframework.util.Assert;
import org.springframework.util.PathMatcher;
import org.springframework.web.util.ParsingPathMatcher;
import org.springframework.web.util.UrlPathHelper;
/**
@ -40,7 +41,7 @@ public class UrlBasedCorsConfigurationSource implements CorsConfigurationSource @@ -40,7 +41,7 @@ public class UrlBasedCorsConfigurationSource implements CorsConfigurationSource
private final Map<String, CorsConfiguration> corsConfigurations = new LinkedHashMap<>();
private PathMatcher pathMatcher = new ParsingPathMatcher();
private PathMatcher pathMatcher = new AntPathMatcher();
private UrlPathHelper urlPathHelper = new UrlPathHelper();

5
spring-webmvc/src/main/java/org/springframework/web/servlet/ResourceServlet.java

@ -17,15 +17,16 @@ @@ -17,15 +17,16 @@
package org.springframework.web.servlet;
import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.util.AntPathMatcher;
import org.springframework.util.PathMatcher;
import org.springframework.util.StringUtils;
import org.springframework.web.context.support.ServletContextResource;
import org.springframework.web.util.ParsingPathMatcher;
/**
* Simple servlet that can expose an internal resource, including a
@ -181,7 +182,7 @@ public class ResourceServlet extends HttpServletBean { @@ -181,7 +182,7 @@ public class ResourceServlet extends HttpServletBean {
* @see org.springframework.util.AntPathMatcher
*/
protected PathMatcher getPathMatcher() {
return new ParsingPathMatcher();
return new AntPathMatcher();
}

7
spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupport.java

@ -22,6 +22,7 @@ import java.util.HashMap; @@ -22,6 +22,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
@ -55,6 +56,7 @@ import org.springframework.http.converter.support.AllEncompassingFormHttpMessage @@ -55,6 +56,7 @@ import org.springframework.http.converter.support.AllEncompassingFormHttpMessage
import org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter;
import org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter;
import org.springframework.http.converter.xml.SourceHttpMessageConverter;
import org.springframework.util.AntPathMatcher;
import org.springframework.util.ClassUtils;
import org.springframework.util.PathMatcher;
import org.springframework.validation.Errors;
@ -93,7 +95,6 @@ import org.springframework.web.servlet.resource.ResourceUrlProvider; @@ -93,7 +95,6 @@ import org.springframework.web.servlet.resource.ResourceUrlProvider;
import org.springframework.web.servlet.resource.ResourceUrlProviderExposingInterceptor;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
import org.springframework.web.servlet.view.ViewResolverComposite;
import org.springframework.web.util.ParsingPathMatcher;
import org.springframework.web.util.UrlPathHelper;
/**
@ -140,7 +141,7 @@ import org.springframework.web.util.UrlPathHelper; @@ -140,7 +141,7 @@ import org.springframework.web.util.UrlPathHelper;
* exception types
* </ul>
*
* <p>Registers an {@link ParsingPathMatcher} and a {@link UrlPathHelper}
* <p>Registers an {@link AntPathMatcher} and a {@link UrlPathHelper}
* to be used by:
* <ul>
* <li>the {@link RequestMappingHandlerMapping},
@ -345,7 +346,7 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv @@ -345,7 +346,7 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv
@Bean
public PathMatcher mvcPathMatcher() {
PathMatcher pathMatcher = getPathMatchConfigurer().getPathMatcher();
return (pathMatcher != null ? pathMatcher : new ParsingPathMatcher());
return (pathMatcher != null ? pathMatcher : new AntPathMatcher());
}
/**

5
spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMapping.java

@ -21,12 +21,14 @@ import java.util.ArrayList; @@ -21,12 +21,14 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactoryUtils;
import org.springframework.core.Ordered;
import org.springframework.util.AntPathMatcher;
import org.springframework.util.Assert;
import org.springframework.util.PathMatcher;
import org.springframework.web.HttpRequestHandler;
@ -41,7 +43,6 @@ import org.springframework.web.cors.UrlBasedCorsConfigurationSource; @@ -41,7 +43,6 @@ import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.servlet.HandlerExecutionChain;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.HandlerMapping;
import org.springframework.web.util.ParsingPathMatcher;
import org.springframework.web.util.UrlPathHelper;
/**
@ -72,7 +73,7 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport @@ -72,7 +73,7 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport
private UrlPathHelper urlPathHelper = new UrlPathHelper();
private PathMatcher pathMatcher = new ParsingPathMatcher();
private PathMatcher pathMatcher = new AntPathMatcher();
private final List<Object> interceptors = new ArrayList<>();

5
spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/WebContentInterceptor.java

@ -20,17 +20,18 @@ import java.util.Enumeration; @@ -20,17 +20,18 @@ import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.http.CacheControl;
import org.springframework.util.AntPathMatcher;
import org.springframework.util.Assert;
import org.springframework.util.PathMatcher;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.support.WebContentGenerator;
import org.springframework.web.util.ParsingPathMatcher;
import org.springframework.web.util.UrlPathHelper;
/**
@ -52,7 +53,7 @@ public class WebContentInterceptor extends WebContentGenerator implements Handle @@ -52,7 +53,7 @@ public class WebContentInterceptor extends WebContentGenerator implements Handle
private UrlPathHelper urlPathHelper = new UrlPathHelper();
private PathMatcher pathMatcher = new ParsingPathMatcher();
private PathMatcher pathMatcher = new AntPathMatcher();
private Map<String, Integer> cacheMappings = new HashMap<>();

5
spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/PatternsRequestCondition.java

@ -25,11 +25,12 @@ import java.util.Iterator; @@ -25,11 +25,12 @@ import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import javax.servlet.http.HttpServletRequest;
import org.springframework.util.AntPathMatcher;
import org.springframework.util.PathMatcher;
import org.springframework.util.StringUtils;
import org.springframework.web.util.ParsingPathMatcher;
import org.springframework.web.util.UrlPathHelper;
/**
@ -104,7 +105,7 @@ public final class PatternsRequestCondition extends AbstractRequestCondition<Pat @@ -104,7 +105,7 @@ public final class PatternsRequestCondition extends AbstractRequestCondition<Pat
this.patterns = Collections.unmodifiableSet(prependLeadingSlash(patterns));
this.pathHelper = (urlPathHelper != null ? urlPathHelper : new UrlPathHelper());
this.pathMatcher = (pathMatcher != null ? pathMatcher : new ParsingPathMatcher());
this.pathMatcher = (pathMatcher != null ? pathMatcher : new AntPathMatcher());
this.useSuffixPatternMatch = useSuffixPatternMatch;
this.useTrailingSlashMatch = useTrailingSlashMatch;
if (fileExtensions != null) {

5
spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/MvcUriComponentsBuilder.java

@ -22,6 +22,7 @@ import java.util.HashMap; @@ -22,6 +22,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.servlet.http.HttpServletRequest;
import org.aopalliance.intercept.MethodInterceptor;
@ -45,6 +46,7 @@ import org.springframework.core.annotation.AnnotatedElementUtils; @@ -45,6 +46,7 @@ import org.springframework.core.annotation.AnnotatedElementUtils;
import org.springframework.core.annotation.SynthesizingMethodParameter;
import org.springframework.objenesis.ObjenesisException;
import org.springframework.objenesis.SpringObjenesis;
import org.springframework.util.AntPathMatcher;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
import org.springframework.util.PathMatcher;
@ -62,7 +64,6 @@ import org.springframework.web.method.support.CompositeUriComponentsContributor; @@ -62,7 +64,6 @@ import org.springframework.web.method.support.CompositeUriComponentsContributor;
import org.springframework.web.servlet.DispatcherServlet;
import org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping;
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
import org.springframework.web.util.ParsingPathMatcher;
import org.springframework.web.util.UriComponents;
import org.springframework.web.util.UriComponentsBuilder;
@ -98,7 +99,7 @@ public class MvcUriComponentsBuilder { @@ -98,7 +99,7 @@ public class MvcUriComponentsBuilder {
private static final SpringObjenesis objenesis = new SpringObjenesis();
private static final PathMatcher pathMatcher = new ParsingPathMatcher();
private static final PathMatcher pathMatcher = new AntPathMatcher();
private static final ParameterNameDiscoverer parameterNameDiscoverer = new DefaultParameterNameDiscoverer();

5
spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceUrlProvider.java

@ -22,6 +22,7 @@ import java.util.Comparator; @@ -22,6 +22,7 @@ import java.util.Comparator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.logging.Log;
@ -31,9 +32,9 @@ import org.springframework.context.ApplicationContext; @@ -31,9 +32,9 @@ import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.core.annotation.AnnotationAwareOrderComparator;
import org.springframework.util.AntPathMatcher;
import org.springframework.util.PathMatcher;
import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping;
import org.springframework.web.util.ParsingPathMatcher;
import org.springframework.web.util.UrlPathHelper;
/**
@ -53,7 +54,7 @@ public class ResourceUrlProvider implements ApplicationListener<ContextRefreshed @@ -53,7 +54,7 @@ public class ResourceUrlProvider implements ApplicationListener<ContextRefreshed
private UrlPathHelper urlPathHelper = new UrlPathHelper();
private PathMatcher pathMatcher = new ParsingPathMatcher();
private PathMatcher pathMatcher = new AntPathMatcher();
private final Map<String, ResourceHttpRequestHandler> handlerMap = new LinkedHashMap<>();

8
spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/InterceptorRegistryTests.java

@ -37,9 +37,11 @@ import org.springframework.web.servlet.handler.MappedInterceptor; @@ -37,9 +37,11 @@ import org.springframework.web.servlet.handler.MappedInterceptor;
import org.springframework.web.servlet.handler.WebRequestHandlerInterceptorAdapter;
import org.springframework.web.servlet.i18n.LocaleChangeInterceptor;
import org.springframework.web.servlet.theme.ThemeChangeInterceptor;
import org.springframework.web.util.ParsingPathMatcher;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
/**
* Test fixture with a {@link InterceptorRegistry}, two {@link HandlerInterceptor}s and two
@ -153,7 +155,7 @@ public class InterceptorRegistryTests { @@ -153,7 +155,7 @@ public class InterceptorRegistryTests {
private List<HandlerInterceptor> getInterceptorsForPath(String lookupPath) {
PathMatcher pathMatcher = new ParsingPathMatcher();
PathMatcher pathMatcher = new AntPathMatcher();
List<HandlerInterceptor> result = new ArrayList<>();
for (Object interceptor : this.registry.getInterceptors()) {
if (interceptor instanceof MappedInterceptor) {

4
spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupportTests.java

@ -18,6 +18,7 @@ package org.springframework.web.servlet.config.annotation; @@ -18,6 +18,7 @@ package org.springframework.web.servlet.config.annotation;
import java.util.List;
import java.util.Locale;
import javax.servlet.http.HttpServletRequest;
import com.fasterxml.jackson.databind.ObjectMapper;
@ -83,7 +84,6 @@ import org.springframework.web.servlet.resource.ResourceUrlProviderExposingInter @@ -83,7 +84,6 @@ import org.springframework.web.servlet.resource.ResourceUrlProviderExposingInter
import org.springframework.web.servlet.view.BeanNameViewResolver;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
import org.springframework.web.servlet.view.ViewResolverComposite;
import org.springframework.web.util.ParsingPathMatcher;
import org.springframework.web.util.UrlPathHelper;
import static com.fasterxml.jackson.databind.DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES;
@ -321,7 +321,7 @@ public class WebMvcConfigurationSupportTests { @@ -321,7 +321,7 @@ public class WebMvcConfigurationSupportTests {
assertNotNull(urlPathHelper);
assertNotNull(pathMatcher);
assertEquals(ParsingPathMatcher.class, pathMatcher.getClass());
assertEquals(AntPathMatcher.class, pathMatcher.getClass());
}
private ApplicationContext initContext(Class<?>... configClasses) {

9
spring-webmvc/src/test/java/org/springframework/web/servlet/handler/HandlerMethodMappingTests.java

@ -16,8 +16,6 @@ @@ -16,8 +16,6 @@
package org.springframework.web.servlet.handler;
import static org.junit.Assert.*;
import java.lang.reflect.Method;
import java.util.Collections;
import java.util.Comparator;
@ -38,9 +36,12 @@ import org.springframework.web.bind.annotation.RequestMapping; @@ -38,9 +36,12 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.context.support.StaticWebApplicationContext;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.util.ParsingPathMatcher;
import org.springframework.web.util.UrlPathHelper;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
/**
* Test for {@link AbstractHandlerMethodMapping}.
@ -245,7 +246,7 @@ public class HandlerMethodMappingTests { @@ -245,7 +246,7 @@ public class HandlerMethodMappingTests {
private UrlPathHelper pathHelper = new UrlPathHelper();
private PathMatcher pathMatcher = new ParsingPathMatcher();
private PathMatcher pathMatcher = new AntPathMatcher();
public MyHandlerMethodMapping() {

10
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/UrlFilenameViewControllerTests.java

@ -18,16 +18,18 @@ package org.springframework.web.servlet.mvc; @@ -18,16 +18,18 @@ package org.springframework.web.servlet.mvc;
import org.junit.Test;
import static org.junit.Assert.*;
import org.springframework.mock.web.test.MockHttpServletRequest;
import org.springframework.mock.web.test.MockHttpServletResponse;
import org.springframework.ui.ModelMap;
import org.springframework.util.AntPathMatcher;
import org.springframework.util.PathMatcher;
import org.springframework.web.servlet.DispatcherServlet;
import org.springframework.web.servlet.HandlerMapping;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.util.ParsingPathMatcher;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
/**
* @author Juergen Hoeller
@ -36,7 +38,7 @@ import org.springframework.web.util.ParsingPathMatcher; @@ -36,7 +38,7 @@ import org.springframework.web.util.ParsingPathMatcher;
*/
public class UrlFilenameViewControllerTests {
private PathMatcher pathMatcher = new ParsingPathMatcher();
private PathMatcher pathMatcher = new AntPathMatcher();
@Test

Loading…
Cancel
Save