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

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

    Details

    • 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:
      None
    • Last commented by a User:
      false

      Description

      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:

      @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.

        Attachments

          Activity

            People

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

              Dates

              • Created:
                Updated:
                Resolved:
                Days since last comment:
                5 years, 48 weeks, 5 days ago