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=32886>.
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=32886
------- Additional Comments From [email protected] 2006-05-18 22:34 -------
(In reply to comment #14)
> I bumped into the problem as well. 2.1 didn't work for me.
> A solution was to change a part of WebdavResource.setWebdavProperties after
>
> if (!itself) {
> String myURI = httpURL.getEscapedURI();
>
> ...
>
> to
>
> if (!itself) {
> String myURI = httpURL.getEscapedURI();
> final String adjustedHref = href.endsWith("/") ?
> href.substring(0, href.length() - 1) : href;
> final String name = URIUtil.getName(adjustedHref);
> char[] childURI = (myURI + (myURI.endsWith("/") ? "" : "/")
> + name).toCharArray();
>
> the problem is that children's hrefs can end with '/' and in this case
> URIUtil.getName returns empty string. Because of that childURI is the same as
> myURI (bug!!!)
Thanks Igor! Everything works fine now. Also thanks to Robert and Philip. For
those who want a fast cut-and-paste solution, simply replace the entire
protected void setWebdavProperties(Enumeration responses)
method in org.apache.webdav.lib.WebdavResource with the following code:
// START: FIX /////////////////////////////////////////////////////
/**
* Set WebDAV properties following to the given http URL.
* This method is fundamental for getting information of a collection.
*
* @param responses An enumeration over {@link ResponseEntity} items, one
* for each resource for which information was returned via PROPFIND.
*
* @exception HttpException
* @exception IOException The socket error with a server.
*/
protected void setWebdavProperties(Enumeration responses)
throws HttpException, IOException {
// Make the resources in the collection empty.
childResources.removeAll();
while (responses.hasMoreElements()) {
ResponseEntity response =
(ResponseEntity) responses.nextElement();
boolean itself = false;
String href = response.getHref();
if (!href.startsWith("/"))
href = URIUtil.getPath(href);
href = decodeMarks(href);
/*
* Decode URIs to common (unescaped) format for comparison
* as HttpClient.URI.setPath() doesn't escape $ and : chars.
*/
String httpURLPath = httpURL.getPath();
String escapedHref = URIUtil.decode(href);
// Normalize them to both have trailing slashes if they differ by
one in length.
int lenDiff = escapedHref.length() - httpURLPath.length();
int compareLen = 0;
if ( lenDiff == -1 && !escapedHref.endsWith("/")) {
compareLen = escapedHref.length();
lenDiff = 0;
}
else
if ( lenDiff == 1 && !httpURLPath.endsWith("/")) {
compareLen = httpURLPath.length();
lenDiff = 0;
}
// if they are the same length then compare them.
if (lenDiff == 0) {
if ((compareLen == 0 && httpURLPath.equals(escapedHref))
|| httpURLPath.regionMatches(0, escapedHref, 0, compareLen))
{
// escaped href and http path are the same
// Set the status code for this resource.
if (response.getStatusCode() > 0)
setStatusCode(response.getStatusCode());
setExistence(true);
itself = true;
}
}
// Get to know each resource.
WebdavResource workingResource = null;
if (itself) {
workingResource = this;
}
else {
workingResource = createWebdavResource(client);
workingResource.setDebug(debug);
}
// clear the current lock set
workingResource.setLockDiscovery(null);
// Process the resource's properties
Enumeration properties = response.getProperties();
while (properties.hasMoreElements()) {
Property property = (Property) properties.nextElement();
// ------------------------------ Checking WebDAV properties
workingResource.processProperty(property);
}
String displayName = workingResource.getDisplayName();
if (displayName == null || displayName.trim().equals("")) {
displayName = getName(href);
}
/** BUGGY CODE
if (!itself) {
String myURI = httpURL.getEscapedURI();
char[] childURI = (myURI + (myURI.endsWith("/") ? "" : "/")
+ URIUtil.getName(href)).toCharArray();
HttpURL childURL = httpURL instanceof HttpsURL
? new HttpsURL(childURI)
: new HttpURL(childURI);
childURL.setRawAuthority(httpURL.getRawAuthority());
workingResource.setHttpURL(childURL, NOACTION, defaultDepth);
workingResource.setExistence(true);
workingResource.setOverwrite(getOverwrite());
}
*/
/** FIX ********/
if (!itself) {
String myURI = httpURL.getEscapedURI();
/**
Checks if href contains trailing '/', and if so removes it.
This ensures URIUtil.getName does not return an empty
String when we don't want it to.
See http://issues.apache.org/bugzilla/show_bug.cgi?id=32886
for more information.
*/
String fixedHref = href.endsWith("/") ?
href.substring(0, href.length() - 1) : href;
char[] childURI = (myURI + (myURI.endsWith("/") ? "" : "/")
+ URIUtil.getName(fixedHref)).toCharArray();
HttpURL childURL = httpURL instanceof HttpsURL
? new HttpsURL(childURI)
: new HttpURL(childURI);
childURL.setRawAuthority(httpURL.getRawAuthority());
workingResource.setHttpURL(childURL, NOACTION, defaultDepth);
workingResource.setExistence(true);
workingResource.setOverwrite(getOverwrite());
}
/**************/
workingResource.setDisplayName(displayName);
if (!itself)
childResources.addResource(workingResource);
}
}
// END: FIX /////////////////////////////////////////////////////
The code is based on Igor's solution and should work fine. Please post here if
you stumble upon any issues the fix causes. In the meantime however, its
working perfectly for me.
Cheers!
Mike N. Christoff
--
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.
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.