tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jan Luehe <Jan.Lu...@Sun.COM>
Subject Re: DO NOT REPLY [Bug 36534] - Context relative URLs returned by ServletContext.getResource() for the same path are not equal
Date Thu, 08 Sep 2005 02:22:22 GMT


Remy Maucherat wrote:
> bugzilla@apache.org wrote:
> 
>>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=36534>.
>>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=36534
>>
>>
>>jan.luehe@sun.com changed:
>>
>>           What    |Removed                     |Added
>>----------------------------------------------------------------------------
>>             Status|RESOLVED                    |REOPENED
>>         Resolution|WONTFIX                     |
>>
>>
>>
>>
>>------- Additional Comments From jan.luehe@sun.com  2005-09-07 19:47 -------
>>Good point about toString(). I have a solution for that as well. Just override
>>org.apache.naming.resources.DirContextURLStreamHandler.toExternalForm() and have
>>it ignore the "authority" part of the URL, as follows (this is copied from
>>java.net.URLStreamHandler.toExternalForm(), with "authority" part ignored):
>>
>>    /**
>>     * Converts a <code>URL</code> of a specific protocol to a
>>     * <code>String</code>.
>>     *
>>     * @param   u   the URL.
>>     * @return  a string representation of the <code>URL</code> argument.
>>     */
>>    protected String toExternalForm(URL u) {
>>
>>	// pre-compute length of StringBuffer
>>	int len = u.getProtocol().length() + 1;
>>	if (u.getPath() != null) {
>>	    len += u.getPath().length();
>>	}
>>	if (u.getQuery() != null) {
>>	    len += 1 + u.getQuery().length();
>>	}
>>	if (u.getRef() != null) 
>>	    len += 1 + u.getRef().length();
>>
>>	StringBuffer result = new StringBuffer(len);
>>	result.append(u.getProtocol());
>>        result.append(":");
>>        if (u.getPath() != null) {
>>            result.append(u.getPath());
>>        }
>>        if (u.getQuery() != null) {
>>            result.append('?');
>>            result.append(u.getQuery());
>>        }
>>	if (u.getRef() != null) {
>>	    result.append("#");
>>            result.append(u.getRef());
>>	}
>>	return result.toString();
>>    }
>>
>>It is important that URLs returned by ServletContext.getResource() that are
>>equal have equals() return TRUE. This works for all other kinds of URLs.
> 
> 
> I hadn't noticed you were the one who filed the bug. Besides skipping 
> the result.append(":"); 

Not sure I understand: the ":" following the protocol is necessary,
so that the printable representation of the context generated URLs
starts with "jndi:".

> you should simply apply the fix, it's a very 
> good solution.

I'm still having problems with CVS, which are preventing me from
committing my fix.

If you can commit this on my behalf, I'd appreciate it.
The complete fix consists of the above diff and the following patch
in org.apache.catalina.core.ApplicationContext:

             try {
                 resources.lookup(path);
                 return new URL
-                    ("jndi", null, 0, getJNDIUri(hostName, fullPath),
-                     new DirContextURLStreamHandler(resources));
+                    ("jndi", "", 0, getJNDIUri(hostName, fullPath),
+		      new DirContextURLStreamHandler(resources));
             } catch (Exception e) {
                 // Ignore
             }

Thanks,

Jan



> Rémy
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org


Mime
View raw message