You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Erwin Hogeweg <er...@me.com.INVALID> on 2019/10/30 11:31:48 UTC

Re: commons-vfs-2.4.1 - Question re. usage of VFS.getManager() - SOLVED

Hi Bernd,

Thanks for your reply. When I tried this again today 

	VFS.getManager().getSchemes()

returns the following (impressive) list of schemes:

	[zip, par, ftps, res, ftp, sar, war, file, gz, tmp, http4s, ear, ejb3, jar, sftp, http4, ram]

and 

	VFS.getManager().resolveFile("ftp://ftp.gnu.org/README", opts);
			
works as expected. So I don’t know what happened but it looks like I spent a lot of time chasing a ghost. Oh well, at least I learned a thing or two.

Thanks for your help anyway.


Erwin




> 
> I think the problem in your case is that the default filesystem manager does not know about the ftp: scheme. The error message is a bit missleading (since a fix done, probably we should file a bug for this).
> 
> The default manager does try to load the FtpProvider and tries to register it with ftp: so I assume loading of the provider failed. Maybe you are missing dependencies like commons-net (see the website for the dependencies per provider).
> 
> For debugging you can print manager.getSchemes() to see the available schemes (providers).
> Gruss
> Bernd
> 
> 
> --
> http://bernd.eckenfels.net
> 
> ________________________________
> Von: Erwin Hogeweg <er...@me.com.invalid>
> Gesendet: Mittwoch, Oktober 30, 2019 3:29 AM
> An: Commons Users List
> Betreff: commons-vfs-2.4.1 - Question re. usage of VFS.getManager()
> 
> All -
> 
> I am trying to set up a VFS but I struggled a while to get past a FileSystemException. After looking at the VFS source code I understood what was going on, and I was able to create a work-around. However, I am not sure that what I hacked together is the right approach so I am looking for some guidance from the experts here…
> 
> This is what I was trying to do:
> 
> FileObject path = VFS.getManager().resolveFile("ftp://ftp.gnu.org/README", new FileSystemOptions());
> 
> The issue is, or at least appears to be, that the FileSystemManager doesn’t have a baseFile so the resolveFile blows up with this exception:
> 
> org.apache.commons.vfs2.FileSystemException: Could not find file with URI "ftp://ftp.gnu.org/README" because it is a relative path, and no base URI was provided.
> at org.apache.commons.vfs2.FileSystemException.requireNonNull(FileSystemException.java:87)
> 
> I could not find how/where to define that baseFile so I eventually settled on this work-around:
> 
> StandardFileSystemManager fsManager = (StandardFileSystemManager) VFS.getManager(); // YUCK!
> fsManager.setBaseFile(new File("")); // Another YUCK.
> FileObject path = fsManager.resolveFile("ftp://ftp.gnu.org/README", opts);
> 
> That works, and now I end up with the correct (expected) path. It doesn’t feel right though so any advice would be greatly appreciated.
> 
> 
> Cheers,
> 
> Erwin
> 
>