2

Can any one provide me an example implementation to transfer files from http server to Local using Commons VFS API.

I have tried below code,

StandardFileSystemManager manager = new StandardFileSystemManager();
    manager.init();
    if ("http".equals(source.getScheme())) {
            manager.addProvider("http", new HttpFileProvider());
            manager.setCacheStrategy(CacheStrategy.ON_CALL);
            manager.setFilesCache(new SoftRefFilesCache());
    } else if ("https".equals(source.getScheme())) {
            manager.addProvider("https", new HttpsFileProvider());
            manager.setCacheStrategy(CacheStrategy.ON_CALL);
            manager.setFilesCache(new SoftRefFilesCache());
    }...

But I am getting the error below while trying to run.

Caused by: org.apache.commons.vfs2.FileSystemException: Multiple providers registered for URL scheme "http".
at org.apache.commons.vfs2.impl.DefaultFileSystemManager.addProvider(DefaultFileSystemManager.java:180)
at org.apache.commons.vfs2.impl.DefaultFileSystemManager.addProvider(DefaultFileSystemManager.java:158)
at com.scb.smartbatch.adapters.VFSAdapter.copyFiles(VFSAdapter.java:150)
at com.scb.smartbatch.adapters.VFSAdapter.send(VFSAdapter.java:762)
... 33 more

Please provide inputs whether I missed something here.

Copilot
  • 782
  • 6
  • 17
anand_206
  • 31
  • 4

1 Answers1

1

If you use the StandardFileSystemManager() it will read its configuration from the classpath (from provider.xml and vfs-provider.xml files in the core and sandbox jar). It is therefore already initialized with providers for http and https.

You can either do if (manager.hasProvider("http")) around adding the provider or you just skip adding the providers and rely on automatic configuration. Typically you would use VFS.getManager() to get a fully configured FileSystemManager with all known providers registered.

If you want to configure the manager compeltely by hand, you would use a new DefaultFileSystemManger() instead. (this requires to add stuff like cache, replicator and so on).

eckes
  • 10,103
  • 1
  • 59
  • 71