History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: XWIKI-1113
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Minor Minor
Assignee: Vincent Massol
Reporter: Shawn Lauzon
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
XWiki Core

getResourceAsStream must start with a "/"

Created: 20/Apr/07 02:40   Updated: 06/Jun/07 13:49
Component/s: Core
Affects Version/s: 1.0 RC1
Fix Version/s: 1.1 M2

File Attachments: 1. Text File XWIKI-1113.patch (2 kb)


keywords: getResource getResourceAsStream patch
Date of First Response: 06/Jun/07 13:49
Resolution Date: 06/Jun/07 13:49


 Description  « Hide
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.



 All   Comments   Change History      Sort Order: Ascending order - Click to sort in descending order
Shawn Lauzon - 20/Apr/07 02:41
Changed from Build (accident) to Core

Shawn Lauzon - 06/Jun/07 13:30
Attached patch which fixes this problem. There seem to be only two places that don't start the call with a '/', and when those are fixed the warnings disappear.

Vincent Massol - 06/Jun/07 13:49
Applied as is, thanks!

Next time, make sure to create the patch with directories relative to the xwiki source tree (your patch had absolute paths which made it a little bit harder to apply).