当前位置: 首页>>代码示例>>Java>>正文


Java AmazonS3Exception类代码示例

本文整理汇总了Java中com.amazonaws.services.s3.model.AmazonS3Exception的典型用法代码示例。如果您正苦于以下问题:Java AmazonS3Exception类的具体用法?Java AmazonS3Exception怎么用?Java AmazonS3Exception使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


AmazonS3Exception类属于com.amazonaws.services.s3.model包,在下文中一共展示了AmazonS3Exception类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getObject

import com.amazonaws.services.s3.model.AmazonS3Exception; //导入依赖的package包/类
@Override
public S3Object getObject(GetObjectRequest getObjectRequest)
        throws AmazonClientException, AmazonServiceException {
    // in ESBlobStoreContainerTestCase.java, the prefix is empty,
    // so the key and blobName are equivalent to each other
    String blobName = getObjectRequest.getKey();

    if (!blobs.containsKey(blobName)) {
        throw new AmazonS3Exception("[" + blobName + "] does not exist.");
    }

    // the HTTP request attribute is irrelevant for reading
    S3ObjectInputStream stream = new S3ObjectInputStream(
            blobs.get(blobName), null, false);
    S3Object s3Object = new S3Object();
    s3Object.setObjectContent(stream);
    return s3Object;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:19,代码来源:MockAmazonS3.java

示例2: readBlob

import com.amazonaws.services.s3.model.AmazonS3Exception; //导入依赖的package包/类
@Override
public InputStream readBlob(String blobName) throws IOException {
    int retry = 0;
    while (retry <= blobStore.numberOfRetries()) {
        try {
            S3Object s3Object = SocketAccess.doPrivileged(() -> blobStore.client().getObject(blobStore.bucket(), buildKey(blobName)));
            return s3Object.getObjectContent();
        } catch (AmazonClientException e) {
            if (blobStore.shouldRetry(e) && (retry < blobStore.numberOfRetries())) {
                retry++;
            } else {
                if (e instanceof AmazonS3Exception) {
                    if (404 == ((AmazonS3Exception) e).getStatusCode()) {
                        throw new NoSuchFileException("Blob object [" + blobName + "] not found: " + e.getMessage());
                    }
                }
                throw e;
            }
        }
    }
    throw new BlobStoreException("retries exhausted while attempting to access blob object [name:" + blobName + ", bucket:" + blobStore.bucket() + "]");
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:23,代码来源:S3BlobContainer.java

示例3: move

import com.amazonaws.services.s3.model.AmazonS3Exception; //导入依赖的package包/类
@Override
public void move(String sourceBlobName, String targetBlobName) throws IOException {
    try {
        CopyObjectRequest request = new CopyObjectRequest(blobStore.bucket(), buildKey(sourceBlobName),
            blobStore.bucket(), buildKey(targetBlobName));

        if (blobStore.serverSideEncryption()) {
            ObjectMetadata objectMetadata = new ObjectMetadata();
            objectMetadata.setSSEAlgorithm(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION);
            request.setNewObjectMetadata(objectMetadata);
        }

        SocketAccess.doPrivilegedVoid(() -> {
            blobStore.client().copyObject(request);
            blobStore.client().deleteObject(blobStore.bucket(), buildKey(sourceBlobName));
        });

    } catch (AmazonS3Exception e) {
        throw new IOException(e);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:22,代码来源:S3BlobContainer.java

示例4: putObject

import com.amazonaws.services.s3.model.AmazonS3Exception; //导入依赖的package包/类
@Override
public PutObjectResult putObject(PutObjectRequest putObjectRequest)
        throws AmazonClientException, AmazonServiceException {
    String blobName = putObjectRequest.getKey();
    DigestInputStream stream = (DigestInputStream) putObjectRequest.getInputStream();

    if (blobs.containsKey(blobName)) {
        throw new AmazonS3Exception("[" + blobName + "] already exists.");
    }

    blobs.put(blobName, stream);

    // input and output md5 hashes need to match to avoid an exception
    String md5 = Base64.encodeAsString(stream.getMessageDigest().digest());
    PutObjectResult result = new PutObjectResult();
    result.setContentMd5(md5);

    return result;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:20,代码来源:MockAmazonS3.java

示例5: copyObject

import com.amazonaws.services.s3.model.AmazonS3Exception; //导入依赖的package包/类
@Override
public CopyObjectResult copyObject(CopyObjectRequest copyObjectRequest)
        throws AmazonClientException, AmazonServiceException {
    String sourceBlobName = copyObjectRequest.getSourceKey();
    String targetBlobName = copyObjectRequest.getDestinationKey();

    if (!blobs.containsKey(sourceBlobName)) {
        throw new AmazonS3Exception("Source blob [" +
                sourceBlobName + "] does not exist.");
    }

    if (blobs.containsKey(targetBlobName)) {
        throw new AmazonS3Exception("Target blob [" +
                targetBlobName + "] already exists.");
    }

    blobs.put(targetBlobName, blobs.get(sourceBlobName));
    return new CopyObjectResult(); // nothing is done with it
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:20,代码来源:MockAmazonS3.java

示例6: 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

示例7: getS3Value

import com.amazonaws.services.s3.model.AmazonS3Exception; //导入依赖的package包/类
/**
 * Attempt to fetch a secret from S3.
 *
 * @param s3path where to fetch it from
 * @return the content of the file found on S3
 * @throws IOException on problems streaming the content of the file
 * @throws AmazonS3Exception on problems communicating with amazon
 */
private String getS3Value(final SecretPath s3path) throws IOException, AmazonS3Exception {
    LOG.info("Fetching secret from s3://" + s3path.bucket + "/" + s3path.key);
    if (s3Client == null) {
        if (awsCredentialsProvider != null) {
            s3Client = AmazonS3ClientBuilder.standard().withCredentials(awsCredentialsProvider)
                    .build();
        } else {
            s3Client = AmazonS3ClientBuilder.standard().build();
        }
    }
    final S3Object s3object
            = s3Client.getObject(new GetObjectRequest(s3path.bucket, s3path.key));
    final BufferedReader reader
            = new BufferedReader(new InputStreamReader(s3object.getObjectContent()));
    final StringBuilder b = new StringBuilder();
    String line;
    while((line = reader.readLine()) != null) {
        b.append(line);
    }
    LOG.info("Found secret");
    reader.close();
    return b.toString();
}
 
开发者ID:secondbase,项目名称:secondbase,代码行数:32,代码来源:S3SecretHandler.java

示例8: shouldRetryCompleteMultipartUpload

import com.amazonaws.services.s3.model.AmazonS3Exception; //导入依赖的package包/类
private boolean shouldRetryCompleteMultipartUpload(AmazonWebServiceRequest originalRequest,
                                                   AmazonS3Exception exception,
                                                   int retriesAttempted) {

    final RetryPolicy retryPolicy = clientConfiguration.getRetryPolicy();

    if (retryPolicy == null || retryPolicy.getRetryCondition() == null) {
        return false;
    }

    if (retryPolicy == PredefinedRetryPolicies.NO_RETRY_POLICY) {
        return false;
    }

    return completeMultipartUploadRetryCondition.shouldRetry
            (originalRequest, exception, retriesAttempted);
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:18,代码来源:AmazonS3Client.java

示例9: getBucketRegionViaHeadRequest

import com.amazonaws.services.s3.model.AmazonS3Exception; //导入依赖的package包/类
/**
 * Retrieves the region of the bucket by making a HeadBucket request to us-west-1 region.
 *
 * Currently S3 doesn't return region in a HEAD Bucket request if the bucket
 * owner has enabled bucket to accept only SigV4 requests via bucket
 * policies.
 */
private String getBucketRegionViaHeadRequest(String bucketName) {
    String bucketRegion = null;

    try {
        Request<HeadBucketRequest> request = createRequest(bucketName, null,
                new HeadBucketRequest(bucketName), HttpMethodName.HEAD);

        HeadBucketResult result = invoke(request, new HeadBucketResultHandler(), bucketName, null, true);
        bucketRegion = result.getBucketRegion();
    } catch (AmazonS3Exception exception) {
        if (exception.getAdditionalDetails() != null) {
            bucketRegion = exception.getAdditionalDetails().get(
                Headers.S3_BUCKET_REGION);
        }
    }

    if (bucketRegion == null && log.isDebugEnabled()) {
        log.debug("Not able to derive region of the " + bucketName + " from the HEAD Bucket requests.");
    }

    return bucketRegion;
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:30,代码来源:AmazonS3Client.java

示例10: createExceptionFromHeaders

import com.amazonaws.services.s3.model.AmazonS3Exception; //导入依赖的package包/类
private AmazonS3Exception createExceptionFromHeaders(
        HttpResponse errorResponse, String errorResponseXml) {
    final Map<String, String> headers = errorResponse.getHeaders();
    final int statusCode = errorResponse.getStatusCode();
    final AmazonS3ExceptionBuilder exceptionBuilder = new AmazonS3ExceptionBuilder();
    exceptionBuilder.setErrorMessage(errorResponse.getStatusText());
    exceptionBuilder.setErrorResponseXml(errorResponseXml);
    exceptionBuilder.setStatusCode(statusCode);
    exceptionBuilder
            .setExtendedRequestId(headers.get(Headers.EXTENDED_REQUEST_ID));
    exceptionBuilder.setRequestId(headers.get(Headers.REQUEST_ID));
    exceptionBuilder.setCloudFrontId(headers.get(Headers.CLOUD_FRONT_ID));
    exceptionBuilder
            .setErrorCode(statusCode + " " + errorResponse.getStatusText());
    exceptionBuilder.addAdditionalDetail(Headers.S3_BUCKET_REGION,
            errorResponse.getHeaders().get(Headers.S3_BUCKET_REGION));
    return exceptionBuilder.build();
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:19,代码来源:S3ErrorResponseHandler.java

示例11: shouldNotUploadStreamingWithWrongEncryptionKey

import com.amazonaws.services.s3.model.AmazonS3Exception; //导入依赖的package包/类
/**
 * Tests if Object can be uploaded with wrong KMS Key
 */
@Test
public void shouldNotUploadStreamingWithWrongEncryptionKey() {
  final byte[] bytes = UPLOAD_FILE_NAME.getBytes();
  final InputStream stream = new ByteArrayInputStream(bytes);
  final String objectKey = UUID.randomUUID().toString();
  s3Client.createBucket(BUCKET_NAME);
  final ObjectMetadata metadata = new ObjectMetadata();
  metadata.setContentLength(bytes.length);
  final PutObjectRequest putObjectRequest =
      new PutObjectRequest(BUCKET_NAME, objectKey, stream, metadata);
  putObjectRequest.setSSEAwsKeyManagementParams(new SSEAwsKeyManagementParams(TEST_WRONG_KEYREF));

  thrown.expect(AmazonS3Exception.class);
  thrown.expectMessage(containsString("Status Code: 400; Error Code: KMS.NotFoundException"));
  s3Client.putObject(putObjectRequest);
}
 
开发者ID:adobe,项目名称:S3Mock,代码行数:20,代码来源:AmazonClientUploadIT.java

示例12: shouldNotObjectCopyWithWrongEncryptionKey

import com.amazonaws.services.s3.model.AmazonS3Exception; //导入依赖的package包/类
/**
 * Tests that an object wont be copied with wrong encryption Key
 *
 * @throws Exception if an Exception occurs
 */
@Test
public void shouldNotObjectCopyWithWrongEncryptionKey() {
  final File uploadFile = new File(UPLOAD_FILE_NAME);
  final String sourceKey = UPLOAD_FILE_NAME;
  final String destinationBucketName = "destinationBucket";
  final String destinationKey = "copyOf" + sourceKey;

  s3Client.putObject(new PutObjectRequest(BUCKET_NAME, sourceKey, uploadFile));

  final CopyObjectRequest copyObjectRequest =
      new CopyObjectRequest(BUCKET_NAME, sourceKey, destinationBucketName, destinationKey);
  copyObjectRequest
      .setSSEAwsKeyManagementParams(new SSEAwsKeyManagementParams(TEST_WRONG_KEYREF));

  thrown.expect(AmazonS3Exception.class);
  thrown.expectMessage(containsString("Status Code: 400; Error Code: KMS.NotFoundException"));
  s3Client.copyObject(copyObjectRequest);
}
 
开发者ID:adobe,项目名称:S3Mock,代码行数:24,代码来源:AmazonClientUploadIT.java

示例13: shouldGetObjectMetadata

import com.amazonaws.services.s3.model.AmazonS3Exception; //导入依赖的package包/类
/**
 * Tests if the Metadata of an existing file can be retrieved.
 */
@Test
public void shouldGetObjectMetadata() {
  final String nonExistingFileName = "nonExistingFileName";
  final File uploadFile = new File(UPLOAD_FILE_NAME);
  s3Client.createBucket(BUCKET_NAME);

  final PutObjectResult putObjectResult =
      s3Client.putObject(new PutObjectRequest(BUCKET_NAME, UPLOAD_FILE_NAME, uploadFile));
  final ObjectMetadata metadataExisting =
      s3Client.getObjectMetadata(BUCKET_NAME, UPLOAD_FILE_NAME);

  assertThat("The ETags should be identically!", metadataExisting.getETag(),
      is(putObjectResult.getETag()));

  thrown.expect(AmazonS3Exception.class);
  thrown.expectMessage(containsString("Status Code: 404"));
  s3Client.getObjectMetadata(BUCKET_NAME, nonExistingFileName);
}
 
开发者ID:adobe,项目名称:S3Mock,代码行数:22,代码来源:AmazonClientUploadIT.java

示例14: 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

示例15: getFileStatusKeyBased

import com.amazonaws.services.s3.model.AmazonS3Exception; //导入依赖的package包/类
private FileStatus getFileStatusKeyBased(String key, Path path) throws AmazonS3Exception {
  LOG.trace("internal method - get file status by key {}, path {}", key, path);
  FileStatus cachedFS = memoryCache.getFileStatus(path.toString());
  if (cachedFS != null) {
    return cachedFS;
  }
  ObjectMetadata meta = mClient.getObjectMetadata(mBucket, key);
  String sparkOrigin = meta.getUserMetaDataOf("data-origin");
  boolean stocatorCreated = false;
  if (sparkOrigin != null) {
    String tmp = (String) sparkOrigin;
    if (tmp.equals("stocator")) {
      stocatorCreated = true;
    }
  }
  mCachedSparkOriginated.put(key, Boolean.valueOf(stocatorCreated));
  FileStatus fs = createFileStatus(meta.getContentLength(), key, meta.getLastModified(), path);
  memoryCache.putFileStatus(path.toString(), fs);
  return fs;
}
 
开发者ID:SparkTC,项目名称:stocator,代码行数:21,代码来源:COSAPIClient.java


注:本文中的com.amazonaws.services.s3.model.AmazonS3Exception类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。