Search in sources :

Example 1 with FileTransferHttpClient

use of com.axway.ats.action.http.FileTransferHttpClient in project ats-framework by Axway.

the class HtmlFileDownloader method downloadFile.

/**
 * Perform the file/image download.
 *
 * @param downloadUrl
 * @return download file absolute path
 * @throws IOException
 * @throws FileTransferClientException
 */
public String downloadFile(String downloadUrl) throws IOException {
    if (StringUtils.isNullOrEmpty(downloadUrl)) {
        throw new UiElementException("The element you have specified does not link to anything!");
    }
    URL url = new URL(downloadUrl);
    String fileName = url.getPath();
    String remoteFilePath = null;
    if (fileName.indexOf('/') > -1) {
        int separator = fileName.lastIndexOf('/');
        remoteFilePath = fileName.substring(0, separator + 1);
        fileName = fileName.substring(separator + 1);
    }
    FileTransferHttpClient transferClient = new FileTransferHttpClient();
    transferClient.connect(url.getHost(), null, null);
    if (this.mimicWebDriverCookieState) {
        for (org.openqa.selenium.Cookie cookie : this.webDriver.manage().getCookies()) {
            transferClient.addCookie(cookie.getName(), cookie.getValue(), cookie.getDomain(), cookie.getPath(), cookie.getExpiry(), cookie.isSecure());
        }
        if (this.webDriver instanceof org.openqa.selenium.phantomjs.PhantomJSDriver && System.getProperty(PhantomJsDriver.HTTP_ONLY_COOKIES_PROPERTY) != null) {
            for (org.openqa.selenium.Cookie cookie : PhantomJsDriver.getHttpOnlyCookies()) {
                transferClient.addCookie(cookie.getName(), cookie.getValue(), cookie.getDomain(), cookie.getPath(), cookie.getExpiry(), cookie.isSecure());
            }
        }
    }
    transferClient.downloadFile(this.downloadDir + fileName, remoteFilePath, fileName);
    return this.downloadDir + fileName;
}
Also used : UiElementException(com.axway.ats.uiengine.exceptions.UiElementException) URL(java.net.URL) FileTransferHttpClient(com.axway.ats.action.http.FileTransferHttpClient)

Example 2 with FileTransferHttpClient

use of com.axway.ats.action.http.FileTransferHttpClient in project ats-framework by Axway.

the class ClientFactory method getClient.

/**
 * Returns the {@link IFileTransferClient} that handles transfers via the specified {@link TransferProtocol}. Since
 * no port is provided the default port would be used when initiating the connection.
 *
 * @return the {@link IFileTransferClient} that handles transfers via the specified {@link TransferProtocol}
 * @param protocol the {@link TransferProtocol} to use
 * @param keystoreFile the file containing the key store
 * @param keystringPassphrase the pass phrase to the key store
 * @throws Exception
 * @see {@link TransferProtocol}
 */
public final IFileTransferClient getClient(TransferProtocol protocol, String keystoreFile, String keystringPassphrase) throws Exception {
    switch(protocol) {
        case FTPS:
            FtpsClient ftps = new FtpsClient();
            ftps.setCustomPort(protocol.getDefaultPort());
            return ftps;
        case HTTPS:
            FileTransferHttpClient https = new FileTransferHttpClient();
            https.setOverSsl(true);
            https.setCustomPort(protocol.getDefaultPort());
            return https;
        default:
            throw new Exception("No implementation for the " + protocol + " is currently available");
    }
}
Also used : FtpsClient(com.axway.ats.core.filetransfer.FtpsClient) FileTransferHttpClient(com.axway.ats.action.http.FileTransferHttpClient) FileTransferException(com.axway.ats.common.filetransfer.FileTransferException)

Example 3 with FileTransferHttpClient

use of com.axway.ats.action.http.FileTransferHttpClient 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
 * @return the {@link IFileTransferClient} that handles transfers via the specified {@link TransferProtocol}
 * @throws FileTransferException
 * @see {@link TransferProtocol}
 */
public IFileTransferClient getClient(TransferProtocol protocol, int port) throws FileTransferException {
    switch(protocol) {
        case FTP:
            FtpClient ftp = new FtpClient();
            ftp.setCustomPort(port);
            return ftp;
        case FTPS:
            FtpsClient ftps = new FtpsClient();
            ftps.setCustomPort(port);
            return ftps;
        case SFTP:
            SftpClient sftp = new SftpClient();
            sftp.setCustomPort(port);
            return sftp;
        case HTTP:
            FileTransferHttpClient http = new FileTransferHttpClient();
            http.setCustomPort(port);
            return http;
        case HTTPS:
            FileTransferHttpClient https = new FileTransferHttpClient();
            https.setOverSsl(true);
            https.setCustomPort(port);
            return https;
        default:
            throw new FileTransferException("No implementation for the " + protocol + " protocol is currently available");
    }
}
Also used : FileTransferException(com.axway.ats.common.filetransfer.FileTransferException) FtpsClient(com.axway.ats.core.filetransfer.FtpsClient) SftpClient(com.axway.ats.core.filetransfer.SftpClient) FtpClient(com.axway.ats.core.filetransfer.FtpClient) FileTransferHttpClient(com.axway.ats.action.http.FileTransferHttpClient)

Aggregations

FileTransferHttpClient (com.axway.ats.action.http.FileTransferHttpClient)3 FileTransferException (com.axway.ats.common.filetransfer.FileTransferException)2 FtpsClient (com.axway.ats.core.filetransfer.FtpsClient)2 FtpClient (com.axway.ats.core.filetransfer.FtpClient)1 SftpClient (com.axway.ats.core.filetransfer.SftpClient)1 UiElementException (com.axway.ats.uiengine.exceptions.UiElementException)1 URL (java.net.URL)1