use of org.apache.commons.vfs2.FileSystemOptions in project artisynth_core by artisynth.
the class FileCacher method setDefaultFsOptions.
public static void setDefaultFsOptions(FileSystemOptions opts) throws FileSystemException {
// SSH Defaults
// Don't check host key
// Use paths relative to root (as opposed to the user's home dir)
// 10 second timeout
SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(opts, "no");
SftpFileSystemConfigBuilder.getInstance().setUserDirIsRoot(opts, true);
SftpFileSystemConfigBuilder.getInstance().setTimeout(opts, 10000);
/**
* Allow connection to silly UBC servers who don't update their credentials
*/
TrustStrategy[] ts = { new UnsafeTrustStrategy() };
HttpFileSystemConfigBuilder httpBuilder = HttpFileSystemConfigBuilder.getInstance();
WebdavFileSystemConfigBuilder webdavBuilder = WebdavFileSystemConfigBuilder.getInstance();
// allow all SSL connections
httpBuilder.setTrustStrategies(opts, ts);
webdavBuilder.setTrustStrategies(opts, ts);
// silly deprecated UBC cipher suite
String[] ciphers = httpBuilder.getDefaultSSLCipherSuites();
ciphers = Arrays.copyOf(ciphers, ciphers.length + 1);
ciphers[ciphers.length - 1] = "SSL_RSA_WITH_RC4_128_SHA";
httpBuilder.setEnabledSSLCipherSuites(opts, ciphers);
webdavBuilder.setEnabledSSLCipherSuites(opts, ciphers);
}
use of org.apache.commons.vfs2.FileSystemOptions in project esup-sgc by EsupPortail.
the class VfsAccessService method open.
protected void open() throws FileSystemException {
if (root == null) {
FileSystemOptions fsOptions = new FileSystemOptions();
fsManager = VFS.getManager();
root = fsManager.resolveFile(uri, fsOptions);
}
}
use of org.apache.commons.vfs2.FileSystemOptions in project pentaho-kettle by pentaho.
the class ConnectionManagerTest method testNullConnectionName.
@Test
public void testNullConnectionName() {
FileSystemOptions fileSystemOptions = VFSHelper.getOpts("file://fakefile.ktr", null);
Assert.assertNull(fileSystemOptions);
}
use of org.apache.commons.vfs2.FileSystemOptions in project pentaho-kettle by pentaho.
the class KettleSftpFileSystemConfigBuilder method setParameter.
/**
* Publicly expose a generic way to set parameters
*/
@Override
public void setParameter(FileSystemOptions opts, String name, String value, String fullParameterName, String vfsUrl) throws IOException {
if (!fullParameterName.startsWith("vfs.sftp")) {
// This is not an SFTP parameter. Delegate to the generic handler
super.setParameter(opts, name, value, fullParameterName, vfsUrl);
} else {
// Check for the presence of a host in the full variable name
try {
// Parse server name from vfsFilename
FileNameParser sftpFilenameParser = SftpFileNameParser.getInstance();
URLFileName file = (URLFileName) sftpFilenameParser.parseUri(null, null, vfsUrl);
if (!parameterContainsHost(fullParameterName) || fullParameterName.endsWith(file.getHostName())) {
// Match special cases for parameter names
if (name.equalsIgnoreCase("AuthKeyPassphrase")) {
setParam(opts, UserInfo.class.getName(), new PentahoUserInfo(value));
} else if (name.equals("identity")) {
IdentityInfo[] identities = (IdentityInfo[]) this.getParam(opts, IDENTITY_KEY);
if (identities == null) {
identities = new IdentityInfo[] { new IdentityInfo(new File(value)) };
} else {
// Copy, in a Java 5 friendly manner, identities into a larger array
IdentityInfo[] temp = new IdentityInfo[identities.length + 1];
System.arraycopy(identities, 0, temp, 0, identities.length);
identities = temp;
identities[identities.length - 1] = new IdentityInfo(new File(value));
}
setParam(opts, IDENTITY_KEY, identities);
} else {
super.setParameter(opts, name, value, fullParameterName, vfsUrl);
}
} else {
// No host match found
log.logDebug("No host match found for: " + fullParameterName);
}
} catch (IOException e) {
log.logError("Failed to set VFS parameter: [" + fullParameterName + "] " + value, e);
}
}
}
use of org.apache.commons.vfs2.FileSystemOptions in project pentaho-kettle by pentaho.
the class KettleVFS method getFileObject.
// IMPORTANT:
// We have one problem with VFS: if the file is in a subdirectory of the current one: somedir/somefile
// In that case, VFS doesn't parse the file correctly.
// We need to put file: in front of it to make it work.
// However, how are we going to verify this?
//
// We are going to see if the filename starts with one of the known protocols like file: zip: ram: smb: jar: etc.
// If not, we are going to assume it's a file, when no scheme found ( flag as null ), and it only changes if
// a scheme is provided.
//
public static FileObject getFileObject(String vfsFilename, VariableSpace space, FileSystemOptions fsOptions) throws KettleFileException {
// Protect the code below from invalid input.
if (vfsFilename == null) {
throw new IllegalArgumentException("Unexpected null VFS filename.");
}
try {
FileSystemManager fsManager = getInstance().getFileSystemManager();
String[] schemes = fsManager.getSchemes();
String scheme = getScheme(schemes, vfsFilename);
// Waiting condition - PPP-4374:
// We have to check for hasScheme even if scheme is null because that scheme could not
// be available by getScheme at the time we validate our scheme flag ( Kitchen loading problem )
// So we check if - even it has not a scheme - our vfsFilename has a possible scheme format (PROVIDER_PATTERN_SCHEME)
// If it does, then give it some time and tries to load. It stops when timeout is up or a scheme is found.
int timeOut = TIMEOUT_LIMIT;
if (hasSchemePattern(vfsFilename, PROVIDER_PATTERN_SCHEME)) {
while (scheme == null && timeOut > 0) {
// ask again to refresh schemes list
schemes = fsManager.getSchemes();
try {
Thread.sleep(TIME_TO_SLEEP_STEP);
timeOut -= TIME_TO_SLEEP_STEP;
scheme = getScheme(schemes, vfsFilename);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
break;
}
}
}
fsOptions = getFileSystemOptions(scheme, vfsFilename, space, fsOptions);
String filename = normalizePath(vfsFilename, scheme);
return fsOptions != null ? fsManager.resolveFile(filename, fsOptions) : fsManager.resolveFile(filename);
} catch (IOException e) {
throw new KettleFileException("Unable to get VFS File object for filename '" + cleanseFilename(vfsFilename) + "' : " + e.getMessage(), e);
}
}
Aggregations