當前位置: 首頁>>代碼示例>>Java>>正文


Java AmazonS3Exception.setStatusCode方法代碼示例

本文整理匯總了Java中com.amazonaws.services.s3.model.AmazonS3Exception.setStatusCode方法的典型用法代碼示例。如果您正苦於以下問題:Java AmazonS3Exception.setStatusCode方法的具體用法?Java AmazonS3Exception.setStatusCode怎麽用?Java AmazonS3Exception.setStatusCode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.amazonaws.services.s3.model.AmazonS3Exception的用法示例。


在下文中一共展示了AmazonS3Exception.setStatusCode方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testFetchOffsetNewTopic

import com.amazonaws.services.s3.model.AmazonS3Exception; //導入方法依賴的package包/類
public void testFetchOffsetNewTopic() throws Exception {
  AmazonS3 s3Mock = mock(AmazonS3.class);
  S3Writer s3Writer = new S3Writer(testBucket, "pfx", s3Mock);

  // Non existing topic should return 0 offset
  // Since the file won't exist. code will expect the initial fetch to 404
  AmazonS3Exception ase = new AmazonS3Exception("The specified key does not exist.");
  ase.setStatusCode(404);
  when(s3Mock.getObject(eq(testBucket), eq("pfx/last_chunk_index.new_topic-00000.txt")))
    .thenThrow(ase)
    .thenReturn(null);

  TopicPartition tp = new TopicPartition("new_topic", 0);
  long offset = s3Writer.fetchOffset(tp);
  assertEquals(0, offset);
  verify(s3Mock).getObject(eq(testBucket), eq("pfx/last_chunk_index.new_topic-00000.txt"));
}
 
開發者ID:DeviantArt,項目名稱:kafka-connect-s3,代碼行數:18,代碼來源:S3WriterTest.java

示例2: getObject

import com.amazonaws.services.s3.model.AmazonS3Exception; //導入方法依賴的package包/類
@Override
public S3Object getObject(String bucketName, String key) throws AmazonClientException, AmazonServiceException {
    if (shouldFail(bucketName, key, readFailureRate)) {
        logger.info("--> random read failure on getObject method: throwing an exception for [bucket={}, key={}]", bucketName, key);
        AmazonS3Exception ex = new AmazonS3Exception("Random S3 read exception");
        ex.setStatusCode(404);
        throw ex;
    } else {
        return super.getObject(bucketName, key);
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:12,代碼來源:TestAmazonS3.java

示例3: 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;
}
 
開發者ID:IBM,項目名稱:ibm-cos-sdk-java,代碼行數:17,代碼來源:AmazonS3ExceptionBuilder.java

示例4: getObjectMetadata

import com.amazonaws.services.s3.model.AmazonS3Exception; //導入方法依賴的package包/類
@Override
public ObjectMetadata getObjectMetadata(String bucketName, String key) throws AmazonServiceException {
  AmazonS3Exception exception = new AmazonS3Exception("Internal Error");
  exception.setStatusCode(500);
  exception.setErrorType(ErrorType.Service);
  throw exception;
}
 
開發者ID:HubSpot,項目名稱:S3Decorators,代碼行數:8,代碼來源:HystrixS3DecoratorTest.java

示例5: 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);
    }
}
 
開發者ID:allenai,項目名稱:science-parse,代碼行數:34,代碼來源:ScholarBucketPaperSource.java

示例6: getObjectMetadata

import com.amazonaws.services.s3.model.AmazonS3Exception; //導入方法依賴的package包/類
@Override
public ObjectMetadata getObjectMetadata(String bucketName, String key)
        throws AmazonClientException
{
    if (getObjectMetadataHttpCode != SC_OK) {
        AmazonS3Exception exception = new AmazonS3Exception("Failing getObjectMetadata call with " + getObjectMetadataHttpCode);
        exception.setStatusCode(getObjectMetadataHttpCode);
        throw exception;
    }
    return null;
}
 
開發者ID:y-lan,項目名稱:presto,代碼行數:12,代碼來源:MockAmazonS3.java

示例7: getObject

import com.amazonaws.services.s3.model.AmazonS3Exception; //導入方法依賴的package包/類
@Override
public S3Object getObject(GetObjectRequest getObjectRequest)
        throws AmazonClientException
{
    if (getObjectHttpCode != SC_OK) {
        AmazonS3Exception exception = new AmazonS3Exception("Failing getObject call with " + getObjectHttpCode);
        exception.setStatusCode(getObjectHttpCode);
        throw exception;
    }
    return null;
}
 
開發者ID:y-lan,項目名稱:presto,代碼行數:12,代碼來源:MockAmazonS3.java

示例8: 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;
}
 
開發者ID:codewise,項目名稱:RxS3,代碼行數:11,代碼來源:AmazonS3ExceptionBuilder.java


注:本文中的com.amazonaws.services.s3.model.AmazonS3Exception.setStatusCode方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。