Class AmazonWebServiceClient
- Direct Known Subclasses:
AmazonApiGatewayClient
,AmazonAutoScalingClient
,AmazonCloudFormationClient
,AmazonCloudFrontClient
,AmazonCloudSearchClient
,AmazonCloudSearchDomainClient
,AmazonCloudWatchClient
,AmazonCloudWatchEventsClient
,AmazonCodeDeployClient
,AmazonCognitoIdentityClient
,AmazonCognitoSyncClient
,AmazonConfigClient
,AmazonDirectConnectClient
,AmazonDynamoDBClient
,AmazonDynamoDBStreamsClient
,AmazonEC2Client
,AmazonECRClient
,AmazonECSClient
,AmazonElastiCacheClient
,AmazonElasticFileSystemClient
,AmazonElasticLoadBalancingClient
,AmazonElasticMapReduceClient
,AmazonElasticTranscoderClient
,AmazonGameLiftClient
,AmazonGlacierClient
,AmazonIdentityManagementClient
,AmazonImportExportClient
,AmazonInspectorClient
,AmazonKinesisClient
,AmazonKinesisFirehoseClient
,AmazonMachineLearningClient
,AmazonRDSClient
,AmazonRedshiftClient
,AmazonRoute53Client
,AmazonRoute53DomainsClient
,AmazonS3Client
,AmazonSimpleDBClient
,AmazonSimpleEmailServiceClient
,AmazonSimpleWorkflowClient
,AmazonSNSClient
,AmazonSQSClient
,AmazonWorkspacesClient
,AWSApplicationAutoScalingClient
,AWSApplicationDiscoveryClient
,AWSCertificateManagerClient
,AWSCloudHSMClient
,AWSCloudTrailClient
,AWSCodeCommitClient
,AWSCodePipelineClient
,AWSCognitoIdentityProviderClient
,AWSDatabaseMigrationServiceClient
,AWSDeviceFarmClient
,AWSDirectoryServiceClient
,AWSElasticBeanstalkClient
,AWSElasticsearchClient
,AWSIotClient
,AWSIotDataClient
,AWSKMSClient
,AWSLambdaClient
,AWSLogsClient
,AWSMarketplaceCommerceAnalyticsClient
,AWSMarketplaceMeteringClient
,AWSOpsWorksClient
,AWSSecurityTokenServiceClient
,AWSSimpleSystemsManagementClient
,AWSStorageGatewayClient
,AWSSupportClient
,AWSWAFClient
,DataPipelineClient
Responsible for basic client capabilities that are the same across all AWS SDK Java clients (ex: setting the client endpoint).
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected AmazonHttpClient
Low level client for sending requests to AWS services.protected ClientConfiguration
The client configurationprotected URI
The service endpoint to which this client will send requests.static final boolean
protected final List
<RequestHandler2> Optional request handlers for additional request processing.protected int
Optional offset (in seconds) to use when signing requests -
Constructor Summary
ConstructorsModifierConstructorDescriptionAmazonWebServiceClient
(ClientConfiguration clientConfiguration) Constructs a new AmazonWebServiceClient object using the specified configuration.AmazonWebServiceClient
(ClientConfiguration clientConfiguration, RequestMetricCollector requestMetricCollector) Constructs a new AmazonWebServiceClient object using the specified configuration and request metric collector.protected
AmazonWebServiceClient
(ClientConfiguration clientConfiguration, RequestMetricCollector requestMetricCollector, boolean disableStrictHostNameVerification) -
Method Summary
Modifier and TypeMethodDescriptionvoid
addRequestHandler
(RequestHandler requestHandler) Deprecated.void
addRequestHandler
(RequestHandler2 requestHandler2) Appends a request handler to the list of registered handlers that are run as part of a request's lifecycle.protected final <T extends AmazonWebServiceRequest>
TbeforeMarshalling
(T request) Runs thebeforeMarshalling
method of anyRequestHandler2
s associated with this client.final void
configureRegion
(Regions region) Convenient method for setting region.protected final ExecutionContext
Deprecated.protected ExecutionContext
protected final ExecutionContext
createExecutionContext
(Request<?> req) protected final void
endClientExecution
(AWSRequestMetrics awsRequestMetrics, Request<?> request, Response<?> response) Convenient method to end the client execution without logging the awsRequestMetrics.protected final void
endClientExecution
(AWSRequestMetrics awsRequestMetrics, Request<?> request, Response<?> response, boolean loggingAwsRequestMetrics) Common routine to end a client AWS request/response execution and collect the request metrics.protected final RequestMetricCollector
findRequestMetricCollector
(Request<?> req) Returns the most specific request metric collector, starting from the request level, then client level, then finally the AWS SDK level.Returns the client specificRequestMetricCollector
; or null if there is none.protected String
Deprecated.bygetServiceName()
.Returns the service abbreviation for this service, used for identifying service endpoints by region, identifying the necessary signer, etc.protected String
Internal method for implementinggetServiceName()
.protected Signer
Returns the signer.getSignerByURI
(URI uri) Returns the signer based on the given URI and the current AWS client configuration.final String
Returns the signer region override.int
Returns the optional value for time offset for this client.protected static boolean
protected final boolean
Returns true if request metric collection is applicable to the given request; false otherwise.void
removeRequestHandler
(RequestHandler requestHandler) Removes a request handler from the list of registered handlers that are run as part of a request's lifecycle.void
removeRequestHandler
(RequestHandler2 requestHandler2) protected RequestMetricCollector
Returns the client specific request metric collector if there is one; or the one at the AWS SDK level otherwise.void
setEndpoint
(String endpoint) Overrides the default endpoint for this client.protected void
setEndpointPrefix
(String endpointPrefix) An internal method used to explicitly override the service name for region metadata.void
An alternative tosetEndpoint(String)
, sets the regional endpoint for this client's service calls.final void
setServiceNameIntern
(String serviceName) An internal method used to explicitly override the service name computed by the default implementation.final void
setSignerRegionOverride
(String signerRegionOverride) An internal method used to explicitly override the internal signer region computed by the default implementation.void
setTimeOffset
(int timeOffset) Sets the optional value for time offset for this client.void
shutdown()
Shuts down this client object, releasing any resources that might be held open.<T extends AmazonWebServiceClient>
TwithEndpoint
(String endpoint) Fluent method forsetEndpoint(String)
.<T extends AmazonWebServiceClient>
TwithRegion
(Region region) Fluent method forsetRegion(Region)
.<T extends AmazonWebServiceClient>
TwithRegion
(Regions region) Convenient fluent method for setting region.withTimeOffset
(int timeOffset) Sets the optional value for time offset for this client.
-
Field Details
-
LOGGING_AWS_REQUEST_METRIC
public static final boolean LOGGING_AWS_REQUEST_METRIC- See Also:
-
endpoint
The service endpoint to which this client will send requests.Subclass should only read but not assign to this field, at least not without synchronization on the enclosing object for thread-safety reason.
-
clientConfiguration
The client configuration -
client
Low level client for sending requests to AWS services. -
requestHandler2s
Optional request handlers for additional request processing. -
timeOffset
protected int timeOffsetOptional offset (in seconds) to use when signing requests
-
-
Constructor Details
-
AmazonWebServiceClient
Constructs a new AmazonWebServiceClient object using the specified configuration.- Parameters:
clientConfiguration
- The client configuration for this client.
-
AmazonWebServiceClient
public AmazonWebServiceClient(ClientConfiguration clientConfiguration, RequestMetricCollector requestMetricCollector) Constructs a new AmazonWebServiceClient object using the specified configuration and request metric collector.- Parameters:
clientConfiguration
- The client configuration for this client.requestMetricCollector
- optional request metric collector to be used at the http client level; can be null.
-
AmazonWebServiceClient
protected AmazonWebServiceClient(ClientConfiguration clientConfiguration, RequestMetricCollector requestMetricCollector, boolean disableStrictHostNameVerification)
-
-
Method Details
-
getSigner
Returns the signer.Note, however, the signer configured for S3 is incomplete at this stage as the information on the S3 bucket and key is not yet known.
-
setEndpoint
Overrides the default endpoint for this client. Callers can use this method to control which AWS region they want to work with.This method is not threadsafe. Endpoints should be configured when the client is created and before any service requests are made. Changing it afterwards creates inevitable race conditions for any service requests in transit.
Callers can pass in just the endpoint (ex: "ec2.amazonaws.com") or a full URL, including the protocol (ex: "https://ec2.amazonaws.com"). If the protocol is not specified here, the default protocol from this client's
ClientConfiguration
will be used, which by default is HTTPS.For more information on using AWS regions with the AWS SDK for Java, and a complete list of all available endpoints for all AWS services, see: http://developer.amazonwebservices.com/connect/entry.jspa?externalID=3912
- Parameters:
endpoint
- The endpoint (ex: "ec2.amazonaws.com") or a full URL, including the protocol (ex: "https://ec2.amazonaws.com") of the region specific AWS endpoint this client will communicate with.- Throws:
IllegalArgumentException
- If any problems are detected with the specified endpoint.
-
getSignerByURI
Returns the signer based on the given URI and the current AWS client configuration. Currently only the SQS client can have different region on a per request basis. For other AWS clients, the region remains the same on a per AWS client level.Note, however, the signer returned for S3 is incomplete at this stage as the information on the S3 bucket and key is not yet known.
-
setRegion
An alternative tosetEndpoint(String)
, sets the regional endpoint for this client's service calls. Callers can use this method to control which AWS region they want to work with.This method is not threadsafe. A region should be configured when the client is created and before any service requests are made. Changing it afterwards creates inevitable race conditions for any service requests in transit or retrying.
By default, all service endpoints in all regions use the https protocol. To use http instead, specify it in the
ClientConfiguration
supplied at construction.- Parameters:
region
- The region this client will communicate with. SeeRegion.getRegion(com.amazonaws.regions.Regions)
for accessing a given region.- Throws:
IllegalArgumentException
- If the given region is null, or if this service isn't available in the given region. SeeRegion.isServiceSupported(String)
- See Also:
-
configureRegion
Convenient method for setting region.- Parameters:
region
- region to set to; must not be null.- See Also:
-
shutdown
public void shutdown()Shuts down this client object, releasing any resources that might be held open. This is an optional method, and callers are not expected to call it, but can if they want to explicitly release any open resources. Once a client has been shutdown, it should not be used to make any more requests. -
addRequestHandler
Deprecated.byaddRequestHandler(RequestHandler2)
. Appends a request handler to the list of registered handlers that are run as part of a request's lifecycle.- Parameters:
requestHandler
- The new handler to add to the current list of request handlers.
-
addRequestHandler
Appends a request handler to the list of registered handlers that are run as part of a request's lifecycle.- Parameters:
requestHandler2
- The new handler to add to the current list of request handlers.
-
removeRequestHandler
Removes a request handler from the list of registered handlers that are run as part of a request's lifecycle.- Parameters:
requestHandler
- The handler to remove from the current list of request handlers.
-
removeRequestHandler
-
beforeMarshalling
Runs thebeforeMarshalling
method of anyRequestHandler2
s associated with this client.- Parameters:
request
- the request passed in from the user- Returns:
- the (possibly different) request to marshal
-
createExecutionContext
-
createExecutionContext
-
createExecutionContext
Deprecated.bycreateExecutionContext(AmazonWebServiceRequest)
. This method exists only for backward compatiblity reason, so that clients compiled against the older version of this class won't getNoSuchMethodError
at runtime. However, calling this methods would effectively ignore and disable the request metric collector, if any, specified at the request level. Request metric collector specified at the service client or AWS SDK level will still be honored. -
isProfilingEnabled
protected static boolean isProfilingEnabled() -
isRequestMetricsEnabled
Returns true if request metric collection is applicable to the given request; false otherwise. -
setTimeOffset
public void setTimeOffset(int timeOffset) Sets the optional value for time offset for this client. This value will be applied to all requests processed through this client. Value is in seconds, positive values imply the current clock is "fast", negative values imply clock is slow.- Parameters:
timeOffset
- The optional value for time offset (in seconds) for this client.
-
withTimeOffset
Sets the optional value for time offset for this client. This value will be applied to all requests processed through this client. Value is in seconds, positive values imply the current clock is "fast", negative values imply clock is slow.- Parameters:
timeOffset
- The optional value for time offset (in seconds) for this client.- Returns:
- the updated web service client
-
getTimeOffset
public int getTimeOffset()Returns the optional value for time offset for this client. This value will be applied to all requests processed through this client. Value is in seconds, positive values imply the current clock is "fast", negative values imply clock is slow.- Returns:
- The optional value for time offset (in seconds) for this client.
-
getRequestMetricsCollector
Returns the client specificRequestMetricCollector
; or null if there is none. -
requestMetricCollector
Returns the client specific request metric collector if there is one; or the one at the AWS SDK level otherwise. -
findRequestMetricCollector
Returns the most specific request metric collector, starting from the request level, then client level, then finally the AWS SDK level. -
endClientExecution
protected final void endClientExecution(AWSRequestMetrics awsRequestMetrics, Request<?> request, Response<?> response) Convenient method to end the client execution without logging the awsRequestMetrics. -
endClientExecution
protected final void endClientExecution(AWSRequestMetrics awsRequestMetrics, Request<?> request, Response<?> response, @Deprecated boolean loggingAwsRequestMetrics) Common routine to end a client AWS request/response execution and collect the request metrics. Caller of this routine is responsible for starting the event forAWSRequestMetrics.Field.ClientExecuteTime
and call this method in a try-finally block.- Parameters:
loggingAwsRequestMetrics
- deprecated and ignored
-
getServiceAbbreviation
Deprecated.bygetServiceName()
. -
getServiceName
Returns the service abbreviation for this service, used for identifying service endpoints by region, identifying the necessary signer, etc. Used to be call "getServiceAbbreviation". -
getEndpointPrefix
- Returns:
- the service name that should be used when computing the region endpoints. This method returns the value of the regionMetadataServiceName configuration in the internal config file if such configuration is specified for the current client, otherwise it returns the same service name that is used for request signing.
-
setEndpointPrefix
An internal method used to explicitly override the service name for region metadata. This service name is used to compute the region endpoints. -
getServiceNameIntern
Internal method for implementinggetServiceName()
. Method is protected by intent so peculiar subclass that don't follow the class naming convention can choose to return whatever service name as needed. -
setServiceNameIntern
An internal method used to explicitly override the service name computed by the default implementation. This method is not expected to be normally called except for AWS internal development purposes. -
getSignerRegionOverride
Returns the signer region override. -
setSignerRegionOverride
An internal method used to explicitly override the internal signer region computed by the default implementation. This method is not expected to be normally called except for AWS internal development purposes. -
withRegion
Fluent method forsetRegion(Region)
.Example: AmazonDynamoDBClient client = new AmazonDynamoDBClient(...).
withRegion(...); - See Also:
-
withRegion
Convenient fluent method for setting region.- Parameters:
region
- region to set to; must not be null.- See Also:
-
withEndpoint
Fluent method forsetEndpoint(String)
.Example: AmazonDynamoDBClient client = new AmazonDynamoDBClient(...).
withEndPoint(...); - See Also:
-
addRequestHandler(RequestHandler2)
.