Search in sources :

Example 1 with ConnectionTimeoutException

use of ch.cyberduck.core.exception.ConnectionTimeoutException in project cyberduck by iterate-ch.

the class FTPListServiceTest method testListIOFailureStat.

@Test(expected = ConnectionTimeoutException.class)
public void testListIOFailureStat() throws Exception {
    final FTPListService service = new FTPListService(session, null, TimeZone.getDefault());
    service.remove(FTPListService.Command.lista);
    service.remove(FTPListService.Command.mlsd);
    final AtomicBoolean set = new AtomicBoolean();
    service.implementations.put(FTPListService.Command.stat, new ListService() {

        @Override
        public AttributedList<Path> list(final Path directory, final ListProgressListener listener) throws BackgroundException {
            if (set.get()) {
                fail();
            }
            set.set(true);
            throw new ConnectionTimeoutException("t", new SocketTimeoutException());
        }
    });
    final Path directory = new FTPWorkdirService(session).find();
    final AttributedList<Path> list = service.list(directory, new DisabledListProgressListener());
}
Also used : Path(ch.cyberduck.core.Path) DisabledListProgressListener(ch.cyberduck.core.DisabledListProgressListener) ListService(ch.cyberduck.core.ListService) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ConnectionTimeoutException(ch.cyberduck.core.exception.ConnectionTimeoutException) SocketTimeoutException(java.net.SocketTimeoutException) AttributedList(ch.cyberduck.core.AttributedList) ListProgressListener(ch.cyberduck.core.ListProgressListener) DisabledListProgressListener(ch.cyberduck.core.DisabledListProgressListener) FTPWorkdirService(ch.cyberduck.core.ftp.FTPWorkdirService) BackgroundException(ch.cyberduck.core.exception.BackgroundException) Test(org.junit.Test) IntegrationTest(ch.cyberduck.test.IntegrationTest) AbstractFTPTest(ch.cyberduck.core.ftp.AbstractFTPTest)

Example 2 with ConnectionTimeoutException

use of ch.cyberduck.core.exception.ConnectionTimeoutException in project cyberduck by iterate-ch.

the class S3Session method login.

@Override
public void login(final Proxy proxy, final LoginCallback prompt, final CancelCallback cancel) throws BackgroundException {
    if (Scheme.isURL(host.getProtocol().getContext())) {
        try {
            final Credentials temporary = new AWSSessionCredentialsRetriever(trust, key, this, host.getProtocol().getContext()).get();
            client.setProviderCredentials(new AWSSessionCredentials(temporary.getUsername(), temporary.getPassword(), temporary.getToken()));
        } catch (ConnectionTimeoutException | ConnectionRefusedException | ResolveFailedException | NotfoundException | InteroperabilityException e) {
            log.warn(String.format("Failure to retrieve session credentials from . %s", e.getMessage()));
            throw new LoginFailureException(e.getDetail(false), e);
        }
    } else {
        final Credentials credentials;
        // Only for AWS
        if (isAwsHostname(host.getHostname())) {
            // Try auto-configure
            credentials = new STSCredentialsConfigurator(new ThreadLocalHostnameDelegatingTrustManager(trust, host.getHostname()), key, prompt).configure(host);
        } else {
            credentials = host.getCredentials();
        }
        if (StringUtils.isNotBlank(credentials.getToken())) {
            client.setProviderCredentials(credentials.isAnonymousLogin() ? null : new AWSSessionCredentials(credentials.getUsername(), credentials.getPassword(), credentials.getToken()));
        } else {
            client.setProviderCredentials(credentials.isAnonymousLogin() ? null : new AWSCredentials(credentials.getUsername(), credentials.getPassword()));
        }
    }
    if (host.getCredentials().isPassed()) {
        log.warn(String.format("Skip verifying credentials with previous successful authentication event for %s", this));
        return;
    }
    try {
        final Location.Name location = new S3PathStyleFallbackAdapter<>(this, new BackgroundExceptionCallable<Location.Name>() {

            @Override
            public Location.Name call() throws BackgroundException {
                return new S3LocationFeature(S3Session.this, client.getRegionEndpointCache()).getLocation(new DelegatingHomeFeature(new DefaultPathHomeFeature(host)).find());
            }
        }).call();
        if (log.isDebugEnabled()) {
            log.debug(String.format("Retrieved region %s", location));
        }
        if (!Location.unknown.equals(location)) {
            client.getConfiguration().setProperty("storage-service.default-region", location.getIdentifier());
        }
    } catch (AccessDeniedException | InteroperabilityException e) {
        log.warn(String.format("Failure %s querying region", e));
        final Path home = new DefaultHomeFinderService(this).find();
        if (log.isDebugEnabled()) {
            log.debug(String.format("Retrieved %s", home));
        }
    }
}
Also used : Path(ch.cyberduck.core.Path) NotfoundException(ch.cyberduck.core.exception.NotfoundException) AccessDeniedException(ch.cyberduck.core.exception.AccessDeniedException) InteroperabilityException(ch.cyberduck.core.exception.InteroperabilityException) DelegatingHomeFeature(ch.cyberduck.core.shared.DelegatingHomeFeature) DefaultPathHomeFeature(ch.cyberduck.core.shared.DefaultPathHomeFeature) DefaultHomeFinderService(ch.cyberduck.core.shared.DefaultHomeFinderService) ConnectionRefusedException(ch.cyberduck.core.exception.ConnectionRefusedException) ResolveFailedException(ch.cyberduck.core.exception.ResolveFailedException) AWSCredentials(org.jets3t.service.security.AWSCredentials) BackgroundExceptionCallable(ch.cyberduck.core.threading.BackgroundExceptionCallable) ConnectionTimeoutException(ch.cyberduck.core.exception.ConnectionTimeoutException) LoginFailureException(ch.cyberduck.core.exception.LoginFailureException) AWSSessionCredentials(org.jets3t.service.security.AWSSessionCredentials) ThreadLocalHostnameDelegatingTrustManager(ch.cyberduck.core.ssl.ThreadLocalHostnameDelegatingTrustManager) AWSSessionCredentialsRetriever(ch.cyberduck.core.auth.AWSSessionCredentialsRetriever) AWSCredentials(org.jets3t.service.security.AWSCredentials) Credentials(ch.cyberduck.core.Credentials) AWSSessionCredentials(org.jets3t.service.security.AWSSessionCredentials) STSCredentialsConfigurator(ch.cyberduck.core.sts.STSCredentialsConfigurator)

Example 3 with ConnectionTimeoutException

use of ch.cyberduck.core.exception.ConnectionTimeoutException in project cyberduck by iterate-ch.

the class S3ExceptionMappingService method map.

@Override
public BackgroundException map(final ServiceException e) {
    if (e.getCause() instanceof ServiceException) {
        return this.map((ServiceException) e.getCause());
    }
    final StringBuilder buffer = new StringBuilder();
    if (StringUtils.isNotBlank(e.getErrorMessage())) {
        // S3 protocol message parsed from XML
        this.append(buffer, StringEscapeUtils.unescapeXml(e.getErrorMessage()));
    } else {
        this.append(buffer, e.getResponseStatus());
        this.append(buffer, e.getMessage());
        this.append(buffer, e.getErrorCode());
    }
    switch(e.getResponseCode()) {
        case HttpStatus.SC_FORBIDDEN:
            if (StringUtils.isNotBlank(e.getErrorCode())) {
                switch(e.getErrorCode()) {
                    case "SignatureDoesNotMatch":
                    case "InvalidAccessKeyId":
                    case "InvalidClientTokenId":
                    case "InvalidSecurity":
                    case "MissingClientTokenId":
                    case "MissingAuthenticationToken":
                        return new LoginFailureException(buffer.toString(), e);
                }
            }
        case HttpStatus.SC_BAD_REQUEST:
            if (StringUtils.isNotBlank(e.getErrorCode())) {
                switch(e.getErrorCode()) {
                    case "RequestTimeout":
                        return new ConnectionTimeoutException(buffer.toString(), e);
                    case "ExpiredToken":
                    case "InvalidToken":
                        return new ExpiredTokenException(buffer.toString(), e);
                }
            }
    }
    if (e.getCause() instanceof IOException) {
        return new DefaultIOExceptionMappingService().map((IOException) e.getCause());
    }
    if (e.getCause() instanceof SAXException) {
        return new InteroperabilityException(buffer.toString(), e);
    }
    if (-1 == e.getResponseCode()) {
        return new InteroperabilityException(buffer.toString(), e);
    }
    return new DefaultHttpResponseExceptionMappingService().map(new HttpResponseException(e.getResponseCode(), buffer.toString()));
}
Also used : ConnectionTimeoutException(ch.cyberduck.core.exception.ConnectionTimeoutException) DefaultHttpResponseExceptionMappingService(ch.cyberduck.core.http.DefaultHttpResponseExceptionMappingService) LoginFailureException(ch.cyberduck.core.exception.LoginFailureException) InteroperabilityException(ch.cyberduck.core.exception.InteroperabilityException) ServiceException(org.jets3t.service.ServiceException) ExpiredTokenException(ch.cyberduck.core.exception.ExpiredTokenException) HttpResponseException(org.apache.http.client.HttpResponseException) IOException(java.io.IOException) DefaultIOExceptionMappingService(ch.cyberduck.core.DefaultIOExceptionMappingService) SAXException(org.xml.sax.SAXException)

Example 4 with ConnectionTimeoutException

use of ch.cyberduck.core.exception.ConnectionTimeoutException in project cyberduck by iterate-ch.

the class AzureExceptionMappingService method map.

@Override
public BackgroundException map(final StorageException failure) {
    final StringBuilder buffer = new StringBuilder();
    this.append(buffer, failure.getMessage());
    if (ExceptionUtils.getRootCause(failure) instanceof UnknownHostException) {
        return new NotfoundException(buffer.toString(), failure);
    }
    switch(failure.getHttpStatusCode()) {
        case 403:
            return new LoginFailureException(buffer.toString(), failure);
        case 404:
            return new NotfoundException(buffer.toString(), failure);
        case 304:
        case 405:
        case 400:
        case 411:
        case 412:
            return new InteroperabilityException(buffer.toString(), failure);
        case 500:
            // OperationTimedOut
            return new ConnectionTimeoutException(buffer.toString(), failure);
        case 503:
            // ServerBusy
            return new RetriableAccessDeniedException(buffer.toString(), failure);
    }
    for (Throwable cause : ExceptionUtils.getThrowableList(failure)) {
        if (cause instanceof SSLException) {
            return new SSLExceptionMappingService().map(buffer.toString(), (SSLException) cause);
        }
    }
    return this.wrap(failure, buffer);
}
Also used : RetriableAccessDeniedException(ch.cyberduck.core.exception.RetriableAccessDeniedException) NotfoundException(ch.cyberduck.core.exception.NotfoundException) ConnectionTimeoutException(ch.cyberduck.core.exception.ConnectionTimeoutException) LoginFailureException(ch.cyberduck.core.exception.LoginFailureException) InteroperabilityException(ch.cyberduck.core.exception.InteroperabilityException) SSLExceptionMappingService(ch.cyberduck.core.ssl.SSLExceptionMappingService) UnknownHostException(java.net.UnknownHostException) SSLException(javax.net.ssl.SSLException)

Aggregations

ConnectionTimeoutException (ch.cyberduck.core.exception.ConnectionTimeoutException)4 InteroperabilityException (ch.cyberduck.core.exception.InteroperabilityException)3 LoginFailureException (ch.cyberduck.core.exception.LoginFailureException)3 Path (ch.cyberduck.core.Path)2 NotfoundException (ch.cyberduck.core.exception.NotfoundException)2 AttributedList (ch.cyberduck.core.AttributedList)1 Credentials (ch.cyberduck.core.Credentials)1 DefaultIOExceptionMappingService (ch.cyberduck.core.DefaultIOExceptionMappingService)1 DisabledListProgressListener (ch.cyberduck.core.DisabledListProgressListener)1 ListProgressListener (ch.cyberduck.core.ListProgressListener)1 ListService (ch.cyberduck.core.ListService)1 AWSSessionCredentialsRetriever (ch.cyberduck.core.auth.AWSSessionCredentialsRetriever)1 AccessDeniedException (ch.cyberduck.core.exception.AccessDeniedException)1 BackgroundException (ch.cyberduck.core.exception.BackgroundException)1 ConnectionRefusedException (ch.cyberduck.core.exception.ConnectionRefusedException)1 ExpiredTokenException (ch.cyberduck.core.exception.ExpiredTokenException)1 ResolveFailedException (ch.cyberduck.core.exception.ResolveFailedException)1 RetriableAccessDeniedException (ch.cyberduck.core.exception.RetriableAccessDeniedException)1 AbstractFTPTest (ch.cyberduck.core.ftp.AbstractFTPTest)1 FTPWorkdirService (ch.cyberduck.core.ftp.FTPWorkdirService)1