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

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

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

AmazonServiceException.getServiceName介绍

[英]Returns the name of the service that sent this error response.
[中]返回发送此错误响应的服务的名称。

代码示例

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

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

代码示例来源: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: org.apache.hadoop/hadoop-aws

public String getServiceName() {
 return getCause().getServiceName();
}

代码示例来源:origin: CODAIT/stocator

public String getServiceName() {
 return getCause().getServiceName();
}

代码示例来源:origin: com.ibm.stocator/stocator

public String getServiceName() {
 return getCause().getServiceName();
}

代码示例来源:origin: com.netflix.spinnaker.kork/kork-core

static String[] buildExceptionTags(AmazonWebServiceRequest originalRequest, Exception exception) {
 final AmazonServiceException ase = amazonServiceException(exception);
 String targetAccountId = DEFAULT_UNKNOWN;
 if (ase.getHttpHeaders() != null) {
  targetAccountId = ase.getHttpHeaders().get("targetAccountId");
 }
 return new String[] {
  "requestType", originalRequest.getClass().getSimpleName(),
  "statusCode", Integer.toString(ase.getStatusCode()),
  "errorCode", Optional.ofNullable(ase.getErrorCode()).orElse(DEFAULT_UNKNOWN),
  "serviceName", Optional.ofNullable(ase.getServiceName()).orElse(DEFAULT_UNKNOWN),
  "errorType", Optional.ofNullable(ase.getErrorType()).orElse(AmazonServiceException.ErrorType.Unknown).name(),
  "accountId", Optional.ofNullable(targetAccountId).orElse(DEFAULT_UNKNOWN)
 };
}

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

@Test
public void testHandleErrorResponseHandlerFailsWith413() throws IOException {
  Request<?> request = new DefaultRequest<String>("ServiceName");
  final HttpResponse httpResponse = new HttpResponse.Builder().statusText("TestResponse")
      .statusCode(413).build();
  HttpResponseHandler<AmazonServiceException> errorResponseHandler = new HttpResponseHandler<AmazonServiceException>() {
    @Override
    public AmazonServiceException handle(HttpResponse response) throws Exception {
      assertSame(response, httpResponse);
      throw new Exception("test");
    }
    @Override
    public boolean needsConnectionLeftOpen() {
      return false;
    }
  };
  AmazonServiceException e = client.handleErrorResponse(request, errorResponseHandler,
      httpResponse);
  assertEquals(e.getStatusCode(), 413);
  assertEquals(e.getErrorCode(), "Request entity too large");
  assertEquals(e.getErrorType(), ErrorType.Client);
  assertEquals(e.getServiceName(), "ServiceName");
}

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

@Test
public void testHandleErrorResponseHandlerFailsWith503() throws IOException {
  Request<?> request = new DefaultRequest<String>("ServiceName");
  final HttpResponse httpResponse = new HttpResponse.Builder()
      .statusText("Service unavailable")
      .statusCode(503).build();
  HttpResponseHandler<AmazonServiceException> errorResponseHandler = new HttpResponseHandler<AmazonServiceException>() {
    @Override
    public AmazonServiceException handle(HttpResponse response) throws Exception {
      assertSame(response, httpResponse);
      throw new Exception("test");
    }
    @Override
    public boolean needsConnectionLeftOpen() {
      return false;
    }
  };
  AmazonServiceException e = client.handleErrorResponse(request, errorResponseHandler,
      httpResponse);
  assertEquals(e.getStatusCode(), 503);
  assertEquals(e.getErrorCode(), "Service unavailable");
  assertEquals(e.getErrorType(), ErrorType.Service);
  assertEquals(e.getServiceName(), "ServiceName");
}

代码示例来源:origin: org.apache.nifi/nifi-aws-abstract-processors

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: aws-amplify/aws-sdk-android

@Test
public void testHandleErrorResponse() throws IOException {
  final Request<?> request = new DefaultRequest<String>("ServiceName");
  final HttpResponse httpResponse = new HttpResponse.Builder().statusText("TestResponse")
      .statusCode(400).build();
  HttpResponseHandler<AmazonServiceException> errorResponseHandler = new HttpResponseHandler<AmazonServiceException>() {
    @Override
    public AmazonServiceException handle(HttpResponse response) throws Exception {
      assertSame(response, httpResponse);
      AmazonServiceException ase = new AmazonServiceException("Test");
      ase.setErrorCode("TestError");
      ase.setErrorType(ErrorType.Service);
      ase.setServiceName(request.getServiceName());
      ase.setStatusCode(response.getStatusCode());
      return ase;
    }
    @Override
    public boolean needsConnectionLeftOpen() {
      return false;
    }
  };
  AmazonServiceException e = client.handleErrorResponse(request, errorResponseHandler,
      httpResponse);
  assertEquals(e.getStatusCode(), 400);
  assertEquals(e.getErrorCode(), "TestError");
  assertEquals(e.getErrorType(), ErrorType.Service);
  assertEquals(e.getServiceName(), "ServiceName");
}

代码示例来源:origin: org.apache.hadoop/hadoop-aws

/**
 * Get low level details of an amazon exception for logging; multi-line.
 * @param e exception
 * @return string details
 */
public static String stringify(AmazonServiceException e) {
 StringBuilder builder = new StringBuilder(
   String.format("%s: %s error %d: %s; %s%s%n",
     e.getErrorType(),
     e.getServiceName(),
     e.getStatusCode(),
     e.getErrorCode(),
     e.getErrorMessage(),
     (e.isRetryable() ? " (retryable)": "")
   ));
 String rawResponseContent = e.getRawResponseContent();
 if (rawResponseContent != null) {
  builder.append(rawResponseContent);
 }
 return builder.toString();
}

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

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

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

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

代码示例来源:origin: com.amazonaws/dynamodb-streams-kinesis-adapter

/**
 * After determining the transformation in the API specific transform method, this helper method sets the
 * transformed exception's fields to match the original exception. If no transformation occurred, the original
 * exception is returned.
 *
 * @param original    The original DynamoDB Streams exception
 * @param transformed The equivalent Kinesis exception that needs its fields updated
 * @return The final result of the transformation ready to be thrown by the adapter
 */
private static AmazonServiceException applyFields(AmazonServiceException original, AmazonServiceException transformed) {
  if (transformed == null) {
    LOG.error("Could not transform a DynamoDB AmazonServiceException to a compatible Kinesis exception", original);
    return original;
  }
  // Here we update the transformed exception fields with the original exception values
  if (original.getErrorCode() != null) {
    transformed.setErrorCode(original.getErrorCode());
  }
  // Null is transformed to UNKNOWN, so a null value is impossible.
  transformed.setErrorType(original.getErrorType());
  if (original.getRequestId() != null) {
    transformed.setRequestId(original.getRequestId());
  }
  if (original.getServiceName() != null) {
    transformed.setServiceName(original.getServiceName());
  }
  transformed.setStatusCode(original.getStatusCode());
  LOG.error(String.format("DynamoDB Streams exception: %s tranformed to Kinesis %s", original.getClass(), transformed.getClass()), original);
  return transformed;
}

代码示例来源:origin: awslabs/dynamodb-streams-kinesis-adapter

/**
 * After determining the transformation in the API specific transform method, this helper method sets the
 * transformed exception's fields to match the original exception. If no transformation occurred, the original
 * exception is returned.
 *
 * @param original    The original DynamoDB Streams exception
 * @param transformed The equivalent Kinesis exception that needs its fields updated
 * @return The final result of the transformation ready to be thrown by the adapter
 */
private static AmazonServiceException applyFields(AmazonServiceException original, AmazonServiceException transformed) {
  if (transformed == null) {
    LOG.error("Could not transform a DynamoDB AmazonServiceException to a compatible Kinesis exception", original);
    return original;
  }
  // Here we update the transformed exception fields with the original exception values
  if (original.getErrorCode() != null) {
    transformed.setErrorCode(original.getErrorCode());
  }
  // Null is transformed to UNKNOWN, so a null value is impossible.
  transformed.setErrorType(original.getErrorType());
  if (original.getRequestId() != null) {
    transformed.setRequestId(original.getRequestId());
  }
  if (original.getServiceName() != null) {
    transformed.setServiceName(original.getServiceName());
  }
  transformed.setStatusCode(original.getStatusCode());
  LOG.error(String.format("DynamoDB Streams exception: %s tranformed to Kinesis %s", original.getClass(), transformed.getClass()), original);
  return transformed;
}

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

if ((304 == statusCode || 412 == statusCode) && S3_SERVICE_NAME.equals(ase.getServiceName())) {
  populateAndEndSubsegment(currentSubsegment, request, response, ase);
  return;

相关文章