Search in sources :

Example 6 with FileTransferException

use of com.axway.ats.common.filetransfer.FileTransferException in project ats-framework by Axway.

the class FileTransferClient method connect.

/**
 * Connect to a remote host using secure authentication
 *
 * @param hostname
 *            the host to connect to
 * @param keystoreFile
 *            the file containing the key store
 * @param keystorePassword
 *            the key store password
 * @param privateKeyAlias
 *            the private key alias
 */
@PublicAtsApi
public void connect(@Validate(name = "hostname", type = ValidationType.STRING_SERVER_ADDRESS) String hostname, @Validate(name = "keystoreFile", type = ValidationType.STRING_NOT_EMPTY) String keystoreFile, @Validate(name = "keystorePassword", type = ValidationType.STRING_NOT_EMPTY) String keystorePassword, @Validate(name = "privateKeyAlias", type = ValidationType.STRING_NOT_EMPTY) String privateKeyAlias) {
    // validate input parameters
    new Validator().validateMethodParameters(new Object[] { hostname, keystoreFile, keystorePassword, privateKeyAlias });
    // connect using base authentication
    Throwable throwable = null;
    try {
        this.client.connect(hostname, keystoreFile, keystorePassword, privateKeyAlias);
        return;
    } catch (FileTransferException e) {
        throwable = e;
        log.error("Connection attempt failed", e);
    }
    throw new FileTransferException("Could not connect. Look up the reason in the log.", (Exception) throwable);
}
Also used : FileTransferException(com.axway.ats.common.filetransfer.FileTransferException) Validator(com.axway.ats.core.validation.Validator) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 7 with FileTransferException

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);
    }
}
Also used : IFileTransferClient(com.axway.ats.core.filetransfer.model.IFileTransferClient) FileTransferException(com.axway.ats.common.filetransfer.FileTransferException)

Example 8 with FileTransferException

use of com.axway.ats.common.filetransfer.FileTransferException in project ats-framework by Axway.

the class Test_GenericTransferClient method testDisconnectNegative.

/**
 * Test case
 * @throws Exception
 */
@Test(expected = FileTransferException.class)
public void testDisconnectNegative() throws Exception {
    // setup expectations
    ftpMock.disconnect();
    expectLastCall().andThrow(new FileTransferException("Exception"));
    replay(ftpMock);
    // execute operations
    mockedTestObject.disconnect();
    // verify results
    verify(ftpMock);
}
Also used : FileTransferException(com.axway.ats.common.filetransfer.FileTransferException) BaseTest(com.axway.ats.action.BaseTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 9 with FileTransferException

use of com.axway.ats.common.filetransfer.FileTransferException in project ats-framework by Axway.

the class Test_GenericTransferClient method testFileUploadAltException.

/**
 * Test case
 * @throws Exception
 */
@Test(expected = FileTransferException.class)
public void testFileUploadAltException() throws Exception {
    // setup expectations
    File fileMock = createMockAndExpectNew(File.class, SAMPLE_LOCAL_DIRECTORY + SAMPLE_LOCAL_FILE);
    expect(fileMock.getName()).andReturn(SAMPLE_LOCAL_FILE);
    ftpMock.uploadFile(SAMPLE_LOCAL_DIRECTORY + SAMPLE_LOCAL_FILE, SAMPLE_REMOTE_DIRECTORY, SAMPLE_LOCAL_FILE);
    expectLastCall().andThrow(new FileTransferException(SAMPLE_EXCEPTION_MESSAGE));
    replayAll();
    // execute operations
    mockedTestObject.uploadFile(SAMPLE_LOCAL_DIRECTORY + SAMPLE_LOCAL_FILE, SAMPLE_REMOTE_DIRECTORY);
    // verify results
    verify(ftpMock);
}
Also used : FileTransferException(com.axway.ats.common.filetransfer.FileTransferException) File(java.io.File) BaseTest(com.axway.ats.action.BaseTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 10 with FileTransferException

use of com.axway.ats.common.filetransfer.FileTransferException in project ats-framework by Axway.

the class Test_GenericTransferClient method testResumePausedTransferException.

@Test(expected = FileTransferException.class)
public void testResumePausedTransferException() throws Exception {
    // setup expectations
    ftpMock.resumePausedTransfer();
    expectLastCall().andThrow(new FileTransferException(SAMPLE_EXCEPTION_MESSAGE));
    replay(ftpMock);
    // execute operations
    mockedTestObject.resumePausedTransfer();
    // verify results
    verify(ftpMock);
}
Also used : FileTransferException(com.axway.ats.common.filetransfer.FileTransferException) BaseTest(com.axway.ats.action.BaseTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

FileTransferException (com.axway.ats.common.filetransfer.FileTransferException)36 IOException (java.io.IOException)16 File (java.io.File)11 BaseTest (com.axway.ats.action.BaseTest)7 Test (org.junit.Test)7 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)7 FileOutputStream (java.io.FileOutputStream)6 HttpEntity (org.apache.http.HttpEntity)5 HttpResponse (org.apache.http.HttpResponse)5 ClientProtocolException (org.apache.http.client.ClientProtocolException)5 CertificateException (java.security.cert.CertificateException)4 PublicAtsApi (com.axway.ats.common.PublicAtsApi)3 IFileTransferClient (com.axway.ats.core.filetransfer.model.IFileTransferClient)3 SftpException (com.jcraft.jsch.SftpException)3 FileInputStream (java.io.FileInputStream)3 FileNotFoundException (java.io.FileNotFoundException)3 OutputStream (java.io.OutputStream)3 HttpGet (org.apache.http.client.methods.HttpGet)3 HttpPost (org.apache.http.client.methods.HttpPost)3 SshCipher (com.axway.ats.common.filetransfer.SshCipher)2