简体   繁体   中英

Using Commons-VFS over HTTP

I am trying to browse and retrieve files from an HTTP server using the Commons VFS to implement the directory browsing functionality, find below my code snippet,

try {
    StandardFileSystemManager manager = new StandardFileSystemManager();
    manager.addProvider("http", new HttpFileProvider());
    manager.setCacheStrategy(CacheStrategy.ON_CALL);
    manager.setFilesCache(new SoftRefFilesCache());
    FileObject fileObject = manager.resolveFile("http://localhost");
    System.out.println(fileObject.getChildren());
} catch (FileSystemException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

But when i run this code i get the following exception,

org.apache.commons.vfs.FileSystemException: Could not list the contents of "http://localhost/" because it is not a folder.
at org.apache.commons.vfs.provider.AbstractFileObject.getChildren(AbstractFileObject.java:527)
at org.apache.commons.vfs.impl.DecoratedFileObject.getChildren(DecoratedFileObject.java:105)
at org.apache.commons.vfs.cache.OnCallRefreshFileObject.getChildren(OnCallRefreshFileObject.java:105)
at VFSClient.main(VFSClient.java:31)

But the server is up and running and am able to browse the directories.

Can anyone tell me what could be reason for this error, am I missing something ??

Consider implementing a simple concrete repo on FS2 . FS2 is a middleware api that handles all the CRUD, etc operations you need in a filesystem but can be backed by any persistence mechanism relatively easily.

HTTP seems not to support LIST_CHILDREN:

fileObject.getFileSystem().hasCapability(Capability.LIST_CHILDREN)

would return false

what version of VFS are you using? maybe v2.0 would help. The documentation says so: http://commons.apache.org/vfs/filesystems.html

Contrary to what the documentation says, I don't think this is implemented yet. Take a look at https://issues.apache.org/jira/browse/VFS-199

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM