com.amazonaws.AmazonServiceException.getStatusCode()方法的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(12.7k)|赞(0)|评价(0)|浏览(119)

本文整理了Java中com.amazonaws.AmazonServiceException.getStatusCode()方法的一些代码示例,展示了AmazonServiceException.getStatusCode()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。AmazonServiceException.getStatusCode()方法的具体详情如下:
包路径:com.amazonaws.AmazonServiceException
类名称:AmazonServiceException
方法名:getStatusCode

AmazonServiceException.getStatusCode介绍

[英]Returns the HTTP status code that was returned with this service exception.
[中]返回与此服务异常一起返回的HTTP状态代码。

代码示例

代码示例来源:origin: aws/aws-sdk-java

@Override
public boolean matches(AmazonServiceException ase) {
  return expectedStatusCode == ase.getStatusCode();
}

代码示例来源:origin: aws/aws-sdk-java

private int extractHttpStatusCode(AmazonServiceException exception) {
    return exception.getStatusCode();
  }
}

代码示例来源:origin: aws/aws-sdk-java

@Override
public boolean doesBucketExist(String bucketName)
    throws SdkClientException, AmazonServiceException {
  try {
    headBucket(new HeadBucketRequest(bucketName));
    return true;
  } catch (AmazonServiceException ase) {
    // A redirect error or a forbidden error means the bucket exists. So
    // returning true.
    if ((ase.getStatusCode() == Constants.BUCKET_REDIRECT_STATUS_CODE)
      || (ase.getStatusCode() == Constants.BUCKET_ACCESS_FORBIDDEN_STATUS_CODE)) {
      return true;
    }
    if (ase.getStatusCode() == Constants.NO_SUCH_BUCKET_STATUS_CODE) {
      return false;
    }
    throw ase;
  }
}

代码示例来源:origin: aws/aws-sdk-java

@Override
public boolean doesBucketExistV2(String bucketName) throws SdkClientException {
  try {
    getBucketAcl(bucketName);
    return true;
  } catch (AmazonServiceException ase) {
    // A redirect error or an AccessDenied exception means the bucket exists but it's not in this region
    // or we don't have permissions to it.
    if ((ase.getStatusCode() == Constants.BUCKET_REDIRECT_STATUS_CODE) || "AccessDenied".equals(ase.getErrorCode())) {
      return true;
    }
    if (ase.getStatusCode() == Constants.NO_SUCH_BUCKET_STATUS_CODE) {
      return false;
    }
    throw ase;
  }
}

代码示例来源:origin: aws/aws-sdk-java

/**
 * Returns true if the specified exception is a request entity too large error.
 *
 * @param exception The exception to test.
 * @return True if the exception resulted from a request entity too large error message from a service, otherwise false.
 */
public static boolean isRequestEntityTooLargeException(SdkBaseException exception) {
  return isAse(exception) && toAse(exception).getStatusCode() == HttpStatus.SC_REQUEST_TOO_LONG;
}

代码示例来源:origin: aws/aws-sdk-java

/**
 * Returns true if the specified exception is a retryable service side exception.
 *
 * @param exception The exception to test.
 * @return True if the exception resulted from a retryable service error, otherwise false.
 */
public static boolean isRetryableServiceException(SdkBaseException exception) {
  if (!isAse(exception)) {
    return false;
  }
  AmazonServiceException ase = toAse(exception);
  return RETRYABLE_STATUS_CODES.contains(ase.getStatusCode()) || RETRYABLE_ERROR_CODES.contains(ase.getErrorCode());
}

代码示例来源:origin: aws/aws-sdk-java

/**
 * Returns true if the specified exception is a throttling error.
 *
 * @param exception The exception to test.
 * @return True if the exception resulted from a throttling error message from a service, otherwise false.
 */
public static boolean isThrottlingException(SdkBaseException exception) {
  if (!isAse(exception)) {
    return false;
  }
  final AmazonServiceException ase = toAse(exception);
  return THROTTLING_ERROR_CODES.contains(ase.getErrorCode()) || ase.getStatusCode() == 429;
}

代码示例来源:origin: Alluxio/alluxio

@Override
@Nullable
protected ObjectStatus getObjectStatus(String key) throws IOException {
 try {
  ObjectMetadata meta = mClient.getObjectMetadata(mBucketName, key);
  return new ObjectStatus(key, meta.getETag(), meta.getContentLength(),
    meta.getLastModified().getTime());
 } catch (AmazonServiceException e) {
  if (e.getStatusCode() == 404) { // file not found, possible for exists calls
   return null;
  }
  throw new IOException(e);
 } catch (AmazonClientException e) {
  throw new IOException(e);
 }
}

代码示例来源:origin: apache/nifi

protected List<FlowFile> processServiceException(final ProcessSession session, List<FlowFile> flowFiles,
    AmazonServiceException exception) {
  List<FlowFile> failedFlowFiles = new ArrayList<>();
  for (FlowFile flowFile : flowFiles) {
    Map<String,String> attributes = new HashMap<>();
    attributes.put(DYNAMODB_ERROR_EXCEPTION_MESSAGE, exception.getMessage() );
    attributes.put(DYNAMODB_ERROR_CODE, exception.getErrorCode() );
    attributes.put(DYNAMODB_ERROR_MESSAGE, exception.getErrorMessage() );
    attributes.put(DYNAMODB_ERROR_TYPE, exception.getErrorType().name() );
    attributes.put(DYNAMODB_ERROR_SERVICE, exception.getServiceName() );
    attributes.put(DYNAMODB_ERROR_RETRYABLE, Boolean.toString(exception.isRetryable()));
    attributes.put(DYNAMODB_ERROR_REQUEST_ID, exception.getRequestId() );
    attributes.put(DYNAMODB_ERROR_STATUS_CODE, Integer.toString(exception.getStatusCode()) );
    attributes.put(DYNAMODB_ERROR_EXCEPTION_MESSAGE, exception.getMessage() );
    attributes.put(DYNAMODB_ERROR_RETRYABLE, Boolean.toString(exception.isRetryable()));
    flowFile = session.putAllAttributes(flowFile, attributes);
    failedFlowFiles.add(flowFile);
  }
  return failedFlowFiles;
}

代码示例来源:origin: apache/nifi

/**
 * Populate exception attributes in the flow file
 * @param session process session
 * @param flowFile the flow file
 * @param exception exception thrown during invocation
 * @return FlowFile the updated flow file
 */
private FlowFile populateExceptionAttributes(final ProcessSession session, FlowFile flowFile,
    final AmazonServiceException exception) {
  Map<String,String> attributes = new HashMap<>();
  attributes.put(AWS_LAMBDA_EXCEPTION_MESSAGE, exception.getErrorMessage());
  attributes.put(AWS_LAMBDA_EXCEPTION_ERROR_CODE, exception.getErrorCode());
  attributes.put(AWS_LAMBDA_EXCEPTION_REQUEST_ID, exception.getRequestId());
  attributes.put(AWS_LAMBDA_EXCEPTION_STATUS_CODE, Integer.toString(exception.getStatusCode()));
  if ( exception.getCause() != null )
    attributes.put(AWS_LAMBDA_EXCEPTION_CAUSE, exception.getCause().getMessage());
  attributes.put(AWS_LAMBDA_EXCEPTION_ERROR_TYPE, exception.getErrorType().toString());
  attributes.put(AWS_LAMBDA_EXCEPTION_MESSAGE, exception.getErrorMessage());
  flowFile = session.putAllAttributes(flowFile, attributes);
  return flowFile;
}

代码示例来源:origin: apache/ignite

/**
 * Returns {@code true} if mapping presents for the provided key.
 *
 * @param key Key to check mapping for.
 * @return {@code true} if mapping presents for key.
 * @throws AmazonClientException If an error occurs while querying Amazon S3.
 */
boolean hasKey(String key) throws AmazonClientException {
  assert !F.isEmpty(key);
  try {
    return s3.getObjectMetadata(bucketName, key).getContentLength() != 0;
  }
  catch (AmazonServiceException e) {
    if (e.getStatusCode() != 404)
      throw e;
  }
  return false;
}

代码示例来源:origin: aws/aws-sdk-java

@Override
public String getMessage() {
  return getErrorMessage()
    + " (Service: " + getServiceName()
    + "; Status Code: " + getStatusCode()
    + "; Error Code: " + getErrorCode()
    + "; Request ID: " + getRequestId() + ")";
}

代码示例来源:origin: awsdocs/aws-doc-sdk-examples

public static void main(String[] args) {

    AmazonGuardDuty guardduty =
      AmazonGuardDutyClientBuilder.defaultClient();

    try {
      ListDetectorsRequest request = new ListDetectorsRequest();

      ListDetectorsResult response = guardduty.listDetectors(request);

      for (String detectorId : response.getDetectorIds())
      {
        System.out.println("DetectorId: " + detectorId );
      }
    } catch (AmazonServiceException ase) {
        System.out.println("Caught Exception: " + ase.getMessage());
        System.out.println("Reponse Status Code: " + ase.getStatusCode());
        System.out.println("Error Code: " + ase.getErrorCode());
        System.out.println("Request ID: " + ase.getRequestId());
    }

  }
}

代码示例来源:origin: apache/ignite

if (e.getStatusCode() != 404)
  throw e;

代码示例来源:origin: aws/aws-sdk-java

@Override
public BucketCrossOriginConfiguration getBucketCrossOriginConfiguration(GetBucketCrossOriginConfigurationRequest getBucketCrossOriginConfigurationRequest) {
  getBucketCrossOriginConfigurationRequest = beforeClientExecution(getBucketCrossOriginConfigurationRequest);
  rejectNull(getBucketCrossOriginConfigurationRequest, "The request object parameter getBucketCrossOriginConfigurationRequest must be specified.");
  String bucketName = getBucketCrossOriginConfigurationRequest.getBucketName();
  rejectNull(bucketName, "The bucket name must be specified when retrieving the bucket cross origin configuration.");
  Request<GetBucketCrossOriginConfigurationRequest> request = createRequest(bucketName, null, getBucketCrossOriginConfigurationRequest, HttpMethodName.GET);
  request.addHandlerContext(HandlerContextKey.OPERATION_NAME, "GetBucketCors");
  request.addParameter("cors", null);
  try {
    return invoke(request, new Unmarshallers.BucketCrossOriginConfigurationUnmarshaller(), bucketName, null);
  } catch (AmazonServiceException ase) {
    switch (ase.getStatusCode()) {
    case 404:
      return null;
    default:
      throw ase;
    }
  }
}

代码示例来源:origin: aws/aws-sdk-java

@Override
public BucketLifecycleConfiguration getBucketLifecycleConfiguration(GetBucketLifecycleConfigurationRequest getBucketLifecycleConfigurationRequest) {
  getBucketLifecycleConfigurationRequest = beforeClientExecution(getBucketLifecycleConfigurationRequest);
  rejectNull(getBucketLifecycleConfigurationRequest, "The request object pamameter getBucketLifecycleConfigurationRequest must be specified.");
  String bucketName = getBucketLifecycleConfigurationRequest.getBucketName();
  rejectNull(bucketName, "The bucket name must be specifed when retrieving the bucket lifecycle configuration.");
  Request<GetBucketLifecycleConfigurationRequest> request = createRequest(bucketName, null, getBucketLifecycleConfigurationRequest, HttpMethodName.GET);
  request.addHandlerContext(HandlerContextKey.OPERATION_NAME, "GetBucketLifecycleConfiguration");
  request.addParameter("lifecycle", null);
  try {
    return invoke(request, new Unmarshallers.BucketLifecycleConfigurationUnmarshaller(), bucketName, null);
  } catch (AmazonServiceException ase) {
    switch (ase.getStatusCode()) {
    case 404:
      return null;
    default:
      throw ase;
    }
  }
}

代码示例来源:origin: aws/aws-sdk-java

@Override
public BucketTaggingConfiguration getBucketTaggingConfiguration(GetBucketTaggingConfigurationRequest getBucketTaggingConfigurationRequest) {
  getBucketTaggingConfigurationRequest = beforeClientExecution(getBucketTaggingConfigurationRequest);
  rejectNull(getBucketTaggingConfigurationRequest, "The request object parameter getBucketTaggingConfigurationRequest must be specifed.");
  String bucketName = getBucketTaggingConfigurationRequest.getBucketName();
  rejectNull(bucketName, "The bucket name must be specified when retrieving the bucket tagging configuration.");
  Request<GetBucketTaggingConfigurationRequest> request = createRequest(bucketName, null, getBucketTaggingConfigurationRequest, HttpMethodName.GET);
  request.addHandlerContext(HandlerContextKey.OPERATION_NAME, "GetBucketTagging");
  request.addParameter("tagging", null);
  try {
    return invoke(request, new Unmarshallers.BucketTaggingConfigurationUnmarshaller(), bucketName, null);
  } catch (AmazonServiceException ase) {
    switch (ase.getStatusCode()) {
    case 404:
      return null;
    default:
      throw ase;
    }
  }
}

代码示例来源:origin: aws/aws-sdk-java

@Override
public BucketWebsiteConfiguration getBucketWebsiteConfiguration(GetBucketWebsiteConfigurationRequest getBucketWebsiteConfigurationRequest)
    throws SdkClientException, AmazonServiceException {
  getBucketWebsiteConfigurationRequest = beforeClientExecution(getBucketWebsiteConfigurationRequest);
  rejectNull(getBucketWebsiteConfigurationRequest, "The request object parameter getBucketWebsiteConfigurationRequest must be specified.");
  String bucketName = getBucketWebsiteConfigurationRequest.getBucketName();
  rejectNull(bucketName,
    "The bucket name parameter must be specified when requesting a bucket's website configuration");
  Request<GetBucketWebsiteConfigurationRequest> request = createRequest(bucketName, null, getBucketWebsiteConfigurationRequest, HttpMethodName.GET);
  request.addHandlerContext(HandlerContextKey.OPERATION_NAME, "GetBucketWebsite");
  request.addParameter("website", null);
  request.addHeader("Content-Type", "application/xml");
  try {
    return invoke(request, new Unmarshallers.BucketWebsiteConfigurationUnmarshaller(), bucketName, null);
  } catch (AmazonServiceException ase) {
    if (ase.getStatusCode() == 404) return null;
    throw ase;
  }
}

代码示例来源:origin: aws/aws-sdk-java

throw new AmazonClientException("Unrecognized service response for the dry-run request.");
} catch (AmazonServiceException ase) {
  if (ase.getErrorCode().equals("DryRunOperation") && ase.getStatusCode() == 412) {
    return new DryRunResult<X>(true, request, ase.getMessage(), ase);
  } else if (ase.getErrorCode().equals("UnauthorizedOperation") && ase.getStatusCode() == 403) {
    return new DryRunResult<X>(false, request, ase.getMessage(), ase);
  } else if (ase.getErrorCode().equals("AuthFailure")) {

代码示例来源:origin: aws/aws-sdk-java

@Override
public AmazonServiceException handle(HttpResponse response) throws Exception {
  final AmazonServiceException ase = handleAse(response);
  ase.setStatusCode(response.getStatusCode());
  ase.setServiceName(response.getRequest().getServiceName());
  awsRequestMetrics.addPropertyWith(AWSRequestMetrics.Field.AWSRequestID, ase.getRequestId())
      .addPropertyWith(AWSRequestMetrics.Field.AWSErrorCode, ase.getErrorCode())
      .addPropertyWith(AWSRequestMetrics.Field.StatusCode, ase.getStatusCode());
  return ase;
}

相关文章