-
Notifications
You must be signed in to change notification settings - Fork 38.7k
Description
Jason Arndt opened SPR-8461 and commented
When using the ResourceHttpRequestHandler to serve static resources the ServletContextResource's getFile() method that is used doesn't work when not deploying exploded.
Here is the scenario:
-
wire up in spring config
<mvc:resources mapping="/resources/**" location="/resources/" /> -
DispatcherServlet gets the request and delegates to the ResourceHttpRequestHandler.getResource()
-
ResourceHttpRequestHandler uses the ServletContextResource from it's list of locations to check "exists" and "readable"
-
ServletContextResource says yes it exists
-
isReadable() hops to AbstractFileResolvingResource, which determines that is is a "file system resolution" and calls getFile() on ServletContextResource. NOTE: the url that is returned by Weblogic is file:c:/weblogic/tmp/blah/blah/blah/resources/images/img.gif
-
The ServletContextResource.getFile() uses WebUtils.getRealPath(), which is returning /resources/images/img.gif and it tries to then create a File object.
I was able to work around this issue by creating and plugging in a custom ServletContextResource class that overrides the getFile() method and does this:
@Override
public File getFile() throws IOException {
////////////////////////////////////////////////////
//TODO: this fixes a Bug in spring...they are using file path resolution, so use it here too...
// @see
AbstractFileResolvingResource.isReadable()
//String realPath = WebUtils.getRealPath(this.servletContext, this.path);
//return new File(realPath);
////////////////////////////////////////////////////////
URL url = getServletContext().getResource(getPath());
String realPath = url.getPath();
return new File(realPath);
}
I have tested this using Weblogic 10.3 deployed exploded, not exploded, and using the eclipse plugin which is basically exploded.
Affects: 3.0.5, 3.1 M1, 3.1 M2
4 votes, 6 watchers