use of org.jets3t.service.ServiceException in project cyberduck by iterate-ch.
the class S3BucketListService method list.
@Override
public AttributedList<Path> list(final Path directory, final ListProgressListener listener) throws BackgroundException {
if (log.isDebugEnabled()) {
log.debug(String.format("List containers for %s", session));
}
try {
final AttributedList<Path> buckets = new AttributedList<>();
// List all buckets owned
for (StorageBucket b : session.getClient().listAllBuckets()) {
final Path bucket = new Path(PathNormalizer.normalize(b.getName()), EnumSet.of(Path.Type.volume, Path.Type.directory));
if (b.getOwner() != null) {
// Null if the owner is not available
bucket.attributes().setOwner(b.getOwner().getId());
}
bucket.attributes().setCreationDate(b.getCreationDate().getTime());
if (b.isLocationKnown()) {
bucket.attributes().setRegion(b.getLocation());
}
if (region.getIdentifier() != null) {
final String location;
if (!b.isLocationKnown()) {
location = session.getFeature(Location.class).getLocation(bucket).getIdentifier();
} else {
location = b.getLocation();
}
if (!StringUtils.equals(location, region.getIdentifier())) {
log.warn(String.format("Skip bucket %s in region %s", bucket, location));
continue;
}
bucket.attributes().setRegion(location);
}
buckets.add(bucket);
listener.chunk(directory, buckets);
}
return buckets;
} catch (ServiceException e) {
throw new S3ExceptionMappingService().map("Listing directory {0} failed", e, directory);
}
}
use of org.jets3t.service.ServiceException in project cyberduck by iterate-ch.
the class S3BucketRegionRedirectStrategy method getRedirect.
@Override
public HttpUriRequest getRedirect(final HttpRequest request, final HttpResponse response, final HttpContext context) throws ProtocolException {
if (response.containsHeader("x-amz-bucket-region")) {
final Header header = response.getFirstHeader("x-amz-bucket-region");
log.warn(String.format("Received redirect response %s with %s", response, header));
final String uri = StringUtils.replaceEach(request.getRequestLine().getUri(), session.getHost().getProtocol().getRegions().stream().map(Location.Name::getIdentifier).toArray(String[]::new), session.getHost().getProtocol().getRegions().stream().map(location -> header.getValue()).toArray(String[]::new));
final HttpUriRequest redirect = RequestBuilder.copy(request).setUri(uri).build();
log.warn(String.format("Retry request with URI %s", redirect.getURI()));
try {
authorizer.authorizeHttpRequest(redirect, context, null);
} catch (ServiceException e) {
throw new RedirectException(e.getMessage(), e);
}
// Update cache with new region
if (StringUtils.isEmpty(RequestEntityRestStorageService.findBucketInHostname(session.getHost()))) {
requestEntityRestStorageService.getRegionEndpointCache().putRegionForBucketName(ServiceUtils.findBucketNameInHostname(((HttpUriRequest) request).getURI().getHost(), requestEntityRestStorageService.getJetS3tProperties().getStringProperty("s3service.s3-endpoint", session.getHost().getHostname())), header.getValue());
} else {
requestEntityRestStorageService.getRegionEndpointCache().putRegionForBucketName(RequestEntityRestStorageService.findBucketInHostname(session.getHost()), header.getValue());
}
return redirect;
}
return super.getRedirect(request, response, context);
}
use of org.jets3t.service.ServiceException in project cyberduck by iterate-ch.
the class S3ExceptionMappingServiceTest method testMapping.
@Test
public void testMapping() {
assertEquals("Message. Please contact your web hosting service provider for assistance.", new S3ExceptionMappingService().map(new ServiceException("message")).getDetail());
assertEquals("Exceeded 403 retry limit (1). Please contact your web hosting service provider for assistance.", new S3ExceptionMappingService().map(new ServiceException("Exceeded 403 retry limit (1).")).getDetail());
assertEquals("Interoperability failure", new S3ExceptionMappingService().map(new ServiceException("Exceeded 403 retry limit (1).")).getMessage());
}
use of org.jets3t.service.ServiceException in project cyberduck by iterate-ch.
the class S3ExceptionMappingServiceTest method testHandshakeFailure.
@Test
public void testHandshakeFailure() {
final SSLHandshakeException f = new SSLHandshakeException("f");
f.initCause(new CertificateException("c"));
assertEquals(ConnectionCanceledException.class, new S3ExceptionMappingService().map(new ServiceException(f)).getClass());
}
use of org.jets3t.service.ServiceException in project cyberduck by iterate-ch.
the class S3ExceptionMappingServiceTest method testLoginFailure.
@Test
public void testLoginFailure() {
final ServiceException f = new ServiceException("m", "<null/>");
f.setResponseCode(401);
f.setErrorMessage("m");
assertTrue(new S3ExceptionMappingService().map(f) instanceof LoginFailureException);
}
Aggregations