List of usage examples for com.amazonaws.services.s3.internal ServiceUtils isS3USStandardEndpoint
public static boolean isS3USStandardEndpoint(String endpoint)
From source file:org.ow2.proactive.scheduler.examples.S3ConnectorUtils.java
License:Open Source License
/** * Get or initialize the S3 client./*from w w w .j a v a2 s . c o m*/ * Note: this method must be synchronized because we're accessing the * field and we're calling this method from a worker thread. * * @return the S3 client */ protected static synchronized AmazonS3 getS3Client(String accessKey, String secretKey, String... args) { BasicAWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey); AmazonS3ClientBuilder builder = AmazonS3ClientBuilder.standard() .withCredentials(new AWSStaticCredentialsProvider(credentials)); if (args.length == 1) { builder = builder.withRegion(args[0]); } else { String endpoint = args[0] + "://" + args[1]; String clientRegion = null; if (!ServiceUtils.isS3USStandardEndpoint(endpoint) && (clientRegion = AwsHostNameUtils .parseRegion(args[1], AmazonS3Client.S3_SERVICE_NAME)) == null) { throw new IllegalArgumentException("Invalid region in " + args[1]); } builder = builder .withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(endpoint, clientRegion)); } builder = builder.withPathStyleAccessEnabled(true); return builder.build(); }