use of org.apache.camel.component.file.GenericFileOperationFailedException in project camel by apache.
the class FtpLoginTest method testBadLogin.
@Test
public void testBadLogin() throws Exception {
try {
uploadFile("dummy", "cantremeber");
fail("Should have thrown a GenericFileOperationFailedException");
} catch (GenericFileOperationFailedException e) {
// expected
assertEquals(530, e.getCode());
}
// assert file NOT created
File file = new File(FTP_ROOT_DIR + "/login/report.txt");
assertFalse("The file should NOT exists", file.exists());
}
use of org.apache.camel.component.file.GenericFileOperationFailedException in project camel by apache.
the class SftpConsumerAutoCreateTest method testNoAutoCreate.
@Test
public void testNoAutoCreate() throws Exception {
SftpEndpoint endpoint = (SftpEndpoint) this.getMandatoryEndpoint(getFtpUrl() + "&autoCreate=false");
endpoint.start();
try {
endpoint.getExchanges();
fail("Should fail with 550 No such directory.");
} catch (GenericFileOperationFailedException ignored) {
// ignore
}
}
use of org.apache.camel.component.file.GenericFileOperationFailedException in project camel by apache.
the class FtpConsumerDeleteNoWritePermissionTest method testConsumerDeleteNoWritePermission.
@Test
public void testConsumerDeleteNoWritePermission() throws Exception {
PollingConsumer consumer = context.getEndpoint(getFtpUrl()).createPollingConsumer();
consumer.start();
Exchange out = consumer.receive(3000);
assertNotNull("Should get the file", out);
try {
// give consumer time to try to delete the file
Thread.sleep(1000);
consumer.stop();
} catch (GenericFileOperationFailedException fofe) {
// expected, ignore
}
}
use of org.apache.camel.component.file.GenericFileOperationFailedException in project camel by apache.
the class GenericFileRenameExclusiveReadLockStrategy method acquireExclusiveReadLock.
@Override
public boolean acquireExclusiveReadLock(GenericFileOperations<T> operations, GenericFile<T> file, Exchange exchange) throws Exception {
LOG.trace("Waiting for exclusive read lock to file: {}", file);
// the trick is to try to rename the file, if we can rename then we have exclusive read
// since its a Generic file we cannot use java.nio to get a RW lock
String newName = file.getFileName() + ".camelExclusiveReadLock";
// make a copy as result and change its file name
GenericFile<T> newFile = file.copyFrom(file);
newFile.changeFileName(newName);
StopWatch watch = new StopWatch();
boolean exclusive = false;
while (!exclusive) {
// timeout check
if (timeout > 0) {
long delta = watch.taken();
if (delta > timeout) {
CamelLogger.log(LOG, readLockLoggingLevel, "Cannot acquire read lock within " + timeout + " millis. Will skip the file: " + file);
// we could not get the lock within the timeout period, so return false
return false;
}
}
try {
exclusive = operations.renameFile(file.getAbsoluteFilePath(), newFile.getAbsoluteFilePath());
} catch (GenericFileOperationFailedException ex) {
if (ex.getCause() != null && ex.getCause() instanceof FileNotFoundException) {
exclusive = false;
} else {
throw ex;
}
}
if (exclusive) {
LOG.trace("Acquired exclusive read lock to file: {}", file);
// rename it back so we can read it
operations.renameFile(newFile.getAbsoluteFilePath(), file.getAbsoluteFilePath());
} else {
boolean interrupted = sleep();
if (interrupted) {
// we were interrupted while sleeping, we are likely being shutdown so return false
return false;
}
}
}
return true;
}
Aggregations