Uploaded image for project: 'XWiki Platform'
  1. XWiki Platform
  2. XWIKI-1113

getResourceAsStream must start with a "/"

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • Minor
    • 1.1 M2
    • 1.0 RC1
    • {Unused} Core
    • None
    • getResource getResourceAsStream patch

    Description

      The Servlet 2.3 specification (and later) states that calls to getResource() and getResourceAsStream() must begin with a "/". SRV.3.5 states:

      The getResource and getResourceAsStream methods take a String with a
      leading "/" as argument which gives the path of the resource relative to the root of
      the context.

      The current implementation first tries to pass it as given (which seems to often be without a slash), and if that fails adds a slash and tries again. Web containers such as WebSphere return null when passed without a "/" (and generates an error), and so each call turns into 2 calls (as well as filling up the log).

      A simple fix is as follows in com.xpn.xwiki.XWiki:

      public InputStream getResourceAsStream(String s) throws MalformedURLException
      {
      if (!s.startsWith("/"))

      { s = "/" + s; }

      InputStream is = getEngineContext().getResourceAsStream(s);

      return is;
      }

      A better fix would probably be to find the places which do not include the "/" and add it.

      Attachments

        Activity

          People

            vmassol Vincent Massol
            lauzon Shawn Lauzon
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: