Java 类com.amazonaws.transform.JsonErrorUnmarshaller 实例源码

项目:apigateway-generic-java-sdk    文件:GenericApiGatewayClient.java   
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;
    }
}
项目:ibm-cos-sdk-java    文件:SdkJsonProtocolFactory.java   
@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));
}
项目:ibm-cos-sdk-java    文件:SdkStructuredJsonFactoryImpl.java   
@Override
public JsonErrorResponseHandler createErrorResponseHandler(
        final List<JsonErrorUnmarshaller> errorUnmarshallers, String customErrorCodeFieldName) {
    return new JsonErrorResponseHandler(errorUnmarshallers,
                                        getErrorCodeParser(customErrorCodeFieldName),
                                        JsonErrorMessageParser.DEFAULT_ERROR_MESSAGE_PARSER,
                                        jsonFactory);
}
项目:ibm-cos-sdk-java    文件:JsonErrorResponseHandler.java   
public JsonErrorResponseHandler(
        List<JsonErrorUnmarshaller> errorUnmarshallers,
        ErrorCodeParser errorCodeParser,
        JsonErrorMessageParser errorMessageParser,
        JsonFactory jsonFactory) {
    this.unmarshallers = errorUnmarshallers;
    this.errorCodeParser = errorCodeParser;
    this.errorMessageParser = errorMessageParser;
    this.jsonFactory = jsonFactory;
}
项目:ibm-cos-sdk-java    文件:JsonErrorResponseHandler.java   
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;
}
项目:ibm-cos-sdk-java    文件:SdkStructuredIonFactoryTest.java   
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);
}
项目:ibm-cos-sdk-java    文件:JsonErrorResponseHandlerTest.java   
@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);
}
项目:ivona-speechcloud-sdk-java    文件:IvonaSpeechCloudClient.java   
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"));
}
项目:ibm-cos-sdk-java    文件:SdkStructuredJsonFactory.java   
/**
 * 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);