當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。