Search in sources :

Example 26 with ServiceException

use of org.jets3t.service.ServiceException in project cyberduck by iterate-ch.

the class S3DefaultDeleteFeature method delete.

public void delete(final Map<Path, TransferStatus> files, final PasswordCallback prompt, final Callback callback) throws BackgroundException {
    final List<Path> containers = new ArrayList<Path>();
    for (Path file : files.keySet()) {
        if (containerService.isContainer(file)) {
            containers.add(file);
        } else {
            callback.delete(file);
            final Path bucket = containerService.getContainer(file);
            if (file.getType().contains(Path.Type.upload)) {
                // In-progress multipart upload
                try {
                    multipartService.delete(new MultipartUpload(file.attributes().getVersionId(), bucket.isRoot() ? StringUtils.EMPTY : bucket.getName(), containerService.getKey(file)));
                } catch (NotfoundException ignored) {
                    log.warn(String.format("Ignore failure deleting multipart upload %s", file));
                }
            } else {
                try {
                    // Always returning 204 even if the key does not exist. Does not return 404 for non-existing keys
                    session.getClient().deleteVersionedObject(file.attributes().getVersionId(), bucket.isRoot() ? StringUtils.EMPTY : bucket.getName(), containerService.getKey(file));
                } catch (ServiceException e) {
                    throw new S3ExceptionMappingService().map("Cannot delete {0}", e, file);
                }
            }
        }
    }
    for (Path file : containers) {
        callback.delete(file);
        try {
            final String bucket = containerService.getContainer(file).getName();
            session.getClient().deleteBucket(bucket);
            session.getClient().getRegionEndpointCache().removeRegionForBucketName(bucket);
        } catch (ServiceException e) {
            throw new S3ExceptionMappingService().map("Cannot delete {0}", e, file);
        }
    }
}
Also used : Path(ch.cyberduck.core.Path) NotfoundException(ch.cyberduck.core.exception.NotfoundException) ServiceException(org.jets3t.service.ServiceException) ArrayList(java.util.ArrayList) MultipartUpload(org.jets3t.service.model.MultipartUpload)

Example 27 with ServiceException

use of org.jets3t.service.ServiceException 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()));
}
Also used : ConnectionTimeoutException(ch.cyberduck.core.exception.ConnectionTimeoutException) DefaultHttpResponseExceptionMappingService(ch.cyberduck.core.http.DefaultHttpResponseExceptionMappingService) LoginFailureException(ch.cyberduck.core.exception.LoginFailureException) InteroperabilityException(ch.cyberduck.core.exception.InteroperabilityException) ServiceException(org.jets3t.service.ServiceException) ExpiredTokenException(ch.cyberduck.core.exception.ExpiredTokenException) HttpResponseException(org.apache.http.client.HttpResponseException) IOException(java.io.IOException) DefaultIOExceptionMappingService(ch.cyberduck.core.DefaultIOExceptionMappingService) SAXException(org.xml.sax.SAXException)

Example 28 with ServiceException

use of org.jets3t.service.ServiceException in project cyberduck by iterate-ch.

the class S3HttpRequestRetryHandler method retryRequest.

@Override
public boolean retryRequest(final IOException exception, final int executionCount, final HttpContext context) {
    if (executionCount <= MAX_RETRIES) {
        if (super.retryRequest(exception, executionCount, context)) {
            final Object attribute = context.getAttribute(HttpCoreContext.HTTP_REQUEST);
            if (attribute instanceof HttpUriRequest) {
                final HttpUriRequest method = (HttpUriRequest) attribute;
                log.warn(String.format("Retrying request %s", method));
                try {
                    // Build the authorization string for the method.
                    authorizer.authorizeHttpRequest(method, context, null);
                    return true;
                } catch (ServiceException e) {
                    log.warn("Unable to generate updated authorization string for retried request", e);
                }
            }
        }
    }
    return false;
}
Also used : HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) ServiceException(org.jets3t.service.ServiceException)

Example 29 with ServiceException

use of org.jets3t.service.ServiceException in project cyberduck by iterate-ch.

the class SpectraReadFeature method read.

@Override
public InputStream read(final Path file, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException {
    // Make sure file is available in cache
    final List<TransferStatus> chunks = bulk.query(Transfer.Type.download, file, status);
    // Sort chunks by offset
    chunks.sort(Comparator.comparingLong(TransferStatus::getOffset));
    final List<LazyInputStream> streams = new ArrayList<>();
    for (TransferStatus chunk : chunks) {
        final LazyInputStream in = new LazyInputStream(new LazyInputStream.OpenCallback() {

            @Override
            public InputStream open() throws IOException {
                try {
                    return session.getClient().getObjectImpl(false, containerService.getContainer(file).getName(), containerService.getKey(file), null, null, null, null, null, null, file.attributes().getVersionId(), new HashMap<String, Object>(), chunk.getParameters()).getDataInputStream();
                } catch (ServiceException e) {
                    throw new IOException(e.getMessage(), e);
                }
            }
        });
        streams.add(in);
    }
    // Concatenate streams
    return new SequenceInputStream(Collections.enumeration(streams));
}
Also used : SequenceInputStream(java.io.SequenceInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ServiceException(org.jets3t.service.ServiceException) SequenceInputStream(java.io.SequenceInputStream) TransferStatus(ch.cyberduck.core.transfer.TransferStatus)

Example 30 with ServiceException

use of org.jets3t.service.ServiceException in project cyberduck by iterate-ch.

the class S3AccessControlListFeature method setPermission.

@Override
public void setPermission(final Path file, final Acl acl) throws BackgroundException {
    try {
        // Read owner from bucket
        final AccessControlList list = this.toAcl(acl);
        final Path bucket = containerService.getContainer(file);
        if (containerService.isContainer(file)) {
            session.getClient().putBucketAcl(bucket.isRoot() ? StringUtils.EMPTY : bucket.getName(), list);
        } else {
            if (file.isFile() || file.isPlaceholder()) {
                session.getClient().putObjectAcl(bucket.isRoot() ? StringUtils.EMPTY : bucket.getName(), containerService.getKey(file), list);
            }
        }
    } catch (ServiceException e) {
        final BackgroundException failure = new S3ExceptionMappingService().map("Cannot change permissions of {0}", e, file);
        if (file.isPlaceholder()) {
            if (failure instanceof NotfoundException) {
                // No placeholder file may exist but we just have a common prefix
                return;
            }
        }
        throw failure;
    }
}
Also used : AccessControlList(org.jets3t.service.acl.AccessControlList) Path(ch.cyberduck.core.Path) NotfoundException(ch.cyberduck.core.exception.NotfoundException) ServiceException(org.jets3t.service.ServiceException) BackgroundException(ch.cyberduck.core.exception.BackgroundException)

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