use of ch.cyberduck.core.exception.ConnectionCanceledException in project cyberduck by iterate-ch.
the class BrickExceptionMappingService method map.
@Override
public BackgroundException map(final ApiException failure) {
switch(failure.getCode()) {
case HttpStatus.SC_UNPROCESSABLE_ENTITY:
return new LockedException(StringUtils.EMPTY, failure);
}
for (Throwable cause : ExceptionUtils.getThrowableList(failure)) {
if (cause instanceof SocketException) {
// Map Connection has been shutdown: javax.net.ssl.SSLException: java.net.SocketException: Broken pipe
return new DefaultSocketExceptionMappingService().map((SocketException) cause);
}
if (cause instanceof HttpResponseException) {
return new DefaultHttpResponseExceptionMappingService().map((HttpResponseException) cause);
}
if (cause instanceof IOException) {
return new DefaultIOExceptionMappingService().map((IOException) cause);
}
if (cause instanceof IllegalStateException) {
// Caused by: ch.cyberduck.core.sds.io.swagger.client.ApiException: javax.ws.rs.ProcessingException: java.lang.IllegalStateException: Connection pool shut down
return new ConnectionCanceledException(cause);
}
}
final StringBuilder buffer = new StringBuilder();
this.parse(buffer, failure.getResponseBody());
return new DefaultHttpResponseExceptionMappingService().map(failure, buffer, failure.getCode());
}
use of ch.cyberduck.core.exception.ConnectionCanceledException in project cyberduck by iterate-ch.
the class BrickPairingSchedulerFeature method repeat.
public void repeat(final PasswordCallback callback) {
final long timeout = new HostPreferences(session.getHost()).getLong("brick.pairing.interrupt.ms");
final long start = System.currentTimeMillis();
scheduler.repeat(() -> {
try {
if (System.currentTimeMillis() - start > timeout) {
throw new ConnectionCanceledException(String.format("Interrupt polling for pairing key after %d", timeout));
}
this.operate(callback);
} catch (ConnectionCanceledException e) {
log.warn(String.format("Cancel processing scheduled task. %s", e.getMessage()), e);
callback.close(null);
this.shutdown();
} catch (BackgroundException e) {
log.warn(String.format("Failure processing scheduled task. %s", e.getMessage()), e);
callback.close(null);
this.shutdown();
}
}, new HostPreferences(session.getHost()).getLong("brick.pairing.interval.ms"), TimeUnit.MILLISECONDS);
}
use of ch.cyberduck.core.exception.ConnectionCanceledException in project cyberduck by iterate-ch.
the class CertificateStoreX509KeyManager method chooseClientAlias.
@Override
public String chooseClientAlias(final String[] keyTypes, final Principal[] issuers, final Socket socket) {
try {
final X509Certificate selected;
final String hostname = socket.getInetAddress().getHostName();
try {
final String alias = bookmark.getCredentials().getCertificate();
if (StringUtils.isNotBlank(alias)) {
log.info(String.format("Return saved certificate alias %s for host %s", alias, bookmark));
return alias;
}
selected = callback.choose(prompt, keyTypes, issuers, bookmark);
} catch (ConnectionCanceledException e) {
if (log.isInfoEnabled()) {
log.info(String.format("No certificate selected for socket %s", socket));
}
return null;
}
if (null == selected) {
if (log.isInfoEnabled()) {
log.info(String.format("No certificate selected for socket %s", socket));
}
// Disconnect
return null;
}
final String[] aliases = this.getClientAliases(keyTypes, issuers);
if (null != aliases) {
final KeyStore store;
try {
store = this.getKeystore();
} catch (IOException e) {
return null;
}
for (String alias : aliases) {
if (store.getCertificate(alias).equals(selected)) {
if (log.isInfoEnabled()) {
log.info(String.format("Selected certificate alias %s for certificate %s", alias, selected));
}
bookmark.getCredentials().setCertificate(alias);
return alias;
}
}
}
log.warn(String.format("No matching alias found for selected certificate %s", selected));
// Return null if there are no matches
return null;
} catch (KeyStoreException e) {
log.error(String.format("Keystore not loaded %s", e.getMessage()));
}
// Return null if there are no matches
return null;
}
use of ch.cyberduck.core.exception.ConnectionCanceledException in project cyberduck by iterate-ch.
the class CalculateSizeWorker method calculateSize.
/**
* Calculates recursively the size of this path if a directory
* Potentially lengthy operation
*
* @param p Directory or file
* @return The size of the file or the sum of all containing files if a directory
*/
private long calculateSize(final Session<?> session, final Path p) throws BackgroundException {
long size = 0;
if (this.isCanceled()) {
throw new ConnectionCanceledException();
}
listener.message(MessageFormat.format(LocaleFactory.localizedString("Getting size of {0}", "Status"), p.getName()));
if (p.isDirectory()) {
for (Path next : session.getFeature(ListService.class).list(p, new WorkerListProgressListener(this, listener))) {
size += this.calculateSize(session, next);
}
} else if (p.isFile()) {
size += p.attributes().getSize();
total += size;
this.update(total);
}
return size;
}
use of ch.cyberduck.core.exception.ConnectionCanceledException in project cyberduck by iterate-ch.
the class MoveWorker method run.
@Override
public Map<Path, Path> run(final Session<?> session) throws BackgroundException {
final Session<?> destination = target.borrow(new BackgroundActionState() {
@Override
public boolean isCanceled() {
return MoveWorker.this.isCanceled();
}
@Override
public boolean isRunning() {
return true;
}
});
try {
final Move feature = session.getFeature(Move.class).withTarget(destination);
if (log.isDebugEnabled()) {
log.debug(String.format("Run with feature %s", feature));
}
final ListService list = session.getFeature(ListService.class);
// sort ascending by timestamp to move older versions first
final Map<Path, Path> sorted = new TreeMap<>(new VersionsComparator(true));
sorted.putAll(files);
final Map<Path, Path> result = new HashMap<>();
for (Map.Entry<Path, Path> entry : sorted.entrySet()) {
if (this.isCanceled()) {
throw new ConnectionCanceledException();
}
final Map<Path, Path> recursive = this.compile(feature, list, entry.getKey(), entry.getValue());
if (log.isDebugEnabled()) {
log.debug(String.format("Compiled recursive list %s", recursive));
}
for (Map.Entry<Path, Path> r : recursive.entrySet()) {
if (r.getKey().isDirectory() && !feature.isRecursive(r.getKey(), r.getValue())) {
log.warn(String.format("Move operation is not recursive. Create directory %s", r.getValue()));
// Create directory unless copy implementation is recursive
result.put(r.getKey(), session.getFeature(Directory.class).mkdir(r.getValue(), new TransferStatus().withRegion(r.getKey().attributes().getRegion())));
} else {
final TransferStatus status = this.status(session, r);
result.put(r.getKey(), feature.move(r.getKey(), r.getValue(), status, new Delete.Callback() {
@Override
public void delete(final Path file) {
listener.message(MessageFormat.format(LocaleFactory.localizedString("Deleting {0}", "Status"), file.getName()));
}
}, callback));
}
}
// Find previous folders to be deleted
final List<Path> folders = recursive.entrySet().stream().filter(f -> !feature.isRecursive(f.getKey(), f.getValue())).collect(Collectors.toCollection(ArrayList::new)).stream().map(Map.Entry::getKey).filter(Path::isDirectory).collect(Collectors.toCollection(ArrayList::new));
if (!folders.isEmpty()) {
// Must delete inverse
Collections.reverse(folders);
final Delete delete = session.getFeature(Delete.class);
for (Path folder : folders) {
log.warn(String.format("Delete source directory %s", folder));
final TransferStatus status = new TransferStatus().withLockId(this.getLockId(folder));
delete.delete(Collections.singletonMap(folder, status), callback, new Delete.DisabledCallback());
}
}
}
return result;
} finally {
target.release(destination, null);
}
}
Aggregations