GenericApiGatewayClient(ClientConfiguration clientConfiguration, String endpoint, Region region, AWSCredentialsProvider credentials, String apiKey, AmazonHttpClient httpClient) { super(clientConfiguration); setRegion(region); setEndpoint(endpoint); this.credentials = credentials; this.apiKey = apiKey; this.signer = new AWS4Signer(); this.signer.setServiceName(API_GATEWAY_SERVICE_NAME); this.signer.setRegionName(region.getName()); final JsonOperationMetadata metadata = new JsonOperationMetadata().withHasStreamingSuccessResponse(false).withPayloadJson(false); final Unmarshaller<GenericApiGatewayResponse, JsonUnmarshallerContext> responseUnmarshaller = in -> new GenericApiGatewayResponse(in.getHttpResponse()); this.responseHandler = SdkStructuredPlainJsonFactory.SDK_JSON_FACTORY.createResponseHandler(metadata, responseUnmarshaller); JsonErrorUnmarshaller defaultErrorUnmarshaller = new JsonErrorUnmarshaller(GenericApiGatewayException.class, null) { @Override public AmazonServiceException unmarshall(JsonNode jsonContent) throws Exception { return new GenericApiGatewayException(jsonContent.toString()); } }; this.errorResponseHandler = SdkStructuredPlainJsonFactory.SDK_JSON_FACTORY.createErrorResponseHandler( Collections.singletonList(defaultErrorUnmarshaller), null); if (httpClient != null) { super.client = httpClient; } }
@SuppressWarnings("unchecked") private void createErrorUnmarshallers() { for (JsonErrorShapeMetadata errorMetadata : metadata.getErrorShapeMetadata()) { errorUnmarshallers.add(new JsonErrorUnmarshaller( (Class<? extends AmazonServiceException>) errorMetadata.getModeledClass(), errorMetadata.getErrorCode())); } errorUnmarshallers.add(new JsonErrorUnmarshaller( (Class<? extends AmazonServiceException>) metadata.getBaseServiceExceptionClass(), null)); }
@Override public JsonErrorResponseHandler createErrorResponseHandler( final List<JsonErrorUnmarshaller> errorUnmarshallers, String customErrorCodeFieldName) { return new JsonErrorResponseHandler(errorUnmarshallers, getErrorCodeParser(customErrorCodeFieldName), JsonErrorMessageParser.DEFAULT_ERROR_MESSAGE_PARSER, jsonFactory); }
public JsonErrorResponseHandler( List<JsonErrorUnmarshaller> errorUnmarshallers, ErrorCodeParser errorCodeParser, JsonErrorMessageParser errorMessageParser, JsonFactory jsonFactory) { this.unmarshallers = errorUnmarshallers; this.errorCodeParser = errorCodeParser; this.errorMessageParser = errorMessageParser; this.jsonFactory = jsonFactory; }
private AmazonServiceException unmarshallException(String errorCode, JsonContent jsonContent) { for (JsonErrorUnmarshaller unmarshaller : unmarshallers) { if (unmarshaller.matchErrorCode(errorCode)) { try { return unmarshaller.unmarshall(jsonContent.getJsonNode()); } catch (Exception e) { LOG.info("Unable to unmarshall exception content", e); return null; } } } return null; }
private AmazonServiceException handleError(HttpResponse error) throws Exception { List<JsonErrorUnmarshaller> unmarshallers = new LinkedList<JsonErrorUnmarshaller>(); unmarshallers.add(new JsonErrorUnmarshaller(InvalidParameterException.class, ERROR_TYPE)); JsonErrorResponseHandler handler = SdkStructuredIonFactory.SDK_ION_BINARY_FACTORY.createErrorResponseHandler(unmarshallers, NO_CUSTOM_ERROR_CODE_FIELD_NAME); return handler.handle(error); }
@Test public void handle_NoUnmarshallersAdded_ReturnsGenericAmazonServiceException() throws Exception { responseHandler = new JsonErrorResponseHandler(new ArrayList<JsonErrorUnmarshaller>(), new JsonErrorCodeParser(), JsonErrorMessageParser.DEFAULT_ERROR_MESSAGE_PARSER, new JsonFactory()); AmazonServiceException ase = responseHandler.handle(httpResponse); assertNotNull(ase); }
private void init() { exceptionUnmarshallers = new ArrayList<JsonErrorUnmarshaller>(); exceptionUnmarshallers.add(new JsonErrorUnmarshaller()); signer = new AWS4Signer(); signer.setServiceName(SERVICE_NAME); setServiceNameIntern(SERVICE_NAME); HandlerChainFactory chainFactory = new HandlerChainFactory(); requestHandler2s.addAll(chainFactory.newRequestHandlerChain("/com.ivona.services/tts/request.handlers")); requestHandler2s.addAll(chainFactory.newRequestHandlerChain("/com.ivona.services/tts/request.handler2s")); }
/** * Returns the error response handler for handling a error response. * * @param errorUnmarshallers Response unmarshallers to unamrshall the error responses. */ JsonErrorResponseHandler createErrorResponseHandler( List<JsonErrorUnmarshaller> errorUnmarshallers, String customErrorCodeFieldName);