Search in sources :

Example 1 with ConnectionRefusedException

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

the class DefaultSessionPoolTest method testConnectRefuse.

@Test(expected = ConnectionRefusedException.class)
public void testConnectRefuse() throws Exception {
    final DefaultSessionPool pool = new DefaultSessionPool(new TestLoginConnectionService() {

        @Override
        public boolean check(final Session<?> session, final CancelCallback callback) throws BackgroundException {
            throw new ConnectionRefusedException("t", new RuntimeException());
        }
    }, new DisabledX509TrustManager(), new DefaultX509KeyManager(), new DefaultVaultRegistry(new DisabledPasswordCallback()), new DisabledTranscriptListener(), new Host(new TestProtocol(), "t"));
    pool.borrow(BackgroundActionState.running);
}
Also used : DisabledX509TrustManager(ch.cyberduck.core.ssl.DisabledX509TrustManager) TestProtocol(ch.cyberduck.core.TestProtocol) Host(ch.cyberduck.core.Host) ConnectionRefusedException(ch.cyberduck.core.exception.ConnectionRefusedException) DisabledTranscriptListener(ch.cyberduck.core.DisabledTranscriptListener) TestLoginConnectionService(ch.cyberduck.core.TestLoginConnectionService) DefaultVaultRegistry(ch.cyberduck.core.vault.DefaultVaultRegistry) CancelCallback(ch.cyberduck.core.threading.CancelCallback) DefaultX509KeyManager(ch.cyberduck.core.ssl.DefaultX509KeyManager) DisabledPasswordCallback(ch.cyberduck.core.DisabledPasswordCallback) BackgroundException(ch.cyberduck.core.exception.BackgroundException) Test(org.junit.Test)

Example 2 with ConnectionRefusedException

use of ch.cyberduck.core.exception.ConnectionRefusedException 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 ConnectionRefusedException

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

the class DAVSessionTest method testConnectRefused.

@Test(expected = ConnectionRefusedException.class)
public void testConnectRefused() throws Exception {
    final Host host = new Host(new DAVSSLProtocol(), "localhost", 2121);
    final DAVSession session = new DAVSession(host, new CertificateStoreX509TrustManager(new DisabledCertificateTrustCallback(), new DefaultTrustManagerHostnameCallback(host), new DefaultCertificateStore()), new CertificateStoreX509KeyManager(new DisabledCertificateIdentityCallback(), host, new DefaultCertificateStore()));
    try {
        session.open(Proxy.DIRECT, new DisabledHostKeyCallback(), new DisabledLoginCallback(), new DisabledCancelCallback());
        session.login(Proxy.DIRECT, new DisabledLoginCallback(), new DisabledCancelCallback());
    } catch (ConnectionRefusedException e) {
        assertEquals("Connection failed", e.getMessage());
        throw e;
    }
}
Also used : ConnectionRefusedException(ch.cyberduck.core.exception.ConnectionRefusedException) CertificateStoreX509TrustManager(ch.cyberduck.core.ssl.CertificateStoreX509TrustManager) DefaultTrustManagerHostnameCallback(ch.cyberduck.core.ssl.DefaultTrustManagerHostnameCallback) CertificateStoreX509KeyManager(ch.cyberduck.core.ssl.CertificateStoreX509KeyManager) Test(org.junit.Test) IntegrationTest(ch.cyberduck.test.IntegrationTest)

Example 4 with ConnectionRefusedException

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

the class SegmentRetryCallableTest method testRetry.

@Test
public void testRetry() throws Exception {
    final AtomicInteger count = new AtomicInteger();
    final SegmentRetryCallable<Void> c = new SegmentRetryCallable<Void>(new Host(new TestProtocol()), 2, 0, new BackgroundExceptionCallable<Void>() {

        @Override
        public Void call() throws BackgroundException {
            throw new ConnectionRefusedException("d", new SocketException());
        }
    }, new TransferStatus(), new BytecountStreamListener()) {

        @Override
        public boolean retry(final BackgroundException failure, final ProgressListener progress, final BackgroundActionState cancel) {
            count.incrementAndGet();
            return super.retry(failure, progress, cancel);
        }
    };
    try {
        c.call();
        fail();
    } catch (ConnectionRefusedException e) {
    // Expected
    }
    assertEquals(3, count.get());
}
Also used : SocketException(java.net.SocketException) TestProtocol(ch.cyberduck.core.TestProtocol) BackgroundActionState(ch.cyberduck.core.threading.BackgroundActionState) Host(ch.cyberduck.core.Host) ConnectionRefusedException(ch.cyberduck.core.exception.ConnectionRefusedException) BytecountStreamListener(ch.cyberduck.core.BytecountStreamListener) ProgressListener(ch.cyberduck.core.ProgressListener) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BackgroundException(ch.cyberduck.core.exception.BackgroundException) Test(org.junit.Test)

Example 5 with ConnectionRefusedException

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

the class TransferBackgroundActionTest method testResumeOnRetryWithException.

@Test
public void testResumeOnRetryWithException() {
    final AtomicBoolean alert = new AtomicBoolean();
    final AbstractController controller = new AbstractController() {

        @Override
        public void invoke(final MainAction runnable, final boolean wait) {
            runnable.run();
        }
    };
    final Host host = new Host(new TestProtocol(), "test.cyberduck.ch");
    final TransferOptions options = new TransferOptions();
    final TransferBackgroundAction action = new TransferBackgroundAction(controller, new DefaultSessionPool(new TestLoginConnectionService(), new DisabledX509TrustManager(), new DefaultX509KeyManager(), new DefaultVaultRegistry(new DisabledPasswordCallback()), new DisabledTranscriptListener(), host) {

        @Override
        public Session<?> borrow(final BackgroundActionState callback) throws BackgroundException {
            throw new ConnectionRefusedException("d", new SocketException());
        }
    }, SessionPool.DISCONNECTED, new TransferAdapter(), new DownloadTransfer(host, Collections.singletonList(new TransferItem(new Path("/home/test", EnumSet.of(Path.Type.file)), new NullLocal("/t")))), options) {

        @Override
        public boolean alert(final BackgroundException failure) {
            final boolean alerted = alert.get();
            alert.set(true);
            return !alerted;
        }
    };
    assertFalse(alert.get());
    // Connect, prepare and run
    new BackgroundCallable<Boolean>(action, controller).call();
    assertTrue(alert.get());
    assertTrue(action.hasFailed());
// assertTrue(options.resumeRequested);
}
Also used : SocketException(java.net.SocketException) DisabledX509TrustManager(ch.cyberduck.core.ssl.DisabledX509TrustManager) TestProtocol(ch.cyberduck.core.TestProtocol) DefaultSessionPool(ch.cyberduck.core.pool.DefaultSessionPool) ConnectionRefusedException(ch.cyberduck.core.exception.ConnectionRefusedException) TransferOptions(ch.cyberduck.core.transfer.TransferOptions) DefaultVaultRegistry(ch.cyberduck.core.vault.DefaultVaultRegistry) DownloadTransfer(ch.cyberduck.core.transfer.DownloadTransfer) NullLocal(ch.cyberduck.core.NullLocal) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Path(ch.cyberduck.core.Path) TransferAdapter(ch.cyberduck.core.transfer.TransferAdapter) Host(ch.cyberduck.core.Host) AbstractController(ch.cyberduck.core.AbstractController) DisabledTranscriptListener(ch.cyberduck.core.DisabledTranscriptListener) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TestLoginConnectionService(ch.cyberduck.core.TestLoginConnectionService) DefaultX509KeyManager(ch.cyberduck.core.ssl.DefaultX509KeyManager) DisabledPasswordCallback(ch.cyberduck.core.DisabledPasswordCallback) TransferItem(ch.cyberduck.core.transfer.TransferItem) BackgroundException(ch.cyberduck.core.exception.BackgroundException) NullSession(ch.cyberduck.core.NullSession) Session(ch.cyberduck.core.Session) NullTransferSession(ch.cyberduck.core.NullTransferSession) Test(org.junit.Test)

Aggregations

ConnectionRefusedException (ch.cyberduck.core.exception.ConnectionRefusedException)12 Test (org.junit.Test)7 InteroperabilityException (ch.cyberduck.core.exception.InteroperabilityException)6 BackgroundException (ch.cyberduck.core.exception.BackgroundException)5 Host (ch.cyberduck.core.Host)4 TestProtocol (ch.cyberduck.core.TestProtocol)4 LoginFailureException (ch.cyberduck.core.exception.LoginFailureException)4 NotfoundException (ch.cyberduck.core.exception.NotfoundException)4 AccessDeniedException (ch.cyberduck.core.exception.AccessDeniedException)3 SocketException (java.net.SocketException)3 DefaultIOExceptionMappingService (ch.cyberduck.core.DefaultIOExceptionMappingService)2 DisabledPasswordCallback (ch.cyberduck.core.DisabledPasswordCallback)2 DisabledTranscriptListener (ch.cyberduck.core.DisabledTranscriptListener)2 Path (ch.cyberduck.core.Path)2 TestLoginConnectionService (ch.cyberduck.core.TestLoginConnectionService)2 DefaultX509KeyManager (ch.cyberduck.core.ssl.DefaultX509KeyManager)2 DisabledX509TrustManager (ch.cyberduck.core.ssl.DisabledX509TrustManager)2 DefaultVaultRegistry (ch.cyberduck.core.vault.DefaultVaultRegistry)2 AbstractController (ch.cyberduck.core.AbstractController)1 BytecountStreamListener (ch.cyberduck.core.BytecountStreamListener)1