Search in sources :

Example 31 with ServiceException

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);
    }
}
Also used : Path(ch.cyberduck.core.Path) AttributedList(ch.cyberduck.core.AttributedList) ServiceException(org.jets3t.service.ServiceException) StorageBucket(org.jets3t.service.model.StorageBucket) Location(ch.cyberduck.core.features.Location)

Example 32 with ServiceException

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);
}
Also used : HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) Header(org.apache.http.Header) ServiceException(org.jets3t.service.ServiceException) RedirectException(org.apache.http.client.RedirectException)

Example 33 with ServiceException

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());
}
Also used : ServiceException(org.jets3t.service.ServiceException) S3ServiceException(org.jets3t.service.S3ServiceException) Test(org.junit.Test)

Example 34 with ServiceException

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());
}
Also used : ServiceException(org.jets3t.service.ServiceException) S3ServiceException(org.jets3t.service.S3ServiceException) CertificateException(java.security.cert.CertificateException) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) Test(org.junit.Test)

Example 35 with ServiceException

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);
}
Also used : LoginFailureException(ch.cyberduck.core.exception.LoginFailureException) ServiceException(org.jets3t.service.ServiceException) S3ServiceException(org.jets3t.service.S3ServiceException) Test(org.junit.Test)

Aggregations

ServiceException (org.jets3t.service.ServiceException)67 S3ServiceException (org.jets3t.service.S3ServiceException)24 Path (ch.cyberduck.core.Path)22 IOException (java.io.IOException)18 S3Object (org.jets3t.service.model.S3Object)16 StorageObject (org.jets3t.service.model.StorageObject)9 Test (org.junit.Test)9 AccessDeniedException (ch.cyberduck.core.exception.AccessDeniedException)8 InteroperabilityException (ch.cyberduck.core.exception.InteroperabilityException)8 NotfoundException (ch.cyberduck.core.exception.NotfoundException)8 ArrayList (java.util.ArrayList)7 BackgroundException (ch.cyberduck.core.exception.BackgroundException)6 MultipartUpload (org.jets3t.service.model.MultipartUpload)6 PathAttributes (ch.cyberduck.core.PathAttributes)4 HostPreferences (ch.cyberduck.core.preferences.HostPreferences)4 SegmentLoadingException (io.druid.segment.loading.SegmentLoadingException)4 BufferedInputStream (java.io.BufferedInputStream)4 InputStream (java.io.InputStream)4 AttributedList (ch.cyberduck.core.AttributedList)3 DefaultIOExceptionMappingService (ch.cyberduck.core.DefaultIOExceptionMappingService)3