Search in sources :

Example 16 with FileTransferClient

use of com.adaptris.filetransfer.FileTransferClient in project interlok by adaptris.

the class FtpPasswordConnectionCase method testConnect_OverrideUserOnly.

@Test
public void testConnect_OverrideUserOnly() throws Exception {
    Assume.assumeTrue(areTestsEnabled());
    FileTransferConnectionUsingPassword connection = (FileTransferConnectionUsingPassword) createConnection();
    connection.setDefaultUserName(null);
    try {
        start(connection);
        FileTransferClient client = connection.connect(getDestinationStringWithOverrideUserOnly());
    } finally {
        stop(connection);
    }
}
Also used : FileTransferClient(com.adaptris.filetransfer.FileTransferClient) Test(org.junit.Test)

Example 17 with FileTransferClient

use of com.adaptris.filetransfer.FileTransferClient in project interlok by adaptris.

the class FtpConnectionCase method testConnect.

@Test
public void testConnect() throws Exception {
    Assume.assumeTrue(areTestsEnabled());
    FileTransferConnection connection = createConnection();
    try {
        start(connection);
        FileTransferClient client = connection.connect(getDestinationString());
    } finally {
        stop(connection);
    }
}
Also used : FileTransferClient(com.adaptris.filetransfer.FileTransferClient) Test(org.junit.Test)

Example 18 with FileTransferClient

use of com.adaptris.filetransfer.FileTransferClient in project interlok by adaptris.

the class FtpConnectionCase method testConnect_UserOverride.

@Test
public void testConnect_UserOverride() throws Exception {
    Assume.assumeTrue(areTestsEnabled());
    FileTransferConnection connection = createConnection();
    connection.setDefaultUserName(null);
    try {
        start(connection);
        log.debug("testConnect_UserOverride connecting to : " + getDestinationStringWithOverride());
        FileTransferClient client = connection.connect(getDestinationStringWithOverride());
    } finally {
        stop(connection);
    }
}
Also used : FileTransferClient(com.adaptris.filetransfer.FileTransferClient) Test(org.junit.Test)

Example 19 with FileTransferClient

use of com.adaptris.filetransfer.FileTransferClient in project interlok by adaptris.

the class RelaxedFtpProducer method doProduce.

/**
 * @see com.adaptris.core.AdaptrisMessageProducerImp#produce(AdaptrisMessage)
 */
@Override
public void doProduce(AdaptrisMessage msg, String endpoint) throws ProduceException {
    FileTransferConnection conn = retrieveConnection(FileTransferConnection.class);
    FileTransferClient client = null;
    try {
        client = conn.connect(endpoint);
        String dirRoot = conn.getDirectoryRoot(endpoint);
        String fileName = filenameCreator().createName(msg);
        String destFilename = dirRoot + SLASH + fileName;
        if (dirRoot.endsWith(SLASH)) {
            destFilename = dirRoot + fileName;
        }
        log.debug("destFilename=[{}]", destFilename);
        msg.addMetadata(CoreConstants.PRODUCED_NAME_KEY, fileName);
        if (getEncoder() != null) {
            byte[] bytesToWrite = encode(msg);
            client.put(bytesToWrite, destFilename);
        } else {
            try (InputStream in = msg.getInputStream()) {
                client.put(in, destFilename);
            }
        }
    } catch (Exception e) {
        throw new ProduceException(e);
    } finally {
        conn.disconnect(client);
    }
}
Also used : FileTransferClient(com.adaptris.filetransfer.FileTransferClient) InputStream(java.io.InputStream) ProduceException(com.adaptris.core.ProduceException) CoreException(com.adaptris.core.CoreException) ProduceException(com.adaptris.core.ProduceException)

Example 20 with FileTransferClient

use of com.adaptris.filetransfer.FileTransferClient in project interlok by adaptris.

the class FtpConnectionCase method testConnect_NoUser.

@Test
public void testConnect_NoUser() throws Exception {
    Assume.assumeTrue(areTestsEnabled());
    FileTransferConnection connection = createConnection();
    connection.setDefaultUserName(null);
    try {
        start(connection);
        FileTransferClient client = connection.connect(getDestinationString());
        fail();
    } catch (Exception expected) {
    } finally {
        stop(connection);
    }
}
Also used : FileTransferClient(com.adaptris.filetransfer.FileTransferClient) Test(org.junit.Test)

Aggregations

FileTransferClient (com.adaptris.filetransfer.FileTransferClient)39 Test (org.junit.Test)30 File (java.io.File)4 IOException (java.io.IOException)4 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)3 PasswordException (com.adaptris.security.exc.PasswordException)3 CoreException (com.adaptris.core.CoreException)2 ProduceException (com.adaptris.core.ProduceException)2 CommonsNetFtpClient (com.adaptris.ftp.CommonsNetFtpClient)2 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 After (org.junit.After)2 InputFieldHint (com.adaptris.annotation.InputFieldHint)1 FileNameCreator (com.adaptris.core.FileNameCreator)1 ServiceException (com.adaptris.core.ServiceException)1 FileTransferException (com.adaptris.filetransfer.FileTransferException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 Random (java.util.Random)1