本文整理汇总了Java中com.amazonaws.AmazonWebServiceClient类的典型用法代码示例。如果您正苦于以下问题:Java AmazonWebServiceClient类的具体用法?Java AmazonWebServiceClient怎么用?Java AmazonWebServiceClient使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AmazonWebServiceClient类属于com.amazonaws包,在下文中一共展示了AmazonWebServiceClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: tryConfigureEndpointOrRegion
import com.amazonaws.AmazonWebServiceClient; //导入依赖的package包/类
/**
* Common support code: attempts to configure client endpoint and/or region.
*
* @param client A constructed writer-specific service client.
* @param endpoint A possibly-null endpoint specification.
*/
protected <T extends AmazonWebServiceClient> T tryConfigureEndpointOrRegion(T client, String endpoint)
{
// explicit endpoint takes precedence over region retrieved from environment
if (endpoint != null)
{
LogLog.debug(getClass().getSimpleName() + ": configuring endpoint: " + endpoint);
client.setEndpoint(endpoint);
return client;
}
String region = System.getenv("AWS_REGION");
if (region != null)
{
LogLog.debug(getClass().getSimpleName() + ": configuring region: " + region);
client.configureRegion(Regions.fromName(region));
return client;
}
return client;
}
示例2: initS3ClientIfEnabled
import com.amazonaws.AmazonWebServiceClient; //导入依赖的package包/类
Optional<AmazonWebServiceClient> initS3ClientIfEnabled() {
Optional<S3Configuration> s3 = Optional.empty();
if ((null != s3Bucket) && (null != s3Path)) {
S3Configuration config = new S3Configuration();
config.setBucket(s3Bucket);
config.setPath(s3Path);
config.setRegion(s3Region);
config.setAccessKey(s3AwsKey);
config.setSecretKey(s3AwsSecret);
s3 = Optional.of(config);
}
return s3.map(config ->
new AwsClientBuilder(config.getRegion(),
config.getAccessKey(),
config.getSecretKey()).build(AmazonS3Client.class));
}
示例3: testBuildWithRegion
import com.amazonaws.AmazonWebServiceClient; //导入依赖的package包/类
@Test
@SuppressWarnings("deprecation")
public void testBuildWithRegion() {
Region region = Region.getRegion(Regions.US_WEST_1);
AmazonWebServiceClient mockedS3 = createMock(AmazonWebServiceClient.class);
AwsClientBuilder builder = createPartialMock(AwsClientBuilder.class,
new String[] {"instantiateClient"}, region);
try {
expect(builder.instantiateClient(AmazonS3Client.class))
.andReturn(mockedS3);
mockedS3.setRegion(region);
expectLastCall();
replay(mockedS3, builder);
builder.build(AmazonS3Client.class);
verify(mockedS3, builder);
} catch (Exception ex) {
fail("Unexpected exception: " + ex.getMessage());
}
}
示例4: testBuildWithoutRegion
import com.amazonaws.AmazonWebServiceClient; //导入依赖的package包/类
@Test
public void testBuildWithoutRegion() {
AmazonWebServiceClient mockedS3 = createMock(AmazonWebServiceClient.class);
try {
AwsClientBuilder builder = createPartialMockAndInvokeDefaultConstructor(AwsClientBuilder.class,
"instantiateClient");
expect(builder.instantiateClient(AmazonS3Client.class))
.andReturn(mockedS3);
replay(mockedS3, builder);
builder.build(AmazonS3Client.class);
verify(mockedS3, builder);
} catch (Exception ex) {
fail("Unexpected exception: " + ex.getMessage());
}
}
示例5: init
import com.amazonaws.AmazonWebServiceClient; //导入依赖的package包/类
@PostConstruct
public void init() {
// TODO
// this parameters have to be configurable
cache = CacheBuilder.newBuilder()
.maximumSize(500)
.expireAfterAccess(50, TimeUnit.MINUTES)
.removalListener((RemovalNotification<Key<?>, AmazonWebServiceClient> notification) -> {
logger.debug("Shutting down expired client for key: {}", notification.getKey());
notification.getValue().shutdown();
}).build(new CacheLoader<Key<?>, AmazonWebServiceClient>() {
@Override
public AmazonWebServiceClient load(@Nonnull final Key<?> key) throws Exception {
logger.debug("CacheLoader active for Key : {}", key);
return key.region.createClient(
key.type,
new STSAssumeRoleSessionCredentialsProvider(
buildRoleArn(key.accountId),
ROLE_SESSION_NAME),
new ClientConfiguration().withMaxErrorRetry(MAX_ERROR_RETRY));
}
});
}
示例6: testCachingClientProvider
import com.amazonaws.AmazonWebServiceClient; //导入依赖的package包/类
@Test
public void testCachingClientProvider() throws InterruptedException {
final AmazonWebServiceClient client = provider.getClient(
AmazonEC2Client.class, "",
Region.getRegion(Regions.EU_CENTRAL_1));
Assertions.assertThat(client).isNotNull();
System.out.println(client.toString());
for (int i = 0; i < 10; i++) {
final AmazonEC2Client other = provider.getClient(
AmazonEC2Client.class, "",
Region.getRegion(Regions.EU_CENTRAL_1));
Assertions.assertThat(other).isNotNull();
Assertions.assertThat(other).isEqualTo(client);
System.out.println(other.toString());
TimeUnit.SECONDS.sleep(2);
}
}
示例7: configureServiceClient
import com.amazonaws.AmazonWebServiceClient; //导入依赖的package包/类
static void configureServiceClient(AmazonWebServiceClient client, Optional<String> endpoint, Optional<String> regionName)
{
// Configure endpoint or region. Endpoint takes precedence over region.
if (endpoint.isPresent()) {
client.setEndpoint(endpoint.get());
}
else if (regionName.isPresent()) {
Regions region;
try {
region = Regions.fromName(regionName.get());
}
catch (IllegalArgumentException e) {
throw new ConfigException("Illegal AWS region: " + regionName.get());
}
client.setRegion(Region.getRegion(region));
}
}
示例8: createClient
import com.amazonaws.AmazonWebServiceClient; //导入依赖的package包/类
private C createClient() {
Class<? extends C> clientImplType = factory.getClientImplType();
C client = ReflectionUtils.newInstance(
clientImplType, credentials, configuration);
if (client instanceof AmazonWebServiceClient) {
AmazonWebServiceClient awsc = (AmazonWebServiceClient) client;
if (region != null) {
awsc.setRegion(region);
}
if (endpoint != null) {
awsc.setEndpoint(endpoint);
}
}
return client;
}
示例9: configure
import com.amazonaws.AmazonWebServiceClient; //导入依赖的package包/类
@Override
public void configure(final Env env, final Config config, final Binder binder) {
callbacks.build().forEach(it -> {
ConfigCredentialsProvider creds = new ConfigCredentialsProvider(config);
AmazonWebServiceClient service = it.apply(creds, config);
creds.service(service.getServiceName());
Class serviceType = service.getClass();
Class[] interfaces = serviceType.getInterfaces();
if (interfaces.length > 0) {
// pick first
binder.bind(interfaces[0]).toInstance(service);
}
binder.bind(serviceType).toInstance(service);
env.onStop(new AwsShutdownSupport(service));
after(env, binder, config, service);
});
}
示例10: createClient
import com.amazonaws.AmazonWebServiceClient; //导入依赖的package包/类
static <T extends AmazonWebServiceClient> T createClient( Class<T> clientType,
Identity identity )
{
Regions r = Regions.US_EAST_1;
if ( StringUtils.isNotBlank( identity.getAwsRegionName() ) )
{
r = Regions.fromName( identity.getAwsRegionName() );
}
AWSCredentialsProvider creds =
new StaticCredentialsProvider(
new BasicAWSCredentials(
identity.getAwsAccessKeyId(),
identity.getAwsSecretKey() ) );
return Region.getRegion( r ).createClient( clientType, creds, null );
}
示例11: createClient
import com.amazonaws.AmazonWebServiceClient; //导入依赖的package包/类
/**
* Creates a new service client of the class given and configures it. If
* credentials or config are null, defaults will be used.
*
* @param serviceClass The service client class to instantiate, e.g. AmazonS3Client.class
* @param credentials The credentials provider to use, or null for the default
* credentials provider
* @param config The configuration to use, or null for the default
* configuration
* @deprecated use appropriate {@link com.amazonaws.client.builder.AwsClientBuilder} implementation
* for the service being constructed. For example:
* {@code AmazonSNSClientBuilder.standard().withRegion(region).build();}
*/
@Deprecated
public <T extends AmazonWebServiceClient> T createClient(Class<T> serviceClass,
AWSCredentialsProvider credentials,
ClientConfiguration config) {
Constructor<T> constructor;
T client;
try {
if (credentials == null && config == null) {
constructor = serviceClass.getConstructor();
client = constructor.newInstance();
} else if (credentials == null) {
constructor = serviceClass.getConstructor(ClientConfiguration.class);
client = constructor.newInstance(config);
} else if (config == null) {
constructor = serviceClass.getConstructor(AWSCredentialsProvider.class);
client = constructor.newInstance(credentials);
} else {
constructor = serviceClass.getConstructor(AWSCredentialsProvider.class, ClientConfiguration.class);
client = constructor.newInstance(credentials, config);
}
client.setRegion(this);
return client;
} catch (Exception e) {
throw new RuntimeException("Couldn't instantiate instance of " + serviceClass, e);
}
}
示例12: ExecutionContext
import com.amazonaws.AmazonWebServiceClient; //导入依赖的package包/类
@Deprecated
public ExecutionContext(List<RequestHandler2> requestHandler2s, boolean isMetricEnabled,
AmazonWebServiceClient awsClient) {
this.requestHandler2s = requestHandler2s;
awsRequestMetrics = isMetricEnabled ? new AWSRequestMetricsFullSupport() : new AWSRequestMetrics();
this.awsClient = awsClient;
this.signerProvider = new SignerProvider() {
@Override
public Signer getSigner(SignerProviderContext context) {
return getSignerByURI(context.getUri());
}
};
}
示例13: configureMutableProperties
import com.amazonaws.AmazonWebServiceClient; //导入依赖的package包/类
/**
* Region and endpoint logic is tightly coupled to the client class right now so it's easier to
* set them after client creation and let the normal logic kick in. Ideally this should resolve
* the endpoint and signer information here and just pass that information as is to the client.
*
* @param clientInterface Client to configure
*/
@SdkInternalApi
final TypeToBuild configureMutableProperties(TypeToBuild clientInterface) {
AmazonWebServiceClient client = (AmazonWebServiceClient) clientInterface;
setRegion(client);
client.makeImmutable();
return clientInterface;
}
示例14: legacyGetSignerBehavior
import com.amazonaws.AmazonWebServiceClient; //导入依赖的package包/类
@Test
public void legacyGetSignerBehavior() throws Exception {
AmazonWebServiceClient webServiceClient = mock(AmazonWebServiceClient.class);
ExecutionContext executionContext = new ExecutionContext(null, false, webServiceClient);
URI testUri = new URI("http://foo.amazon.com");
executionContext.getSigner(SignerProviderContext.builder().withUri(testUri).build());
verify(webServiceClient, times(1)).getSignerByURI(testUri);
}
示例15: AWSCucumberStepdefs
import com.amazonaws.AmazonWebServiceClient; //导入依赖的package包/类
@Inject
public AWSCucumberStepdefs(AmazonWebServiceClient client) {
this.client = client;
this.client.setRegion(RegionUtils.getRegion("us-east-1"));
Class<?> httpClientClass = Classes.childClassOf(AmazonWebServiceClient.class, this.client);
this.packageName = httpClientClass.getPackage().getName();
}