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