Backported DispatcherServlet and ServletContextResourcePatternResolver refinements

Issue: SPR-13011
This commit is contained in:
Juergen Hoeller
2015-05-11 19:58:36 +02:00
parent eb6368ca3f
commit adb54b2c69
2 changed files with 101 additions and 81 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -37,8 +37,8 @@ import org.springframework.util.StringUtils;
/**
* ServletContext-aware subclass of {@link PathMatchingResourcePatternResolver},
* able to find matching resources below the web application root directory
* via Servlet 2.3's {@code ServletContext.getResourcePaths}.
* Falls back to the superclass' file system checking for other resources.
* via {@link ServletContext#getResourcePaths}. Falls back to the superclass'
* file system checking for other resources.
*
* @author Juergen Hoeller
* @since 1.1.2
@@ -160,15 +160,20 @@ public class ServletContextResourcePatternResolver extends PathMatchingResourceP
}
try {
JarFile jarFile = new JarFile(jarFilePath);
for (Enumeration<JarEntry> entries = jarFile.entries(); entries.hasMoreElements();) {
JarEntry entry = entries.nextElement();
String entryPath = entry.getName();
if (getPathMatcher().match(entryPattern, entryPath)) {
result.add(new UrlResource(
ResourceUtils.URL_PROTOCOL_JAR,
ResourceUtils.FILE_URL_PREFIX + jarFilePath + ResourceUtils.JAR_URL_SEPARATOR + entryPath));
try {
for (Enumeration<JarEntry> entries = jarFile.entries(); entries.hasMoreElements();) {
JarEntry entry = entries.nextElement();
String entryPath = entry.getName();
if (getPathMatcher().match(entryPattern, entryPath)) {
result.add(new UrlResource(
ResourceUtils.URL_PROTOCOL_JAR,
ResourceUtils.FILE_URL_PREFIX + jarFilePath + ResourceUtils.JAR_URL_SEPARATOR + entryPath));
}
}
}
finally {
jarFile.close();
}
}
catch (IOException ex) {
if (logger.isWarnEnabled()) {