You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by bu...@apache.org on 2007/04/18 13:15:38 UTC
DO NOT REPLY [Bug 42157] New: - URLs returned by ServletContext.getResource() cannot resolve, directories cannot be browsed...
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG�
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=42157>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND�
INSERTED IN THE BUG DATABASE.
http://issues.apache.org/bugzilla/show_bug.cgi?id=42157
Summary: URLs returned by ServletContext.getResource() cannot
resolve, directories cannot be browsed...
Product: Tomcat 5
Version: 5.5.23
Platform: PC
OS/Version: Linux
Status: NEW
Severity: critical
Priority: P1
Component: Catalina
AssignedTo: tomcat-dev@jakarta.apache.org
ReportedBy: rui.damas@gmail.com
The URLs returned by ServletContext.getResource(String) cannot resolve, ie...
URL url = getResource("/WEB-INF/");
// url = "jndi:/servername//WEB-INF/"
URI uri = url.toURI().resolve("aFile.txt");
// uri = "jndi:/servername/WEB-INF/"
// misses the double slash and
uri.toURL().openStream();
// will fail
// noticed also...
URLConnection c = url.openConnection();
c.getInputStream();
// should return a stream containing the lits of files
// (like for the "file" protocol)
// so that directories can be browsed and add to URL.
// and...
c.getContentType();
// could return some special content type so that
// files can be ditinguished from directories or
// maybe something like...
Boolean.parse(c.getRequestProperty("is-directory"));
--
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org
DO NOT REPLY [Bug 42157] - URLs returned by ServletContext.getResource() cannot resolve, directories cannot be browsed...
Posted by bu...@apache.org.
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG�
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=42157>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND�
INSERTED IN THE BUG DATABASE.
http://issues.apache.org/bugzilla/show_bug.cgi?id=42157
------- Additional Comments From rui.damas@gmail.com 2007-04-20 03:08 -------
(In reply to comment #8)
William... you are absolutely right :D
I just read: http://tomcat.apache.org/tomcat-5.5-doc/config/context.html
tested it and it works beautifully \o/
I use tomcat for a few years now... I guess when I started missed that path
detail and until now I've never had trouble.... so I presumed the configuration
was fine (maybe initially used some file already bad configured that worked
fine or simply was being dumb, really don't remember).
I'm sorry for wasting you time on this.
and thank you for clearly care to explain my mistake.
As you say i was trying to help and did spent time reading the source
code (plus the time i tried solve this in the code i'm writing),
so don't be "bothered" at this.
I wish that some day Remy is able to provide such quality as you in his replies.
Again, thank you very much :D
--
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org
DO NOT REPLY [Bug 42157] - URLs returned by ServletContext.getResource() cannot resolve, directories cannot be browsed...
Posted by bu...@apache.org.
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG�
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=42157>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND�
INSERTED IN THE BUG DATABASE.
http://issues.apache.org/bugzilla/show_bug.cgi?id=42157
------- Additional Comments From rui.damas@gmail.com 2007-04-18 10:54 -------
Ok, I know that :), because when i use winstone server (that does not jndi) over
the same webapp i get a "file:" URL from getResource...
But the problem is that the jndi URL returned has the TWO SLASHES after and not
before the server name, dont't know about jndi protocol but i think that this
must be plain wrong because all URLs i've seen have the TWO SLASHES before the
server name and not after.
Would you please give me a better explanation... I still believe this is a bug.
(In reply to comment #3)
> I made a mistake: it will not return a file: URL in most cases. The stream
> handler factory for the jndi: protocol is set during Tomcat startup, however.
--
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org
DO NOT REPLY [Bug 42157] - URLs returned by ServletContext.getResource() cannot resolve, directories cannot be browsed...
Posted by bu...@apache.org.
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG�
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=42157>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND�
INSERTED IN THE BUG DATABASE.
http://issues.apache.org/bugzilla/show_bug.cgi?id=42157
remm@apache.org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|REOPENED |RESOLVED
Resolution| |WONTFIX
------- Additional Comments From remm@apache.org 2007-04-18 15:42 -------
The stream handler factory for the jndi: protocol is set during Tomcat startup,
which means the code you cut & pasted will work, as long as the stream handler
is correctly set. Please do not reopen the report.
--
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org
DO NOT REPLY [Bug 42157] - URLs returned by ServletContext.getResource() cannot resolve, directories cannot be browsed...
Posted by bu...@apache.org.
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG�
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=42157>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND�
INSERTED IN THE BUG DATABASE.
http://issues.apache.org/bugzilla/show_bug.cgi?id=42157
------- Additional Comments From rui.damas@gmail.com 2007-04-19 03:24 -------
Ok... i have taken a look at the source code of version 5.5.23 to better
understand why this behaviour...
The URL is constructed at ApplicationContext.getResource() at lines 501-503:
return new URL
("jndi", "", 0, getJNDIUri(hostName, fullPath),
new DirContextURLStreamHandler(resources));
Where the hostName is part of the path.
Why is the hostName at the host name parameter instead of ""?...
My only guess is that the host name parameter could possibly be
be used to represent jndi resources on other machines and hostName
is used to represent the virtual host, is that why?
But thats not really the problem...
The path gets built using getJNDIUri(hostName, fullPath), lines 967-972:
private static String getJNDIUri(String hostName, String path) {
if (!path.startsWith("/"))
return "/" + hostName + "/" + path;
else
return "/" + hostName + path;
}
Here is where the URL gets the TWO SHASHES...
I see you do check the path... but the hostName is not checked
so the second slash must come from the hostName,
obviously this cannot be solved here because the URL handlers
do understand the path with two slashes.
I started to track where the host name comes from and reached
StandartHost class somewhere arround:
public ObjectName preRegister(MBeanServer server, ObjectName oname )
public ObjectName createObjectName(String domain, ObjectName parent)
public void setName(String name) {
public String getName() {
... Why does the (virtual) hostName comes with a slash?
is it supposed to be like this?
I bumped into this when codding a servlet that uses XSLT transformations,
which uses URI's to resolve resources, because URI.resolve will alter
the two slashes to one, the URLConnection will not work.
This feels ridiculous, is it suposed to not be able use XSLT transformations?
Does this has another solution?
I could use the getRealPath() but that only works for file://, and will
disable the possibility of storing the webapp in a ".war" file.
--
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org
DO NOT REPLY [Bug 42157] - URLs returned by ServletContext.getResource() cannot resolve, directories cannot be browsed...
Posted by bu...@apache.org.
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG�
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=42157>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND�
INSERTED IN THE BUG DATABASE.
http://issues.apache.org/bugzilla/show_bug.cgi?id=42157
------- Additional Comments From remm@apache.org 2007-04-18 09:08 -------
I made a mistake: it will not return a file: URL in most cases. The stream
handler factory for the jndi: protocol is set during Tomcat startup, however.
--
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org
DO NOT REPLY [Bug 42157] - URLs returned by ServletContext.getResource() cannot resolve, directories cannot be browsed...
Posted by bu...@apache.org.
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG�
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=42157>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND�
INSERTED IN THE BUG DATABASE.
http://issues.apache.org/bugzilla/show_bug.cgi?id=42157
------- Additional Comments From rui.damas@gmail.com 2007-04-18 08:23 -------
Ok, the lack of directory listing support i understand.
But as for the URI.resolve... i do not understand.
Shouldn't a URL be URI "compatible"... the error happens because the
getResource returns one of these: "jndi:/servername//WEB-INF/"
shouldn't it be more like "jndi://servername/WEB-INF/" as most URLs,
it makes sense and URIs would work fine.
And i'am running this over a "a regular file environment", bellow is the HOST
element that I'm using in server.xml.
<Host name="alphabit" unpackWARs="false"
appBase="/data/http/">
<Context path="/" docBase="KISSLet"/>
</Host>
(In reply to comment #1)
> This will not be addressed (toURI().resolve is useless, and getInputStream for a
> folder is a proprietary capability). When running Tomcat over a regular file
> based environment, it will return file: URL, but if you keep to normal URL
> manipulation, you may use it over non file based repositories.
(In reply to comment #1)
> This will not be addressed (toURI().resolve is useless, and getInputStream for a
> folder is a proprietary capability). When running Tomcat over a regular file
> based environment, it will return file: URL, but if you keep to normal URL
> manipulation, you may use it over non file based repositories.
--
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org
DO NOT REPLY [Bug 42157] - URLs returned by ServletContext.getResource() cannot resolve, directories cannot be browsed...
Posted by bu...@apache.org.
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG�
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=42157>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND�
INSERTED IN THE BUG DATABASE.
http://issues.apache.org/bugzilla/show_bug.cgi?id=42157
remm@apache.org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution| |WONTFIX
------- Additional Comments From remm@apache.org 2007-04-18 05:17 -------
This will not be addressed (toURI().resolve is useless, and getInputStream for a
folder is a proprietary capability). When running Tomcat over a regular file
based environment, it will return file: URL, but if you keep to normal URL
manipulation, you may use it over non file based repositories.
--
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org
DO NOT REPLY [Bug 42157] - URLs returned by ServletContext.getResource() cannot resolve, directories cannot be browsed...
Posted by bu...@apache.org.
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG�
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=42157>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND�
INSERTED IN THE BUG DATABASE.
http://issues.apache.org/bugzilla/show_bug.cgi?id=42157
rui.damas@gmail.com changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|RESOLVED |REOPENED
Resolution|WONTFIX |
------- Additional Comments From rui.damas@gmail.com 2007-04-18 14:18 -------
When you wrote "toURI().resolve is useless"...
I've searched a bit and that's not correct, since all URLs are URIs
(http://www.google.com/search?q=%22all+URLs+are+URIs%22) using toURI().resolve
should work and be useful.
at the URI java class documentation explains the following format:
[scheme:][//authority][path][?query][#fragment]
and not: [scheme:][/authority//][path][?query][#fragment]
In "jndi:/servername//WEB-INF/" the server name is actually part the of the
path, i tested it and...
URL url = context.getResource("/WEB-INF/");
url.getHost();
// returns ""
url.getPath();
// returns "/servername//WEB-INF/"
I'm reopening the bug, at least till someone confirm that that's way is supposed
to be.
--
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org
DO NOT REPLY [Bug 42157] - URLs returned by ServletContext.getResource() cannot resolve, directories cannot be browsed...
Posted by bu...@apache.org.
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG�
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=42157>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND�
INSERTED IN THE BUG DATABASE.
http://issues.apache.org/bugzilla/show_bug.cgi?id=42157
------- Additional Comments From william.barker@wilshire.com 2007-04-19 22:58 -------
Of course if you had spent 1/20th of the time reading the Tomcat documentation
that you have spent on this, or if you had bothered to ask on the users list,
you would have learned that all of your problems are because of your invalid
<Context> definition from #2. You *must* leave out the ending '/' character
when defining the path in the <Context>.
As Remy has been nice enough to point out (repeatedly), your use case works as
expected in Tomcat.
--
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org