当前位置: 首页>>代码示例>>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;未经允许,请勿转载。