Search in sources :

Example 1 with ConnectionCanceledException

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());
}
Also used : SocketException(java.net.SocketException) DefaultHttpResponseExceptionMappingService(ch.cyberduck.core.http.DefaultHttpResponseExceptionMappingService) LockedException(ch.cyberduck.core.exception.LockedException) DefaultSocketExceptionMappingService(ch.cyberduck.core.DefaultSocketExceptionMappingService) ConnectionCanceledException(ch.cyberduck.core.exception.ConnectionCanceledException) HttpResponseException(org.apache.http.client.HttpResponseException) IOException(java.io.IOException) DefaultIOExceptionMappingService(ch.cyberduck.core.DefaultIOExceptionMappingService)

Example 2 with ConnectionCanceledException

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);
}
Also used : ConnectionCanceledException(ch.cyberduck.core.exception.ConnectionCanceledException) BackgroundException(ch.cyberduck.core.exception.BackgroundException) HostPreferences(ch.cyberduck.core.preferences.HostPreferences)

Example 3 with ConnectionCanceledException

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;
}
Also used : ConnectionCanceledException(ch.cyberduck.core.exception.ConnectionCanceledException) IOException(java.io.IOException) KeyStoreException(java.security.KeyStoreException) KeyStore(java.security.KeyStore) X509Certificate(java.security.cert.X509Certificate)

Example 4 with ConnectionCanceledException

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;
}
Also used : Path(ch.cyberduck.core.Path) ListService(ch.cyberduck.core.ListService) ConnectionCanceledException(ch.cyberduck.core.exception.ConnectionCanceledException)

Example 5 with ConnectionCanceledException

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);
    }
}
Also used : Path(ch.cyberduck.core.Path) CachingFindFeature(ch.cyberduck.core.CachingFindFeature) Move(ch.cyberduck.core.features.Move) Delete(ch.cyberduck.core.features.Delete) CachingAttributesFinderFeature(ch.cyberduck.core.CachingAttributesFinderFeature) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) HashMap(java.util.HashMap) ListService(ch.cyberduck.core.ListService) StringUtils(org.apache.commons.lang3.StringUtils) MessageFormat(java.text.MessageFormat) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) ConnectionCanceledException(ch.cyberduck.core.exception.ConnectionCanceledException) Cache(ch.cyberduck.core.Cache) Map(java.util.Map) Find(ch.cyberduck.core.features.Find) AttributesFinder(ch.cyberduck.core.features.AttributesFinder) Session(ch.cyberduck.core.Session) AttributedList(ch.cyberduck.core.AttributedList) LocaleFactory(ch.cyberduck.core.LocaleFactory) MappingMimeTypeService(ch.cyberduck.core.MappingMimeTypeService) TimestampComparator(ch.cyberduck.ui.comparator.TimestampComparator) BackgroundException(ch.cyberduck.core.exception.BackgroundException) DefaultAttributesFinderFeature(ch.cyberduck.core.shared.DefaultAttributesFinderFeature) Collectors(java.util.stream.Collectors) BackgroundActionState(ch.cyberduck.core.threading.BackgroundActionState) Objects(java.util.Objects) List(java.util.List) Logger(org.apache.logging.log4j.Logger) TreeMap(java.util.TreeMap) SessionPool(ch.cyberduck.core.pool.SessionPool) Path(ch.cyberduck.core.Path) ProgressListener(ch.cyberduck.core.ProgressListener) DefaultFindFeature(ch.cyberduck.core.shared.DefaultFindFeature) Directory(ch.cyberduck.core.features.Directory) ConnectionCallback(ch.cyberduck.core.ConnectionCallback) LogManager(org.apache.logging.log4j.LogManager) Collections(java.util.Collections) Delete(ch.cyberduck.core.features.Delete) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ConnectionCanceledException(ch.cyberduck.core.exception.ConnectionCanceledException) BackgroundActionState(ch.cyberduck.core.threading.BackgroundActionState) TreeMap(java.util.TreeMap) ListService(ch.cyberduck.core.ListService) ConnectionCallback(ch.cyberduck.core.ConnectionCallback) Move(ch.cyberduck.core.features.Move) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) TreeMap(java.util.TreeMap)

Aggregations

ConnectionCanceledException (ch.cyberduck.core.exception.ConnectionCanceledException)66 Path (ch.cyberduck.core.Path)28 BackgroundException (ch.cyberduck.core.exception.BackgroundException)17 ArrayList (java.util.ArrayList)16 TransferStatus (ch.cyberduck.core.transfer.TransferStatus)12 IOException (java.io.IOException)11 ExecutionException (java.util.concurrent.ExecutionException)11 Future (java.util.concurrent.Future)11 ThreadPool (ch.cyberduck.core.threading.ThreadPool)10 Test (org.junit.Test)9 ListService (ch.cyberduck.core.ListService)8 PathContainerService (ch.cyberduck.core.PathContainerService)8 DisabledListProgressListener (ch.cyberduck.core.DisabledListProgressListener)7 HashMap (java.util.HashMap)7 DefaultIOExceptionMappingService (ch.cyberduck.core.DefaultIOExceptionMappingService)6 IntegrationTest (ch.cyberduck.test.IntegrationTest)6 AttributedList (ch.cyberduck.core.AttributedList)5 Host (ch.cyberduck.core.Host)5 LinkedHashMap (java.util.LinkedHashMap)5 ChecksumException (ch.cyberduck.core.exception.ChecksumException)4