當前位置: 首頁>>代碼示例>>Java>>正文


Java AmazonS3Exception.getStatusCode方法代碼示例

本文整理匯總了Java中com.amazonaws.services.s3.model.AmazonS3Exception.getStatusCode方法的典型用法代碼示例。如果您正苦於以下問題:Java AmazonS3Exception.getStatusCode方法的具體用法?Java AmazonS3Exception.getStatusCode怎麽用?Java AmazonS3Exception.getStatusCode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.amazonaws.services.s3.model.AmazonS3Exception的用法示例。


在下文中一共展示了AmazonS3Exception.getStatusCode方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: deleteShortUrl

import com.amazonaws.services.s3.model.AmazonS3Exception; //導入方法依賴的package包/類
/**
 * This method deletes the url for code
 * 
 * @param code
 */
public void deleteShortUrl(String code) {
	try {
		// get the object
		ObjectMetadata metaData = this.s3Client.getObjectMetadata(this.bucket, code);
		String url = metaData.getUserMetaDataOf("url");
		logger.info("The url to be deleted {}", url);
		this.s3Client.deleteObject(this.bucket, code);
		this.s3Client.deleteObject(this.bucket + "-dummy", code + Base64.encodeBase64String(url.getBytes()));

	} catch (AmazonS3Exception ex) {
		if (ex.getStatusCode() == HttpStatus.SC_NOT_FOUND) {
			return;
		}
		logger.warn("Unable to get object status", ex);
		throw ex;
	}

}
 
開發者ID:weblegit,項目名稱:urlshortner,代碼行數:24,代碼來源:UrlShortnerService.java

示例2: isFileExisting

import com.amazonaws.services.s3.model.AmazonS3Exception; //導入方法依賴的package包/類
/**
 * A method that returns true if a correct s3 URI was provided and false otherwise.
 *
 * @param uri The provided URI for the file.
 * @return a boolean value that shows whether the correct URI was provided
 */
boolean isFileExisting(AmazonS3URI uri) {

    boolean exist = true;

    try {
        aws.getObjectMetadata(uri.getBucket(), uri.getKey());
    } catch (AmazonS3Exception e) {
        if (e.getStatusCode() == HttpStatus.SC_FORBIDDEN
                || e.getStatusCode() == HttpStatus.SC_NOT_FOUND) {
            exist = false;
        } else {
            throw e;
        }
    }
    return exist;
}
 
開發者ID:epam,項目名稱:htsjdk-s3-plugin,代碼行數:23,代碼來源:S3Client.java

示例3: retrieve

import com.amazonaws.services.s3.model.AmazonS3Exception; //導入方法依賴的package包/類
@Override
public void retrieve( char[] path )
        throws IOException
{
    String pathValue = String.valueOf( path );
    try
    {
        LOG.log( Level.FINE, () -> "Retrieving " + getBucketName() + ":" + pathValue );
        S3Object obj = getS3().getObject( new GetObjectRequest( getBucketName(), pathValue ) );
        FileSystemUtils.copyFromRemote( () -> obj.getObjectContent(), getDelegate(), path );
        LOG.log( Level.FINE, () -> "Retrieved " + getBucketName() + ":" + pathValue );
    } catch( AmazonS3Exception ex )
    {
        LOG.log( Level.FINE, () -> "Error " + ex.getStatusCode() + " " + getBucketName() + ":" + pathValue );
        if( ex.getStatusCode() == 404 )
        {
            throw new FileNotFoundException( pathValue );
        }
        throw new IOException( "Cannot access " + pathValue, ex );
    }
}
 
開發者ID:peter-mount,項目名稱:filesystem,代碼行數:22,代碼來源:S3Retriever.java

示例4: getRegionForBucket

import com.amazonaws.services.s3.model.AmazonS3Exception; //導入方法依賴的package包/類
public String getRegionForBucket(String bucket) {
    // Just querying for the location for a bucket can be done with the local client
    AmazonS3 client = getLocalS3Client();
    try {
        String region = client.getBucketLocation(bucket);
        if ("US".equals(region)) {
            // GetBucketLocation requests return null for us-east-1 which the SDK then replaces with "US".
            // So change it to the actual region.
            region = "us-east-1";
        }
        return region;
    } catch (AmazonS3Exception e) {
        if (e.getStatusCode() == Response.Status.NOT_FOUND.getStatusCode()) {
            // If the bucket doesn't exist then return null
            return null;
        }
        throw e;
    }
}
 
開發者ID:bazaarvoice,項目名稱:emodb,代碼行數:20,代碼來源:AmazonS3Provider.java

示例5: writeScanCompleteFile

import com.amazonaws.services.s3.model.AmazonS3Exception; //導入方法依賴的package包/類
@Override
protected boolean writeScanCompleteFile(URI fileUri, byte[] contents)
        throws IOException {
    String bucket = fileUri.getHost();
    String key = getKeyFromPath(fileUri);

    try {
        // The following will throw an exception unless the file already exists
        _amazonS3.getObjectMetadata(bucket, key);
        return false;
    } catch (AmazonS3Exception e) {
        if (e.getStatusCode() != Response.Status.NOT_FOUND.getStatusCode()) {
            // Expected case is not found, meaning the file does not exist
            // All other cases are some unexpected error
            throw new IOException(e);
        }
    }

    uploadContents(bucket, key, contents);
    return true;
}
 
開發者ID:bazaarvoice,項目名稱:emodb,代碼行數:22,代碼來源:S3ScanWriter.java

示例6: mapShortCode

import com.amazonaws.services.s3.model.AmazonS3Exception; //導入方法依賴的package包/類
@Override
public boolean mapShortCode(String code, String paramString) throws IOException {
    if(!enabled) {
        throw new IllegalStateException("Shortlink feature disabled");
    }

    try {
        // does object exist?
        client.getObjectMetadata(bucket, OBJECT_PREFIX + code);
    } catch (AmazonS3Exception e) {
        if (e.getStatusCode() != 404) {
            log.warn(e);
            return false;
        }
    }

    byte[] paramStringBytes = paramString.getBytes(StringUtils.UTF8);
    InputStream is = new ByteArrayInputStream(paramStringBytes);
    ObjectMetadata metadata = new ObjectMetadata();
    metadata.setContentType("text/plain");
    metadata.setContentLength(paramStringBytes.length);

    client.putObject(new PutObjectRequest(bucket, OBJECT_PREFIX + code, is, metadata));
    return true;
}
 
開發者ID:indeedeng,項目名稱:iql,代碼行數:26,代碼來源:S3ShortLinkRepository.java

示例7: findAllResourcesThatMatches

import com.amazonaws.services.s3.model.AmazonS3Exception; //導入方法依賴的package包/類
private void findAllResourcesThatMatches(String bucketName, Set<Resource> resources, String prefix, String keyPattern) {
    ListObjectsRequest listObjectsRequest = new ListObjectsRequest().withBucketName(bucketName).withPrefix(prefix);
    ObjectListing objectListing = null;

    do {
        try {
            if (objectListing == null) {
                objectListing = this.amazonS3.listObjects(listObjectsRequest);
            } else {
                objectListing = this.amazonS3.listNextBatchOfObjects(objectListing);
            }
            Set<Resource> newResources = getResourcesFromObjectSummaries(bucketName, keyPattern, objectListing.getObjectSummaries());
            if (!newResources.isEmpty()) {
                resources.addAll(newResources);
            }
        } catch (AmazonS3Exception e) {
            if (301 != e.getStatusCode()) {
                throw e;
            }
        }
    } while (objectListing != null && objectListing.isTruncated());
}
 
開發者ID:spring-cloud,項目名稱:spring-cloud-aws,代碼行數:23,代碼來源:PathMatchingSimpleStorageResourcePatternResolver.java

示例8: getObjectMetadata

import com.amazonaws.services.s3.model.AmazonS3Exception; //導入方法依賴的package包/類
private ObjectMetadata getObjectMetadata() {
    if (this.objectMetadata == null) {
        try {
            GetObjectMetadataRequest metadataRequest = new GetObjectMetadataRequest(this.bucketName, this.objectName);
            if (this.versionId != null) {
                metadataRequest.setVersionId(this.versionId);
            }
            this.objectMetadata = this.amazonS3.getObjectMetadata(metadataRequest);
        } catch (AmazonS3Exception e) {
            // Catch 404 (object not found) and 301 (bucket not found, moved permanently)
            if (e.getStatusCode() == 404 || e.getStatusCode() == 301) {
                this.objectMetadata = null;
            } else {
                throw e;
            }
        }
    }
    return this.objectMetadata;
}
 
開發者ID:spring-cloud,項目名稱:spring-cloud-aws,代碼行數:20,代碼來源:SimpleStorageResource.java

示例9: checkConfiguration

import com.amazonaws.services.s3.model.AmazonS3Exception; //導入方法依賴的package包/類
public void checkConfiguration() throws RuntimeException {
    if(Strings.isNullOrEmpty(amazonS3BucketName)) {
        throw new RuntimeException("Amazon S3 bucket name is not defined");
    }
    try {
        if (!amazonS3.doesBucketExist(amazonS3BucketName)) {
            throw new RuntimeException("Bucket '" + amazonS3BucketName + "' not found for user '" + awsCredentials.getAWSAccessKeyId() + "'");
        }
    } catch (AmazonS3Exception e) {
        if (e.getStatusCode() == 403 && "SignatureDoesNotMatch".equals(e.getErrorCode())) {
            throw new RuntimeException("Invalid credentials AWSAccessKeyId='" + awsCredentials.getAWSAccessKeyId() + "', AWSSecretKey=**** to access bucket '" + amazonS3BucketName + "'", e);
        } else {
            throw e;
        }
    }
}
 
開發者ID:cloudbees-attic,項目名稱:bees-shop-clickstart,代碼行數:17,代碼來源:AmazonS3FileStorageService.java

示例10: shouldRetry

import com.amazonaws.services.s3.model.AmazonS3Exception; //導入方法依賴的package包/類
protected boolean shouldRetry(AmazonClientException e) {
    if (e instanceof AmazonS3Exception) {
        AmazonS3Exception s3e = (AmazonS3Exception) e;
        if (s3e.getStatusCode() == 400 && "RequestTimeout".equals(s3e.getErrorCode())) {
            return true;
        }
    }
    return e.isRetryable();
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:10,代碼來源:S3BlobStore.java

示例11: getObjectCode

import com.amazonaws.services.s3.model.AmazonS3Exception; //導入方法依賴的package包/類
private String getObjectCode() {
	while (true) {
		String code = Util.generate();
		try {
			this.s3Client.getObjectMetadata(this.bucket, code);
		} catch (AmazonS3Exception ex) {
			if (ex.getStatusCode() == HttpStatus.SC_NOT_FOUND) {
				return code;
			}
			logger.warn("Unable to get object status", ex);
			throw ex;
		}
	}
}
 
開發者ID:weblegit,項目名稱:urlshortner,代碼行數:15,代碼來源:UrlShortnerService.java

示例12: doesObjectExist

import com.amazonaws.services.s3.model.AmazonS3Exception; //導入方法依賴的package包/類
@Override
public boolean doesObjectExist(String bucketName, String objectName)
        throws AmazonServiceException, SdkClientException {
    try {
        getObjectMetadata(bucketName, objectName);
        return true;
    } catch (AmazonS3Exception e) {
        if (e.getStatusCode() == 404) {
            return false;
        }
        throw e;
    }
}
 
開發者ID:IBM,項目名稱:ibm-cos-sdk-java,代碼行數:14,代碼來源:AmazonS3Client.java

示例13: invoke

import com.amazonaws.services.s3.model.AmazonS3Exception; //導入方法依賴的package包/類
@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
    try {
        return invocation.proceed();
    } catch (AmazonS3Exception e) {
        if (301 == e.getStatusCode()) {
            AmazonS3 redirectClient = buildAmazonS3ForRedirectLocation(this.amazonS3, e);
            return ReflectionUtils.invokeMethod(invocation.getMethod(), redirectClient, invocation.getArguments());
        } else {
            throw e;
        }
    }
}
 
開發者ID:spring-cloud,項目名稱:spring-cloud-aws,代碼行數:14,代碼來源:AmazonS3ProxyFactory.java

示例14: isNotFoundError

import com.amazonaws.services.s3.model.AmazonS3Exception; //導入方法依賴的package包/類
private boolean isNotFoundError(AmazonS3Exception e)
{
    return (e.getStatusCode() == 404) || (e.getStatusCode() == 403);
}
 
開發者ID:dcos,項目名稱:exhibitor,代碼行數:5,代碼來源:S3ConfigProvider.java

示例15: testDeleteRemoved

import com.amazonaws.services.s3.model.AmazonS3Exception; //導入方法依賴的package包/類
@Test
public void testDeleteRemoved() throws Exception {
    if (!checkEnvs()) return;

    final String key = "testDeleteRemoved_" + random(10);

    main = new MirrorMain(new String[]{OPT_VERBOSE, OPT_PREFIX, key,
            OPT_DELETE_REMOVED, OPT_SOURCE_BUCKET, SOURCE, OPT_DESTINATION_BUCKET, DESTINATION});
    main.init();

    // Write some files to dest
    final int numDestFiles = 3;
    final String[] destKeys = new String[numDestFiles];
    final S32S3TestFile[] destFiles = new S32S3TestFile[numDestFiles];
    for (int i = 0; i < numDestFiles; i++) {
        destKeys[i] = key + "-dest" + i;
        destFiles[i] = createTestFile(destKeys[i], S32S3TestFile.Copy.DEST, S32S3TestFile.Clean.DEST);
    }

    // Write 1 file to source
    final String srcKey = key + "-src";
    final S32S3TestFile srcFile = createTestFile(srcKey, S32S3TestFile.Copy.SOURCE, S32S3TestFile.Clean.SOURCE_AND_DEST);

    // Initiate copy
    main.run();

    // Expect only 1 copy and numDestFiles deletes
    assertEquals(1, main.getContext().getStats().objectsCopied.get());
    assertEquals(numDestFiles, main.getContext().getStats().objectsDeleted.get());

    // Expect none of the original dest files to be there anymore
    for (int i = 0; i < numDestFiles; i++) {
        try {
            ((AmazonS3Client) main.getSourceClient()).getObjectMetadata(DESTINATION, destKeys[i]);
            fail("testDeleteRemoved: expected " + destKeys[i] + " to be removed from destination bucket " + DESTINATION);
        } catch (AmazonS3Exception e) {
            if (e.getStatusCode() != 404) {
                fail("testDeleteRemoved: unexpected exception (expected statusCode == 404): " + e);
            }
        }
    }

    // Expect source file to now be present in both source and destination buckets
    ObjectMetadata metadata;
    metadata = ((AmazonS3Client) main.getSourceClient()).getObjectMetadata(SOURCE, srcKey);
    assertEquals(srcFile.data.length(), metadata.getContentLength());

    metadata = ((AmazonS3Client) main.getSourceClient()).getObjectMetadata(DESTINATION, srcKey);
    assertEquals(srcFile.data.length(), metadata.getContentLength());
}
 
開發者ID:DevOps-TangoMe,項目名稱:BucketSyncer,代碼行數:51,代碼來源:S32S3MirrorTest.java


注:本文中的com.amazonaws.services.s3.model.AmazonS3Exception.getStatusCode方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。