Archive for September, 2007

commons-vfs : Cannot list children of HTTP folders (VFS-79)

Update: I’ve submitted this patch to Apache, with the issue code: VFS-199

I’ve been doing some development with commons-vfs lately and ran into an issue where the http file system provider doesn’t support the listing of http folders. A search on the commons-vfs JIRA yielded no results, but a search on google resulted in a reference to the deleted bug VFS-79. The original author of the bug summed up my problem as:

The following code produces the below exception at f.getChildren(), even though
the specified location is a folder with children. Similar problems exist for
other protocol supported by VFS.

FileSystemManager fsManager = VFS.getManager();
final FileObject f = fsManager.resolveFile(
            "http://people.apache.org/builds/jakarta-commons/nightly/commons-vfs/" );
FileObject[] children = f.getChildren();

Exception in thread “main” org.apache.commons.vfs.FileSystemException: Could
not list the contents of
“http://people.apache.org/builds/jakarta-commons/nightly/commons-vfs”; because
it is not a folder.
        at  org.apache.commons.vfs.provider.AbstractFileObject.getChildren(AbstractFileObject.java:525)
        at com.bashpole.reflectorGadget.reflectionGroup.Sync.test(Sync.java:118)

The bug was marked as won’t fix, with the comment:

Yep, unhappily the http filesystem do not support the getChildren method.

System.err.println(”can list children=” +
f.getFileSystem().hasCapability(Capability.LIST_CHILDREN));

Some people already asked about this feature and maybe also started to
implement it, but not patch has been submitted yet. The problem is, that its
not necessarily easy to parse the html output.

I’m going to need http browse support in a project I’m working on, so I went ahead and added the LIST_CHILDREN capability. I’ve included the patched files to apply to the commons-vfs trunk, ideally I’d like to see this end up on the official trunk but I’d want the Apache guys to check it out first!

There is a decent chance this patch won’t work on some folders and should be considered a proof of concept, so if you find any bugs then please comment here so I can fix them! I’d also be curious to know if you find this patch useful.