agave-files/files-api/src/main/java/org/iplantc/service/io/resources/FileManagementResource.java
/**
     * Fetches a {@link RemoteDataClient} for the requested system and authenticates
     * for use in the remainder of this session.
     * @param remoteSystem
     * @param internalUsername
     * @return
     * @throws ResourceException
     */
Fetches a  RemoteDataClient for the requested system and authenticates
for use in the remainder of this session.
@param remoteSystem
@param internalUsername
@return
@throws ResourceException
Fetches a RemoteDataClient for the requested system and authenticates for use in the remainder of this session . @param remoteSystem @param internalUsername @return @throws ResourceException
private RemoteDataClient initRemoteDataClientForSystem(RemoteSystem remoteSystem, String internalUsername) 
    throws ResourceException 
    {
		RemoteDataClient rdc = null;
		try
        {
    		if (remoteSystem != null) {
    			rdc = new RemoteDataClientFactory().getInstance(
                    remoteSystem, internalUsername);
    			rdc.authenticate();
    			return rdc;
	        }
    		else {
    			String msg = "No system found to satisfy the request.";
    			log.error(msg);
    			throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST,
    						                msg, new SystemUnknownException());
    		}
		} 
		catch (RemoteDataException e) {
			String msg = "Failed to connect to the remote system. "+ e.getMessage();
			log.error(msg, e);
			try { if (rdc != null) rdc.disconnect(); } catch (Exception ignored) {}
        	throw new ResourceException(Status.SERVER_ERROR_INTERNAL, msg);
		} catch (RemoteCredentialException | IOException e) {
			String msg = "Failed to authenticate to the remote system. " + e.getMessage();
			log.error(msg, e);
			try { if (rdc != null) rdc.disconnect(); } catch (Exception ignored) {}
			throw new ResourceException(Status.SERVER_ERROR_BAD_GATEWAY, msg);
		}
    }
private RemoteDataClient initRemoteDataClientForSystem ( RemoteSystem remoteSystem , String internalUsername ) throws ResourceException { RemoteDataClient rdc = null ; try { if ( remoteSystem != null ) { rdc = new RemoteDataClientFactory ( ) . getInstance ( remoteSystem , internalUsername ) ; rdc . authenticate ( ) ; return rdc ; } else { String msg = "No system found to satisfy the request." ; log . error ( msg ) ; throw new ResourceException ( Status . CLIENT_ERROR_BAD_REQUEST , msg , new SystemUnknownException ( ) ) ; } } catch ( RemoteDataException e ) { String msg = "Failed to connect to the remote system. " + e . getMessage ( ) ; log . error ( msg , e ) ; try { if ( rdc != null ) rdc . disconnect ( ) ; } catch ( Exception ignored ) { } throw new ResourceException ( Status . SERVER_ERROR_INTERNAL , msg ) ; } catch ( RemoteCredentialException | IOException e ) { String msg = "Failed to authenticate to the remote system. " + e . getMessage ( ) ; log . error ( msg , e ) ; try { if ( rdc != null ) rdc . disconnect ( ) ; } catch ( Exception ignored ) { } throw new ResourceException ( Status . SERVER_ERROR_BAD_GATEWAY , msg ) ; } }
Fetches a {@link RemoteDataClient} for the requested system and authenticates
 for use in the remainder of this session.
Fetches a { @link RemoteDataClient } for the requested system and authenticates for use in the remainder of this session .
// get a valid client // authenticate for the remaining request.