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; }
/** * 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; }
/** * 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")); }
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());
@Override public String getMessage() { return getErrorMessage() + " (Service: " + getServiceName() + "; Status Code: " + getStatusCode() + "; Error Code: " + getErrorCode() + "; Request ID: " + getRequestId() + ")"; }
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()); } } }
System.out.println("Reponse Status Code: " + ase.getStatusCode()); System.out.println("Error Code: " + ase.getErrorCode()); System.out.println("Request ID: " + ase.getRequestId());
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 " +
@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; }
@Override public String getMessage() { return getErrorMessage() + " (Service: " + getServiceName() + "; Status Code: " + getStatusCode() + "; Error Code: " + getErrorCode() + "; Request ID: " + getRequestId() + ")"; }
@Override public String getMessage() { return getErrorMessage() + " (Service: " + getServiceName() + "; Status Code: " + getStatusCode() + "; Error Code: " + getErrorCode() + "; Request ID: " + getRequestId() + ")"; }
@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")); }
@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"); }
@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; }
@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"); } }
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());
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()); }
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; }
@Override public String getMessage() { return getErrorMessage() + " (Service: " + getServiceName() + "; Status Code: " + getStatusCode() + "; Error Code: " + getErrorCode() + "; Request ID: " + getRequestId() + ")"; }
@Override public String getMessage() { return getErrorMessage() + " (Service: " + getServiceName() + "; Status Code: " + getStatusCode() + "; Error Code: " + getErrorCode() + "; Request ID: " + getRequestId() + ")"; }