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