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);
}
}
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;
}
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);
}
}
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;
}
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);
}
}
Aggregations