|
|
|
@ -1,5 +1,5 @@ |
|
|
|
/* |
|
|
|
/* |
|
|
|
* Copyright 2002-2012 the original author or authors. |
|
|
|
* Copyright 2002-2016 the original author or authors. |
|
|
|
* |
|
|
|
* |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
@ -86,7 +86,8 @@ import org.springframework.web.context.support.ServletContextResource; |
|
|
|
* @see #setDefaultUrl |
|
|
|
* @see #setDefaultUrl |
|
|
|
* @see #setAllowedResources |
|
|
|
* @see #setAllowedResources |
|
|
|
* @see #setApplyLastModified |
|
|
|
* @see #setApplyLastModified |
|
|
|
* @deprecated in favor of the ResourceHttpRequestHandler |
|
|
|
* @deprecated as of Spring 4.3.5, in favor of |
|
|
|
|
|
|
|
* {@link org.springframework.web.servlet.resource.ResourceHttpRequestHandler} |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@SuppressWarnings("serial") |
|
|
|
@SuppressWarnings("serial") |
|
|
|
@Deprecated |
|
|
|
@Deprecated |
|
|
|
@ -177,8 +178,8 @@ public class ResourceServlet extends HttpServletBean { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Return a PathMatcher to use for matching the "allowedResources" URL pattern. |
|
|
|
* Return a {@link PathMatcher} to use for matching the "allowedResources" URL pattern. |
|
|
|
* Default is AntPathMatcher. |
|
|
|
* <p>The default is {@link AntPathMatcher}. |
|
|
|
* @see #setAllowedResources |
|
|
|
* @see #setAllowedResources |
|
|
|
* @see org.springframework.util.AntPathMatcher |
|
|
|
* @see org.springframework.util.AntPathMatcher |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@ -195,7 +196,7 @@ public class ResourceServlet extends HttpServletBean { |
|
|
|
protected final void doGet(HttpServletRequest request, HttpServletResponse response) |
|
|
|
protected final void doGet(HttpServletRequest request, HttpServletResponse response) |
|
|
|
throws ServletException, IOException { |
|
|
|
throws ServletException, IOException { |
|
|
|
|
|
|
|
|
|
|
|
// determine URL of resource to include
|
|
|
|
// Determine URL of resource to include...
|
|
|
|
String resourceUrl = determineResourceUrl(request); |
|
|
|
String resourceUrl = determineResourceUrl(request); |
|
|
|
|
|
|
|
|
|
|
|
if (resourceUrl != null) { |
|
|
|
if (resourceUrl != null) { |
|
|
|
@ -222,7 +223,7 @@ public class ResourceServlet extends HttpServletBean { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// no resource URL specified -> try to include default URL.
|
|
|
|
// No resource URL specified -> try to include default URL.
|
|
|
|
else if (!includeDefaultUrl(request, response)) { |
|
|
|
else if (!includeDefaultUrl(request, response)) { |
|
|
|
throw new ServletException("No target resource URL found for request"); |
|
|
|
throw new ServletException("No target resource URL found for request"); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -272,18 +273,18 @@ public class ResourceServlet extends HttpServletBean { |
|
|
|
if (this.contentType != null) { |
|
|
|
if (this.contentType != null) { |
|
|
|
response.setContentType(this.contentType); |
|
|
|
response.setContentType(this.contentType); |
|
|
|
} |
|
|
|
} |
|
|
|
String[] resourceUrls = |
|
|
|
|
|
|
|
StringUtils.tokenizeToStringArray(resourceUrl, RESOURCE_URL_DELIMITERS); |
|
|
|
String[] resourceUrls = StringUtils.tokenizeToStringArray(resourceUrl, RESOURCE_URL_DELIMITERS); |
|
|
|
for (int i = 0; i < resourceUrls.length; i++) { |
|
|
|
for (String url : resourceUrls) { |
|
|
|
// check whether URL matches allowed resources
|
|
|
|
// Check whether URL matches allowed resources
|
|
|
|
if (this.allowedResources != null && !this.pathMatcher.match(this.allowedResources, resourceUrls[i])) { |
|
|
|
if (this.allowedResources != null && !this.pathMatcher.match(this.allowedResources, url)) { |
|
|
|
throw new ServletException("Resource [" + resourceUrls[i] + |
|
|
|
throw new ServletException("Resource [" + url + |
|
|
|
"] does not match allowed pattern [" + this.allowedResources + "]"); |
|
|
|
"] does not match allowed pattern [" + this.allowedResources + "]"); |
|
|
|
} |
|
|
|
} |
|
|
|
if (logger.isDebugEnabled()) { |
|
|
|
if (logger.isDebugEnabled()) { |
|
|
|
logger.debug("Including resource [" + resourceUrls[i] + "]"); |
|
|
|
logger.debug("Including resource [" + url + "]"); |
|
|
|
} |
|
|
|
} |
|
|
|
RequestDispatcher rd = request.getRequestDispatcher(resourceUrls[i]); |
|
|
|
RequestDispatcher rd = request.getRequestDispatcher(url); |
|
|
|
rd.include(request, response); |
|
|
|
rd.include(request, response); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -311,8 +312,8 @@ public class ResourceServlet extends HttpServletBean { |
|
|
|
if (resourceUrl != null) { |
|
|
|
if (resourceUrl != null) { |
|
|
|
String[] resourceUrls = StringUtils.tokenizeToStringArray(resourceUrl, RESOURCE_URL_DELIMITERS); |
|
|
|
String[] resourceUrls = StringUtils.tokenizeToStringArray(resourceUrl, RESOURCE_URL_DELIMITERS); |
|
|
|
long latestTimestamp = -1; |
|
|
|
long latestTimestamp = -1; |
|
|
|
for (int i = 0; i < resourceUrls.length; i++) { |
|
|
|
for (String url : resourceUrls) { |
|
|
|
long timestamp = getFileTimestamp(resourceUrls[i]); |
|
|
|
long timestamp = getFileTimestamp(url); |
|
|
|
if (timestamp > latestTimestamp) { |
|
|
|
if (timestamp > latestTimestamp) { |
|
|
|
latestTimestamp = timestamp; |
|
|
|
latestTimestamp = timestamp; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -338,8 +339,10 @@ public class ResourceServlet extends HttpServletBean { |
|
|
|
return lastModifiedTime; |
|
|
|
return lastModifiedTime; |
|
|
|
} |
|
|
|
} |
|
|
|
catch (IOException ex) { |
|
|
|
catch (IOException ex) { |
|
|
|
logger.warn("Couldn't retrieve last-modified timestamp of [" + resource + |
|
|
|
if (logger.isWarnEnabled()) { |
|
|
|
"] - using ResourceServlet startup time"); |
|
|
|
logger.warn("Couldn't retrieve last-modified timestamp of " + resource + |
|
|
|
|
|
|
|
" - using ResourceServlet startup time"); |
|
|
|
|
|
|
|
} |
|
|
|
return -1; |
|
|
|
return -1; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|