4646import org .apache .commons .logging .LogFactory ;
4747import org .springframework .core .style .ToStringCreator ;
4848import org .springframework .http .HttpMethod ;
49+ import org .springframework .util .AntPathMatcher ;
50+ import org .springframework .util .PathMatcher ;
4951import org .springframework .web .context .WebApplicationContext ;
5052
5153import com .googlecode .concurrentlinkedhashmap .ConcurrentLinkedHashMap ;
@@ -66,6 +68,7 @@ public class DefaultUrlMappingsHolder implements UrlMappings {
6668
6769 private static final transient Log LOG = LogFactory .getLog (DefaultUrlMappingsHolder .class );
6870 private static final int DEFAULT_MAX_WEIGHTED_CAPACITY = 5000 ;
71+ public static final UrlMappingInfo [] EMPTY_RESULTS = new UrlMappingInfo [0 ];
6972
7073 private int maxWeightedCacheCapacity = DEFAULT_MAX_WEIGHTED_CAPACITY ;
7174 private Map <String , UrlMappingInfo > cachedMatches ;
@@ -79,20 +82,21 @@ public int weightOf(List<UrlMappingInfo> values) {
7982 }
8083 }
8184
82- private List <UrlMapping > urlMappings = new ArrayList <UrlMapping >();
85+ private List <UrlMapping > urlMappings = new ArrayList <>();
8386 private UrlMapping [] mappings ;
84- private List excludePatterns ;
85- private Map <UrlMappingKey , UrlMapping > mappingsLookup = new HashMap <UrlMappingKey , UrlMapping >();
86- private Map <String , UrlMapping > namedMappings = new HashMap <String , UrlMapping >();
87- private UrlMappingsList mappingsListLookup = new UrlMappingsList ();
88- private Set <String > DEFAULT_NAMESPACE_PARAMS = CollectionUtils .newSet (
89- UrlMapping .NAMESPACE , UrlMapping .CONTROLLER , UrlMapping .ACTION );
90- private Set <String > DEFAULT_CONTROLLER_PARAMS = CollectionUtils .newSet (
91- UrlMapping .CONTROLLER , UrlMapping .ACTION );
92- private Set <String > DEFAULT_ACTION_PARAMS = CollectionUtils .newSet (UrlMapping .ACTION );
9387 private UrlCreatorCache urlCreatorCache ;
9488 // capacity of the UrlCreatoreCache is the estimated number of char's stored in cached objects
9589 private int urlCreatorMaxWeightedCacheCapacity = 160000 ;
90+ private final List excludePatterns ;
91+ private final Map <UrlMappingKey , UrlMapping > mappingsLookup = new HashMap <>();
92+ private final Map <String , UrlMapping > namedMappings = new HashMap <>();
93+ private final UrlMappingsList mappingsListLookup = new UrlMappingsList ();
94+ private final Set <String > DEFAULT_NAMESPACE_PARAMS = CollectionUtils .newSet (
95+ UrlMapping .NAMESPACE , UrlMapping .CONTROLLER , UrlMapping .ACTION );
96+ private final Set <String > DEFAULT_CONTROLLER_PARAMS = CollectionUtils .newSet (
97+ UrlMapping .CONTROLLER , UrlMapping .ACTION );
98+ private final Set <String > DEFAULT_ACTION_PARAMS = CollectionUtils .newSet (UrlMapping .ACTION );
99+ private final PathMatcher pathMatcher = new AntPathMatcher ();
96100
97101 public DefaultUrlMappingsHolder (List <UrlMapping > mappings ) {
98102 this (mappings , null , false );
@@ -359,7 +363,7 @@ private UrlCreator resolveUrlCreator(final String controller,
359363 }
360364 }
361365 if (mapping == null || (mapping instanceof ResponseCodeUrlMapping )) {
362- Set <String > lookupParams = new HashSet <String >(DEFAULT_NAMESPACE_PARAMS );
366+ Set <String > lookupParams = new HashSet <>(DEFAULT_NAMESPACE_PARAMS );
363367 Set <String > paramKeys = new HashSet <String >(params .keySet ());
364368 paramKeys .removeAll (lookupParams );
365369 lookupParams .addAll (paramKeys );
@@ -478,6 +482,8 @@ public UrlMappingInfo[] matchAll(String uri) {
478482 }
479483
480484 public UrlMappingInfo [] matchAll (String uri , String httpMethod ) {
485+ if (isExcluded (uri )) return EMPTY_RESULTS ;
486+
481487 boolean anyHttpMethod = httpMethod != null && httpMethod .equalsIgnoreCase (UrlMapping .ANY_HTTP_METHOD );
482488 List <UrlMappingInfo > matchingUrls = new ArrayList <UrlMappingInfo >();
483489 UriToUrlMappingKey cacheKey = new UriToUrlMappingKey (uri , httpMethod , UrlMapping .ANY_VERSION );
@@ -506,7 +512,20 @@ public UrlMappingInfo[] matchAll(String uri, String httpMethod) {
506512 return matchingUrls .toArray (new UrlMappingInfo [matchingUrls .size ()]);
507513 }
508514
515+ private boolean isExcluded (String uri ) {
516+ if (excludePatterns != null ) {
517+ for (Object excludePattern : excludePatterns ) {
518+ if (pathMatcher .match (excludePattern .toString (), uri )) {
519+ return true ;
520+ }
521+ }
522+ }
523+ return false ;
524+ }
525+
509526 public UrlMappingInfo [] matchAll (String uri , String httpMethod , String version ) {
527+ if (isExcluded (uri )) return EMPTY_RESULTS ;
528+
510529 List <UrlMappingInfo > matchingUrls ;
511530 UriToUrlMappingKey cacheKey = new UriToUrlMappingKey (uri , httpMethod , version );
512531 if (cachedListMatches .containsKey (cacheKey )) {
0 commit comments