use of com.axway.ats.common.filetransfer.FileTransferException in project ats-framework by Axway.
the class HttpClient method performDownloadFile.
@Override
protected void performDownloadFile(String localFile, String remoteDir, String remoteFile) throws FileTransferException {
checkClientInitialized();
final String getUrl = constructDownloadUrl(remoteDir, remoteFile);
log.info("Downloading " + getUrl);
HttpGet httpGetMethod = new HttpGet(getUrl);
HttpEntity responseEntity = null;
OutputStream outstream = null;
boolean errorSavingFile = true;
try {
// add headers specified by the user
addRequestHeaders(httpGetMethod);
// download the file
HttpResponse response = httpClient.execute(httpGetMethod, httpContext);
if (200 != response.getStatusLine().getStatusCode()) {
throw new FileTransferException("Downloading " + getUrl + " returned " + response.getStatusLine());
}
// save the file
responseEntity = response.getEntity();
if (responseEntity != null) {
outstream = new FileOutputStream(localFile);
responseEntity.writeTo(outstream);
outstream.flush();
errorSavingFile = false;
} else {
throw new FileTransferException("No file present in the response");
}
} catch (ClientProtocolException e) {
log.error("Unable to download file!", e);
throw new FileTransferException(e);
} catch (IOException e) {
log.error("Unable to download file!", e);
throw new FileTransferException(e);
} finally {
if (responseEntity != null) {
IoUtils.closeStream(outstream);
if (errorSavingFile) {
try {
// We were not able to properly stream the entity content
// to the local file system. The next line consumes the
// entity content closes the underlying stream.
EntityUtils.consume(responseEntity);
} catch (IOException e) {
// we tried our best to release the resources
}
}
}
}
log.info("Successfully downloaded '" + localFile + "' from '" + remoteDir + remoteFile + "' at " + this.hostname);
}
use of com.axway.ats.common.filetransfer.FileTransferException in project ats-framework by Axway.
the class ClientFactory method loadCustomClient.
/**
* Instantiates the custom file transfer client
*
* @param customFileTransferClient the class name of the custom client
* @return
* @throws FileTransferException
*/
private IFileTransferClient loadCustomClient(String customFileTransferClient) throws FileTransferException {
try {
// load the custom client class
Class<?> customFileTransferClientClass = this.getClass().getClassLoader().loadClass(customFileTransferClient);
// make an instance of the custom client
IFileTransferClient client = (IFileTransferClient) customFileTransferClientClass.newInstance();
log.info("Loaded custom file transfer client: " + customFileTransferClient);
return client;
} catch (ClassNotFoundException e) {
throw new FileTransferException("Custom file transfer client not found in the classpath: " + customFileTransferClient);
} catch (ClassCastException e) {
throw new FileTransferException("Wrong type of the custom file transfer client: " + customFileTransferClient);
} catch (InstantiationException e) {
throw new FileTransferException("Unable to create an instance of the custom file transfer client: " + customFileTransferClient);
} catch (IllegalAccessException e) {
throw new FileTransferException("Unable to create an instance of the custom file transfer client: " + customFileTransferClient);
}
}
use of com.axway.ats.common.filetransfer.FileTransferException in project ats-framework by Axway.
the class ClientFactory method getClient.
/**
* Returns a product specific {@link IFileTransferClient} that handles transfers via the specified {@link TransferProtocol}.
*
* @param protocol the {@link TransferProtocol} to use
* @param port a custom port to use when connecting
* @param customFileTransferClient the class name of the custom client
* @return the {@link IFileTransferClient} that handles transfers via the specified {@link TransferProtocol}
* @throws FileTransferException
* @see {@link TransferProtocol}
*/
public IFileTransferClient getClient(TransferProtocol protocol, int port, String customFileTransferClient) throws FileTransferException {
switch(protocol) {
case FTP:
return new FtpClient(port);
case FTPS:
return new FtpsClient(port);
case SFTP:
return new SftpClient(port);
case HTTP:
return new HttpClient(port);
case HTTPS:
return new HttpsClient(port);
case HTTP_CUSTOM:
case HTTPS_CUSTOM:
case PESIT_CUSTOM:
case CUSTOM:
// load the custom client
IFileTransferClient client = loadCustomClient(customFileTransferClient);
client.setCustomPort(port);
return client;
default:
throw new FileTransferException("No implementation for the " + protocol + " protocol is currently available");
}
}
use of com.axway.ats.common.filetransfer.FileTransferException in project ats-framework by Axway.
the class AbstractFileTransferClient method resumePausedTransfer.
public synchronized void resumePausedTransfer() throws FileTransferException {
checkPausedTransferRunning(true);
final Logger log = LogManager.getLogger(AbstractFileTransferClient.class);
while (!canResume) {
try {
log.debug("Waiting for the transfer to start...");
// Wait to be notified when the transfer is started and will be paused.
this.wait();
} catch (InterruptedException e) {
throw new FileTransferException("Interrupted while waiting for a transfer to start", e);
}
}
// for the next resume
canResume = false;
// Notify the thread that is performing the transfer to continue.
this.notifyAll();
try {
log.debug("Waiting for the transfer to finish...");
// Wait to be notified that the transfer is done.
this.wait();
} catch (InterruptedException e) {
throw new FileTransferException("Interrupted while waiting for a transfer to finish", e);
} finally {
// the paused transfer has finished
this.isTransferStartedAndPaused = false;
}
}
use of com.axway.ats.common.filetransfer.FileTransferException in project ats-framework by Axway.
the class FtpClient method disconnect.
/**
* Disconnect from the remote host
*
* @throws FileTransferException
*/
@Override
public void disconnect() throws FileTransferException {
if (this.ftpConnection != null && this.ftpConnection.isConnected()) {
try {
this.ftpConnection.disconnect();
this.ftpConnection = null;
} catch (IOException e) {
throw new FileTransferException(e);
}
}
}
Aggregations