diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/setup/StandaloneMockMvcBuilderTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/setup/StandaloneMockMvcBuilderTests.java index 7c31562e7c5e..6307294718ad 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/setup/StandaloneMockMvcBuilderTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/setup/StandaloneMockMvcBuilderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -48,6 +48,7 @@ * @author Rossen Stoyanchev * @author Rob Winch * @author Sebastien Deleuze + * @author Mike Smithson */ public class StandaloneMockMvcBuilderTests { @@ -82,7 +83,7 @@ public void suffixPatternMatch() throws Exception { request = new MockHttpServletRequest("GET", "/persons.xml"); chain = hm.getHandler(request); - assertThat(chain).isNull(); + assertThat(chain).isNotNull(); } @Test // SPR-12553 diff --git a/spring-web/src/main/java/org/springframework/web/util/pattern/PathPattern.java b/spring-web/src/main/java/org/springframework/web/util/pattern/PathPattern.java index 81fd66763897..fee035d5b6cf 100644 --- a/spring-web/src/main/java/org/springframework/web/util/pattern/PathPattern.java +++ b/spring-web/src/main/java/org/springframework/web/util/pattern/PathPattern.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -160,8 +160,7 @@ public class PathPattern implements Comparable { if (elem instanceof CaptureTheRestPathElement || elem instanceof WildcardTheRestPathElement) { this.catchAll = true; } - if (elem instanceof SeparatorPathElement && elem.next != null && - elem.next instanceof WildcardPathElement && elem.next.next == null) { + if (elem instanceof SeparatorPathElement && elem.next instanceof WildcardPathElement && elem.next.next == null) { this.endsWithSeparatorWildcard = true; } elem = elem.next; @@ -325,7 +324,7 @@ public PathContainer extractPathWithinPattern(PathContainer path) { } } - PathContainer resultPath = null; + PathContainer resultPath; if (multipleAdjacentSeparators) { // Need to rebuild the path without the duplicate adjacent separators StringBuilder buf = new StringBuilder(); diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/RequestMappingInfo.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/RequestMappingInfo.java index f2a55f60a232..a4d111f31767 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/RequestMappingInfo.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/RequestMappingInfo.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -280,11 +280,7 @@ public int compareTo(RequestMappingInfo other, ServerWebExchange exchange) { if (result != 0) { return result; } - result = this.customConditionHolder.compareTo(other.customConditionHolder, exchange); - if (result != 0) { - return result; - } - return 0; + return this.customConditionHolder.compareTo(other.customConditionHolder, exchange); } @Override diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/PathMatchConfigurer.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/PathMatchConfigurer.java index 50d6716eb98a..f115417e992d 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/PathMatchConfigurer.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/PathMatchConfigurer.java @@ -44,10 +44,10 @@ public class PathMatchConfigurer { @Nullable - private Boolean suffixPatternMatch; + private Boolean suffixPatternMatch = Boolean.TRUE; @Nullable - private Boolean registeredSuffixPatternMatch; + private Boolean registeredSuffixPatternMatch = Boolean.TRUE; @Nullable private Boolean trailingSlashMatch; @@ -83,7 +83,7 @@ public PathMatchConfigurer setUseSuffixPatternMatch(Boolean suffixPatternMatch) * {@link WebMvcConfigurer#configureContentNegotiation configure content * negotiation}. This is generally recommended to reduce ambiguity and to * avoid issues such as when a "." appears in the path for other reasons. - *

By default this is set to "false". + *

By default this is set to "true". * @see WebMvcConfigurer#configureContentNegotiation * @deprecated as of 5.2.4. See class-level note in * {@link RequestMappingHandlerMapping} on the deprecation of path extension @@ -159,7 +159,8 @@ public Boolean isUseSuffixPatternMatch() { } /** - * Whether to use registered suffixes for pattern matching. + * Whether to use registered suffixes for pattern matching. By default, this + * is set to 'true' * @deprecated as of 5.2.4. See class-level note in * {@link RequestMappingHandlerMapping} on the deprecation of path extension * config options. diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/PatternsRequestCondition.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/PatternsRequestCondition.java index 846e4f646296..a3d52de562cc 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/PatternsRequestCondition.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/PatternsRequestCondition.java @@ -87,7 +87,7 @@ public PatternsRequestCondition(String[] patterns, @Nullable UrlPathHelper urlPa * @param patterns the URL patterns to use; if 0, the condition will match to every request. * @param urlPathHelper for determining the lookup path of a request * @param pathMatcher for path matching with patterns - * @param useSuffixPatternMatch whether to enable matching by suffix (".*") + * @param useSuffixPatternMatch whether to enable matching by suffix (".*"), defaults to "true" * @param useTrailingSlashMatch whether to match irrespective of a trailing slash * @deprecated as of 5.2.4. See class-level note in * {@link org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping} @@ -105,7 +105,7 @@ public PatternsRequestCondition(String[] patterns, @Nullable UrlPathHelper urlPa * @param patterns the URL patterns to use; if 0, the condition will match to every request. * @param urlPathHelper a {@link UrlPathHelper} for determining the lookup path for a request * @param pathMatcher a {@link PathMatcher} for pattern path matching - * @param useSuffixPatternMatch whether to enable matching by suffix (".*") + * @param useSuffixPatternMatch whether to enable matching by suffix (".*"), defaults to "true" * @param useTrailingSlashMatch whether to match irrespective of a trailing slash * @param fileExtensions a list of file extensions to consider for path matching * @deprecated as of 5.2.4. See class-level note in diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerMapping.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerMapping.java index 9b679e493818..f05020a7da0f 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerMapping.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerMapping.java @@ -73,6 +73,7 @@ * @author Arjen Poutsma * @author Rossen Stoyanchev * @author Sam Brannen + * @author Mike Smithson * @since 3.1 */ public class RequestMappingHandlerMapping extends RequestMappingInfoHandlerMapping @@ -80,7 +81,7 @@ public class RequestMappingHandlerMapping extends RequestMappingInfoHandlerMappi private boolean useSuffixPatternMatch = true; - private boolean useRegisteredSuffixPatternMatch = false; + private boolean useRegisteredSuffixPatternMatch = true; private boolean useTrailingSlashMatch = true; @@ -113,7 +114,7 @@ public void setUseSuffixPatternMatch(boolean useSuffixPatternMatch) { * explicitly registered with the {@link ContentNegotiationManager}. This * is generally recommended to reduce ambiguity and to avoid issues such as * when a "." appears in the path for other reasons. - *

By default this is set to "false". + *

By default this is set to "true". * @deprecated as of 5.2.4. See class level comment about deprecation of * path extension config options note also that in 5.3 the default for this * property will switch from {@code false} to {@code true}. diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerMappingTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerMappingTests.java index 3a5b7a2fce41..eb3dbb3a5b61 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerMappingTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerMappingTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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.lang.annotation.Target; import java.lang.reflect.Method; import java.security.Principal; -import java.util.Arrays; import java.util.Collections; import java.util.HashSet; import java.util.Map; @@ -59,6 +58,7 @@ * * @author Rossen Stoyanchev * @author Sam Brannen + * @author Mike Smithson */ public class RequestMappingHandlerMappingTests { @@ -73,7 +73,7 @@ public class RequestMappingHandlerMappingTests { @Test public void useRegisteredSuffixPatternMatch() { assertThat(this.handlerMapping.useSuffixPatternMatch()).isTrue(); - assertThat(this.handlerMapping.useRegisteredSuffixPatternMatch()).isFalse(); + assertThat(this.handlerMapping.useRegisteredSuffixPatternMatch()).isTrue(); Map fileExtensions = Collections.singletonMap("json", MediaType.APPLICATION_JSON); PathExtensionContentNegotiationStrategy strategy = new PathExtensionContentNegotiationStrategy(fileExtensions); @@ -85,7 +85,7 @@ public void useRegisteredSuffixPatternMatch() { assertThat(this.handlerMapping.useSuffixPatternMatch()).isTrue(); assertThat(this.handlerMapping.useRegisteredSuffixPatternMatch()).isTrue(); - assertThat(this.handlerMapping.getFileExtensions()).isEqualTo(Arrays.asList("json")); + assertThat(this.handlerMapping.getFileExtensions()).isEqualTo(Collections.singletonList("json")); } @Test @@ -159,6 +159,7 @@ public void pathPrefix() throws NoSuchMethodException { @Test // gh-23907 public void pathPrefixPreservesPathMatchingSettings() throws NoSuchMethodException { this.handlerMapping.setUseSuffixPatternMatch(false); + this.handlerMapping.setUseRegisteredSuffixPatternMatch(false); this.handlerMapping.setPathPrefixes(Collections.singletonMap("/api", HandlerTypePredicate.forAnyHandlerType())); this.handlerMapping.afterPropertiesSet(); @@ -175,7 +176,7 @@ public void pathPrefixPreservesPathMatchingSettings() throws NoSuchMethodExcepti } @Test - public void resolveRequestMappingViaComposedAnnotation() throws Exception { + public void resolveRequestMappingViaComposedAnnotation() { RequestMappingInfo info = assertComposedAnnotationMapping("postJson", "/postJson", RequestMethod.POST); assertThat(info.getConsumesCondition().getConsumableMediaTypes().iterator().next().toString()) @@ -185,7 +186,7 @@ public void resolveRequestMappingViaComposedAnnotation() throws Exception { } @Test // SPR-14988 - public void getMappingOverridesConsumesFromTypeLevelAnnotation() throws Exception { + public void getMappingOverridesConsumesFromTypeLevelAnnotation() { RequestMappingInfo requestMappingInfo = assertComposedAnnotationMapping(RequestMethod.POST); ConsumesRequestCondition condition = requestMappingInfo.getConsumesCondition(); @@ -206,31 +207,31 @@ public void consumesWithOptionalRequestBody() { } @Test - public void getMapping() throws Exception { + public void getMapping() { assertComposedAnnotationMapping(RequestMethod.GET); } @Test - public void postMapping() throws Exception { + public void postMapping() { assertComposedAnnotationMapping(RequestMethod.POST); } @Test - public void putMapping() throws Exception { + public void putMapping() { assertComposedAnnotationMapping(RequestMethod.PUT); } @Test - public void deleteMapping() throws Exception { + public void deleteMapping() { assertComposedAnnotationMapping(RequestMethod.DELETE); } @Test - public void patchMapping() throws Exception { + public void patchMapping() { assertComposedAnnotationMapping(RequestMethod.PATCH); } - private RequestMappingInfo assertComposedAnnotationMapping(RequestMethod requestMethod) throws Exception { + private RequestMappingInfo assertComposedAnnotationMapping(RequestMethod requestMethod) { String methodName = requestMethod.name().toLowerCase(); String path = "/" + methodName; @@ -238,7 +239,7 @@ private RequestMappingInfo assertComposedAnnotationMapping(RequestMethod request } private RequestMappingInfo assertComposedAnnotationMapping(String methodName, String path, - RequestMethod requestMethod) throws Exception { + RequestMethod requestMethod) { Class clazz = ComposedAnnotationController.class; Method method = ClassUtils.getMethod(clazz, methodName, (Class[]) null);