You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Peter Crowther <Pe...@melandra.com> on 2004/11/12 15:32:25 UTC
getResource (was RE: URL.setURLStreamHandlerFactory - Tomcat 5.0)
> From: Shapira, Yoav [mailto:Yoav.Shapira@mpi.com]
Yoav, I have *no* idea what this list would do without you...
> We discussed
> this back as jar as June: see the thread and accompanying
> Bugzilla issue
> at http://issues.apache.org/bugzilla/show_bug.cgi?id=29631.
> We decided
> not to allow customization of this for 5.0.x, as too much would be
> involved.
Saw it - hence my response on this list.
> However, before even opening such a discussion, we should consider
> alternatives for your use-case.
Absolutely!
> >- I want to read X.xml from code within the JSP. What are the ways,
> >accoring to the JSP and servlet specs, that I can do this?
>
> Numerous ways, with two good ones coming to mind and two bad ones.
>
> Good:
> URL xUrl = getServletContext().getResource("/path/to/x.xml");
OK.
> URL xUrl = getClass().getResource("/path/to/x.xml/on/classpath");
OK. That's an interesting case, may need to hack with the classloader.
> Bad:
> URL xUrl = new File("/path/to/x.xml").toURI().toURL();
I'm willing to allow this to fail. To be honest, I can't see how it
works sensibly anyway...
> URL xUrl = getServletContext().getRealPath("/path/to/x.xml");
Heh. I know a few that do this... it'd be nice to allow this, possibly
by replacing the implementation of getRealPath(), but I'm also willing
to let it fail.
> You would then parse from a URL using the JAXP APIs, that's fairly
> standard. Or maybe another higher-level tool like JDOM if that's your
> cup of tea.
Yes. So, by this time, I need to have remapped the resource so that
opening a stream on the URL gives the 'right' result.
> But note in all these ways the scheme of the URL doesn't
> matter, it's up
> to the server to resolve them. The two Good ones above would
> be jndi:/ URLs.
Indeed. Which is why I have this nasty suspicion I need to get hold of
the stream handler factory - although potentially it sounds like I could
get away with wrapping the jndi: implementation and intercepting
getRealPath().
> If the container can't resolve it using getResource, that means your
> webapp is not compliant to the Servlet Spec.
Well, that's a nice simple statement to work to :-). Thanks! We're
willing to force servlets to be compliant - and to hack Catalina if
necessary, although we'd prefer not to.
> Your resource resolution would be relative to either
> your docBase or your classpath, neither of which are affected by where
> your JSP is.
Cool.
Thanks very much for your help - I'll take a look at this and see what I
can do. If anyone can think of a funnel in Catalina (or elsewhere)
through which all the legitimate requests pass, I'd appreciate knowing
about it as I may be able to intercept there.
- Peter
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org