Uploaded image for project: 'Undertow'
  1. Undertow
  2. UNDERTOW-1561

ServletContext.getResourcePaths() omits Resources that are not available directly on the file system

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • Major
    • None
    • 2.0.21.Final
    • Servlet
    • None

    Description

      In an attempt to fix this Spring Boot issue, I have implemented a custom URLResource subclass that can list resources from a jar. As permitted by the javadoc of Resource, it returns null for both getFile() and getFilePath() as it does not map to a file but to a particular entry within a jar file. Unfortunately, when processing a resource that returns null from getFilePath(), ServletContextImpl.getResourcePaths(String) ignores the resource:

      for (Resource res : resource.list()) {
          Path file = res.getFilePath();
          if (file != null) {
              Path base = res.getResourceManagerRootPath();
              if (base == null) {
                  resources.add(file.toString()); //not much else we can do here
              } else {
                  String filePath = file.toAbsolutePath().toString().substring(base.toAbsolutePath().toString().length());
                  filePath = filePath.replace('\\', '/'); //for windows systems
                  if (Files.isDirectory(file)) {
                      filePath = filePath + "/";
                  }
                  resources.add(filePath);
              }
          }
      }
      

      I considered a workaround when I return a dummy Path along with a null resource manager root path so that the path's toString() is used, but I'm concerned that there may be unexpected side-effects of doing do if getFilePath() is called on the Resource elsewhere.

      Attachments

        Issue Links

          Activity

            People

              rhn-cservice-bbaranow Bartosz Baranowski
              ankinson Andy Wilkinson
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated: