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

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

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

AmazonServiceException.getRequestId介绍

[英]Returns the AWS request ID that uniquely identifies the service request the caller made.
[中]返回用于唯一标识调用方发出的服务请求的AWS请求ID。

代码示例

代码示例来源: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: aws/aws-sdk-java

/**
 * Asserts that the specified AmazonServiceException is valid, meaning it has a non-empty,
 * non-null value for its message, requestId, etc.
 *
 * @param e
 *            The exception to validate.
 */
public static void assertValidException(AmazonServiceException e) {
  assertNotNull(e.getRequestId());
  assertTrue(e.getRequestId().trim().length() > 0);
  assertNotNull(e.getMessage());
  assertTrue(e.getMessage().trim().length() > 0);
  assertNotNull(e.getErrorCode());
  assertTrue(e.getErrorCode().trim().length() > 0);
  assertNotNull(e.getServiceName());
  assertTrue(e.getServiceName().startsWith("Amazon") || e.getServiceName().startsWith("AWS"));
}

代码示例来源:origin: stackoverflow.com

System.out.println("AWS Error Code:   " + ase.getErrorCode());
  System.out.println("Error Type:       " + ase.getErrorType());
  System.out.println("Request ID:       " + ase.getRequestId());
} catch (AmazonClientException ace) {
  System.out.println("Error Message: " + ace.getMessage());

代码示例来源: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: awsdocs/aws-doc-sdk-examples

System.out.println("Reponse Status Code: " + ase.getStatusCode());
System.out.println("Error Code: " + ase.getErrorCode());
System.out.println("Request ID: " + ase.getRequestId());

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

System.out.println("AWS Error Code:   " + ase.getErrorCode());
  System.out.println("Error Type:       " + ase.getErrorType());
  System.out.println("Request ID:       " + ase.getRequestId());
} catch (AmazonClientException ace) {
  System.out.println("Caught an AmazonClientException, which means " +

代码示例来源: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;
}

代码示例来源:origin: com.amazonaws/aws-java-sdk-core

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

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

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

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

@Test
public void testUnmarshall() throws TransformerFactoryConfigurationError, Exception {
  Document xmlDoc = new DocumentImpl();
  Element root = xmlDoc.createElement("ErrorResponse");
  Element requestId = xmlDoc.createElement("RequestId");
  requestId.appendChild(xmlDoc.createTextNode("TestId"));
  Element error = xmlDoc.createElement("Error");
  Element message = xmlDoc.createElement("Message");
  message.appendChild(xmlDoc.createTextNode("TestMessage"));
  Element type = xmlDoc.createElement("Type");
  type.appendChild(xmlDoc.createTextNode("Receiver"));
  error.appendChild(message);
  error.appendChild(type);
  root.appendChild(error);
  root.appendChild(requestId);
  xmlDoc.appendChild(root);
  StandardErrorUnmarshaller seu = new StandardErrorUnmarshaller();
  AmazonServiceException ase = seu.unmarshall(xmlDoc);
  assertEquals(ase.getErrorMessage(), "TestMessage");
  assertEquals(ase.getErrorType(), ErrorType.Service);
  assertEquals(ase.getRequestId(), "TestId");
  Element code = xmlDoc.createElement("Code");
  code.appendChild(xmlDoc.createTextNode("TestCode"));
}

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

@Test
public void testUnmarshall() throws TransformerFactoryConfigurationError, Exception {
  Document xmlDoc = new DocumentImpl();
  Element root = xmlDoc.createElement("Response");
  Element requestId = xmlDoc.createElement("RequestID");
  requestId.appendChild(xmlDoc.createTextNode("TestId"));
  Element errors = xmlDoc.createElement("Errors");
  Element error = xmlDoc.createElement("Error");
  Element message = xmlDoc.createElement("Message");
  message.appendChild(xmlDoc.createTextNode("TestMessage"));
  Element type = xmlDoc.createElement("Type");
  type.appendChild(xmlDoc.createTextNode("server"));
  Element code = xmlDoc.createElement("Code");
  code.appendChild(xmlDoc.createTextNode("TestCode"));
  error.appendChild(message);
  error.appendChild(type);
  error.appendChild(code);
  errors.appendChild(error);
  root.appendChild(errors);
  root.appendChild(requestId);
  xmlDoc.appendChild(root);
  LegacyErrorUnmarshaller leu = new LegacyErrorUnmarshaller();
  AmazonServiceException ase = leu.unmarshall(xmlDoc);
  assertEquals(ase.getErrorCode(), "TestCode");
  assertEquals(ase.getErrorMessage(), "TestMessage");
  assertEquals(ase.getErrorType(), ErrorType.Service);
  assertEquals(ase.getRequestId(), "TestId");
}

代码示例来源:origin: com.amazonaws/aws-java-sdk-core

@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;
}

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

@Test
  public void testJsonErrorResponseReturnsXAmzRequestId() throws Exception {
    List<JsonErrorUnmarshaller> exceptionUnmarshallers = new ArrayList<JsonErrorUnmarshaller>();
    exceptionUnmarshallers.add(new JsonErrorUnmarshaller() {

      @Override
      public AmazonServiceException unmarshall(JsonErrorResponse error) throws Exception {
        return new AmazonServiceException("TestException");
      }

    });
    handler = new JsonErrorResponseHandler(exceptionUnmarshallers);
    response = HttpResponse.builder()
        .statusCode(500)
        .header("X-Amzn-RequestId", "55")
        .content(new ByteArrayInputStream("{}".getBytes(StringUtils.UTF8)))
        .build();
    AmazonServiceException returnedException = handler.handle(response);
    assertEquals(returnedException.getRequestId(), "55");
  }
}

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

final AmazonServiceException ase = handleErrorResponse(request, errorResponseHandler,
    httpResponse);
awsRequestMetrics.addProperty(Field.AWSRequestID, ase.getRequestId());
awsRequestMetrics.addProperty(Field.AWSErrorCode, ase.getErrorCode());
awsRequestMetrics.addProperty(Field.StatusCode, ase.getStatusCode());

代码示例来源:origin: org.jasig.portal/uPortal-portlets

private void logAmazonServiceException(
    final AmazonServiceException exception, final AmazonWebServiceRequest request) {
  log.info(
      "Caught an AmazonServiceException, which means your request made it "
          + "to Amazon S3, but was rejected with an error response for some reason.");
  log.info("Error Message:    {}", exception.getMessage());
  log.info("HTTP Status Code: {}", exception.getStatusCode());
  log.info("AWS Error Code:   {}", exception.getErrorCode());
  log.info("Error Type:       {}", exception.getErrorType());
  log.info("Request ID:       {}", exception.getRequestId());
}

代码示例来源:origin: Netflix/ndbench

protected AmazonServiceException amazonServiceException(AmazonServiceException ase) {
  logger.error("Caught an AmazonServiceException, which means your request made it "
      + "to AWS, but was rejected with an error response for some reason.");
  logger.error("Error Message:    " + ase.getMessage());
  logger.error("HTTP Status Code: " + ase.getStatusCode());
  logger.error("AWS Error Code:   " + ase.getErrorCode());
  logger.error("Error Type:       " + ase.getErrorType());
  logger.error("Request ID:       " + ase.getRequestId());
  return ase;
}

代码示例来源:origin: com.amazonaws/aws-android-sdk-core

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

代码示例来源:origin: Nextdoor/bender

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

相关文章