@Override public AwsServiceException handle(SdkHttpFullResponse response, ExecutionAttributes executionAttributes) { Pair<XmlElement, SdkBytes> xmlAndBytes = parseXml(response); XmlElement document = xmlAndBytes.left(); Optional<XmlElement> errorRoot = errorRootExtractor.apply(document); String errorCode = getErrorCode(errorRoot); AwsServiceException.Builder builder = errorRoot .map(e -> invokeSafely(() -> unmarshallFromErrorCode(response, e, errorCode))) .orElseGet(this::defaultException); AwsErrorDetails awsErrorDetails = AwsErrorDetails.builder() .errorCode(errorCode) .errorMessage(builder.message()) .rawResponse(xmlAndBytes.right()) .sdkHttpResponse(response) .serviceName(executionAttributes.getAttribute(AwsExecutionAttribute.SERVICE_NAME)) .build(); builder.requestId(getRequestId(response, document)) .statusCode(response.statusCode()) .awsErrorDetails(awsErrorDetails); return builder.build(); }
@Override public AwsServiceException handle(SdkHttpFullResponse response, ExecutionAttributes executionAttributes) { Pair<XmlElement, SdkBytes> xmlAndBytes = parseXml(response); XmlElement document = xmlAndBytes.left(); Optional<XmlElement> errorRoot = errorRootExtractor.apply(document); String errorCode = getErrorCode(errorRoot); AwsServiceException.Builder builder = errorRoot .map(e -> invokeSafely(() -> unmarshallFromErrorCode(response, e, errorCode))) .orElseGet(this::defaultException); AwsErrorDetails awsErrorDetails = AwsErrorDetails.builder() .errorCode(errorCode) .errorMessage(builder.message()) .rawResponse(xmlAndBytes.right()) .sdkHttpResponse(response) .serviceName(executionAttributes.getAttribute(AwsExecutionAttribute.SERVICE_NAME)) .build(); builder.requestId(getRequestId(response, document)) .statusCode(response.statusCode()) .awsErrorDetails(awsErrorDetails); return builder.build(); }
@SuppressWarnings("unchecked") @Override public ResponseInputStream<GetObjectResponse> getObject(final GetObjectRequest getObjectRequest) throws S3Exception { final Map<String, BucketItem> bucketItemMap = bucketsWithContents.get(getObjectRequest.bucket()); final BucketItem bucketItem = bucketItemMap.get(getObjectRequest.key()); if (bucketItem != null) { try { return new ResponseInputStream<>(GetObjectResponse.builder().build(), toAbortableInputStream(bucketItem)); } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | InstantiationException e) { throw SdkClientException.create("", e); } } else { throw NoSuchKeyException.builder().message("NoSuchKey").awsErrorDetails(AwsErrorDetails.builder().errorCode("NoSuchKey").build()).build(); } }
/** * Build the {@link AwsErrorDetails} from the metadata in the response. * * @param response HTTP response. * @param executionAttributes Execution attributes. * @param jsonContent Parsed JSON content. * @param errorCode Parsed error code/type. * @param errorMessage Parsed error message. * @return AwsErrorDetails */ private AwsErrorDetails extractAwsErrorDetails(SdkHttpFullResponse response, ExecutionAttributes executionAttributes, JsonContent jsonContent, String errorCode, String errorMessage) { AwsErrorDetails.Builder errorDetails = AwsErrorDetails.builder() .errorCode(errorCode) .serviceName(executionAttributes.getAttribute(SdkExecutionAttribute.SERVICE_NAME)) .sdkHttpResponse(response); if (jsonContent.getRawContent() != null) { errorDetails.rawResponse(SdkBytes.fromByteArray(jsonContent.getRawContent())); } errorDetails.errorMessage(errorMessage); return errorDetails.build(); }
/** * Build the {@link AwsErrorDetails} from the metadata in the response. * * @param response HTTP response. * @param executionAttributes Execution attributes. * @param jsonContent Parsed JSON content. * @param errorCode Parsed error code/type. * @param errorMessage Parsed error message. * @return AwsErrorDetails */ private AwsErrorDetails extractAwsErrorDetails(SdkHttpFullResponse response, ExecutionAttributes executionAttributes, JsonContent jsonContent, String errorCode, String errorMessage) { AwsErrorDetails.Builder errorDetails = AwsErrorDetails.builder() .errorCode(errorCode) .serviceName(executionAttributes.getAttribute(SdkExecutionAttribute.SERVICE_NAME)) .sdkHttpResponse(response); if (jsonContent.getRawContent() != null) { errorDetails.rawResponse(SdkBytes.fromByteArray(jsonContent.getRawContent())); } errorDetails.errorMessage(errorMessage); return errorDetails.build(); }
private AwsErrorDetails fillErrorDetails(AwsErrorDetails original, String errorCode, String errorMessage) { return original.toBuilder().errorMessage(errorMessage).errorCode(errorCode).build(); }