All Downloads are FREE. Search and download functionalities are using the official Maven repository.

software.amazon.awssdk.services.protocolrestjsoncustomized.DefaultProtocolRestJsonCustomizedAsyncClient Maven / Gradle / Ivy

There is a newer version: 2.0.6
Show newest version
/*
 * Copyright 2013-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
 * the License. A copy of the License is located at
 * 
 * http://aws.amazon.com/apache2.0
 * 
 * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
 * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
 * and limitations under the License.
 */

package software.amazon.awssdk.services.protocolrestjsoncustomized;

import java.util.concurrent.CompletableFuture;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import software.amazon.awssdk.annotations.Generated;
import software.amazon.awssdk.annotations.SdkInternalApi;
import software.amazon.awssdk.awscore.client.handler.AwsAsyncClientHandler;
import software.amazon.awssdk.awscore.exception.AwsServiceException;
import software.amazon.awssdk.awscore.internal.protocol.json.AwsJsonProtocol;
import software.amazon.awssdk.awscore.protocol.json.AwsJsonProtocolFactory;
import software.amazon.awssdk.awscore.protocol.json.AwsJsonProtocolMetadata;
import software.amazon.awssdk.core.client.handler.AsyncClientHandler;
import software.amazon.awssdk.core.client.handler.ClientExecutionParams;
import software.amazon.awssdk.core.http.HttpResponseHandler;
import software.amazon.awssdk.core.internal.client.config.SdkClientConfiguration;
import software.amazon.awssdk.core.protocol.json.JsonClientMetadata;
import software.amazon.awssdk.core.protocol.json.JsonErrorResponseMetadata;
import software.amazon.awssdk.core.protocol.json.JsonOperationMetadata;
import software.amazon.awssdk.services.protocolrestjsoncustomized.model.SimpleRequest;
import software.amazon.awssdk.services.protocolrestjsoncustomized.model.SimpleResponse;
import software.amazon.awssdk.services.protocolrestjsoncustomized.transform.SimpleRequestMarshaller;
import software.amazon.awssdk.services.protocolrestjsoncustomized.transform.SimpleResponseUnmarshaller;
import software.amazon.awssdk.utils.CompletableFutureUtils;

/**
 * Internal implementation of {@link ProtocolRestJsonCustomizedAsyncClient}.
 *
 * @see ProtocolRestJsonCustomizedAsyncClient#builder()
 */
@Generated("software.amazon.awssdk:codegen")
@SdkInternalApi
final class DefaultProtocolRestJsonCustomizedAsyncClient implements ProtocolRestJsonCustomizedAsyncClient {
    private static final Logger log = LoggerFactory.getLogger(DefaultProtocolRestJsonCustomizedAsyncClient.class);

    private final AsyncClientHandler clientHandler;

    private final AwsJsonProtocolFactory protocolFactory;

    protected DefaultProtocolRestJsonCustomizedAsyncClient(SdkClientConfiguration clientConfiguration) {
        this.clientHandler = new AwsAsyncClientHandler(clientConfiguration);
        this.protocolFactory = init(false);
    }

    @Override
    public final String serviceName() {
        return SERVICE_NAME;
    }

    /**
     * Invokes the Simple operation asynchronously.
     *
     * @param simpleRequest
     * @return A Java Future containing the result of the Simple operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following * exceptions. *
    *
  • SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). * Can be used for catch all scenarios.
  • *
  • SdkClientException If any client side error occurs such as an IO related failure, failure to get * credentials, etc.
  • *
  • ProtocolRestJsonCustomizedException Base class for all service exceptions. Unknown exceptions will be * thrown as an instance of this type.
  • *
* @sample ProtocolRestJsonCustomizedAsyncClient.Simple */ @Override public CompletableFuture simple(SimpleRequest simpleRequest) { try { HttpResponseHandler responseHandler = protocolFactory.createResponseHandler( new JsonOperationMetadata().withPayloadJson(true).withHasStreamingSuccessResponse(false), new SimpleResponseUnmarshaller()); HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory); return clientHandler.execute(new ClientExecutionParams() .withMarshaller(new SimpleRequestMarshaller(protocolFactory)).withResponseHandler(responseHandler) .withErrorResponseHandler(errorResponseHandler).withInput(simpleRequest)); } catch (Throwable t) { return CompletableFutureUtils.failedFuture(t); } } @Override public void close() { clientHandler.close(); } private software.amazon.awssdk.awscore.protocol.json.AwsJsonProtocolFactory init(boolean supportsCbor) { return new AwsJsonProtocolFactory( new JsonClientMetadata() .withSupportsCbor(supportsCbor) .withSupportsIon(false) .withBaseServiceExceptionClass( software.amazon.awssdk.services.protocolrestjsoncustomized.model.ProtocolRestJsonCustomizedException.class) .withContentTypeOverride(""), AwsJsonProtocolMetadata.builder().protocolVersion("1.1") .protocol(AwsJsonProtocol.REST_JSON).build()); } private HttpResponseHandler createErrorResponseHandler(AwsJsonProtocolFactory protocolFactory) { return protocolFactory.createErrorResponseHandler(new JsonErrorResponseMetadata()); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy