Search in sources :

Example 1 with FileTransferClient

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

the class TestCommonsNetFtp method testBug1483.

@Test
public void testBug1483() throws Exception {
    Assume.assumeTrue(areTestsEnabled());
    String oldName = Thread.currentThread().getName();
    try {
        Thread.currentThread().setName("testBug1483");
        FileTransferClient client = connectClientImpl();
        String[] files = client.dir(getRemoteGetDirectory(), true);
        for (int i = 0; i < files.length; i++) {
            logR.debug(files[i]);
            Matcher m = LIST_DIR_PATTERN.matcher(files[i]);
            assertTrue("Output Should match " + LIST_DIR_FULL, m.matches());
        // logR.debug(HexDump.parse(files[i].getBytes()));
        }
        assertTrue(files.length > 0);
        client.disconnect();
    } finally {
        Thread.currentThread().setName(oldName);
    }
}
Also used : Matcher(java.util.regex.Matcher) FileTransferClient(com.adaptris.filetransfer.FileTransferClient) Test(org.junit.Test)

Example 2 with FileTransferClient

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

the class FileTransferConnection method connect.

/**
 * Connect to the host.
 *
 * @param hostUrl the host to connect to which can be in the form of an url or simply just the hostname in which case the default
 *          credentials and port numbers are used.
 * @return an FtpClient that is ready to use.
 */
public FileTransferClient connect(String hostUrl) throws FileTransferException, IOException, PasswordException {
    FileTransferClient client = lookup(hostUrl);
    if (client == null) {
        client = create(hostUrl);
    }
    addToCache(hostUrl, client);
    return client;
}
Also used : FileTransferClient(com.adaptris.filetransfer.FileTransferClient)

Example 3 with FileTransferClient

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

the class FtpProducer method doProduce.

@Override
public void doProduce(AdaptrisMessage msg, String endpoint) throws ProduceException {
    FileTransferConnection conn = retrieveConnection(FileTransferConnection.class);
    FileTransferClient client = null;
    FileNameCreator creator = filenameCreatorToUse();
    try {
        client = conn.connect(endpoint);
        String dirRoot = conn.getDirectoryRoot(endpoint);
        String fileName = creator.createName(msg);
        String destFilename = dirRoot + destDirectory + SLASH + fileName;
        String buildFilename = dirRoot + buildDirectory + SLASH + fileName;
        if (conn.additionalDebug()) {
            log.trace("buildFilename=[{}], destFilename=[{}]", buildFilename, destFilename);
        } else {
            log.debug("destFilename=[{}]", destFilename);
        }
        msg.addMetadata(CoreConstants.PRODUCED_NAME_KEY, fileName);
        if (getEncoder() != null) {
            byte[] bytesToWrite = encode(msg);
            client.put(bytesToWrite, buildFilename);
        } else {
            try (InputStream in = msg.getInputStream()) {
                client.put(in, buildFilename);
            }
        }
        client.rename(buildFilename, destFilename);
    } catch (Exception e) {
        throw new ProduceException(e);
    } finally {
        conn.disconnect(client);
    }
}
Also used : FileNameCreator(com.adaptris.core.FileNameCreator) 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 4 with FileTransferClient

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

the class AggregatingFtpConsumer method single.

private List<AdaptrisMessage> single(ConfigWrapper cfg, AdaptrisMessageFactory factory) throws Exception {
    FileTransferClient ftpClient = cfg.remote.connect(cfg.endpoint);
    List<AdaptrisMessage> result = new ArrayList<>();
    try {
        String fullPath = cfg.remote.getDirectoryRoot(cfg.endpoint);
        result = Arrays.asList(fetch(ftpClient, fullPath, cfg.remote.additionalDebug(), factory));
    } finally {
        cfg.remote.disconnect(ftpClient);
    }
    return result;
}
Also used : AdaptrisMessage(com.adaptris.core.AdaptrisMessage) FileTransferClient(com.adaptris.filetransfer.FileTransferClient) ArrayList(java.util.ArrayList)

Example 5 with FileTransferClient

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

the class FtpCase method testCachedConnection_ExceedsMaxSize.

@Test
public void testCachedConnection_ExceedsMaxSize() throws Exception {
    Assume.assumeTrue(areTestsEnabled());
    FileTransferConnection connection = createConnection();
    connection.setCacheConnection(true);
    connection.setMaxClientCache(1);
    try {
        start(connection);
        FileTransferClient client = connection.connect(getDestinationString());
        // Should be cached, and equivalent.
        FileTransferClient cached = connection.connect(getDestinationString());
        assertEquals(client, cached);
        FileTransferClient client2 = connection.connect(getDestinationStringWithOverride());
        // This should have emptied the cache (and disconnected client1)...
        cached = connection.connect(getDestinationString());
        assertNotSame(client, cached);
        assertFalse(client.isConnected());
    } 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