From f353a28ff40a0ae58e1848385b2387ae9b50a449 Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Thu, 16 Oct 2014 21:39:13 -0400 Subject: [PATCH] Polish ResourceUrlEncodingFilter --- .../resource/ResourceUrlEncodingFilter.java | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) 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 1bc4417eb9..3ad462d5f2 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,19 +65,20 @@ public class ResourceUrlEncodingFilter extends OncePerRequestFilter { @Override public String encodeURL(String url) { - 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) { - return super.encodeURL(translatedUrl); - } - } - else { - logger.debug("Request attribute exposing ResourceUrlProvider not found under name: " + name); + ResourceUrlProvider resourceUrlProvider = getResourceUrlProvider(); + if (resourceUrlProvider == null) { + logger.debug("Request attribute exposing ResourceUrlProvider not found."); + return super.encodeURL(url); } - return super.encodeURL(url); + String resolvedUrl = resourceUrlProvider.getForRequestUrl(this.request, url); + return (resolvedUrl != null ? super.encodeURL(resolvedUrl) : super.encodeURL(url)); + } + + private ResourceUrlProvider getResourceUrlProvider() { + String name = ResourceUrlProviderExposingInterceptor.RESOURCE_URL_PROVIDER_ATTR; + return (ResourceUrlProvider) this.request.getAttribute(name); } + } }