本文整理匯總了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;
}
}
示例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;
}
示例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 );
}
}
示例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;
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
}
}
示例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();
}
示例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;
}
}
}
示例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;
}
}
示例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;
}
}
}
示例14: isNotFoundError
import com.amazonaws.services.s3.model.AmazonS3Exception; //導入方法依賴的package包/類
private boolean isNotFoundError(AmazonS3Exception e)
{
return (e.getStatusCode() == 404) || (e.getStatusCode() == 403);
}
示例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());
}