@Override public AmazonServiceException unmarshall(Node in) throws Exception { XPath xpath = xpath(); String errorCode = parseErrorCode(in, xpath); String message = asString("Response/Errors/Error/Message", in, xpath); String requestId = asString("Response/RequestID", in, xpath); String errorType = asString("Response/Errors/Error/Type", in, xpath); Constructor<? extends AmazonServiceException> constructor = exceptionClass.getConstructor(String.class); AmazonServiceException ase = constructor.newInstance(message); ase.setErrorCode(errorCode); ase.setRequestId(requestId); if (errorType == null) { ase.setErrorType(ErrorType.Unknown); } else if (errorType.equalsIgnoreCase("server")) { ase.setErrorType(ErrorType.Service); } else if (errorType.equalsIgnoreCase("client")) { ase.setErrorType(ErrorType.Client); } return ase; }
/** * @see com.amazonaws.transform.Unmarshaller#unmarshall(java.lang.Object) */ public AmazonServiceException unmarshall(Node in) throws Exception { XPath xpath = xpath(); String errorCode = parseErrorCode(in, xpath); String errorType = asString("ErrorResponse/Error/Type", in, xpath); String requestId = asString("ErrorResponse/RequestId", in, xpath); String message = asString("ErrorResponse/Error/Message", in, xpath); AmazonServiceException ase = newException(message); ase.setErrorCode(errorCode); ase.setRequestId(requestId); if (errorType == null) { ase.setErrorType(ErrorType.Unknown); } else if (errorType.equalsIgnoreCase("Receiver")) { ase.setErrorType(ErrorType.Service); } else if (errorType.equalsIgnoreCase("Sender")) { ase.setErrorType(ErrorType.Client); } return ase; }
@Override public AmazonServiceException handle(HttpResponse response) throws Exception { JsonContent jsonContent = JsonContent.createJsonContent(response, jsonFactory); String errorCode = errorCodeParser.parseErrorCode(response, jsonContent); AmazonServiceException ase = createException(errorCode, jsonContent); // Jackson has special-casing for 'message' values when deserializing // Throwables, but sometimes the service passes the error message in // other JSON fields - handle it here. if (ase.getErrorMessage() == null) { ase.setErrorMessage(errorMessageParser.parseErrorMessage(response, jsonContent.getJsonNode())); } ase.setErrorCode(errorCode); ase.setServiceName(response.getRequest().getServiceName()); ase.setStatusCode(response.getStatusCode()); ase.setErrorType(getErrorTypeFromStatusCode(response.getStatusCode())); ase.setRawResponse(jsonContent.getRawContent()); String requestId = getRequestIdFromHeaders(response.getHeaders()); if (requestId != null) { ase.setRequestId(requestId); } ase.setHttpHeaders(response.getHeaders()); return ase; }
@Override public AmazonServiceException unmarshall(Node in) throws Exception { String errorCode = parseErrorCode(in); String message = XpathUtils.asString("Response/Errors/Error/Message", in); String requestId = XpathUtils.asString("Response/RequestID", in); String errorType = XpathUtils.asString("Response/Errors/Error/Type", in); Constructor<? extends AmazonServiceException> constructor = exceptionClass .getConstructor(String.class); AmazonServiceException ase = constructor.newInstance(message); ase.setErrorCode(errorCode); ase.setRequestId(requestId); if (errorType == null) { ase.setErrorType(ErrorType.Unknown); } else if ("server".equalsIgnoreCase(errorType)) { ase.setErrorType(ErrorType.Service); } else if ("client".equalsIgnoreCase(errorType)) { ase.setErrorType(ErrorType.Client); } return ase; }
@Override public AmazonServiceException unmarshall(Node in) throws Exception { XPath xpath = xpath(); String errorCode = parseErrorCode(in, xpath); String message = asString("Response/Errors/Error/Message", in, xpath); String requestId = asString("Response/RequestID", in, xpath); String errorType = asString("Response/Errors/Error/Type", in, xpath); Constructor<? extends AmazonServiceException> constructor = exceptionClass.getConstructor(String.class); AmazonServiceException ase = constructor.newInstance(message); ase.setErrorCode(errorCode); ase.setRequestId(requestId); if (errorType == null) { ase.setErrorType(ErrorType.Unknown); } else if (errorType.equalsIgnoreCase("server")) { ase.setErrorType(ErrorType.Service); } else if (errorType.equalsIgnoreCase("client")) { ase.setErrorType(ErrorType.Client); } return ase; }
@Override public AmazonServiceException handle(HttpResponse response) throws Exception { JsonErrorResponse error; try { error = JsonErrorResponse.fromResponse(response); } catch (IOException e) { throw new AmazonClientException("Unable to parse error response", e); } AmazonServiceException ase = runErrorUnmarshallers(error); if (ase == null) return null; ase.setStatusCode(response.getStatusCode()); if (response.getStatusCode() < HTTP_STATUS_INTERNAL_SERVER_ERROR) { ase.setErrorType(ErrorType.Client); } else { ase.setErrorType(ErrorType.Service); } ase.setErrorCode(error.getErrorCode()); for (Entry<String, String> headerEntry : response.getHeaders().entrySet()) { if ("X-Amzn-RequestId".equalsIgnoreCase(headerEntry.getKey())) { ase.setRequestId(headerEntry.getValue()); } } return ase; }
/** * @see com.amazonaws.transform.Unmarshaller#unmarshall(java.lang.Object) */ @Override public AmazonServiceException unmarshall(Node in) throws Exception { String errorCode = parseErrorCode(in); String errorType = XpathUtils.asString("ErrorResponse/Error/Type", in); String requestId = XpathUtils.asString("ErrorResponse/RequestId", in); String message = XpathUtils.asString("ErrorResponse/Error/Message", in); AmazonServiceException ase = newException(message); ase.setErrorCode(errorCode); ase.setRequestId(requestId); if (errorType == null) { ase.setErrorType(ErrorType.Unknown); } else if ("Receiver".equalsIgnoreCase(errorType)) { ase.setErrorType(ErrorType.Service); } else if ("Sender".equalsIgnoreCase(errorType)) { ase.setErrorType(ErrorType.Client); } return ase; }
/** * @see com.amazonaws.transform.Unmarshaller#unmarshall(java.lang.Object) */ public AmazonServiceException unmarshall(Node in) throws Exception { XPath xpath = xpath(); String errorCode = parseErrorCode(in, xpath); String errorType = asString("ErrorResponse/Error/Type", in, xpath); String requestId = asString("ErrorResponse/RequestId", in, xpath); String message = asString("ErrorResponse/Error/Message", in, xpath); AmazonServiceException ase = newException(message); ase.setErrorCode(errorCode); ase.setRequestId(requestId); if (errorType == null) { ase.setErrorType(ErrorType.Unknown); } else if (errorType.equalsIgnoreCase("Receiver")) { ase.setErrorType(ErrorType.Service); } else if (errorType.equalsIgnoreCase("Sender")) { ase.setErrorType(ErrorType.Client); } return ase; }
@Override public AmazonServiceException handle(HttpResponse response) throws Exception { JsonContent jsonContent = JsonContent.createJsonContent(response, jsonFactory); String errorCode = errorCodeParser.parseErrorCode(response, jsonContent); AmazonServiceException ase = createException(errorCode, jsonContent); // Jackson has special-casing for 'message' values when deserializing // Throwables, but sometimes the service passes the error message in // other JSON fields - handle it here. if (ase.getErrorMessage() == null) { ase.setErrorMessage(errorMessageParser.parseErrorMessage(response, jsonContent.getJsonNode())); } ase.setErrorCode(errorCode); ase.setServiceName(response.getRequest().getServiceName()); ase.setStatusCode(response.getStatusCode()); ase.setErrorType(getErrorTypeFromStatusCode(response.getStatusCode())); ase.setRawResponse(jsonContent.getRawContent()); String requestId = getRequestIdFromHeaders(response.getHeaders()); if (requestId != null) { ase.setRequestId(requestId); } ase.setHttpHeaders(response.getHeaders()); return ase; }
@Override public AmazonServiceException unmarshall(Node in) throws Exception { String errorCode = parseErrorCode(in); String message = XpathUtils.asString("Response/Errors/Error/Message", in); String requestId = XpathUtils.asString("Response/RequestID", in); String errorType = XpathUtils.asString("Response/Errors/Error/Type", in); Constructor<? extends AmazonServiceException> constructor = exceptionClass .getConstructor(String.class); AmazonServiceException ase = constructor.newInstance(message); ase.setErrorCode(errorCode); ase.setRequestId(requestId); if (errorType == null) { ase.setErrorType(ErrorType.Unknown); } else if ("server".equalsIgnoreCase(errorType)) { ase.setErrorType(ErrorType.Service); } else if ("client".equalsIgnoreCase(errorType)) { ase.setErrorType(ErrorType.Client); } return ase; }
@Override public AmazonServiceException unmarshall(Node in) throws Exception { String errorCode = parseErrorCode(in); String message = XpathUtils.asString("Response/Errors/Error/Message", in); String requestId = XpathUtils.asString("Response/RequestID", in); String errorType = XpathUtils.asString("Response/Errors/Error/Type", in); Constructor<? extends AmazonServiceException> constructor = exceptionClass .getConstructor(String.class); AmazonServiceException ase = constructor.newInstance(message); ase.setErrorCode(errorCode); ase.setRequestId(requestId); if (errorType == null) { ase.setErrorType(ErrorType.Unknown); } else if ("server".equalsIgnoreCase(errorType)) { ase.setErrorType(ErrorType.Service); } else if ("client".equalsIgnoreCase(errorType)) { ase.setErrorType(ErrorType.Client); } return ase; }
@Override public AmazonServiceException unmarshall(Node in) throws Exception { XPath xpath = xpath(); String errorCode = parseErrorCode(in, xpath); String message = asString("Response/Errors/Error/Message", in, xpath); String requestId = asString("Response/RequestID", in, xpath); String errorType = asString("Response/Errors/Error/Type", in, xpath); Constructor<? extends AmazonServiceException> constructor = exceptionClass.getConstructor(String.class); AmazonServiceException ase = constructor.newInstance(message); ase.setErrorCode(errorCode); ase.setRequestId(requestId); if (errorType == null) { ase.setErrorType(ErrorType.Unknown); } else if (errorType.equalsIgnoreCase("server")) { ase.setErrorType(ErrorType.Service); } else if (errorType.equalsIgnoreCase("client")) { ase.setErrorType(ErrorType.Client); } return ase; }
public AmazonServiceException handle(HttpResponse response) throws Exception { JSONObject jsonBody = getBodyAsJson(response); Class<? extends AmazonServiceException> exceptionClass = exceptionClasses.get(response.getStatusCode()); AmazonServiceException result; // Support other attribute names for the message? // TODO: Inspect exception type (caching details) and apply other values from the body String message = jsonBody.has("message") ? jsonBody.getString("message") : jsonBody.getString("Message"); if (exceptionClass != null) { result = exceptionClass.getConstructor(String.class).newInstance(message); } else { result = AmazonServiceException.class.getConstructor(String.class).newInstance(message); } result.setServiceName(response.getRequest().getServiceName()); result.setStatusCode(response.getStatusCode()); if (response.getStatusCode() < 500) { result.setErrorType(ErrorType.Client); } else { result.setErrorType(ErrorType.Service); } for (Entry<String, String> headerEntry : response.getHeaders().entrySet()) { if (headerEntry.getKey().equalsIgnoreCase("X-Amzn-RequestId")) { result.setRequestId(headerEntry.getValue()); } } return result; }
/** * 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; }
/** * @see com.amazonaws.transform.Unmarshaller#unmarshall(java.lang.Object) */ @Override public AmazonServiceException unmarshall(Node in) throws Exception { String errorCode = parseErrorCode(in); String errorType = XpathUtils.asString("ErrorResponse/Error/Type", in); String requestId = XpathUtils.asString("ErrorResponse/RequestId", in); String message = XpathUtils.asString("ErrorResponse/Error/Message", in); AmazonServiceException ase = newException(message); ase.setErrorCode(errorCode); ase.setRequestId(requestId); if (errorType == null) { ase.setErrorType(ErrorType.Unknown); } else if ("Receiver".equalsIgnoreCase(errorType)) { ase.setErrorType(ErrorType.Service); } else if ("Sender".equalsIgnoreCase(errorType)) { ase.setErrorType(ErrorType.Client); } return ase; }
@Override public AmazonServiceException handle(HttpResponse response) throws Exception { JsonErrorResponse error; try { error = JsonErrorResponse.fromResponse(response); } catch (IOException e) { throw new AmazonClientException("Unable to parse error response", e); } AmazonServiceException ase = runErrorUnmarshallers(error); if (ase == null) return null; ase.setStatusCode(response.getStatusCode()); if (response.getStatusCode() < HTTP_STATUS_INTERNAL_SERVER_ERROR) { ase.setErrorType(ErrorType.Client); } else { ase.setErrorType(ErrorType.Service); } ase.setErrorCode(error.getErrorCode()); for (Entry<String, String> headerEntry : response.getHeaders().entrySet()) { if ("X-Amzn-RequestId".equalsIgnoreCase(headerEntry.getKey())) { ase.setRequestId(headerEntry.getValue()); } } return ase; }
@Override public AmazonServiceException handle(HttpResponse response) throws Exception { JsonErrorResponse error; try { error = JsonErrorResponse.fromResponse(response); } catch (IOException e) { throw new AmazonClientException("Unable to parse error response", e); } AmazonServiceException ase = runErrorUnmarshallers(error); if (ase == null) return null; ase.setStatusCode(response.getStatusCode()); if (response.getStatusCode() < HTTP_STATUS_INTERNAL_SERVER_ERROR) { ase.setErrorType(ErrorType.Client); } else { ase.setErrorType(ErrorType.Service); } ase.setErrorCode(error.getErrorCode()); for (Entry<String, String> headerEntry : response.getHeaders().entrySet()) { if ("X-Amzn-RequestId".equalsIgnoreCase(headerEntry.getKey())) { ase.setRequestId(headerEntry.getValue()); } } return ase; }
/** * @see com.amazonaws.transform.Unmarshaller#unmarshall(java.lang.Object) */ @Override public AmazonServiceException unmarshall(Node in) throws Exception { String errorCode = parseErrorCode(in); String errorType = XpathUtils.asString("ErrorResponse/Error/Type", in); String requestId = XpathUtils.asString("ErrorResponse/RequestId", in); String message = XpathUtils.asString("ErrorResponse/Error/Message", in); AmazonServiceException ase = newException(message); ase.setErrorCode(errorCode); ase.setRequestId(requestId); if (errorType == null) { ase.setErrorType(ErrorType.Unknown); } else if ("Receiver".equalsIgnoreCase(errorType)) { ase.setErrorType(ErrorType.Service); } else if ("Sender".equalsIgnoreCase(errorType)) { ase.setErrorType(ErrorType.Client); } return ase; }
/** * @see com.amazonaws.transform.Unmarshaller#unmarshall(java.lang.Object) */ public AmazonServiceException unmarshall(Node in) throws Exception { XPath xpath = xpath(); String errorCode = parseErrorCode(in, xpath); String errorType = asString("ErrorResponse/Error/Type", in, xpath); String requestId = asString("ErrorResponse/RequestId", in, xpath); String message = asString("ErrorResponse/Error/Message", in, xpath); AmazonServiceException ase = newException(message); ase.setErrorCode(errorCode); ase.setRequestId(requestId); if (errorType == null) { ase.setErrorType(ErrorType.Unknown); } else if (errorType.equalsIgnoreCase("Receiver")) { ase.setErrorType(ErrorType.Service); } else if (errorType.equalsIgnoreCase("Sender")) { ase.setErrorType(ErrorType.Client); } return ase; }
@Override public AmazonServiceException handle(HttpResponse response) throws Exception { JsonContent jsonContent = JsonContent.createJsonContent(response, jsonFactory); String errorCode = errorCodeParser.parseErrorCode(response, jsonContent); AmazonServiceException ase = createException(errorCode, jsonContent); // Jackson has special-casing for 'message' values when deserializing // Throwables, but sometimes the service passes the error message in // other JSON fields - handle it here. if (ase.getErrorMessage() == null) { ase.setErrorMessage(errorMessageParser.parseErrorMessage(response, jsonContent.getJsonNode())); } ase.setErrorCode(errorCode); ase.setServiceName(response.getRequest().getServiceName()); ase.setStatusCode(response.getStatusCode()); ase.setErrorType(getErrorTypeFromStatusCode(response.getStatusCode())); ase.setRawResponse(jsonContent.getRawContent()); String requestId = getRequestIdFromHeaders(response.getHeaders()); if (requestId != null) { ase.setRequestId(requestId); } ase.setHttpHeaders(response.getHeaders()); return ase; }