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);
}
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));
}
}
}
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;
}
}
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());
}
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);
}
Aggregations