public abstract class AmazonWebserviceClient extends Object
Responsible for basic client capabilities that are the same across all AWS SDK Java clients (ex: setting the client endpoint).
Modifier and Type | Field and Description |
---|---|
private static String |
AMAZON |
private static String |
AWS |
protected AmazonHttpClient |
client
Low level client for sending requests to AWS services.
|
protected com.amazonaws.ClientConfiguration |
clientConfiguration
The client configuration
|
protected URI |
endpoint
The service endpoint to which this client will send requests.
|
private String |
endpointPrefix
The service name in region metadata, i.e.
|
private static org.apache.commons.logging.Log |
log |
static boolean |
LOGGING_AWS_REQUEST_METRIC |
protected List<com.amazonaws.handlers.RequestHandler2> |
requestHandler2s
Optional request handlers for additional request processing.
|
private String |
serviceName
The cached service abbreviation for this service, used for identifying service endpoints by
region, identifying the necessary signer, etc.
|
private com.amazonaws.auth.Signer |
signer
AWS signer for authenticating requests.
|
private String |
signerRegionOverride
Used to explicitly override the internal signer region computed by the default
implementation.
|
protected int |
timeOffset
Optional offset (in seconds) to use when signing requests
|
Constructor and Description |
---|
AmazonWebserviceClient(com.amazonaws.ClientConfiguration clientConfiguration)
Constructs a new AmazonWebServiceClient object using the specified configuration.
|
AmazonWebserviceClient(com.amazonaws.ClientConfiguration clientConfiguration,
com.amazonaws.metrics.RequestMetricCollector requestMetricCollector)
Constructs a new AmazonWebServiceClient object using the specified configuration and request
metric collector.
|
Modifier and Type | Method and Description |
---|---|
void |
addRequestHandler(com.amazonaws.handlers.RequestHandler requestHandler)
Deprecated.
by
addRequestHandler(com.amazonaws.handlers.RequestHandler2) .
Appends a request handler to the list of registered handlers that are run as part
of a request's lifecycle. |
void |
addRequestHandler(com.amazonaws.handlers.RequestHandler2 requestHandler2)
Appends a request handler to the list of registered handlers that are run as part of a
request's lifecycle.
|
protected <T extends com.amazonaws.AmazonWebServiceRequest> |
beforeMarshalling(T request)
Runs the
beforeMarshalling method of any RequestHandler2 s associated with
this client. |
private String |
computeServiceName()
Returns the service name of this AWS http client by first looking it up from the SDK internal
configuration, and if not found, derive it from the class name of the immediate subclass of
AmazonWebserviceClient . |
private com.amazonaws.auth.Signer |
computeSignerByServiceRegion(String serviceName,
String regionId,
String signerRegionOverride,
boolean isRegionIdAsSignerParam)
Returns the signer for the given service name, region id, and the current client
configuration.
|
private com.amazonaws.auth.Signer |
computeSignerByURI(URI uri,
String signerRegionOverride,
boolean isRegionIdAsSignerParam)
Returns the signer for the given uri and the current client configuration.
|
protected void |
configSigner(String serviceName,
String regionId)
Deprecated.
this method is now a no-op, as overriding the signer from sublcass is no longer
supported.
|
protected void |
configSigner(URI uri)
Deprecated.
this method is now a no-op, as overriding the signer from sublcass is no longer
supported.
|
protected ExecutionContext |
createExecutionContext(com.amazonaws.AmazonWebServiceRequest req) |
protected void |
endClientExecution(com.amazonaws.util.AWSRequestMetrics awsRequestMetrics,
com.amazonaws.Request<?> request,
com.amazonaws.Response<?> response)
Convenient method to end the client execution without logging the awsRequestMetrics.
|
protected void |
endClientExecution(com.amazonaws.util.AWSRequestMetrics awsRequestMetrics,
com.amazonaws.Request<?> request,
com.amazonaws.Response<?> response,
boolean loggingAwsRequestMetrics)
Common routine to end a client AWS request/response execution and collect the request
metrics.
|
protected com.amazonaws.metrics.RequestMetricCollector |
findRequestMetricCollector(com.amazonaws.Request<?> req)
Returns the most specific request metric collector, starting from the request level, then
client level, then finally the AWS SDK level.
|
private String |
getHttpClientName() |
com.amazonaws.metrics.RequestMetricCollector |
getRequestMetricsCollector()
Returns the client specific
RequestMetricCollector ; or null if
there is none. |
protected String |
getServiceAbbreviation()
Deprecated.
by
getServiceName() . |
String |
getServiceName()
Returns the service abbreviation for this service, used for identifying service endpoints by
region, identifying the necessary signer, etc.
|
private String |
getServiceNameForRegionMetadata() |
protected String |
getServiceNameIntern()
Internal method for implementing
getServiceName() . |
protected com.amazonaws.auth.Signer |
getSigner()
Returns the signer.
|
com.amazonaws.auth.Signer |
getSignerByURI(URI uri)
Returns the signer based on the given URI and the current AWS client configuration.
|
int |
getTimeOffset()
Returns the optional value for time offset for this client.
|
protected static boolean |
isProfilingEnabled() |
protected boolean |
isRequestMetricsEnabled(com.amazonaws.AmazonWebServiceRequest req)
Returns true if request metric collection is applicable to the given request; false
otherwise.
|
private boolean |
isRMCEnabledAtClientOrSdkLevel()
Returns true if request metric collection is enabled at the service client or AWS SDK level
request; false otherwise.
|
void |
removeRequestHandler(com.amazonaws.handlers.RequestHandler requestHandler)
Removes a request handler from the list of registered handlers that are run as part of a
request's lifecycle.
|
void |
removeRequestHandler(com.amazonaws.handlers.RequestHandler2 requestHandler2) |
protected com.amazonaws.metrics.RequestMetricCollector |
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.
|
void |
setEndpoint(String endpoint,
String serviceName,
String regionId)
Deprecated.
|
protected void |
setEndpointPrefix(String endpointPrefix)
An internal method used to explicitly override the service name for region metadata.
|
void |
setRegion(com.amazonaws.regions.Region region)
An alternative to
setEndpoint(String) , sets the regional
endpoint for this client's service calls. |
void |
setServiceNameIntern(String serviceName)
An internal method used to explicitly override the service name 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.
|
private URI |
toURI(String endpoint)
Returns the endpoint as a URI.
|
static URI |
toUri(String endpoint,
com.amazonaws.ClientConfiguration config)
Returns an URI for the given endpoint.
|
AmazonWebserviceClient |
withTimeOffset(int timeOffset)
Sets the optional value for time offset for this client.
|
private static final String AMAZON
private static final String AWS
public static final boolean LOGGING_AWS_REQUEST_METRIC
private static final org.apache.commons.logging.Log log
protected volatile URI endpoint
Subclass should only read but not assign to this field, at least not without synchronization on the enclosing object for thread-safety reason.
private volatile String signerRegionOverride
protected com.amazonaws.ClientConfiguration clientConfiguration
protected AmazonHttpClient client
protected final List<com.amazonaws.handlers.RequestHandler2> requestHandler2s
protected int timeOffset
private volatile com.amazonaws.auth.Signer signer
private volatile String serviceName
private volatile String endpointPrefix
public AmazonWebserviceClient(com.amazonaws.ClientConfiguration clientConfiguration)
clientConfiguration
- The client configuration for this client.public AmazonWebserviceClient(com.amazonaws.ClientConfiguration clientConfiguration, com.amazonaws.metrics.RequestMetricCollector requestMetricCollector)
clientConfiguration
- The client configuration for this client.requestMetricCollector
- optional request metric collector to be used at the http client level; can be
null.protected com.amazonaws.auth.Signer getSigner()
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.
public void setEndpoint(String endpoint) throws IllegalArgumentException
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
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.IllegalArgumentException
- If any problems are detected with the specified endpoint.private URI toURI(String endpoint) throws IllegalArgumentException
IllegalArgumentException
public static URI toUri(String endpoint, com.amazonaws.ClientConfiguration config)
IllegalArgumentException
- if the inputs are null.@Deprecated public void setEndpoint(String endpoint, String serviceName, String regionId)
Overrides the default endpoint for this client ("http://dynamodb.us-east-1.amazonaws.com/") and explicitly provides an AWS region ID and AWS service name to use when the client calculates a signature for requests. In almost all cases, this region ID and service name are automatically determined from the endpoint, and callers should use the simpler one-argument form of setEndpoint instead of this method.
Callers can pass in just the endpoint (ex: "dynamodb.us-east-1.amazonaws.com/") or a full
URL, including the protocol (ex: "http://dynamodb.us-east-1.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
endpoint
- The endpoint (ex: "dynamodb.us-east-1.amazonaws.com/") or a full URL, including
the protocol (ex: "http://dynamodb.us-east-1.amazonaws.com/") of the region
specific AWS endpoint this client will communicate with.serviceName
- This parameter is ignored.regionId
- The ID of the region in which this service resides AND the overriding region for
signing purposes.IllegalArgumentException
- If any problems are detected with the specified endpoint.@Deprecated protected void configSigner(URI uri)
@Deprecated protected void configSigner(String serviceName, String regionId)
public com.amazonaws.auth.Signer getSignerByURI(URI uri)
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.
private com.amazonaws.auth.Signer computeSignerByURI(URI uri, String signerRegionOverride, boolean isRegionIdAsSignerParam)
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.
signerRegionOverride
- the overriding signer region; or null if there is none.isRegionIdAsSignerParam
- true if the "regionId" is used to configure the signer if applicable; false if
this method is called for the purpose of purely setting the communication end
point of this AWS client, and therefore the "regionId" parameter will not be used
directly for configuring the signer.private com.amazonaws.auth.Signer computeSignerByServiceRegion(String serviceName, String regionId, String signerRegionOverride, boolean isRegionIdAsSignerParam)
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.
regionId
- the region for sending AWS requestssignerRegionOverride
- the overriding signer region; or null if there is none.isRegionIdAsSignerParam
- true if the "regionId" is used to configure the signer if applicable; false if
this method is called for the purpose of purely setting the communication end
point of this AWS client, and therefore the "regionId" parameter will not be used
directly for configuring the signer.public void setRegion(com.amazonaws.regions.Region region) throws IllegalArgumentException
setEndpoint(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.
region
- The region this client will communicate with. See
Region.getRegion(com.amazonaws.regions.Regions)
for
accessing a given region.IllegalArgumentException
- If the given region is null, or if this service isn't available in the given
region. See Region.isServiceSupported(String)
Region.getRegion(com.amazonaws.regions.Regions)
,
Region.createClient(Class,
com.amazonaws.auth.AWSCredentialsProvider, com.amazonaws.ClientConfiguration)
public void shutdown()
@Deprecated public void addRequestHandler(com.amazonaws.handlers.RequestHandler requestHandler)
addRequestHandler(com.amazonaws.handlers.RequestHandler2)
.
Appends a request handler to the list of registered handlers that are run as part
of a request's lifecycle.requestHandler
- The new handler to add to the current list of request handlers.public void addRequestHandler(com.amazonaws.handlers.RequestHandler2 requestHandler2)
requestHandler2
- The new handler to add to the current list of request handlers.public void removeRequestHandler(com.amazonaws.handlers.RequestHandler requestHandler)
requestHandler
- The handler to remove from the current list of request handlers.public void removeRequestHandler(com.amazonaws.handlers.RequestHandler2 requestHandler2)
protected ExecutionContext createExecutionContext(com.amazonaws.AmazonWebServiceRequest req)
protected final boolean isRequestMetricsEnabled(com.amazonaws.AmazonWebServiceRequest req)
protected static boolean isProfilingEnabled()
private boolean isRMCEnabledAtClientOrSdkLevel()
public void setTimeOffset(int timeOffset)
timeOffset
- The optional value for time offset (in seconds) for this client.public AmazonWebserviceClient withTimeOffset(int timeOffset)
timeOffset
- The optional value for time offset (in seconds) for this client.public int getTimeOffset()
public com.amazonaws.metrics.RequestMetricCollector getRequestMetricsCollector()
RequestMetricCollector
; or null if
there is none.protected com.amazonaws.metrics.RequestMetricCollector requestMetricCollector()
@Deprecated protected String getServiceAbbreviation()
getServiceName()
.public String getServiceName()
private String getServiceNameForRegionMetadata()
protected String getServiceNameIntern()
getServiceName()
. 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.private String computeServiceName()
AmazonWebserviceClient
. No configuration is necessary if the simple class name of the
http client follows the convention of (Amazon|AWS).*(JavaClient|Client)
.private String getHttpClientName()
public final void setServiceNameIntern(String serviceName)
protected void setEndpointPrefix(String endpointPrefix)
protected final <T extends com.amazonaws.AmazonWebServiceRequest> T beforeMarshalling(T request)
beforeMarshalling
method of any RequestHandler2
s associated with
this client.request
- the request passed in from the userprotected final void endClientExecution(com.amazonaws.util.AWSRequestMetrics awsRequestMetrics, com.amazonaws.Request<?> request, com.amazonaws.Response<?> response)
protected final void endClientExecution(com.amazonaws.util.AWSRequestMetrics awsRequestMetrics, com.amazonaws.Request<?> request, com.amazonaws.Response<?> response, @Deprecated boolean loggingAwsRequestMetrics)
AWSRequestMetrics.Field.ClientExecuteTime
and call this method in
a try-finally block.loggingAwsRequestMetrics
- deprecated and ignoredprotected final com.amazonaws.metrics.RequestMetricCollector findRequestMetricCollector(com.amazonaws.Request<?> req)