[
http://www.stripesframework.org/jira/browse/STS-376?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Ben Gunter closed STS-376.
--------------------------
> MockServletContext.getResource() doesn't seem to work
> -----------------------------------------------------
>
> Key: STS-376
> URL: http://www.stripesframework.org/jira/browse/STS-376
> Project: Stripes
> Issue Type: Bug
> Components: Context Management
> Affects Versions: Release 1.4.3
> Environment: OS X 104.9 + Eclipse 3.2
> Reporter: Andrew Jaquith
> Assignee: Ben Gunter
> Fix For: Release 1.5
>
> Attachments: CustomMockServletContext.java
>
>
> I have a snippet of code in my unit tests that attemps to load a resource
> relative to the webroot. Calling MockServletContext.getResource to try to
> obtain this resource fails when the resource name begins with a slash (/),
> which the servlet specification says it must.
> I determined by trial and error that the following code snippet, in which the
> servlet context is in fact a MockServletContext, works as expected:
> url = m_engine.getServletContext().getResource( "WEB-INF/web.xml"
> );
> ...although it is *wrong*. From the ServletContext.getResource(String)
> JavaDoc (J2EE 1.3):
> "Returns a URL to the resource that is mapped to a specified path. The path
> must begin with a "/" and is interpreted as relative to the current context
> root."
> The code that SHOULD work, but does not, is this:
> url = m_engine.getServletContext().getResource(
> "/WEB-INF/web.xml" );
> The root cause of this issue appears to be how MockServletContext actually
> looks up resources. The source code looks like this:
> /** Uses the current classloader to fetch the resource if it can. */
> public URL getResource(String name) throws MalformedURLException {
> return
> Thread.currentThread().getContextClassLoader().getResource(name);
> }
> I believe what is happening is that the servlet context expects a leading
> slash, and if one is supplied it is retained and passed on to the
> classloader's getResource() method. This will cause the file name to be
> interepreted as an absolute path.
> Recommended fix: inside MockServletContext.getResource, trim the leading
> slash if one was passed.
--
This message is automatically generated by JIRA.
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
------------------------------------------------------------------------------
Learn how Oracle Real Application Clusters (RAC) One Node allows customers
to consolidate database storage, standardize their database environment, and,
should the need arise, upgrade to a full multi-node Oracle RAC database
without downtime or disruption
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
Stripes-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-development