You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Adam Jack <aj...@trysybase.com> on 2003/08/02 15:20:07 UTC

[VFS] Dynamic FSM Configuration

Hi,

With the (very recent) FTP failures on Gump I notice that my FSM
configuration is more static than I'd like. VFS is now (nicely) much more
dynamic w.r.t providers (with optional compilations) however my
configuration seems pretty tied to the existence of some.

I don't know if what I currently have (attached below) is historical or not,
but I have some issues. I can't go directly to the file configuration
approach because I don't know what working directory I will be run in. Also,
how would I keep my file (there only to be dynamic) in synch with the VFS
one. [I really don't want to limit my users to certain providers, I just
want to be dynamic.]

Here are a few question:

1) Could I load a file from a resource (in my jar, say) and somehow pass
that in to VFS FSM, then do my "final tweaks" w/ Replicator/Base? Is this
the best option?

2) Is there a way I can pass in a provider "ID" and have VFS do the
environment check (against it's own compiled base) and register, or not.

3) Is there a better approach than I have listed here? We just want to be
good VFS users w/ some requirements (tmp/replicator/etc.)

All input appreciated. Thanks in advance/

regards

Adam
--
<http://www.try.sybase.com>
Experience Sybase Technology ...



import org.apache.commons.vfs.AllFileSelector;
import org.apache.commons.vfs.Capability;
import org.apache.commons.vfs.FileObject;
import org.apache.commons.vfs.FileSelector;
import org.apache.commons.vfs.FileSystem;
import org.apache.commons.vfs.FileSystemException;
import org.apache.commons.vfs.FileSystemManager;
import org.apache.commons.vfs.FileType;
import org.apache.commons.vfs.impl.DefaultFileReplicator;
import org.apache.commons.vfs.impl.DefaultFileSystemManager;
import org.apache.commons.vfs.provider.FileProvider;
import org.apache.commons.vfs.provider.local.DefaultLocalFileProvider;
import org.apache.commons.vfs.provider.temp.TemporaryFileProvider;
import org.apache.commons.vfs.provider.url.UrlFileProvider;
import org.apache.commons.vfs.provider.zip.ZipFileProvider;




public static FileSystemManager createFSM(String name, String base)
	throws FileSystemException {

	DefaultFileSystemManager fsm = new DefaultFileSystemManager();
	fsm.setLogger(LogFactory.getLog(name));

	FileProvider fileProvider = new DefaultLocalFileProvider();
	fsm.addProvider("file", fileProvider);

	FileProvider tmpProvider = new TemporaryFileProvider();
	fsm.addProvider("tmp", tmpProvider);

	ZipFileProvider zipProvider = new ZipFileProvider();
	fsm.addProvider(new String[] { "jar", "zip" }, zipProvider);
	fsm.addExtensionMap("zip", "zip");
	fsm.addExtensionMap("jar", "jar");
	fsm.addExtensionMap("application/zip", "zip");

	fsm.setReplicator(new DefaultFileReplicator());

	//
		// Load FTP only if in the environment, and loadable
		//
		try {
			if (null
				== RelativelySafe.thrownIfLoaded(
					"org.apache.commons.net.ftp.FTPFile")) {
				fsm.addProvider(
					"ftp",
					new org.apache.commons.vfs.provider.ftp.FtpFileProvider());
			}
		}
		catch (Exception e) {
		}

	FileProvider httpProvider = new UrlFileProvider();
	fsm.addProvider("http", httpProvider);
	fsm.setDefaultProvider(httpProvider);

	// Set Base Directory for Resolveing Relative To...
	fsm.setBaseFile(new java.io.File(base));

	fsm.init();

	return fsm;
}


RE: [VFS] Dynamic FSM Configuration

Posted by Adam Jack <aj...@trysybase.com>.
Hmm, I create a lot of FSMs in my ant tasks, and I get this (below) each
time. I now recall why I went the "hands on method", I can't take all this
output each time.

Is there a way you could reduce this verbosity (perhaps upon request) and/or
allow the provider XML to set a warn/nowarn flag on each provider, or a
default, or ????

I don't think I can even set my logging severity higher, I don't have hands
on that w/ commons-logging.

Thanks in advance.

regards

Adam

[ruperDepend] Aug 6, 2003 4:15:11 PM
org.apache.commons.vfs.impl.StandardFileSystemManager addProvid
er
[ruperDepend] WARNING: Skipping provider
"org.apache.commons.vfs.provider.ftp.FtpFileProvider" becau
se required class "org.apache.commons.net.ftp.FTPFile" is not available.
[ruperDepend] Aug 6, 2003 4:15:11 PM
org.apache.commons.vfs.impl.StandardFileSystemManager addProvid
er
[ruperDepend] WARNING: Skipping provider
"org.apache.commons.vfs.provider.smb.SmbFileProvider" becau
se required class "jcifs.smb.SmbFile" is not available.
[ruperDepend] Aug 6, 2003 4:15:11 PM
org.apache.commons.vfs.impl.StandardFileSystemManager addProvid
er
[ruperDepend] WARNING: Skipping provider
"org.apache.commons.vfs.provider.http.HttpFileProvider" bec
ause required class "org.apache.commons.httpclient.HttpClient" is not
available.
[ruperDepend] Aug 6, 2003 4:15:11 PM
org.apache.commons.vfs.impl.StandardFileSystemManager addProvid
er
[ruperDepend] WARNING: Skipping provider
"org.apache.commons.vfs.provider.webdav.WebdavFileProvider"
 because required class "org.apache.webdav.lib.WebdavResource" is not
available.
[ruperDepend] Aug 6, 2003 4:15:11 PM
org.apache.commons.vfs.impl.StandardFileSystemManager addProvid
er
[ruperDepend] WARNING: Skipping provider
"org.apache.commons.vfs.provider.sftp.SftpFileProvider" bec
ause required class "com.jcraft.jsch.JSch" is not available.
[ruperDepend] Aug 6, 2003 4:15:11 PM
org.apache.commons.vfs.impl.StandardFileSystemManager addProvid
er
[ruperDepend] WARNING: Skipping provider
"org.apache.commons.vfs.provider.ftp.FtpFileProvider" becau
se required class "org.apache.commons.net.ftp.FTPFile" is not available.
[ruperDepend] Aug 6, 2003 4:15:11 PM
org.apache.commons.vfs.impl.StandardFileSystemManager addProvid
er
[ruperDepend] WARNING: Skipping provider
"org.apache.commons.vfs.provider.smb.SmbFileProvider" becau
se required class "jcifs.smb.SmbFile" is not available.
[ruperDepend] Aug 6, 2003 4:15:11 PM
org.apache.commons.vfs.impl.StandardFileSystemManager addProvid
er
[ruperDepend] WARNING: Skipping provider
"org.apache.commons.vfs.provider.http.HttpFileProvider" bec
ause required class "org.apache.commons.httpclient.HttpClient" is not
available.
[ruperDepend] Aug 6, 2003 4:15:11 PM
org.apache.commons.vfs.impl.StandardFileSystemManager addProvid
er
[ruperDepend] WARNING: Skipping provider
"org.apache.commons.vfs.provider.webdav.WebdavFileProvider"
 because required class "org.apache.webdav.lib.WebdavResource" is not
available.
[ruperDepend] Aug 6, 2003 4:15:11 PM
org.apache.commons.vfs.impl.StandardFileSystemManager addProvid
er
[ruperDepend] WARNING: Skipping provider
"org.apache.commons.vfs.provider.sftp.SftpFileProvider" bec
ause required class "com.jcraft.jsch.JSch" is not available.


RE: [VFS] Dynamic FSM Configuration

Posted by Adam Jack <aj...@trysybase.com>.
Adam wrote:

	Yes.  If HttpClient isn't available, the provider won't get added when the
fsm
	is configured.  And so, http urls will fall through to the default
provider,
	which uses java.net.URL.

Ah yes, thanks, I was forgetting the default would do it.

	> 		fsm.setLogger(LogFactory.getLog(name));

	You don't need to set logger, the fsm will use LogFactory to locate one if
it
	hasn't been set.

Thanks, I'll keep it -- just to pass the "name" in. Helps me grok log output
easier.

	ie, all you really need is this:

	fsm = new StandardFileSystemManager();
	fsm.init();
	fsm.setBaseFile( ... );

Sold, changed to that. Thanks very much for the help/feedback.

regards

Adam


Re: [VFS] Dynamic FSM Configuration

Posted by Adam Murdoch <ad...@apache.org>.
On Wed, 6 Aug 2003 05:05 am, Adam Jack wrote:
> Ok, I am trying StandardFileSystemManager :
>
> Q: With this line in the providers.xml ... if HttpClient isn't available,
> will I still get JDK HTTP?

Yes.  If HttpClient isn't available, the provider won't get added when the fsm 
is configured.  And so, http urls will fall through to the default provider, 
which uses java.net.URL.

> Here is what I have (below) w/ lots of old (DefaultFSM) stuff commented
> out. Does what I have left make sense, or is it redundant?

There's a couple of things left that you don't strictly need:

> 		fsm.setLogger(LogFactory.getLog(name));

You don't need to set logger, the fsm will use LogFactory to locate one if it 
hasn't been set.

> 		fsm.setReplicator(new DefaultFileReplicator());

You don't need to do this.  StandardFileSystemManager.init() will set the 
replicator to the same thing.

ie, all you really need is this:

fsm = new StandardFileSystemManager();
fsm.init();
fsm.setBaseFile( ... );

-- 
Adam


RE: [VFS] Dynamic FSM Configuration

Posted by Adam Jack <aj...@trysybase.com>.
Ok, I am trying StandardFileSystemManager :

Q: With this line in the providers.xml ... if HttpClient isn't available,
will I still get JDK HTTP?

	<provider
class-name="org.apache.commons.vfs.provider.http.HttpFileProvider">
        		<scheme name="http"/>
        		<if-available
class-name="org.apache.commons.httpclient.HttpClient"/>
	</provider>


Here is what I have (below) w/ lots of old (DefaultFSM) stuff commented out.
Does what I have left make sense, or is it redundant?

Thanks in advance.

regards

Adam

	public static FileSystemManager createFSM(String name, String base)
		throws FileSystemException {

//
// Note: Was  w/ manual configuration
//
		DefaultFileSystemManager fsm = new StandardFileSystemManager();
		fsm.setLogger(LogFactory.getLog(name));

		fsm.init();
//
//		Done automatically by Standard
//
//		FileProvider fileProvider = new DefaultLocalFileProvider();
//		fsm.addProvider("file", fileProvider);
//
//		FileProvider tmpProvider = new TemporaryFileProvider();
//		fsm.addProvider("tmp", tmpProvider);

//		ZipFileProvider zipProvider = new ZipFileProvider();
//		fsm.addProvider(new String[] { "jar", "zip" }, zipProvider);
//		fsm.addExtensionMap("zip", "zip");
//		fsm.addExtensionMap("jar", "jar");
//		fsm.addExtensionMap("application/zip", "zip");

		fsm.setReplicator(new DefaultFileReplicator());

// When we used Default We hand coded... w/ Standard it reads these from a
file
//
//		//
//		// Load FTP only if in the environment, and loadable
//		//
//		try {
//			if (null
//				== RelativelySafe.thrownIfLoaded(
//					"org.apache.commons.net.ftp.FTPFile")) {
//				fsm.addProvider(
//					"ftp",
//					new org.apache.commons.vfs.provider.ftp.FtpFileProvider());
//			}
//		}
//		catch (Exception e) {
//		}
//
//		FileProvider httpProvider = new UrlFileProvider();
//		fsm.addProvider("http", httpProvider);
//		fsm.setDefaultProvider(httpProvider);

		// Set Base Directory for Resolveing Relative To...
		fsm.setBaseFile(new java.io.File(base));


		return fsm;
	}

-----Original Message-----
From: Adam Jack [mailto:ajack@trysybase.com]
Sent: Saturday, August 02, 2003 7:20 AM
To: commons-user@jakarta.apache.org
Subject: [VFS] Dynamic FSM Configuration


Hi,

With the (very recent) FTP failures on Gump I notice that my FSM
configuration is more static than I'd like. VFS is now (nicely) much more
dynamic w.r.t providers (with optional compilations) however my
configuration seems pretty tied to the existence of some.

I don't know if what I currently have (attached below) is historical or not,
but I have some issues. I can't go directly to the file configuration
approach because I don't know what working directory I will be run in. Also,
how would I keep my file (there only to be dynamic) in synch with the VFS
one. [I really don't want to limit my users to certain providers, I just
want to be dynamic.]

Here are a few question:

1) Could I load a file from a resource (in my jar, say) and somehow pass
that in to VFS FSM, then do my "final tweaks" w/ Replicator/Base? Is this
the best option?

2) Is there a way I can pass in a provider "ID" and have VFS do the
environment check (against it's own compiled base) and register, or not.

3) Is there a better approach than I have listed here? We just want to be
good VFS users w/ some requirements (tmp/replicator/etc.)

All input appreciated. Thanks in advance/

regards

Adam
--
<http://www.try.sybase.com>
Experience Sybase Technology ...



import org.apache.commons.vfs.AllFileSelector;
import org.apache.commons.vfs.Capability;
import org.apache.commons.vfs.FileObject;
import org.apache.commons.vfs.FileSelector;
import org.apache.commons.vfs.FileSystem;
import org.apache.commons.vfs.FileSystemException;
import org.apache.commons.vfs.FileSystemManager;
import org.apache.commons.vfs.FileType;
import org.apache.commons.vfs.impl.DefaultFileReplicator;
import org.apache.commons.vfs.impl.DefaultFileSystemManager;
import org.apache.commons.vfs.provider.FileProvider;
import org.apache.commons.vfs.provider.local.DefaultLocalFileProvider;
import org.apache.commons.vfs.provider.temp.TemporaryFileProvider;
import org.apache.commons.vfs.provider.url.UrlFileProvider;
import org.apache.commons.vfs.provider.zip.ZipFileProvider;




public static FileSystemManager createFSM(String name, String base)
	throws FileSystemException {

	DefaultFileSystemManager fsm = new DefaultFileSystemManager();
	fsm.setLogger(LogFactory.getLog(name));

	FileProvider fileProvider = new DefaultLocalFileProvider();
	fsm.addProvider("file", fileProvider);

	FileProvider tmpProvider = new TemporaryFileProvider();
	fsm.addProvider("tmp", tmpProvider);

	ZipFileProvider zipProvider = new ZipFileProvider();
	fsm.addProvider(new String[] { "jar", "zip" }, zipProvider);
	fsm.addExtensionMap("zip", "zip");
	fsm.addExtensionMap("jar", "jar");
	fsm.addExtensionMap("application/zip", "zip");

	fsm.setReplicator(new DefaultFileReplicator());

	//
		// Load FTP only if in the environment, and loadable
		//
		try {
			if (null
				== RelativelySafe.thrownIfLoaded(
					"org.apache.commons.net.ftp.FTPFile")) {
				fsm.addProvider(
					"ftp",
					new org.apache.commons.vfs.provider.ftp.FtpFileProvider());
			}
		}
		catch (Exception e) {
		}

	FileProvider httpProvider = new UrlFileProvider();
	fsm.addProvider("http", httpProvider);
	fsm.setDefaultProvider(httpProvider);

	// Set Base Directory for Resolveing Relative To...
	fsm.setBaseFile(new java.io.File(base));

	fsm.init();

	return fsm;
}


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org