@Override public Path move(final Path file, final Path renamed, final TransferStatus status, final Delete.Callback callback, final ConnectionCallback connectionCallback) throws BackgroundException { throw new InteroperabilityException("Not supported"); }
@Override public BackgroundException map(final MantaException failure) { final StringBuilder buffer = new StringBuilder(); this.append(buffer, failure.getMessage()); return new InteroperabilityException(buffer.toString(), failure); } }
@Override public BackgroundException map(final HttpResponseException failure) { final StringBuilder buffer = new StringBuilder(); final int statusCode = failure.getStatusCode(); if(statusCode == HttpStatus.SC_OK || statusCode == HttpStatus.SC_MULTI_STATUS) { // HTTP method status this.append(buffer, failure.getMessage()); // Failure unmarshalling XML response return new InteroperabilityException(buffer.toString(), failure); } return super.map(failure); } }
@Override public BackgroundException map(final IOException e) { final StringBuilder buffer = new StringBuilder(); this.append(buffer, e.getMessage()); if(e instanceof FTPConnectionClosedException) { return new ConnectionRefusedException(buffer.toString(), e); } if(e instanceof FTPException) { return this.handle((FTPException) e, buffer); } if(e instanceof MalformedServerReplyException) { return new InteroperabilityException(buffer.toString(), e); } return new DefaultIOExceptionMappingService().map(e); }
throw new InteroperabilityException("Invalid JSON response", e);
private BackgroundException handle(final FTPException e, final StringBuilder buffer) { final int status = e.getCode(); switch(status) { case FTPReply.INSUFFICIENT_STORAGE: case FTPReply.STORAGE_ALLOCATION_EXCEEDED: return new QuotaException(buffer.toString(), e); case FTPReply.NOT_LOGGED_IN: return new LoginFailureException(buffer.toString(), e); case FTPReply.FAILED_SECURITY_CHECK: case FTPReply.DENIED_FOR_POLICY_REASONS: case FTPReply.NEED_ACCOUNT: case FTPReply.NEED_ACCOUNT_FOR_STORING_FILES: case FTPReply.FILE_NAME_NOT_ALLOWED: case FTPReply.FILE_ACTION_NOT_TAKEN: case FTPReply.ACTION_ABORTED: return new AccessDeniedException(buffer.toString(), e); case FTPReply.UNAVAILABLE_RESOURCE: case FTPReply.FILE_UNAVAILABLE: // Requested action not taken. File unavailable (e.g., file not found, no access) return new NotfoundException(buffer.toString(), e); case FTPReply.SERVICE_NOT_AVAILABLE: return new ConnectionRefusedException(buffer.toString(), e); } return new InteroperabilityException(buffer.toString(), e); } }
@Override public BackgroundException map(final ExceptionUDT e) { final StringBuilder buffer = new StringBuilder(); this.append(buffer, e.getError().getDescription()); switch(e.getError()) { case NOSERVER: case ECONNSETUP: case ECONNFAIL: case ECONNLOST: case ECONNREJ: return new ConnectionRefusedException(buffer.toString(), e); case ETIMEOUT: case EINVSOCK: return new ConnectionTimeoutException(buffer.toString(), e); case EWRPERM: return new AccessDeniedException(buffer.toString(), e); case EINVPARAM: return new InteroperabilityException(buffer.toString(), e); case USER_DEFINED_MESSAGE: // Handle UDT Error : -4 : user defined message : UDT send time out [id: 0x3223fa70] case WRAPPER_UNKNOWN: case WRAPPER_UNIMPLEMENTED: case WRAPPER_MESSAGE: return new InteroperabilityException(buffer.toString(), e); } return this.wrap(e, buffer); } }
case HttpStatus.SC_METHOD_NOT_ALLOWED: case HttpStatus.SC_NOT_IMPLEMENTED: return new InteroperabilityException(buffer.toString(), failure); case HttpStatus.SC_REQUEST_TIMEOUT: case HttpStatus.SC_GATEWAY_TIMEOUT: return new InteroperabilityException(buffer.toString(), failure);
public BackgroundException map(final IOException e, final StringBuilder buffer, final DisconnectReason reason) { final String failure = buffer.toString(); if(DisconnectReason.HOST_KEY_NOT_VERIFIABLE.equals(reason)) { log.warn(String.format("Failure verifying host key. %s", failure)); // Host key dismissed by user return new ConnectionCanceledException(e); } if(DisconnectReason.PROTOCOL_ERROR.equals(reason)) { // Too many authentication failures return new InteroperabilityException(failure, e); } if(DisconnectReason.ILLEGAL_USER_NAME.equals(reason)) { return new LoginFailureException(failure, e); } if(DisconnectReason.NO_MORE_AUTH_METHODS_AVAILABLE.equals(reason)) { return new LoginFailureException(failure, e); } if(DisconnectReason.PROTOCOL_VERSION_NOT_SUPPORTED.equals(reason)) { return new InteroperabilityException(failure, e); } if(e instanceof TransportException) { return new ConnectionRefusedException(buffer.toString(), e); } return this.wrap(e, buffer); } }
@Override public BackgroundException map(final StorageException e) { final StringBuilder buffer = new StringBuilder(); this.append(buffer, e.getMessage()); if(ExceptionUtils.getRootCause(e) instanceof UnknownHostException) { return new NotfoundException(buffer.toString(), e); } switch(e.getHttpStatusCode()) { case 403: return new LoginFailureException(buffer.toString(), e); case 404: return new NotfoundException(buffer.toString(), e); case 304: case 405: case 400: case 411: case 412: return new InteroperabilityException(buffer.toString(), e); case 500: // InternalError // OperationTimedOut return new ConnectionTimeoutException(buffer.toString(), e); case 503: // ServerBusy return new RetriableAccessDeniedException(buffer.toString(), e); } return this.wrap(e, buffer); } }
throw new InteroperabilityException("No region found in authentication context"); log.warn(String.format("Fallback to first region %s", region.getRegionId())); if(null == region.getStorageUrl()) { throw new InteroperabilityException(String.format("No storage endpoint found for region %s", region.getRegionId()));
case FAILURE: case OP_UNSUPPORTED: return new InteroperabilityException(buffer.toString(), e); case NO_SUCH_FILE: return new NotfoundException(buffer.toString(), e); return new InteroperabilityException(buffer.toString(), e);
return new InteroperabilityException(buffer.toString(), failure); return new InteroperabilityException(buffer.toString(), failure);
private FileKeyProvider buildProvider(final Local identity, final KeyFormat format) throws InteroperabilityException { switch(format) { case PKCS5: return new PKCS5KeyFile.Factory().create(); case PKCS8: return new PKCS8KeyFile.Factory().create(); case OpenSSH: return new OpenSSHKeyFile.Factory().create(); case OpenSSHv1: return new OpenSSHKeyV1KeyFile.Factory().create(); case PuTTY: return new PuTTYKeyFile.Factory().create(); default: throw new InteroperabilityException(String.format("Unknown key format for file %s", identity.getName())); } }
@Override public void setStatus(final Path file, final boolean enabled) throws BackgroundException { final Path bucket = containerService.getContainer(file); try { if(!ServiceUtils.isBucketNameValidDNSName(bucket.getName())) { throw new InteroperabilityException("The name of the bucket used for Transfer Acceleration must be DNS-compliant and must not contain periods."); } session.getClient().setAccelerateConfig(bucket.getName(), new AccelerateConfig(enabled)); } catch(S3ServiceException failure) { throw new S3ExceptionMappingService().map("Failure to write attributes of {0}", failure, bucket); } }
public void create(final Path bucket, final String location) throws BackgroundException { // Create bucket if(!ServiceUtils.isBucketNameValidDNSName(bucket.getName())) { throw new InteroperabilityException(LocaleFactory.localizedString("Bucket name is not DNS compatible", "S3")); } AccessControlList acl; if(PreferencesFactory.get().getProperty("s3.bucket.acl.default").equals("public-read")) { acl = GSAccessControlList.REST_CANNED_PUBLIC_READ; } else { acl = GSAccessControlList.REST_CANNED_PRIVATE; } try { session.getClient().createBucket(new S3PathContainerService().getContainer(bucket).getName(), location, acl); } catch(ServiceException e) { throw new S3ExceptionMappingService().map("Cannot create folder {0}", e, bucket); } } }
return new InteroperabilityException(buffer.toString(), e);
public void create(final Path bucket, final String location) throws BackgroundException { if(!session.configure().getBoolProperty("s3service.disable-dns-buckets", false)) { if(!ServiceUtils.isBucketNameValidDNSName(bucket.getName())) { throw new InteroperabilityException(LocaleFactory.localizedString("Bucket name is not DNS compatible", "S3")); } } AccessControlList acl; if(PreferencesFactory.get().getProperty("s3.bucket.acl.default").equals("public-read")) { acl = AccessControlList.REST_CANNED_PUBLIC_READ; } else { acl = AccessControlList.REST_CANNED_PRIVATE; } try { final String region; if("us-east-1".equals(location)) { region = "US"; } else { region = location; } // Create bucket session.getClient().createBucket(URIEncoder.encode(containerService.getContainer(bucket).getName()), region, acl); } catch(ServiceException e) { throw new S3ExceptionMappingService().map("Cannot create folder {0}", e, bucket); } } }
@Override public BackgroundException map(final OneDriveAPIException failure) { if(failure.getResponseCode() > 0) { final StringAppender buffer = new StringAppender(); buffer.append(failure.getMessage()); buffer.append(failure.getErrorMessage()); return new HttpResponseExceptionMappingService().map(new HttpResponseException(failure.getResponseCode(), buffer.toString())); } if(ExceptionUtils.getRootCause(failure) instanceof IOException) { return new DefaultIOExceptionMappingService().map((IOException) ExceptionUtils.getRootCause(failure)); } return new InteroperabilityException(failure.getMessage(), failure); } }
@Override public PathAttributes find(final Path file) throws BackgroundException { if(file.isRoot()) { return PathAttributes.EMPTY; } try { if(session.getClient().hasFeature(FTPCmd.MLST.getCommand())) { if(!FTPReply.isPositiveCompletion(session.getClient().sendCommand(FTPCmd.MLST, file.getAbsolute()))) { throw new FTPException(session.getClient().getReplyCode(), session.getClient().getReplyString()); } final FTPDataResponseReader reader = new FTPMlsdListResponseReader(); final AttributedList<Path> attributes = reader.read(file.getParent(), Arrays.asList(session.getClient().getReplyStrings()), new DisabledListProgressListener()); if(attributes.contains(file)) { return attributes.get(attributes.indexOf(file)).attributes(); } } throw new InteroperabilityException("No support for MLST in reply to FEAT"); } catch(IOException e) { throw new FTPExceptionMappingService().map("Failure to read attributes of {0}", e, file); } } }