Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-8461

ServletContextResource getFile should not rely on getRealPath (for WebLogic 10 compatibility)


    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Complete
    • Affects Version/s: 3.0.5, 3.1 M1, 3.1 M2
    • Fix Version/s: 3.1.2, 3.2 M1
    • Component/s: Web
    • Labels:
    • Last commented by a User:


      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
      • 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:

      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.




            • Assignee:
              juergen.hoeller Juergen Hoeller
              jarndt196 Jason Arndt
              Last updater:
              Trevor Marshall
            • Votes:
              4 Vote for this issue
              6 Start watching this issue


              • Created:
                Days since last comment:
                6 years, 5 weeks, 2 days ago