Java Code Examples for org.apache.commons.vfs2.impl.DefaultFileSystemConfigBuilder

The following examples show how to use org.apache.commons.vfs2.impl.DefaultFileSystemConfigBuilder. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: incubator-gobblin   Source File: SimpleJsonExtractor.java    License: Apache License 2.0 6 votes vote down vote up
public SimpleJsonExtractor(WorkUnitState workUnitState) throws FileSystemException {
  this.workUnitState = workUnitState;

  // Resolve the file to pull
  if (workUnitState.getPropAsBoolean(ConfigurationKeys.SOURCE_CONN_USE_AUTHENTICATION, false)) {
    // Add authentication credential if authentication is needed
    UserAuthenticator auth =
        new StaticUserAuthenticator(workUnitState.getProp(ConfigurationKeys.SOURCE_CONN_DOMAIN, ""),
            workUnitState.getProp(ConfigurationKeys.SOURCE_CONN_USERNAME), PasswordManager.getInstance(workUnitState)
                .readPassword(workUnitState.getProp(ConfigurationKeys.SOURCE_CONN_PASSWORD)));
    FileSystemOptions opts = new FileSystemOptions();
    DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth);
    this.fileObject = VFS.getManager().resolveFile(workUnitState.getProp(SOURCE_FILE_KEY), opts);
  } else {
    this.fileObject = VFS.getManager().resolveFile(workUnitState.getProp(SOURCE_FILE_KEY));
  }

  // Open the file for reading
  LOGGER.info("Opening file " + this.fileObject.getURL().toString());
  this.bufferedReader =
      this.closer.register(new BufferedReader(new InputStreamReader(this.fileObject.getContent().getInputStream(),
          ConfigurationKeys.DEFAULT_CHARSET_ENCODING)));
}
 
Example 2
Source Project: commons-vfs   Source File: NestedTarTestCase.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Returns the base folder for tests.
 */
@Override
public FileObject getBaseTestFolder(final FileSystemManager manager) throws Exception {
    // We test with non-empty FS options to make sure they are propagated
    final FileSystemOptions opts = new FileSystemOptions();
    DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts,
            new StaticUserAuthenticator("domain", null, null));

    // Locate the base Tar file
    final String tarFilePath = AbstractVfsTestCase.getTestResource("nested.tar").getAbsolutePath();

    // Now build the nested file system
    final String uri = "tar:file:" + tarFilePath + "!/test.tar";
    final FileObject tarFile = manager.resolveFile(uri, opts);
    final FileObject nestedFS = manager.createFileSystem(tarFile);
    return nestedFS.resolveFile("/");
}
 
Example 3
Source Project: hop   Source File: S3NFileSystemTest.java    License: Apache License 2.0 5 votes vote down vote up
@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() );
}
 
Example 4
Source Project: hop   Source File: S3FileSystemTest.java    License: Apache License 2.0 5 votes vote down vote up
@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 S3FileSystem( fileName, options );
  assertNotNull( fileSystem.getS3Client() );
}
 
Example 5
Source Project: commons-vfs   Source File: AbstractFileSystem.java    License: Apache License 2.0 5 votes vote down vote up
protected AbstractFileSystem(final FileName rootName, final FileObject parentLayer,
        final FileSystemOptions fileSystemOptions) {
    this.parentLayer = parentLayer;
    this.rootName = rootName;
    this.fileSystemOptions = fileSystemOptions;
    final FileSystemConfigBuilder builder = DefaultFileSystemConfigBuilder.getInstance();
    String uri = builder.getRootURI(fileSystemOptions);
    if (uri == null) {
        uri = rootName.getURI();
    }
    this.rootURI = uri;
}
 
Example 6
@Override public FileSystemOptions getOpts( OtherConnectionDetails otherConnectionDetails ) {
  if ( otherConnectionDetails == null ) {
    return null;
  }
  StaticUserAuthenticator auth =
          new StaticUserAuthenticator( otherConnectionDetails.getHost(), otherConnectionDetails.getUsername(),
                  otherConnectionDetails.getPassword() );
  FileSystemOptions opts = new FileSystemOptions();
  try {
    DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator( opts, auth );
  } catch ( FileSystemException fse ) {
    // Ignore and return default options
  }
  return opts;
}
 
Example 7
Source Project: commons-vfs   Source File: UserAuthenticatorUtils.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Authenticates if there is an authenticator, else returns null.
 *
 * @param opts The FileSystemOptions.
 * @param authenticatorTypes An array of types describing the data to be retrieved.
 * @return A UserAuthenticationData object containing the data requested.
 */
public static UserAuthenticationData authenticate(final FileSystemOptions opts,
        final UserAuthenticationData.Type[] authenticatorTypes) {
    final UserAuthenticator auth = DefaultFileSystemConfigBuilder.getInstance().getUserAuthenticator(opts);
    return authenticate(auth, authenticatorTypes);
}