Search in sources :

Example 26 with FileSystemOptions

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);
}
Also used : TrustStrategy(org.apache.http.ssl.TrustStrategy) HttpFileSystemConfigBuilder(org.apache.commons.vfs2.provider.http.HttpFileSystemConfigBuilder) WebdavFileSystemConfigBuilder(org.apache.commons.vfs2.provider.webdav.WebdavFileSystemConfigBuilder)

Example 27 with FileSystemOptions

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);
    }
}
Also used : FileSystemOptions(org.apache.commons.vfs2.FileSystemOptions)

Example 28 with FileSystemOptions

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);
}
Also used : FileSystemOptions(org.apache.commons.vfs2.FileSystemOptions) Test(org.junit.Test)

Example 29 with 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);
        }
    }
}
Also used : URLFileName(org.apache.commons.vfs2.provider.URLFileName) FileNameParser(org.apache.commons.vfs2.provider.FileNameParser) SftpFileNameParser(org.apache.commons.vfs2.provider.sftp.SftpFileNameParser) IdentityInfo(org.apache.commons.vfs2.provider.sftp.IdentityInfo) UserInfo(com.jcraft.jsch.UserInfo) IOException(java.io.IOException) File(java.io.File)

Example 30 with FileSystemOptions

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);
    }
}
Also used : KettleFileException(org.pentaho.di.core.exception.KettleFileException) IOException(java.io.IOException) DefaultFileSystemManager(org.apache.commons.vfs2.impl.DefaultFileSystemManager) FileSystemManager(org.apache.commons.vfs2.FileSystemManager) StandardFileSystemManager(org.apache.commons.vfs2.impl.StandardFileSystemManager)

Aggregations

FileSystemOptions (org.apache.commons.vfs2.FileSystemOptions)97 FileObject (org.apache.commons.vfs2.FileObject)46 FileSystemException (org.apache.commons.vfs2.FileSystemException)29 Test (org.junit.Test)25 IOException (java.io.IOException)16 FileName (org.apache.commons.vfs2.FileName)16 URL (java.net.URL)13 File (java.io.File)12 GenericFileName (org.apache.commons.vfs2.provider.GenericFileName)12 UserAuthenticationData (org.apache.commons.vfs2.UserAuthenticationData)11 StaticUserAuthenticator (org.apache.commons.vfs2.auth.StaticUserAuthenticator)9 FileSystem (org.apache.commons.vfs2.FileSystem)8 ArrayList (java.util.ArrayList)7 DefaultFileSystemManager (org.apache.commons.vfs2.impl.DefaultFileSystemManager)7 FileNotFolderException (org.apache.commons.vfs2.FileNotFolderException)6 Test (org.junit.jupiter.api.Test)6 OutputStream (java.io.OutputStream)5 UserAuthenticator (org.apache.commons.vfs2.UserAuthenticator)5 Before (org.junit.Before)5 AmazonS3 (com.amazonaws.services.s3.AmazonS3)4