Java tutorial
/* * Copyright 2014-2019 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 com.amazonaws.services.dynamodbv2; import org.w3c.dom.*; import java.net.*; import java.util.*; import javax.annotation.Generated; import org.apache.commons.logging.*; import com.amazonaws.*; import com.amazonaws.annotation.SdkInternalApi; import com.amazonaws.auth.*; import com.amazonaws.handlers.*; import com.amazonaws.http.*; import com.amazonaws.internal.*; import com.amazonaws.internal.auth.*; import com.amazonaws.metrics.*; import com.amazonaws.regions.*; import com.amazonaws.transform.*; import com.amazonaws.util.*; import com.amazonaws.protocol.json.*; import com.amazonaws.util.AWSRequestMetrics.Field; import com.amazonaws.annotation.ThreadSafe; import com.amazonaws.client.AwsSyncClientParams; import com.amazonaws.client.builder.AdvancedConfig; import com.amazonaws.services.dynamodbv2.AmazonDynamoDBStreamsClientBuilder; import com.amazonaws.AmazonServiceException; import com.amazonaws.services.dynamodbv2.model.*; import com.amazonaws.services.dynamodbv2.model.transform.*; /** * Client for accessing Amazon DynamoDB Streams. All service calls made using this client are blocking, and will not * return until the service call completes. * <p> * <fullname>Amazon DynamoDB</fullname> * <p> * Amazon DynamoDB Streams provides API actions for accessing streams and processing stream records. To learn more about * application development with Streams, see <a * href="http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Streams.html">Capturing Table Activity with * DynamoDB Streams</a> in the Amazon DynamoDB Developer Guide. * </p> */ @ThreadSafe @Generated("com.amazonaws:aws-java-sdk-code-generator") public class AmazonDynamoDBStreamsClient extends AmazonWebServiceClient implements AmazonDynamoDBStreams { /** Provider for AWS credentials. */ private final AWSCredentialsProvider awsCredentialsProvider; private static final Log log = LogFactory.getLog(AmazonDynamoDBStreams.class); /** Default signing name for the service. */ private static final String DEFAULT_SIGNING_NAME = "dynamodb"; /** Client configuration factory providing ClientConfigurations tailored to this client */ protected static final ClientConfigurationFactory configFactory = new ClientConfigurationFactory(); private final AdvancedConfig advancedConfig; private static final com.amazonaws.protocol.json.SdkJsonProtocolFactory protocolFactory = new com.amazonaws.protocol.json.SdkJsonProtocolFactory( new JsonClientMetadata().withProtocolVersion("1.0").withSupportsCbor(false).withSupportsIon(false) .addErrorMetadata(new JsonErrorShapeMetadata().withErrorCode("TrimmedDataAccessException") .withExceptionUnmarshaller( com.amazonaws.services.dynamodbv2.model.transform.TrimmedDataAccessExceptionUnmarshaller .getInstance())) .addErrorMetadata(new JsonErrorShapeMetadata().withErrorCode("ResourceNotFoundException") .withExceptionUnmarshaller( com.amazonaws.services.dynamodbv2.model.transform.ResourceNotFoundExceptionUnmarshaller .getInstance())) .addErrorMetadata(new JsonErrorShapeMetadata().withErrorCode("ExpiredIteratorException") .withExceptionUnmarshaller( com.amazonaws.services.dynamodbv2.model.transform.ExpiredIteratorExceptionUnmarshaller .getInstance())) .addErrorMetadata(new JsonErrorShapeMetadata().withErrorCode("InternalServerError") .withExceptionUnmarshaller( com.amazonaws.services.dynamodbv2.model.transform.InternalServerErrorExceptionUnmarshaller .getInstance())) .addErrorMetadata(new JsonErrorShapeMetadata().withErrorCode("LimitExceededException") .withExceptionUnmarshaller( com.amazonaws.services.dynamodbv2.model.transform.LimitExceededExceptionUnmarshaller .getInstance())) .withBaseServiceExceptionClass( com.amazonaws.services.dynamodbv2.model.AmazonDynamoDBException.class)); /** * Constructs a new client to invoke service methods on Amazon DynamoDB Streams. A credentials provider chain will * be used that searches for credentials in this order: * <ul> * <li>Environment Variables - AWS_ACCESS_KEY_ID and AWS_SECRET_KEY</li> * <li>Java System Properties - aws.accessKeyId and aws.secretKey</li> * <li>Instance profile credentials delivered through the Amazon EC2 metadata service</li> * </ul> * * <p> * All service calls made using this new client object are blocking, and will not return until the service call * completes. * * @see DefaultAWSCredentialsProviderChain * @deprecated use {@link AmazonDynamoDBStreamsClientBuilder#defaultClient()} */ @Deprecated public AmazonDynamoDBStreamsClient() { this(DefaultAWSCredentialsProviderChain.getInstance(), configFactory.getConfig()); } /** * Constructs a new client to invoke service methods on Amazon DynamoDB Streams. A credentials provider chain will * be used that searches for credentials in this order: * <ul> * <li>Environment Variables - AWS_ACCESS_KEY_ID and AWS_SECRET_KEY</li> * <li>Java System Properties - aws.accessKeyId and aws.secretKey</li> * <li>Instance profile credentials delivered through the Amazon EC2 metadata service</li> * </ul> * * <p> * All service calls made using this new client object are blocking, and will not return until the service call * completes. * * @param clientConfiguration * The client configuration options controlling how this client connects to Amazon DynamoDB Streams (ex: * proxy settings, retry counts, etc.). * * @see DefaultAWSCredentialsProviderChain * @deprecated use {@link AmazonDynamoDBStreamsClientBuilder#withClientConfiguration(ClientConfiguration)} */ @Deprecated public AmazonDynamoDBStreamsClient(ClientConfiguration clientConfiguration) { this(DefaultAWSCredentialsProviderChain.getInstance(), clientConfiguration); } /** * Constructs a new client to invoke service methods on Amazon DynamoDB Streams using the specified AWS account * credentials. * * <p> * All service calls made using this new client object are blocking, and will not return until the service call * completes. * * @param awsCredentials * The AWS credentials (access key ID and secret key) to use when authenticating with AWS services. * @deprecated use {@link AmazonDynamoDBStreamsClientBuilder#withCredentials(AWSCredentialsProvider)} for example: * {@code AmazonDynamoDBStreamsClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(awsCredentials)).build();} */ @Deprecated public AmazonDynamoDBStreamsClient(AWSCredentials awsCredentials) { this(awsCredentials, configFactory.getConfig()); } /** * Constructs a new client to invoke service methods on Amazon DynamoDB Streams using the specified AWS account * credentials and client configuration options. * * <p> * All service calls made using this new client object are blocking, and will not return until the service call * completes. * * @param awsCredentials * The AWS credentials (access key ID and secret key) to use when authenticating with AWS services. * @param clientConfiguration * The client configuration options controlling how this client connects to Amazon DynamoDB Streams (ex: * proxy settings, retry counts, etc.). * @deprecated use {@link AmazonDynamoDBStreamsClientBuilder#withCredentials(AWSCredentialsProvider)} and * {@link AmazonDynamoDBStreamsClientBuilder#withClientConfiguration(ClientConfiguration)} */ @Deprecated public AmazonDynamoDBStreamsClient(AWSCredentials awsCredentials, ClientConfiguration clientConfiguration) { super(clientConfiguration); this.awsCredentialsProvider = new StaticCredentialsProvider(awsCredentials); this.advancedConfig = AdvancedConfig.EMPTY; init(); } /** * Constructs a new client to invoke service methods on Amazon DynamoDB Streams using the specified AWS account * credentials provider. * * <p> * All service calls made using this new client object are blocking, and will not return until the service call * completes. * * @param awsCredentialsProvider * The AWS credentials provider which will provide credentials to authenticate requests with AWS services. * @deprecated use {@link AmazonDynamoDBStreamsClientBuilder#withCredentials(AWSCredentialsProvider)} */ @Deprecated public AmazonDynamoDBStreamsClient(AWSCredentialsProvider awsCredentialsProvider) { this(awsCredentialsProvider, configFactory.getConfig()); } /** * Constructs a new client to invoke service methods on Amazon DynamoDB Streams using the specified AWS account * credentials provider and client configuration options. * * <p> * All service calls made using this new client object are blocking, and will not return until the service call * completes. * * @param awsCredentialsProvider * The AWS credentials provider which will provide credentials to authenticate requests with AWS services. * @param clientConfiguration * The client configuration options controlling how this client connects to Amazon DynamoDB Streams (ex: * proxy settings, retry counts, etc.). * @deprecated use {@link AmazonDynamoDBStreamsClientBuilder#withCredentials(AWSCredentialsProvider)} and * {@link AmazonDynamoDBStreamsClientBuilder#withClientConfiguration(ClientConfiguration)} */ @Deprecated public AmazonDynamoDBStreamsClient(AWSCredentialsProvider awsCredentialsProvider, ClientConfiguration clientConfiguration) { this(awsCredentialsProvider, clientConfiguration, null); } /** * Constructs a new client to invoke service methods on Amazon DynamoDB Streams using the specified AWS account * credentials provider, client configuration options, and request metric collector. * * <p> * All service calls made using this new client object are blocking, and will not return until the service call * completes. * * @param awsCredentialsProvider * The AWS credentials provider which will provide credentials to authenticate requests with AWS services. * @param clientConfiguration * The client configuration options controlling how this client connects to Amazon DynamoDB Streams (ex: * proxy settings, retry counts, etc.). * @param requestMetricCollector * optional request metric collector * @deprecated use {@link AmazonDynamoDBStreamsClientBuilder#withCredentials(AWSCredentialsProvider)} and * {@link AmazonDynamoDBStreamsClientBuilder#withClientConfiguration(ClientConfiguration)} and * {@link AmazonDynamoDBStreamsClientBuilder#withMetricsCollector(RequestMetricCollector)} */ @Deprecated public AmazonDynamoDBStreamsClient(AWSCredentialsProvider awsCredentialsProvider, ClientConfiguration clientConfiguration, RequestMetricCollector requestMetricCollector) { super(clientConfiguration, requestMetricCollector); this.awsCredentialsProvider = awsCredentialsProvider; this.advancedConfig = AdvancedConfig.EMPTY; init(); } public static AmazonDynamoDBStreamsClientBuilder builder() { return AmazonDynamoDBStreamsClientBuilder.standard(); } /** * Constructs a new client to invoke service methods on Amazon DynamoDB Streams using the specified parameters. * * <p> * All service calls made using this new client object are blocking, and will not return until the service call * completes. * * @param clientParams * Object providing client parameters. */ AmazonDynamoDBStreamsClient(AwsSyncClientParams clientParams) { this(clientParams, false); } /** * Constructs a new client to invoke service methods on Amazon DynamoDB Streams using the specified parameters. * * <p> * All service calls made using this new client object are blocking, and will not return until the service call * completes. * * @param clientParams * Object providing client parameters. */ AmazonDynamoDBStreamsClient(AwsSyncClientParams clientParams, boolean endpointDiscoveryEnabled) { super(clientParams); this.awsCredentialsProvider = clientParams.getCredentialsProvider(); this.advancedConfig = clientParams.getAdvancedConfig(); init(); } private void init() { setServiceNameIntern(DEFAULT_SIGNING_NAME); setEndpointPrefix(ENDPOINT_PREFIX); // calling this.setEndPoint(...) will also modify the signer accordingly setEndpoint("https://streams.dynamodb.us-east-1.amazonaws.com"); HandlerChainFactory chainFactory = new HandlerChainFactory(); requestHandler2s .addAll(chainFactory.newRequestHandlerChain("/com/amazonaws/services/dynamodbv2/request.handlers")); requestHandler2s.addAll( chainFactory.newRequestHandler2Chain("/com/amazonaws/services/dynamodbv2/request.handler2s")); requestHandler2s.addAll(chainFactory.getGlobalHandlers()); } /** * <p> * Returns information about a stream, including the current status of the stream, its Amazon Resource Name (ARN), * the composition of its shards, and its corresponding DynamoDB table. * </p> * <note> * <p> * You can call <code>DescribeStream</code> at a maximum rate of 10 times per second. * </p> * </note> * <p> * Each shard in the stream has a <code>SequenceNumberRange</code> associated with it. If the * <code>SequenceNumberRange</code> has a <code>StartingSequenceNumber</code> but no * <code>EndingSequenceNumber</code>, then the shard is still open (able to receive more stream records). If both * <code>StartingSequenceNumber</code> and <code>EndingSequenceNumber</code> are present, then that shard is closed * and can no longer receive more data. * </p> * * @param describeStreamRequest * Represents the input of a <code>DescribeStream</code> operation. * @return Result of the DescribeStream operation returned by the service. * @throws ResourceNotFoundException * The operation tried to access a nonexistent stream. * @throws InternalServerErrorException * An error occurred on the server side. * @sample AmazonDynamoDBStreams.DescribeStream * @see <a href="http://docs.aws.amazon.com/goto/WebAPI/streams-dynamodb-2012-08-10/DescribeStream" * target="_top">AWS API Documentation</a> */ @Override public DescribeStreamResult describeStream(DescribeStreamRequest request) { request = beforeClientExecution(request); return executeDescribeStream(request); } @SdkInternalApi final DescribeStreamResult executeDescribeStream(DescribeStreamRequest describeStreamRequest) { ExecutionContext executionContext = createExecutionContext(describeStreamRequest); AWSRequestMetrics awsRequestMetrics = executionContext.getAwsRequestMetrics(); awsRequestMetrics.startEvent(Field.ClientExecuteTime); Request<DescribeStreamRequest> request = null; Response<DescribeStreamResult> response = null; try { awsRequestMetrics.startEvent(Field.RequestMarshallTime); try { request = new DescribeStreamRequestProtocolMarshaller(protocolFactory) .marshall(super.beforeMarshalling(describeStreamRequest)); // Binds the request metrics to the current request. request.setAWSRequestMetrics(awsRequestMetrics); request.addHandlerContext(HandlerContextKey.SIGNING_REGION, getSigningRegion()); request.addHandlerContext(HandlerContextKey.SERVICE_ID, "DynamoDB Streams"); request.addHandlerContext(HandlerContextKey.OPERATION_NAME, "DescribeStream"); request.addHandlerContext(HandlerContextKey.ADVANCED_CONFIG, advancedConfig); } finally { awsRequestMetrics.endEvent(Field.RequestMarshallTime); } HttpResponseHandler<AmazonWebServiceResponse<DescribeStreamResult>> responseHandler = protocolFactory .createResponseHandler(new JsonOperationMetadata().withPayloadJson(true) .withHasStreamingSuccessResponse(false), new DescribeStreamResultJsonUnmarshaller()); response = invoke(request, responseHandler, executionContext); return response.getAwsResponse(); } finally { endClientExecution(awsRequestMetrics, request, response); } } /** * <p> * Retrieves the stream records from a given shard. * </p> * <p> * Specify a shard iterator using the <code>ShardIterator</code> parameter. The shard iterator specifies the * position in the shard from which you want to start reading stream records sequentially. If there are no stream * records available in the portion of the shard that the iterator points to, <code>GetRecords</code> returns an * empty list. Note that it might take multiple calls to get to a portion of the shard that contains stream records. * </p> * <note> * <p> * <code>GetRecords</code> can retrieve a maximum of 1 MB of data or 1000 stream records, whichever comes first. * </p> * </note> * * @param getRecordsRequest * Represents the input of a <code>GetRecords</code> operation. * @return Result of the GetRecords operation returned by the service. * @throws ResourceNotFoundException * The operation tried to access a nonexistent stream. * @throws LimitExceededException * Your request rate is too high. The AWS SDKs for DynamoDB automatically retry requests that receive this * exception. Your request is eventually successful, unless your retry queue is too large to finish. Reduce * the frequency of requests and use exponential backoff. For more information, go to <a * href="http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/ErrorHandling.html#APIRetries" * >Error Retries and Exponential Backoff</a> in the <i>Amazon DynamoDB Developer Guide</i>. * @throws InternalServerErrorException * An error occurred on the server side. * @throws ExpiredIteratorException * The shard iterator has expired and can no longer be used to retrieve stream records. A shard iterator * expires 15 minutes after it is retrieved using the <code>GetShardIterator</code> action. * @throws TrimmedDataAccessException * The operation attempted to read past the oldest stream record in a shard.</p> * <p> * In DynamoDB Streams, there is a 24 hour limit on data retention. Stream records whose age exceeds this * limit are subject to removal (trimming) from the stream. You might receive a TrimmedDataAccessException * if: * </p> * <ul> * <li> * <p> * You request a shard iterator with a sequence number older than the trim point (24 hours). * </p> * </li> * <li> * <p> * You obtain a shard iterator, but before you use the iterator in a <code>GetRecords</code> request, a * stream record in the shard exceeds the 24 hour period and is trimmed. This causes the iterator to access * a record that no longer exists. * </p> * </li> * @sample AmazonDynamoDBStreams.GetRecords * @see <a href="http://docs.aws.amazon.com/goto/WebAPI/streams-dynamodb-2012-08-10/GetRecords" target="_top">AWS * API Documentation</a> */ @Override public GetRecordsResult getRecords(GetRecordsRequest request) { request = beforeClientExecution(request); return executeGetRecords(request); } @SdkInternalApi final GetRecordsResult executeGetRecords(GetRecordsRequest getRecordsRequest) { ExecutionContext executionContext = createExecutionContext(getRecordsRequest); AWSRequestMetrics awsRequestMetrics = executionContext.getAwsRequestMetrics(); awsRequestMetrics.startEvent(Field.ClientExecuteTime); Request<GetRecordsRequest> request = null; Response<GetRecordsResult> response = null; try { awsRequestMetrics.startEvent(Field.RequestMarshallTime); try { request = new GetRecordsRequestProtocolMarshaller(protocolFactory) .marshall(super.beforeMarshalling(getRecordsRequest)); // Binds the request metrics to the current request. request.setAWSRequestMetrics(awsRequestMetrics); request.addHandlerContext(HandlerContextKey.SIGNING_REGION, getSigningRegion()); request.addHandlerContext(HandlerContextKey.SERVICE_ID, "DynamoDB Streams"); request.addHandlerContext(HandlerContextKey.OPERATION_NAME, "GetRecords"); request.addHandlerContext(HandlerContextKey.ADVANCED_CONFIG, advancedConfig); } finally { awsRequestMetrics.endEvent(Field.RequestMarshallTime); } HttpResponseHandler<AmazonWebServiceResponse<GetRecordsResult>> responseHandler = protocolFactory .createResponseHandler(new JsonOperationMetadata().withPayloadJson(true) .withHasStreamingSuccessResponse(false), new GetRecordsResultJsonUnmarshaller()); response = invoke(request, responseHandler, executionContext); return response.getAwsResponse(); } finally { endClientExecution(awsRequestMetrics, request, response); } } /** * <p> * Returns a shard iterator. A shard iterator provides information about how to retrieve the stream records from * within a shard. Use the shard iterator in a subsequent <code>GetRecords</code> request to read the stream records * from the shard. * </p> * <note> * <p> * A shard iterator expires 15 minutes after it is returned to the requester. * </p> * </note> * * @param getShardIteratorRequest * Represents the input of a <code>GetShardIterator</code> operation. * @return Result of the GetShardIterator operation returned by the service. * @throws ResourceNotFoundException * The operation tried to access a nonexistent stream. * @throws InternalServerErrorException * An error occurred on the server side. * @throws TrimmedDataAccessException * The operation attempted to read past the oldest stream record in a shard.</p> * <p> * In DynamoDB Streams, there is a 24 hour limit on data retention. Stream records whose age exceeds this * limit are subject to removal (trimming) from the stream. You might receive a TrimmedDataAccessException * if: * </p> * <ul> * <li> * <p> * You request a shard iterator with a sequence number older than the trim point (24 hours). * </p> * </li> * <li> * <p> * You obtain a shard iterator, but before you use the iterator in a <code>GetRecords</code> request, a * stream record in the shard exceeds the 24 hour period and is trimmed. This causes the iterator to access * a record that no longer exists. * </p> * </li> * @sample AmazonDynamoDBStreams.GetShardIterator * @see <a href="http://docs.aws.amazon.com/goto/WebAPI/streams-dynamodb-2012-08-10/GetShardIterator" * target="_top">AWS API Documentation</a> */ @Override public GetShardIteratorResult getShardIterator(GetShardIteratorRequest request) { request = beforeClientExecution(request); return executeGetShardIterator(request); } @SdkInternalApi final GetShardIteratorResult executeGetShardIterator(GetShardIteratorRequest getShardIteratorRequest) { ExecutionContext executionContext = createExecutionContext(getShardIteratorRequest); AWSRequestMetrics awsRequestMetrics = executionContext.getAwsRequestMetrics(); awsRequestMetrics.startEvent(Field.ClientExecuteTime); Request<GetShardIteratorRequest> request = null; Response<GetShardIteratorResult> response = null; try { awsRequestMetrics.startEvent(Field.RequestMarshallTime); try { request = new GetShardIteratorRequestProtocolMarshaller(protocolFactory) .marshall(super.beforeMarshalling(getShardIteratorRequest)); // Binds the request metrics to the current request. request.setAWSRequestMetrics(awsRequestMetrics); request.addHandlerContext(HandlerContextKey.SIGNING_REGION, getSigningRegion()); request.addHandlerContext(HandlerContextKey.SERVICE_ID, "DynamoDB Streams"); request.addHandlerContext(HandlerContextKey.OPERATION_NAME, "GetShardIterator"); request.addHandlerContext(HandlerContextKey.ADVANCED_CONFIG, advancedConfig); } finally { awsRequestMetrics.endEvent(Field.RequestMarshallTime); } HttpResponseHandler<AmazonWebServiceResponse<GetShardIteratorResult>> responseHandler = protocolFactory .createResponseHandler(new JsonOperationMetadata().withPayloadJson(true) .withHasStreamingSuccessResponse(false), new GetShardIteratorResultJsonUnmarshaller()); response = invoke(request, responseHandler, executionContext); return response.getAwsResponse(); } finally { endClientExecution(awsRequestMetrics, request, response); } } /** * <p> * Returns an array of stream ARNs associated with the current account and endpoint. If the <code>TableName</code> * parameter is present, then <code>ListStreams</code> will return only the streams ARNs for that table. * </p> * <note> * <p> * You can call <code>ListStreams</code> at a maximum rate of 5 times per second. * </p> * </note> * * @param listStreamsRequest * Represents the input of a <code>ListStreams</code> operation. * @return Result of the ListStreams operation returned by the service. * @throws ResourceNotFoundException * The operation tried to access a nonexistent stream. * @throws InternalServerErrorException * An error occurred on the server side. * @sample AmazonDynamoDBStreams.ListStreams * @see <a href="http://docs.aws.amazon.com/goto/WebAPI/streams-dynamodb-2012-08-10/ListStreams" target="_top">AWS * API Documentation</a> */ @Override public ListStreamsResult listStreams(ListStreamsRequest request) { request = beforeClientExecution(request); return executeListStreams(request); } @SdkInternalApi final ListStreamsResult executeListStreams(ListStreamsRequest listStreamsRequest) { ExecutionContext executionContext = createExecutionContext(listStreamsRequest); AWSRequestMetrics awsRequestMetrics = executionContext.getAwsRequestMetrics(); awsRequestMetrics.startEvent(Field.ClientExecuteTime); Request<ListStreamsRequest> request = null; Response<ListStreamsResult> response = null; try { awsRequestMetrics.startEvent(Field.RequestMarshallTime); try { request = new ListStreamsRequestProtocolMarshaller(protocolFactory) .marshall(super.beforeMarshalling(listStreamsRequest)); // Binds the request metrics to the current request. request.setAWSRequestMetrics(awsRequestMetrics); request.addHandlerContext(HandlerContextKey.SIGNING_REGION, getSigningRegion()); request.addHandlerContext(HandlerContextKey.SERVICE_ID, "DynamoDB Streams"); request.addHandlerContext(HandlerContextKey.OPERATION_NAME, "ListStreams"); request.addHandlerContext(HandlerContextKey.ADVANCED_CONFIG, advancedConfig); } finally { awsRequestMetrics.endEvent(Field.RequestMarshallTime); } HttpResponseHandler<AmazonWebServiceResponse<ListStreamsResult>> responseHandler = protocolFactory .createResponseHandler(new JsonOperationMetadata().withPayloadJson(true) .withHasStreamingSuccessResponse(false), new ListStreamsResultJsonUnmarshaller()); response = invoke(request, responseHandler, executionContext); return response.getAwsResponse(); } finally { endClientExecution(awsRequestMetrics, request, response); } } /** * Returns additional metadata for a previously executed successful, request, typically used for debugging issues * where a service isn't acting as expected. This data isn't considered part of the result data returned by an * operation, so it's available through this separate, diagnostic interface. * <p> * Response metadata is only cached for a limited period of time, so if you need to access this extra diagnostic * information for an executed request, you should use this method to retrieve it as soon as possible after * executing the request. * * @param request * The originally executed request * * @return The response metadata for the specified request, or null if none is available. */ public ResponseMetadata getCachedResponseMetadata(AmazonWebServiceRequest request) { return client.getResponseMetadataForRequest(request); } /** * Normal invoke with authentication. Credentials are required and may be overriden at the request level. **/ private <X, Y extends AmazonWebServiceRequest> Response<X> invoke(Request<Y> request, HttpResponseHandler<AmazonWebServiceResponse<X>> responseHandler, ExecutionContext executionContext) { return invoke(request, responseHandler, executionContext, null, null); } /** * Normal invoke with authentication. Credentials are required and may be overriden at the request level. **/ private <X, Y extends AmazonWebServiceRequest> Response<X> invoke(Request<Y> request, HttpResponseHandler<AmazonWebServiceResponse<X>> responseHandler, ExecutionContext executionContext, URI cachedEndpoint, URI uriFromEndpointTrait) { executionContext.setCredentialsProvider( CredentialUtils.getCredentialsProvider(request.getOriginalRequest(), awsCredentialsProvider)); return doInvoke(request, responseHandler, executionContext, cachedEndpoint, uriFromEndpointTrait); } /** * Invoke with no authentication. Credentials are not required and any credentials set on the client or request will * be ignored for this operation. **/ private <X, Y extends AmazonWebServiceRequest> Response<X> anonymousInvoke(Request<Y> request, HttpResponseHandler<AmazonWebServiceResponse<X>> responseHandler, ExecutionContext executionContext) { return doInvoke(request, responseHandler, executionContext, null, null); } /** * Invoke the request using the http client. Assumes credentials (or lack thereof) have been configured in the * ExecutionContext beforehand. **/ private <X, Y extends AmazonWebServiceRequest> Response<X> doInvoke(Request<Y> request, HttpResponseHandler<AmazonWebServiceResponse<X>> responseHandler, ExecutionContext executionContext, URI discoveredEndpoint, URI uriFromEndpointTrait) { if (discoveredEndpoint != null) { request.setEndpoint(discoveredEndpoint); request.getOriginalRequest().getRequestClientOptions().appendUserAgent("endpoint-discovery"); } else if (uriFromEndpointTrait != null) { request.setEndpoint(uriFromEndpointTrait); } else { request.setEndpoint(endpoint); } request.setTimeOffset(timeOffset); HttpResponseHandler<AmazonServiceException> errorResponseHandler = protocolFactory .createErrorResponseHandler(new JsonErrorResponseMetadata()); return client.execute(request, responseHandler, errorResponseHandler, executionContext); } @com.amazonaws.annotation.SdkInternalApi static com.amazonaws.protocol.json.SdkJsonProtocolFactory getProtocolFactory() { return protocolFactory; } }