diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupport.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupport.java index 13e3d1a0097..1bf7e423206 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupport.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupport.java @@ -77,8 +77,8 @@ import org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExc import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter; import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; import org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver; -import org.springframework.web.servlet.resource.PublicResourceUrlProvider; -import org.springframework.web.servlet.resource.PublicResourceUrlProviderExposingInterceptor; +import org.springframework.web.servlet.resource.ResourceUrlProvider; +import org.springframework.web.servlet.resource.ResourceUrlProviderExposingInterceptor; import org.springframework.web.util.UrlPathHelper; /** @@ -244,7 +244,7 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv InterceptorRegistry registry = new InterceptorRegistry(); addInterceptors(registry); registry.addInterceptor(new ConversionServiceExposingInterceptor(mvcConversionService())); - registry.addInterceptor(new PublicResourceUrlProviderExposingInterceptor(resourceUrlPathTranslator())); + registry.addInterceptor(new ResourceUrlProviderExposingInterceptor(resourceUrlPathTranslator())); this.interceptors = registry.getInterceptors(); } return this.interceptors.toArray(); @@ -358,8 +358,8 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv } @Bean - public PublicResourceUrlProvider resourceUrlPathTranslator() { - PublicResourceUrlProvider translator = new PublicResourceUrlProvider(); + public ResourceUrlProvider resourceUrlPathTranslator() { + ResourceUrlProvider translator = new ResourceUrlProvider(); UrlPathHelper pathHelper = getPathMatchConfigurer().getUrlPathHelper(); if (pathHelper != null) { translator.setUrlPathHelper(pathHelper); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/AbstractResourceResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/AbstractResourceResolver.java index a3a50721a78..fa59c7da011 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/AbstractResourceResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/AbstractResourceResolver.java @@ -49,17 +49,17 @@ public abstract class AbstractResourceResolver implements ResourceResolver { List locations, ResourceResolverChain chain); @Override - public String resolvePublicUrlPath(String resourceUrlPath, List locations, + public String resolveUrlPath(String resourceUrlPath, List locations, ResourceResolverChain chain) { if (logger.isTraceEnabled()) { logger.trace("Resolving public URL for path=\"" + resourceUrlPath + "\""); } - return resolvePublicUrlPathInternal(resourceUrlPath, locations, chain); + return resolveUrlPathInternal(resourceUrlPath, locations, chain); } - protected abstract String resolvePublicUrlPathInternal(String resourceUrlPath, + protected abstract String resolveUrlPathInternal(String resourceUrlPath, List locations, ResourceResolverChain chain); } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/DefaultResourceResolverChain.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/DefaultResourceResolverChain.java index 4f52610398c..8d2f2bc6f07 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/DefaultResourceResolverChain.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/DefaultResourceResolverChain.java @@ -21,8 +21,6 @@ import java.util.List; import javax.servlet.http.HttpServletRequest; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.springframework.core.io.Resource; import org.springframework.util.Assert; @@ -65,13 +63,13 @@ class DefaultResourceResolverChain implements ResourceResolverChain { } @Override - public String resolvePublicUrlPath(String resourcePath, List locations) { + public String resolveUrlPath(String resourcePath, List locations) { ResourceResolver resolver = getNextResolver(); if (resolver == null) { return null; } try { - return resolver.resolvePublicUrlPath(resourcePath, locations, this); + return resolver.resolveUrlPath(resourcePath, locations, this); } finally { this.index--; diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/FingerprintResourceResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/FingerprintResourceResolver.java index c6d444f45e2..df80870a86c 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/FingerprintResourceResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/FingerprintResourceResolver.java @@ -23,8 +23,6 @@ import java.util.regex.Pattern; import javax.servlet.http.HttpServletRequest; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.springframework.core.io.Resource; import org.springframework.util.DigestUtils; import org.springframework.util.FileCopyUtils; @@ -97,10 +95,10 @@ public class FingerprintResourceResolver extends AbstractResourceResolver { } @Override - protected String resolvePublicUrlPathInternal(String resourceUrlPath, List locations, + protected String resolveUrlPathInternal(String resourceUrlPath, List locations, ResourceResolverChain chain) { - String baseUrl = chain.resolvePublicUrlPath(resourceUrlPath, locations); + String baseUrl = chain.resolveUrlPath(resourceUrlPath, locations); if (StringUtils.hasText(baseUrl)) { if (logger.isTraceEnabled()) { logger.trace("Getting the original resource to calculate hash"); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/GzipResourceResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/GzipResourceResolver.java index 57f0c809915..bc0b83e2255 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/GzipResourceResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/GzipResourceResolver.java @@ -25,8 +25,6 @@ import java.util.List; import javax.servlet.http.HttpServletRequest; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.springframework.core.io.AbstractResource; import org.springframework.core.io.Resource; @@ -74,10 +72,10 @@ public class GzipResourceResolver extends AbstractResourceResolver { } @Override - protected String resolvePublicUrlPathInternal(String resourceUrlPath, List locations, + protected String resolveUrlPathInternal(String resourceUrlPath, List locations, ResourceResolverChain chain) { - return chain.resolvePublicUrlPath(resourceUrlPath, locations); + return chain.resolveUrlPath(resourceUrlPath, locations); } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/PathResourceResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/PathResourceResolver.java index 347e2c3e84c..ce5d831f298 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/PathResourceResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/PathResourceResolver.java @@ -48,7 +48,7 @@ public class PathResourceResolver extends AbstractResourceResolver { } @Override - protected String resolvePublicUrlPathInternal(String resourceUrlPath, List locations, + protected String resolveUrlPathInternal(String resourceUrlPath, List locations, ResourceResolverChain chain) { return (getResource(resourceUrlPath, locations) != null ? resourceUrlPath : null); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/PrefixResourceResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/PrefixResourceResolver.java index f99a4b6ec50..1637eb6f140 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/PrefixResourceResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/PrefixResourceResolver.java @@ -16,8 +16,6 @@ package org.springframework.web.servlet.resource; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.springframework.core.io.Resource; import org.springframework.util.Assert; import org.springframework.util.StringUtils; @@ -63,10 +61,10 @@ public class PrefixResourceResolver extends AbstractResourceResolver { } @Override - protected String resolvePublicUrlPathInternal(String resourceUrlPath, List locations, + protected String resolveUrlPathInternal(String resourceUrlPath, List locations, ResourceResolverChain chain) { - String baseUrl = chain.resolvePublicUrlPath(resourceUrlPath, locations); + String baseUrl = chain.resolveUrlPath(resourceUrlPath, locations); if (StringUtils.hasText(baseUrl)) { return this.prefix + (baseUrl.startsWith("/") ? baseUrl : "/" + baseUrl); } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceResolver.java index cf821c5123e..c8d2d1bc7f6 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceResolver.java @@ -62,6 +62,6 @@ public interface ResourceResolver { * @param chain the chain of resolvers to delegate to * @return the resolved public URL path or {@code null} if unresolved */ - String resolvePublicUrlPath(String resourcePath, List locations, ResourceResolverChain chain); + String resolveUrlPath(String resourcePath, List locations, ResourceResolverChain chain); } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceResolverChain.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceResolverChain.java index 77d0142032b..05a0e5a02e9 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceResolverChain.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceResolverChain.java @@ -56,6 +56,6 @@ public interface ResourceResolverChain { * @param locations the locations to search in when looking up resources * @return the resolved public URL path or {@code null} if unresolved */ - String resolvePublicUrlPath(String resourcePath, List locations); + String resolveUrlPath(String resourcePath, List locations); } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceUrlEncodingFilter.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceUrlEncodingFilter.java index ef568f1c5fe..45a30ab8029 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceUrlEncodingFilter.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceUrlEncodingFilter.java @@ -65,8 +65,8 @@ public class ResourceUrlEncodingFilter extends OncePerRequestFilter { @Override public String encodeURL(String url) { - String name = PublicResourceUrlProviderExposingInterceptor.RESOURCE_URL_PROVIDER_ATTR; - PublicResourceUrlProvider urlProvider = (PublicResourceUrlProvider) this.request.getAttribute(name); + String name = ResourceUrlProviderExposingInterceptor.RESOURCE_URL_PROVIDER_ATTR; + ResourceUrlProvider urlProvider = (ResourceUrlProvider) this.request.getAttribute(name); if (urlProvider != null) { String translatedUrl = urlProvider.getForRequestUrl(this.request, url); if (translatedUrl != null) { @@ -74,7 +74,7 @@ public class ResourceUrlEncodingFilter extends OncePerRequestFilter { } } else { - logger.debug("Request attribute exposing PublicResourceUrlProvider not found under name: " + name); + logger.debug("Request attribute exposing ResourceUrlProvider not found under name: " + name); } return super.encodeURL(url); } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/PublicResourceUrlProvider.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceUrlProvider.java similarity index 91% rename from spring-webmvc/src/main/java/org/springframework/web/servlet/resource/PublicResourceUrlProvider.java rename to spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceUrlProvider.java index 65aca87afe3..8924075eeec 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/PublicResourceUrlProvider.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceUrlProvider.java @@ -21,6 +21,7 @@ import org.apache.commons.logging.LogFactory; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationListener; import org.springframework.context.event.ContextRefreshedEvent; +import org.springframework.core.OrderComparator; import org.springframework.util.AntPathMatcher; import org.springframework.util.Assert; import org.springframework.util.PathMatcher; @@ -29,7 +30,10 @@ import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping; import org.springframework.web.util.UrlPathHelper; import javax.servlet.http.HttpServletRequest; +import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; +import java.util.List; import java.util.Map; @@ -44,7 +48,7 @@ import java.util.Map; * @author Rossen Stoyanchev * @since 4.1 */ -public class PublicResourceUrlProvider implements ApplicationListener { +public class ResourceUrlProvider implements ApplicationListener { protected final Log logger = LogFactory.getLog(getClass()); @@ -130,10 +134,15 @@ public class PublicResourceUrlProvider implements ApplicationListener beans = applicationContext.getBeansOfType(SimpleUrlHandlerMapping.class); - for (SimpleUrlHandlerMapping hm : beans.values()) { + + Map map = appContext.getBeansOfType(SimpleUrlHandlerMapping.class); + List handlerMappings = new ArrayList(map.values()); + Collections.sort(handlerMappings, new OrderComparator()); + + for (SimpleUrlHandlerMapping hm : handlerMappings) { for (String pattern : hm.getUrlMap().keySet()) { Object handler = hm.getUrlMap().get(pattern); if (handler instanceof ResourceHttpRequestHandler) { @@ -207,7 +216,7 @@ public class PublicResourceUrlProvider implements ApplicationListener