
templates.common.SyncClientClassBase.ftl Maven / Gradle / Ivy
${fileHeader}
<#assign serviceAbbreviation = (metadata.serviceAbbreviation)!metadata.serviceFullName/>
package ${metadata.packageName};
import org.w3c.dom.*;
<#if metadata.hasApiWithStreamInput>
import java.io.*;
#if>
import java.net.*;
import java.util.*;
import java.util.Map.Entry;
import javax.annotation.Generated;
import org.apache.commons.logging.*;
import com.amazonaws.*;
import com.amazonaws.annotation.SdkInternalApi;
import com.amazonaws.auth.*;
import com.amazonaws.auth.presign.PresignerParams;
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 ${metadata.packageName}.${metadata.syncClientBuilderClassName};
<#if hasWaiters>
import ${metadata.packageName}.waiters.${metadata.syncInterface}Waiters;
#if>
<#if customizationConfig.serviceClientHoldInputStream>
import com.amazonaws.util.ServiceClientHolderInputStream;
#if>
import ${serviceBaseExceptionFqcn};
import ${metadata.packageName}.model.*;
import ${transformPackage}.*;
<#assign documentation = (metadata.documentation)!""/>
/**
* Client for accessing ${serviceAbbreviation}. All service calls made
* using this client are blocking, and will not return until the service call
* completes.
*
* ${documentation}
*/
@ThreadSafe
@Generated("com.amazonaws:aws-java-sdk-code-generator")
public class ${metadata.syncClient} extends AmazonWebServiceClient implements ${metadata.syncInterface} {
<#if customizationConfig.requestMetrics?has_content>
// register the service specific set of predefined metrics
static {
AwsSdkMetrics.addAll(Arrays.asList(${customizationConfig.requestMetrics}.values()));
}
#if>
/** Provider for AWS credentials. */
private final AWSCredentialsProvider awsCredentialsProvider;
private static final Log log = LogFactory.getLog(${metadata.syncInterface}.class);
/** Default signing name for the service. */
private static final String DEFAULT_SIGNING_NAME = "${metadata.signingName}";
<#if hasWaiters>
private volatile ${metadata.syncInterface}Waiters waiters;
#if>
/** Client configuration factory providing ClientConfigurations tailored to this client */
protected static final ${clientConfigFactory} configFactory = new ${clientConfigFactory}();
<@AdditionalSyncClientFieldsMacro.content .data_model />
<#if customizationConfig.emitClientConstructors()>
/**
* Constructs a new client to invoke service methods on
* ${serviceAbbreviation}. A credentials provider chain will be used
* that searches for credentials in this order:
*
* - Environment Variables - AWS_ACCESS_KEY_ID and AWS_SECRET_KEY
* - Java System Properties - aws.accessKeyId and aws.secretKey
* - Instance profile credentials delivered through the Amazon EC2 metadata service
*
*
*
* 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 ${metadata.syncClientBuilderClassName}#defaultClient()}
*/
@Deprecated
public ${metadata.syncClient}() {
this(DefaultAWSCredentialsProviderChain.getInstance(), configFactory.getConfig());
}
/**
* Constructs a new client to invoke service methods on
* ${serviceAbbreviation}. A credentials provider chain will be used
* that searches for credentials in this order:
*
* - Environment Variables - AWS_ACCESS_KEY_ID and AWS_SECRET_KEY
* - Java System Properties - aws.accessKeyId and aws.secretKey
* - Instance profile credentials delivered through the Amazon EC2 metadata service
*
*
*
* 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 ${serviceAbbreviation}
* (ex: proxy settings, retry counts, etc.).
*
* @see DefaultAWSCredentialsProviderChain
* @deprecated use {@link ${metadata.syncClientBuilderClassName}#withClientConfiguration(ClientConfiguration)}
*/
@Deprecated
public ${metadata.syncClient}(ClientConfiguration clientConfiguration) {
this(DefaultAWSCredentialsProviderChain.getInstance(), clientConfiguration);
}
/**
* Constructs a new client to invoke service methods on
* ${serviceAbbreviation} using the specified AWS account credentials.
*
*
* 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 ${metadata.syncClientBuilderClassName}#withCredentials(AWSCredentialsProvider)} for example:
* {@code ${metadata.syncClientBuilderClassName}.standard().withCredentials(new AWSStaticCredentialsProvider(awsCredentials)).build();}
*/
@Deprecated
public ${metadata.syncClient}(AWSCredentials awsCredentials) {
this(awsCredentials, configFactory.getConfig());
}
/**
* Constructs a new client to invoke service methods on
* ${serviceAbbreviation} using the specified AWS account credentials
* and client configuration options.
*
*
* 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 ${serviceAbbreviation}
* (ex: proxy settings, retry counts, etc.).
* @deprecated use {@link ${metadata.syncClientBuilderClassName}#withCredentials(AWSCredentialsProvider)} and
* {@link ${metadata.syncClientBuilderClassName}#withClientConfiguration(ClientConfiguration)}
*/
@Deprecated
public ${metadata.syncClient}(AWSCredentials awsCredentials, ClientConfiguration clientConfiguration) {
super(clientConfiguration);
this.awsCredentialsProvider = new StaticCredentialsProvider(awsCredentials);
init();
}
/**
* Constructs a new client to invoke service methods on
* ${serviceAbbreviation} using the specified AWS account credentials provider.
*
*
* 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 ${metadata.syncClientBuilderClassName}#withCredentials(AWSCredentialsProvider)}
*/
@Deprecated
public ${metadata.syncClient}(AWSCredentialsProvider awsCredentialsProvider) {
this(awsCredentialsProvider, configFactory.getConfig());
}
/**
* Constructs a new client to invoke service methods on
* ${serviceAbbreviation} using the specified AWS account credentials
* provider and client configuration options.
*
*
* 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 ${serviceAbbreviation}
* (ex: proxy settings, retry counts, etc.).
* @deprecated use {@link ${metadata.syncClientBuilderClassName}#withCredentials(AWSCredentialsProvider)} and
* {@link ${metadata.syncClientBuilderClassName}#withClientConfiguration(ClientConfiguration)}
*/
@Deprecated
public ${metadata.syncClient}(AWSCredentialsProvider awsCredentialsProvider, ClientConfiguration clientConfiguration) {
this(awsCredentialsProvider, clientConfiguration, null);
}
/**
* Constructs a new client to invoke service methods on
* ${serviceAbbreviation} using the specified AWS account credentials
* provider, client configuration options, and request metric collector.
*
*
* 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 ${serviceAbbreviation}
* (ex: proxy settings, retry counts, etc.).
* @param requestMetricCollector optional request metric collector
* @deprecated use {@link ${metadata.syncClientBuilderClassName}#withCredentials(AWSCredentialsProvider)} and
* {@link ${metadata.syncClientBuilderClassName}#withClientConfiguration(ClientConfiguration)} and
* {@link ${metadata.syncClientBuilderClassName}#withMetricsCollector(RequestMetricCollector)}
*/
@Deprecated
public ${metadata.syncClient}(AWSCredentialsProvider awsCredentialsProvider,
ClientConfiguration clientConfiguration,
RequestMetricCollector requestMetricCollector) {
super(clientConfiguration, requestMetricCollector);
this.awsCredentialsProvider = awsCredentialsProvider;
init();
}
#if>
public static ${metadata.syncClientBuilderClassName} builder() {
return ${metadata.syncClientBuilderClassName}.standard();
}
/**
* Constructs a new client to invoke service methods on
* ${serviceAbbreviation} using the specified parameters.
*
*
* 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.
*/
${metadata.syncClient}(AwsSyncClientParams clientParams) {
super(clientParams);
this.awsCredentialsProvider = clientParams.getCredentialsProvider();
init();
}
<@ClientInitMethodMacro.content .data_model />
<#list operations?values as operationModel>
<@ClientMethodForOperation.content metadata operationModel/>
<@ClientMethodForOperationWithSimpleForm.content operationModel />
#list>
<#if AdditionalClientMethodsMacro?has_content>
<@AdditionalClientMethodsMacro.content .data_model />
#if>
<#assign responseMetadataClassName=customizationConfig.customResponseMetadataClassName!"ResponseMetadata" />
/**
* 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.
*
* 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 ${responseMetadataClassName} getCachedResponseMetadata(AmazonWebServiceRequest request) {
<#if customizationConfig.customResponseMetadataClassName?has_content>
ResponseMetadata metadata = client.getResponseMetadataForRequest(request);
if (metadata != null)
return new ${responseMetadataClassName}(metadata);
else
return null;
<#else>
return client.getResponseMetadataForRequest(request);
#if>
}
<#if customizationConfig.customSignerProvider?has_content>
@Override
protected final SignerProvider createSignerProvider(Signer signer) {
return new ${customizationConfig.customSignerProvider}(this, signer);
}
#if>
<#if customizationConfig.calculateCRC32FromCompressedData>
@Override
protected final boolean calculateCRC32FromCompressedData() {
return true;
}
#if>
/**
* Normal invoke with authentication. Credentials are required and may be overriden at the
* request level.
**/
private Response invoke(Request request,
HttpResponseHandler> responseHandler,
ExecutionContext executionContext) {
executionContext.setCredentialsProvider(CredentialUtils.getCredentialsProvider
(request.getOriginalRequest(), awsCredentialsProvider));
return doInvoke(request, responseHandler, executionContext);
}
/**
* Invoke with no authentication. Credentials are not required and any credentials set on the
* client or request will be ignored for this operation.
**/
private Response anonymousInvoke(Request request,
HttpResponseHandler> responseHandler,
ExecutionContext executionContext) {
return doInvoke(request, responseHandler, executionContext);
}
/**
* Invoke the request using the http client. Assumes credentials (or lack thereof) have been
* configured in the ExecutionContext beforehand.
**/
private Response doInvoke(Request request,
HttpResponseHandler> responseHandler,
ExecutionContext executionContext) {
request.setEndpoint(endpoint);
request.setTimeOffset(timeOffset);
<@ClientInvokeMethodErrorResponseHandlerCreation.content metadata customizationConfig />
return client.execute(request, responseHandler,
errorResponseHandler, executionContext);
}
<#if hasWaiters>
@Override
public ${metadata.syncInterface}Waiters waiters(){
if(waiters == null) {
synchronized (this) {
if(waiters == null) {
waiters = new ${metadata.syncInterface}Waiters(this);
}
}
}
return waiters;
}
@Override
public void shutdown() {
super.shutdown();
if (waiters != null) {
waiters.shutdown();
}
}
#if>
<#if customizationConfig.presignersFqcn??>
@Override
public ${customizationConfig.presignersFqcn} presigners() {
return new ${customizationConfig.presignersFqcn}(PresignerParams.builder()
.endpoint(endpoint)
.credentialsProvider(awsCredentialsProvider)
.signerProvider(getSignerProvider())
.build());
}
#if>
}