Java Code Examples for com.amazonaws.services.s3.model.AmazonS3Exception#getErrorCode()
The following examples show how to use
com.amazonaws.services.s3.model.AmazonS3Exception#getErrorCode() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: S3CommonFileObject.java From hop with Apache License 2.0 | 6 votes |
private void handleAttachExceptionFallback( String bucket, String keyWithDelimiter, AmazonS3Exception exception ) throws FileSystemException { ListObjectsRequest listObjectsRequest = new ListObjectsRequest() .withBucketName( bucket ) .withPrefix( keyWithDelimiter ) .withDelimiter( DELIMITER ); ObjectListing ol = fileSystem.getS3Client().listObjects( listObjectsRequest ); if ( !( ol.getCommonPrefixes().isEmpty() && ol.getObjectSummaries().isEmpty() ) ) { injectType( FileType.FOLDER ); } else { //Folders don't really exist - they will generate a "NoSuchKey" exception // confirms key doesn't exist but connection okay String errorCode = exception.getErrorCode(); if ( !errorCode.equals( "NoSuchKey" ) ) { // bubbling up other connection errors logger.error( "Could not get information on " + getQualifiedName(), exception ); // make sure this gets printed for the user throw new FileSystemException( "vfs.provider/get-type.error", getQualifiedName(), exception ); } } }
Example 2
Source File: S3CommonFileObject.java From hop with Apache License 2.0 | 5 votes |
protected void handleAttachException( String key, String bucket ) throws IOException { String keyWithDelimiter = key + DELIMITER; try { s3ObjectMetadata = fileSystem.getS3Client().getObjectMetadata( bucketName, key ); injectType( FileType.FOLDER ); this.key = keyWithDelimiter; } catch ( AmazonS3Exception e1 ) { String errorCode = e1.getErrorCode(); try { //S3 Object does not exist (could be the process of creating a new file. Lets fallback to old the old behavior. (getting the s3 object) if ( errorCode.equals( "404 Not Found" ) ) { s3Object = getS3Object( keyWithDelimiter, bucket ); s3ObjectMetadata = s3Object.getObjectMetadata(); injectType( FileType.FOLDER ); this.key = keyWithDelimiter; } else { //The exception was not related with not finding the file handleAttachExceptionFallback( bucket, keyWithDelimiter, e1 ); } } catch ( AmazonS3Exception e2 ) { //something went wrong getting the s3 object handleAttachExceptionFallback( bucket, keyWithDelimiter, e2 ); } } finally { closeS3Object(); } }
Example 3
Source File: S3FileObject.java From hop with Apache License 2.0 | 5 votes |
@Override public void handleAttachException( String key, String bucket ) throws FileSystemException { SimpleEntry<String, String> newPath = fixFilePath( key, bucket ); String keyWithDelimiter = newPath.getKey() + DELIMITER; try { s3Object = getS3Object( keyWithDelimiter, newPath.getValue() ); s3ObjectMetadata = s3Object.getObjectMetadata(); injectType( FileType.FOLDER ); } catch ( AmazonS3Exception e2 ) { ListObjectsRequest listObjectsRequest = new ListObjectsRequest() .withBucketName( newPath.getValue() ) .withPrefix( keyWithDelimiter ) .withDelimiter( DELIMITER ); ObjectListing ol = fileSystem.getS3Client().listObjects( listObjectsRequest ); if ( !( ol.getCommonPrefixes().isEmpty() && ol.getObjectSummaries().isEmpty() ) ) { injectType( FileType.FOLDER ); } else { //Folders don't really exist - they will generate a "NoSuchKey" exception String errorCode = e2.getErrorCode(); // confirms key doesn't exist but connection okay if ( !errorCode.equals( "NoSuchKey" ) ) { // bubbling up other connection errors logger.error( "Could not get information on " + getQualifiedName(), e2 ); // make sure this gets printed for the user throw new FileSystemException( "vfs.provider/get-type.error", getQualifiedName(), e2 ); } } } }
Example 4
Source File: S3RateLimiter.java From emodb with Apache License 2.0 | 5 votes |
private boolean isRequestRateExceededException(Throwable t) { if (t instanceof AmazonS3Exception) { AmazonS3Exception e = (AmazonS3Exception) t; // Several ways AWS communicates rate limit exceeded: 503 status codes and "SlowDown" error codes. // Check for either. return e.getStatusCode() == HttpStatus.SC_SERVICE_UNAVAILABLE || (e.getErrorCode() != null && e.getErrorCode().toLowerCase().contains("slowdown")); } return false; }