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


Java AmazonClientException類代碼示例

本文整理匯總了Java中com.amazonaws.AmazonClientException的典型用法代碼示例。如果您正苦於以下問題:Java AmazonClientException類的具體用法?Java AmazonClientException怎麽用?Java AmazonClientException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


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

示例1: initiateMultiPartUpload

import com.amazonaws.AmazonClientException; //導入依賴的package包/類
private MultiPartUpload initiateMultiPartUpload() throws IOException {
  final ObjectMetadata om = createDefaultMetadata();
  final InitiateMultipartUploadRequest initiateMPURequest =
      new InitiateMultipartUploadRequest(bucket, key, om);
  initiateMPURequest.setCannedACL(cannedACL);
  try {
    return new MultiPartUpload(
        client.initiateMultipartUpload(initiateMPURequest).getUploadId());
  } catch (AmazonServiceException ase) {
    throw new IOException("Unable to initiate MultiPartUpload (server side)" +
        ": " + ase, ase);
  } catch (AmazonClientException ace) {
    throw new IOException("Unable to initiate MultiPartUpload (client side)" +
        ": " + ace, ace);
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:17,代碼來源:S3AFastOutputStream.java

示例2: sendEmail

import com.amazonaws.AmazonClientException; //導入依賴的package包/類
/**
 * Send email.
 *
 * @param eMsg the e msg
 * @return true, if successful
 */
public boolean sendEmail(EmailMessage eMsg) {

    SendEmailRequest request = new SendEmailRequest().withSource(eMsg.getFromAddress());
    Destination dest = new Destination().withToAddresses(eMsg.getToAddresses());
    dest.setCcAddresses(eMsg.getToCcAddresses());
    request.setDestination(dest);
    Content subjContent = new Content().withData(eMsg.getSubject());
    Message msg = new Message().withSubject(subjContent);
    Content textContent = new Content().withData(eMsg.getTxtMessage());
    Body body = new Body().withText(textContent);
    if (eMsg.getHtmlMessage() != null) {
        Content htmlContent = new Content().withData(eMsg.getHtmlMessage());
        body.setHtml(htmlContent);
    }
    msg.setBody(body);
    request.setMessage(msg);
    try {
        emailClient.sendEmail(request);
        logger.debug(msg);
    } catch (AmazonClientException e) {
        logger.error(e.getMessage());
        return false;
    }
    return true;
}
 
開發者ID:oneops,項目名稱:oneops,代碼行數:32,代碼來源:EmailService.java

示例3: leasing_a_new_connection_fails_with_connection_pool_timeout

import com.amazonaws.AmazonClientException; //導入依賴的package包/類
@Test(timeout = 60 * 1000)
public void leasing_a_new_connection_fails_with_connection_pool_timeout()
        throws Exception {

    String localhostEndpoint = "http://localhost:" + server.getPort();

    AmazonHttpClient httpClient = new AmazonHttpClient(
            new ClientConfiguration()
                    .withMaxConnections(1)
                    .withConnectionTimeout(100)
                    .withMaxErrorRetry(0));

    Request<?> request = new EmptyHttpRequest(localhostEndpoint, HttpMethodName.GET);

    // Block the first connection in the pool with this request.
    httpClient.requestExecutionBuilder().request(request).execute(new EmptyAWSResponseHandler());

    try {
        // A new connection will be leased here which would fail in
        // ConnectionPoolTimeoutException.
        httpClient.requestExecutionBuilder().request(request).execute();
        Assert.fail("Connection pool timeout exception is expected!");
    } catch (AmazonClientException e) {
        Assert.assertTrue(e.getCause() instanceof ConnectionPoolTimeoutException);
    }
}
 
開發者ID:IBM,項目名稱:ibm-cos-sdk-java,代碼行數:27,代碼來源:ConnectionPoolMaxConnectionsIntegrationTest.java

示例4: readBlob

import com.amazonaws.AmazonClientException; //導入依賴的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

示例5: copyObject

import com.amazonaws.AmazonClientException; //導入依賴的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: createBucket

import com.amazonaws.AmazonClientException; //導入依賴的package包/類
@Override
public Bucket createBucket(CreateBucketRequest createBucketRequest) throws AmazonClientException, AmazonServiceException {
    if ("nonExistingBucket".equals(createBucketRequest.getBucketName())) {
        nonExistingBucketCreated = true; 
    }
    
    Bucket bucket = new Bucket();
    bucket.setName(createBucketRequest.getBucketName());
    bucket.setCreationDate(new Date());
    bucket.setOwner(new Owner("c2efc7302b9011ba9a78a92ac5fd1cd47b61790499ab5ddf5a37c31f0638a8fc ", "Christian Mueller"));
    return bucket;
}
 
開發者ID:syndesisio,項目名稱:connectors,代碼行數:13,代碼來源:AmazonS3ClientMock.java

示例7: shouldRetry_MaxErrorNotExceeded_DelegatesToLegacyRetryCondition

import com.amazonaws.AmazonClientException; //導入依賴的package包/類
@Test
public void shouldRetry_MaxErrorNotExceeded_DelegatesToLegacyRetryCondition() {
    final RetryPolicyContext context = RetryPolicyContexts.LEGACY;
    adapter.shouldRetry(context);

    verify(retryCondition).shouldRetry(
            eq((AmazonWebServiceRequest) context.originalRequest()),
            eq((AmazonClientException) context.exception()),
            eq(context.retriesAttempted()));
}
 
開發者ID:IBM,項目名稱:ibm-cos-sdk-java,代碼行數:11,代碼來源:RetryPolicyAdapterTest.java

示例8: shouldRetry

import com.amazonaws.AmazonClientException; //導入依賴的package包/類
@Override
public boolean shouldRetry(RetryPolicyContext context) {
    if (context.retriesAttempted() >= getMaxErrorRetry()) {
        return false;
    }
    return legacyRetryPolicy.getRetryCondition().shouldRetry(
            (AmazonWebServiceRequest) context.originalRequest(),
            (AmazonClientException) context.exception(),
            context.retriesAttempted());
}
 
開發者ID:IBM,項目名稱:ibm-cos-sdk-java,代碼行數:11,代碼來源:RetryPolicyAdapter.java

示例9: invalidate

import com.amazonaws.AmazonClientException; //導入依賴的package包/類
/**
 * You can make any number of invalidation requests, but you can have only three invalidation requests
 * in progress at one time. Each request can contain up to 1,000 objects to invalidate. If you
 * exceed these limits, you get an error message.
 * <p>
 * It usually takes 10 to 15 minutes to complete your invalidation request, depending on
 * the size of your request.
 */
@Override
public void invalidate(final Path container, final Distribution.Method method, final List<Path> files, final LoginCallback prompt) throws BackgroundException {
    try {
        final Distribution d = this.read(container, method, prompt);
        final List<String> keys = new ArrayList<String>();
        for(Path file : files) {
            if(containerService.isContainer(file)) {
                // To invalidate all of the objects in a distribution
                keys.add(String.format("%s*", String.valueOf(Path.DELIMITER)));
            }
            else {
                if(file.isDirectory()) {
                    // The *, which replaces 0 or more characters, must be the last character in the invalidation path
                    keys.add(String.format("/%s*", containerService.getKey(file)));
                }
                else {
                    keys.add(String.format("/%s", containerService.getKey(file)));
                }
            }
        }
        if(keys.isEmpty()) {
            log.warn("No keys selected for invalidation");
        }
        else {
            final AmazonCloudFront client = client(container);
            client.createInvalidation(new CreateInvalidationRequest(d.getId(),
                new InvalidationBatch(new Paths().withItems(keys).withQuantity(keys.size()), new AlphanumericRandomStringService().random())
            ));
        }
    }
    catch(AmazonClientException e) {
        throw new AmazonServiceExceptionMappingService().map("Cannot write CDN configuration", e);
    }
}
 
開發者ID:iterate-ch,項目名稱:cyberduck,代碼行數:43,代碼來源:CloudFrontDistributionConfiguration.java

示例10: testRoleProfileWithNoSourceName

import com.amazonaws.AmazonClientException; //導入依賴的package包/類
/**
 * Tests loading a profile that assumes a role, but the source profile does not exist.
 */
@Test
public void testRoleProfileWithNoSourceName() throws URISyntaxException {
    checkDeferredException(ProfileResourceLoader.roleProfileWithNoSourceName(),
                           AmazonClientException.class, "test",
                           "Should throw an exception as there is a role profile with a missing source role");
}
 
開發者ID:IBM,項目名稱:ibm-cos-sdk-java,代碼行數:10,代碼來源:CredentialProfilesTest.java

示例11: noRegionProvidedExplicitlyOrImplicitly_ThrowsException

import com.amazonaws.AmazonClientException; //導入依賴的package包/類
/**
 * If no region is explicitly given and no region can be found from the {@link
 * AwsRegionProvider} implementation then the builder should fail to build clients. We mock the
 * provider to yield consistent results for the tests.
 */
@Test(expected = AmazonClientException.class)
public void noRegionProvidedExplicitlyOrImplicitly_ThrowsException() {
    AwsRegionProvider mockRegionProvider = mock(AwsRegionProvider.class);
    when(mockRegionProvider.getRegion()).thenReturn(null);
    new ConcreteAsyncBuilder(mockRegionProvider).build();
}
 
開發者ID:IBM,項目名稱:ibm-cos-sdk-java,代碼行數:12,代碼來源:AwsClientBuilderTest.java

示例12: map

import com.amazonaws.AmazonClientException; //導入依賴的package包/類
@Override
public BackgroundException map(final AmazonClientException e) {
    final StringBuilder buffer = new StringBuilder();
    if(e instanceof AmazonServiceException) {
        final AmazonServiceException failure = (AmazonServiceException) e;
        this.append(buffer, failure.getErrorMessage());
        switch(failure.getStatusCode()) {
            case HttpStatus.SC_BAD_REQUEST:
                switch(failure.getErrorCode()) {
                    case "Throttling":
                        return new RetriableAccessDeniedException(buffer.toString(), e);
                    case "AccessDeniedException":
                        return new AccessDeniedException(buffer.toString(), e);
                    case "UnrecognizedClientException":
                        return new LoginFailureException(buffer.toString(), e);
                }
            case HttpStatus.SC_FORBIDDEN:
                switch(failure.getErrorCode()) {
                    case "SignatureDoesNotMatch":
                        return new LoginFailureException(buffer.toString(), e);
                    case "InvalidAccessKeyId":
                        return new LoginFailureException(buffer.toString(), e);
                    case "InvalidClientTokenId":
                        return new LoginFailureException(buffer.toString(), e);
                    case "InvalidSecurity":
                        return new LoginFailureException(buffer.toString(), e);
                    case "MissingClientTokenId":
                        return new LoginFailureException(buffer.toString(), e);
                    case "MissingAuthenticationToken":
                        return new LoginFailureException(buffer.toString(), e);
                }
        }
        return new HttpResponseExceptionMappingService().map(new HttpResponseException(failure.getStatusCode(), buffer.toString()));
    }
    this.append(buffer, e.getMessage());
    return this.wrap(e, buffer);
}
 
開發者ID:iterate-ch,項目名稱:cyberduck,代碼行數:38,代碼來源:AmazonServiceExceptionMappingService.java

示例13: testRetryPolicyLevelMaxErrorRetry

import com.amazonaws.AmazonClientException; //導入依賴的package包/類
/**
 * -- Explicitly set maxErrorRetry in ClientConfiguration level;
 * -- Custom RetryPolicy's that want to override such setting.
 */
@Test
public void testRetryPolicyLevelMaxErrorRetry() {
    // This should be ignored
    clientConfiguration.setMaxErrorRetry(random.nextInt(3));
    
    // A custom policy that doesn't honor the ClientConfig level maxErrorRetry
    int RETRY_POLICY_LEVEL_MAX_ERROR_RETRY = 5;
    clientConfiguration.setRetryPolicy(new RetryPolicy(null, null, RETRY_POLICY_LEVEL_MAX_ERROR_RETRY, false));
    testActualRetries(RETRY_POLICY_LEVEL_MAX_ERROR_RETRY);
    
    // A custom policy that "honors" the ClientConfig level maxErrorRetry,
    // but actually denies any retry in its condition.
    clientConfiguration.setRetryPolicy(new RetryPolicy(
            new RetryPolicy.RetryCondition() {

                @Override
                public boolean shouldRetry(
                        AmazonWebServiceRequest originalRequest,
                        AmazonClientException exception,
                        int retriesAttempted) {
                    return false;
                }
            }, null, RETRY_POLICY_LEVEL_MAX_ERROR_RETRY, true)
    );
    // No retry is expected
    testActualRetries(0);
}
 
開發者ID:IBM,項目名稱:ibm-cos-sdk-java,代碼行數:32,代碼來源:ClientConfigurationMaxErrorRetryTest.java

示例14: testLoadCredentialsThrowsAceWhenClientResponseDontHaveKeys

import com.amazonaws.AmazonClientException; //導入依賴的package包/類
/**
 * Test that when credentials are null and response from client does not have access key/secret key,
 * throws AmazonClientException.
 */
@Test
public void testLoadCredentialsThrowsAceWhenClientResponseDontHaveKeys() {
    // Stub for success response but without keys in the response body
    stubForSuccessResponseWithCustomBody(200, successResponseWithInvalidBody);

    TestCredentialsProvider credentialsProvider = new TestCredentialsProvider();

    try {
        credentialsProvider.getCredentials();
        fail("Expected an AmazonClientException");
    } catch (AmazonClientException ace) {
        assertEquals("Unable to load credentials.", ace.getMessage());
    }
}
 
開發者ID:IBM,項目名稱:ibm-cos-sdk-java,代碼行數:19,代碼來源:EC2CredentialsFetcherTest.java

示例15: describePlacementGroups

import com.amazonaws.AmazonClientException; //導入依賴的package包/類
@Override
public DescribePlacementGroupsResult describePlacementGroups(DescribePlacementGroupsRequest describePlacementGroupsRequest) throws AmazonServiceException, AmazonClientException {
    throw new UnsupportedOperationException("Not supported in mock");
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:5,代碼來源:AmazonEC2Mock.java


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