|
|
|
@ -36,8 +36,7 @@ import org.springframework.web.util.UrlPathHelper; |
|
|
|
/** |
|
|
|
/** |
|
|
|
* A filter that wraps the {@link HttpServletResponse} and overrides its |
|
|
|
* A filter that wraps the {@link HttpServletResponse} and overrides its |
|
|
|
* {@link HttpServletResponse#encodeURL(String) encodeURL} method in order to |
|
|
|
* {@link HttpServletResponse#encodeURL(String) encodeURL} method in order to |
|
|
|
* translate internal resource request URLs into public URL paths for external |
|
|
|
* translate internal resource request URLs into public URL paths for external use. |
|
|
|
* use. |
|
|
|
|
|
|
|
* |
|
|
|
* |
|
|
|
* @author Jeremy Grelle |
|
|
|
* @author Jeremy Grelle |
|
|
|
* @author Rossen Stoyanchev |
|
|
|
* @author Rossen Stoyanchev |
|
|
|
@ -52,7 +51,8 @@ public class ResourceUrlEncodingFilter extends GenericFilterBean { |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) |
|
|
|
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) |
|
|
|
throws IOException, ServletException { |
|
|
|
throws ServletException, IOException { |
|
|
|
|
|
|
|
|
|
|
|
if (!(request instanceof HttpServletRequest) || !(response instanceof HttpServletResponse)) { |
|
|
|
if (!(request instanceof HttpServletRequest) || !(response instanceof HttpServletResponse)) { |
|
|
|
throw new ServletException("ResourceUrlEncodingFilter only supports HTTP requests"); |
|
|
|
throw new ServletException("ResourceUrlEncodingFilter only supports HTTP requests"); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -63,6 +63,7 @@ public class ResourceUrlEncodingFilter extends GenericFilterBean { |
|
|
|
filterChain.doFilter(wrappedRequest, wrappedResponse); |
|
|
|
filterChain.doFilter(wrappedRequest, wrappedResponse); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static class ResourceUrlEncodingRequestWrapper extends HttpServletRequestWrapper { |
|
|
|
private static class ResourceUrlEncodingRequestWrapper extends HttpServletRequestWrapper { |
|
|
|
|
|
|
|
|
|
|
|
@Nullable |
|
|
|
@Nullable |
|
|
|
@ -78,11 +79,11 @@ public class ResourceUrlEncodingFilter extends GenericFilterBean { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void setAttribute(String name, Object o) { |
|
|
|
public void setAttribute(String name, Object value) { |
|
|
|
super.setAttribute(name, o); |
|
|
|
super.setAttribute(name, value); |
|
|
|
if (ResourceUrlProviderExposingInterceptor.RESOURCE_URL_PROVIDER_ATTR.equals(name)) { |
|
|
|
if (ResourceUrlProviderExposingInterceptor.RESOURCE_URL_PROVIDER_ATTR.equals(name)) { |
|
|
|
if(o instanceof ResourceUrlProvider) { |
|
|
|
if (value instanceof ResourceUrlProvider) { |
|
|
|
initLookupPath((ResourceUrlProvider) o); |
|
|
|
initLookupPath((ResourceUrlProvider) value); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -109,10 +110,11 @@ public class ResourceUrlEncodingFilter extends GenericFilterBean { |
|
|
|
@Nullable |
|
|
|
@Nullable |
|
|
|
public String resolveUrlPath(String url) { |
|
|
|
public String resolveUrlPath(String url) { |
|
|
|
if (this.resourceUrlProvider == null) { |
|
|
|
if (this.resourceUrlProvider == null) { |
|
|
|
logger.debug("Request attribute exposing ResourceUrlProvider not found"); |
|
|
|
logger.trace("ResourceUrlProvider not available via request attribute " + |
|
|
|
|
|
|
|
"ResourceUrlProviderExposingInterceptor.RESOURCE_URL_PROVIDER_ATTR"); |
|
|
|
return null; |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
if (url.startsWith(this.prefixLookupPath)) { |
|
|
|
if (this.indexLookupPath != null && url.startsWith(this.prefixLookupPath)) { |
|
|
|
int suffixIndex = getQueryParamsIndex(url); |
|
|
|
int suffixIndex = getQueryParamsIndex(url); |
|
|
|
String suffix = url.substring(suffixIndex); |
|
|
|
String suffix = url.substring(suffixIndex); |
|
|
|
String lookupPath = url.substring(this.indexLookupPath, suffixIndex); |
|
|
|
String lookupPath = url.substring(this.indexLookupPath, suffixIndex); |
|
|
|
@ -150,4 +152,4 @@ public class ResourceUrlEncodingFilter extends GenericFilterBean { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|