Search in sources :

Example 16 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 17 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 18 with FileSystemOptions

use of org.apache.commons.vfs2.FileSystemOptions in project hop by apache.

the class S3NFileSystemTest method setUp.

@Before
public void setUp() throws Exception {
    fileName = new S3NFileName(S3FileNameTest.SCHEME, "/", "", FileType.FOLDER);
    fileSystem = new S3NFileSystem(fileName, new FileSystemOptions());
}
Also used : S3NFileSystem(org.apache.hop.vfs.s3.s3n.vfs.S3NFileSystem) S3NFileName(org.apache.hop.vfs.s3.s3n.vfs.S3NFileName) FileSystemOptions(org.apache.commons.vfs2.FileSystemOptions) Before(org.junit.Before)

Example 19 with FileSystemOptions

use of org.apache.commons.vfs2.FileSystemOptions in project hop by apache.

the class S3NFileSystemTest method testGetS3Service.

@Test
public void testGetS3Service() throws Exception {
    assertNotNull(fileSystem.getS3Client());
    FileSystemOptions options = new FileSystemOptions();
    UserAuthenticator authenticator = mock(UserAuthenticator.class);
    UserAuthenticationData authData = mock(UserAuthenticationData.class);
    when(authenticator.requestAuthentication(S3FileProvider.AUTHENTICATOR_TYPES)).thenReturn(authData);
    when(authData.getData(UserAuthenticationData.USERNAME)).thenReturn("username".toCharArray());
    when(authData.getData(UserAuthenticationData.PASSWORD)).thenReturn("password".toCharArray());
    DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(options, authenticator);
    fileSystem = new S3NFileSystem(fileName, options);
    assertNotNull(fileSystem.getS3Client());
}
Also used : S3NFileSystem(org.apache.hop.vfs.s3.s3n.vfs.S3NFileSystem) UserAuthenticationData(org.apache.commons.vfs2.UserAuthenticationData) UserAuthenticator(org.apache.commons.vfs2.UserAuthenticator) FileSystemOptions(org.apache.commons.vfs2.FileSystemOptions) Test(org.junit.Test)

Example 20 with FileSystemOptions

use of org.apache.commons.vfs2.FileSystemOptions in project hop by apache.

the class S3FileObjectTest method setUp.

@Before
public void setUp() throws Exception {
    s3ServiceMock = mock(AmazonS3.class);
    S3Object s3Object = new S3Object();
    s3Object.setKey(OBJECT_NAME);
    s3Object.setBucketName(BUCKET_NAME);
    filename = new S3FileName(SCHEME, BUCKET_NAME, BUCKET_NAME, FileType.FOLDER);
    S3FileName rootFileName = new S3FileName(SCHEME, "", "", FileType.FOLDER);
    S3HopProperty s3HopProperty = mock(S3HopProperty.class);
    when(s3HopProperty.getPartSize()).thenReturn("5MB");
    S3FileSystem fileSystem = new S3FileSystem(rootFileName, new FileSystemOptions(), new StorageUnitConverter(), s3HopProperty);
    fileSystemSpy = spy(fileSystem);
    VfsComponentContext context = mock(VfsComponentContext.class);
    final DefaultFileSystemManager fsm = new DefaultFileSystemManager();
    FilesCache cache = mock(FilesCache.class);
    fsm.setFilesCache(cache);
    fsm.setCacheStrategy(CacheStrategy.ON_RESOLVE);
    when(context.getFileSystemManager()).thenReturn(fsm);
    fileSystemSpy.setContext(context);
    S3FileObject s3FileObject = new S3FileObject(filename, fileSystemSpy);
    s3FileObjectBucketSpy = spy(s3FileObject);
    s3FileObjectFileSpy = spy(new S3FileObject(new S3FileName(SCHEME, BUCKET_NAME, BUCKET_NAME + "/" + origKey, FileType.IMAGINARY), fileSystemSpy));
    S3FileObject s3FileObjectRoot = new S3FileObject(rootFileName, fileSystemSpy);
    s3FileObjectSpyRoot = spy(s3FileObjectRoot);
    // specify the behaviour of S3 Service
    // when( s3ServiceMock.getBucket( BUCKET_NAME ) ).thenReturn( testBucket );
    when(s3ServiceMock.getObject(BUCKET_NAME, OBJECT_NAME)).thenReturn(s3Object);
    when(s3ServiceMock.getObject(BUCKET_NAME, OBJECT_NAME)).thenReturn(s3Object);
    when(s3ServiceMock.listBuckets()).thenReturn(createBuckets());
    when(s3ServiceMock.doesBucketExistV2(BUCKET_NAME)).thenReturn(true);
    childObjectListing = mock(ObjectListing.class);
    when(childObjectListing.getObjectSummaries()).thenReturn(createObjectSummaries(0)).thenReturn(new ArrayList<>());
    when(childObjectListing.getCommonPrefixes()).thenReturn(new ArrayList<>()).thenReturn(createCommonPrefixes(3));
    when(childObjectListing.isTruncated()).thenReturn(true).thenReturn(false);
    when(s3ServiceMock.listObjects(any(ListObjectsRequest.class))).thenReturn(childObjectListing);
    when(s3ServiceMock.listObjects(anyString(), anyString())).thenReturn(childObjectListing);
    when(s3ServiceMock.listNextBatchOfObjects(any(ObjectListing.class))).thenReturn(childObjectListing);
    s3ObjectMock = mock(S3Object.class);
    s3ObjectInputStream = mock(S3ObjectInputStream.class);
    s3ObjectMetadata = mock(ObjectMetadata.class);
    when(s3ObjectMock.getObjectContent()).thenReturn(s3ObjectInputStream);
    when(s3ServiceMock.getObjectMetadata(anyString(), anyString())).thenReturn(s3ObjectMetadata);
    when(s3ObjectMetadata.getContentLength()).thenReturn(contentLength);
    when(s3ObjectMetadata.getLastModified()).thenReturn(testDate);
    when(s3ServiceMock.getObject(anyString(), anyString())).thenReturn(s3ObjectMock);
    when(fileSystemSpy.getS3Client()).thenReturn(s3ServiceMock);
}
Also used : AmazonS3(com.amazonaws.services.s3.AmazonS3) StorageUnitConverter(org.apache.hop.core.util.StorageUnitConverter) ArrayList(java.util.ArrayList) S3FileSystem(org.apache.hop.vfs.s3.s3.vfs.S3FileSystem) S3FileObject(org.apache.hop.vfs.s3.s3.vfs.S3FileObject) S3FileName(org.apache.hop.vfs.s3.s3.vfs.S3FileName) VfsComponentContext(org.apache.commons.vfs2.provider.VfsComponentContext) DefaultFileSystemManager(org.apache.commons.vfs2.impl.DefaultFileSystemManager) S3HopProperty(org.apache.hop.vfs.s3.s3common.S3HopProperty) Before(org.junit.Before)

Aggregations

FileSystemOptions (org.apache.commons.vfs2.FileSystemOptions)98 FileObject (org.apache.commons.vfs2.FileObject)47 FileSystemException (org.apache.commons.vfs2.FileSystemException)29 Test (org.junit.Test)25 IOException (java.io.IOException)17 FileName (org.apache.commons.vfs2.FileName)17 URL (java.net.URL)13 GenericFileName (org.apache.commons.vfs2.provider.GenericFileName)13 File (java.io.File)12 UserAuthenticationData (org.apache.commons.vfs2.UserAuthenticationData)12 StaticUserAuthenticator (org.apache.commons.vfs2.auth.StaticUserAuthenticator)9 FileSystem (org.apache.commons.vfs2.FileSystem)8 DefaultFileSystemManager (org.apache.commons.vfs2.impl.DefaultFileSystemManager)8 ArrayList (java.util.ArrayList)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