本文整理匯總了Java中com.amazonaws.services.s3.model.AmazonS3Exception.setErrorCode方法的典型用法代碼示例。如果您正苦於以下問題:Java AmazonS3Exception.setErrorCode方法的具體用法?Java AmazonS3Exception.setErrorCode怎麽用?Java AmazonS3Exception.setErrorCode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.amazonaws.services.s3.model.AmazonS3Exception
的用法示例。
在下文中一共展示了AmazonS3Exception.setErrorCode方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testThatHandlerErrorsWhenWeCantFindTheConfigFile
import com.amazonaws.services.s3.model.AmazonS3Exception; //導入方法依賴的package包/類
@Test(expected = RuntimeException.class)
public void testThatHandlerErrorsWhenWeCantFindTheConfigFile() {
String arn = "arn:aws:lambda:us-west-2:1111111:function:dev-gateway-fas342452-6d86-LambdaWAFBlacklistingFun-1LSORI5GUP95H";
String bucketName = "dev-cerberusconfigbucket";
List<Bucket> bucketList = Lists.newLinkedList();
bucketList.add(new Bucket(bucketName));
AmazonS3Exception e = new AmazonS3Exception("foo");
e.setErrorCode("NoSuchKey");
when(amazonS3Client.getObject(any())).thenThrow(e);
when(amazonS3Client.listBuckets()).thenReturn(bucketList);
handler.getConfiguration(arn);
}
示例2: build
import com.amazonaws.services.s3.model.AmazonS3Exception; //導入方法依賴的package包/類
/**
* Creates a new AmazonS3Exception object with the values set.
*/
public AmazonS3Exception build() {
AmazonS3Exception s3Exception = errorResponseXml == null ? new AmazonS3Exception(
errorMessage) : new AmazonS3Exception(errorMessage,
errorResponseXml);
s3Exception.setErrorCode(errorCode);
s3Exception.setExtendedRequestId(extendedRequestId);
s3Exception.setStatusCode(statusCode);
s3Exception.setRequestId(requestId);
s3Exception.setCloudFrontId(cloudFrontId);
s3Exception.setAdditionalDetails(additionalDetails);
s3Exception.setErrorType(errorTypeOf(statusCode));
return s3Exception;
}
示例3: listObjects
import com.amazonaws.services.s3.model.AmazonS3Exception; //導入方法依賴的package包/類
/**
* {@inheritDoc}
* <p/>
* If the bucket does not exist, returns a listing with an empty list. If a prefix is specified in listObjectsRequest, only keys starting with the prefix
* will be returned.
*/
@Override
public ObjectListing listObjects(ListObjectsRequest listObjectsRequest, AmazonS3 s3Client)
{
LOGGER.debug("listObjects(): listObjectsRequest.getBucketName() = " + listObjectsRequest.getBucketName());
String bucketName = listObjectsRequest.getBucketName();
if (MOCK_S3_BUCKET_NAME_NO_SUCH_BUCKET_EXCEPTION.equals(bucketName))
{
AmazonS3Exception amazonS3Exception = new AmazonS3Exception(MOCK_S3_BUCKET_NAME_NO_SUCH_BUCKET_EXCEPTION);
amazonS3Exception.setErrorCode("NoSuchBucket");
throw amazonS3Exception;
}
ObjectListing objectListing = new ObjectListing();
objectListing.setBucketName(bucketName);
MockS3Bucket mockS3Bucket = mockS3Buckets.get(bucketName);
if (mockS3Bucket != null)
{
for (MockS3Object mockS3Object : mockS3Bucket.getObjects().values())
{
String s3ObjectKey = mockS3Object.getKey();
if (listObjectsRequest.getPrefix() == null || s3ObjectKey.startsWith(listObjectsRequest.getPrefix()))
{
S3ObjectSummary s3ObjectSummary = new S3ObjectSummary();
s3ObjectSummary.setBucketName(bucketName);
s3ObjectSummary.setKey(s3ObjectKey);
s3ObjectSummary.setSize(mockS3Object.getData().length);
s3ObjectSummary.setStorageClass(mockS3Object.getObjectMetadata() != null ? mockS3Object.getObjectMetadata().getStorageClass() : null);
objectListing.getObjectSummaries().add(s3ObjectSummary);
}
}
}
return objectListing;
}
示例4: getPdf
import com.amazonaws.services.s3.model.AmazonS3Exception; //導入方法依賴的package包/類
@Override
public InputStream getPdf(final String paperId) throws IOException {
// We download to a temp file first. If we gave out an InputStream that comes directly from
// S3, it would time out if the caller of this function reads the stream too slowly.
final String key = paperId.substring(0, 4) + "/" + paperId.substring(4) + ".pdf";
final S3Object object;
try {
object = s3.getObject(bucket, key);
} catch(final AmazonS3Exception e) {
final AmazonS3Exception rethrown =
new AmazonS3Exception(
String.format(
"Error for key s3://%s/%s",
bucket,
key),
e);
rethrown.setExtendedRequestId(e.getExtendedRequestId());
rethrown.setErrorCode(e.getErrorCode());
rethrown.setErrorType(e.getErrorType());
rethrown.setRequestId(e.getRequestId());
rethrown.setServiceName(e.getServiceName());
rethrown.setStatusCode(e.getStatusCode());
throw rethrown;
}
final Path tempFile = Files.createTempFile(paperId + ".", ".paper.pdf");
try {
Files.copy(object.getObjectContent(), tempFile, StandardCopyOption.REPLACE_EXISTING);
return new BufferedInputStream(Files.newInputStream(tempFile));
} finally {
Files.deleteIfExists(tempFile);
}
}
示例5: build
import com.amazonaws.services.s3.model.AmazonS3Exception; //導入方法依賴的package包/類
public AmazonS3Exception build() {
AmazonS3Exception result = new AmazonS3Exception(message);
result.setStatusCode(statusCode);
result.setErrorCode(errorCode);
result.setRequestId(requestId);
result.setServiceName(SERVICE_NAME);
return result;
}
示例6: listVersions
import com.amazonaws.services.s3.model.AmazonS3Exception; //導入方法依賴的package包/類
/**
* {@inheritDoc}
* <p/>
* If the bucket does not exist, returns a listing with an empty list. If a prefix is specified in listVersionsRequest, only versions starting with the
* prefix will be returned.
*/
@Override
public VersionListing listVersions(ListVersionsRequest listVersionsRequest, AmazonS3 s3Client)
{
LOGGER.debug("listVersions(): listVersionsRequest.getBucketName() = " + listVersionsRequest.getBucketName());
String bucketName = listVersionsRequest.getBucketName();
if (MOCK_S3_BUCKET_NAME_NO_SUCH_BUCKET_EXCEPTION.equals(bucketName))
{
AmazonS3Exception amazonS3Exception = new AmazonS3Exception(MOCK_S3_BUCKET_NAME_NO_SUCH_BUCKET_EXCEPTION);
amazonS3Exception.setErrorCode("NoSuchBucket");
throw amazonS3Exception;
}
else if (MOCK_S3_BUCKET_NAME_INTERNAL_ERROR.equals(bucketName))
{
throw new AmazonServiceException(S3Operations.ERROR_CODE_INTERNAL_ERROR);
}
VersionListing versionListing = new VersionListing();
versionListing.setBucketName(bucketName);
MockS3Bucket mockS3Bucket = mockS3Buckets.get(bucketName);
if (mockS3Bucket != null)
{
for (MockS3Object mockS3Object : mockS3Bucket.getVersions().values())
{
String s3ObjectKey = mockS3Object.getKey();
if (listVersionsRequest.getPrefix() == null || s3ObjectKey.startsWith(listVersionsRequest.getPrefix()))
{
S3VersionSummary s3VersionSummary = new S3VersionSummary();
s3VersionSummary.setBucketName(bucketName);
s3VersionSummary.setKey(s3ObjectKey);
s3VersionSummary.setVersionId(mockS3Object.getVersion());
s3VersionSummary.setSize(mockS3Object.getData().length);
s3VersionSummary.setStorageClass(mockS3Object.getObjectMetadata() != null ? mockS3Object.getObjectMetadata().getStorageClass() : null);
versionListing.getVersionSummaries().add(s3VersionSummary);
}
}
}
return versionListing;
}