List of usage examples for com.amazonaws.services.s3 S3ClientOptions S3ClientOptions
@Deprecated
public S3ClientOptions()
From source file:UploadUrlGenerator.java
License:Open Source License
public static void main(String[] args) throws Exception { Options opts = new Options(); opts.addOption(Option.builder().longOpt(ENDPOINT_OPTION).required().hasArg().argName("url") .desc("Sets the ECS S3 endpoint to use, e.g. https://ecs.company.com:9021").build()); opts.addOption(Option.builder().longOpt(ACCESS_KEY_OPTION).required().hasArg().argName("access-key") .desc("Sets the Access Key (user) to sign the request").build()); opts.addOption(Option.builder().longOpt(SECRET_KEY_OPTION).required().hasArg().argName("secret") .desc("Sets the secret key to sign the request").build()); opts.addOption(Option.builder().longOpt(BUCKET_OPTION).required().hasArg().argName("bucket-name") .desc("The bucket containing the object").build()); opts.addOption(Option.builder().longOpt(KEY_OPTION).required().hasArg().argName("object-key") .desc("The object name (key) to access with the URL").build()); opts.addOption(Option.builder().longOpt(EXPIRES_OPTION).hasArg().argName("minutes") .desc("Minutes from local time to expire the request. 1 day = 1440, 1 week=10080, " + "1 month (30 days)=43200, 1 year=525600. Defaults to 1 hour (60).") .build());// w w w. j a v a2 s .co m opts.addOption(Option.builder().longOpt(VERB_OPTION).hasArg().argName("http-verb").type(HttpMethod.class) .desc("The HTTP verb that will be used with the URL (PUT, GET, etc). Defaults to GET.").build()); opts.addOption(Option.builder().longOpt(CONTENT_TYPE_OPTION).hasArg().argName("mimetype") .desc("Sets the Content-Type header (e.g. image/jpeg) that will be used with the request. " + "Must match exactly. Defaults to application/octet-stream for PUT/POST and " + "null for all others") .build()); DefaultParser dp = new DefaultParser(); CommandLine cmd = null; try { cmd = dp.parse(opts, args); } catch (ParseException e) { System.err.println("Error: " + e.getMessage()); HelpFormatter hf = new HelpFormatter(); hf.printHelp("java -jar UploadUrlGenerator-xxx.jar", opts, true); System.exit(255); } URI endpoint = URI.create(cmd.getOptionValue(ENDPOINT_OPTION)); String accessKey = cmd.getOptionValue(ACCESS_KEY_OPTION); String secretKey = cmd.getOptionValue(SECRET_KEY_OPTION); String bucket = cmd.getOptionValue(BUCKET_OPTION); String key = cmd.getOptionValue(KEY_OPTION); HttpMethod method = HttpMethod.GET; if (cmd.hasOption(VERB_OPTION)) { method = HttpMethod.valueOf(cmd.getOptionValue(VERB_OPTION).toUpperCase()); } int expiresMinutes = 60; if (cmd.hasOption(EXPIRES_OPTION)) { expiresMinutes = Integer.parseInt(cmd.getOptionValue(EXPIRES_OPTION)); } String contentType = null; if (method == HttpMethod.PUT || method == HttpMethod.POST) { contentType = "application/octet-stream"; } if (cmd.hasOption(CONTENT_TYPE_OPTION)) { contentType = cmd.getOptionValue(CONTENT_TYPE_OPTION); } BasicAWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey); ClientConfiguration cc = new ClientConfiguration(); // Force use of v2 Signer. ECS does not support v4 signatures yet. cc.setSignerOverride("S3SignerType"); AmazonS3Client s3 = new AmazonS3Client(credentials, cc); s3.setEndpoint(endpoint.toString()); S3ClientOptions s3c = new S3ClientOptions(); s3c.setPathStyleAccess(true); s3.setS3ClientOptions(s3c); // Sign the URL Calendar c = Calendar.getInstance(); c.add(Calendar.MINUTE, expiresMinutes); GeneratePresignedUrlRequest req = new GeneratePresignedUrlRequest(bucket, key).withExpiration(c.getTime()) .withMethod(method); if (contentType != null) { req = req.withContentType(contentType); } URL u = s3.generatePresignedUrl(req); System.out.printf("URL: %s\n", u.toURI().toASCIIString()); System.out.printf("HTTP Verb: %s\n", method); System.out.printf("Expires: %s\n", c.getTime()); System.out.println("To Upload with curl:"); StringBuilder sb = new StringBuilder(); sb.append("curl "); if (method != HttpMethod.GET) { sb.append("-X "); sb.append(method.toString()); sb.append(" "); } if (contentType != null) { sb.append("-H \"Content-Type: "); sb.append(contentType); sb.append("\" "); } if (method == HttpMethod.POST || method == HttpMethod.PUT) { sb.append("-T <filename> "); } sb.append("\""); sb.append(u.toURI().toASCIIString()); sb.append("\""); System.out.println(sb.toString()); System.exit(0); }
From source file:br.com.semanticwot.cd.conf.AmazonConfiguration.java
@Bean @Profile("dev")/* w ww . jav a2 s . c o m*/ public AmazonS3Client s3Ninja() { AWSCredentials credentials = new BasicAWSCredentials("AKIAIOSFODNN7EXAMPLE", "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"); AmazonS3Client newClient = new AmazonS3Client(credentials, new ClientConfiguration()); newClient.setS3ClientOptions(new S3ClientOptions().withPathStyleAccess(true)); newClient.setEndpoint("http://localhost:9444/s3"); return newClient; }
From source file:br.com.semanticwot.cd.conf.AmazonConfiguration.java
@Bean @Profile("prod")/* w w w. ja v a 2 s . c o m*/ public AmazonS3Client s3Amazon() { AWSCredentials credentials = new BasicAWSCredentials("AKIAIOSFODNN7EXAMPLE", "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"); AmazonS3Client newClient = new AmazonS3Client(credentials, new ClientConfiguration()); newClient.setS3ClientOptions(new S3ClientOptions().withPathStyleAccess(true)); return newClient; }
From source file:com.emc.ecs.sync.source.S3Source.java
License:Open Source License
@Override public void configure(SyncSource source, Iterator<SyncFilter> filters, SyncTarget target) { Assert.hasText(accessKey, "accessKey is required"); Assert.hasText(secretKey, "secretKey is required"); Assert.hasText(bucketName, "bucketName is required"); Assert.isTrue(bucketName.matches("[A-Za-z0-9._-]+"), bucketName + " is not a valid bucket name"); AWSCredentials creds = new BasicAWSCredentials(accessKey, secretKey); ClientConfiguration config = new ClientConfiguration(); if (protocol != null) config.setProtocol(Protocol.valueOf(protocol.toUpperCase())); if (legacySignatures) config.setSignerOverride("S3SignerType"); if (socketTimeoutMs >= 0) config.setSocketTimeout(socketTimeoutMs); s3 = new AmazonS3Client(creds, config); if (endpoint != null) s3.setEndpoint(endpoint);//from w w w.java 2 s . c o m // TODO: generalize uri translation AwsS3Util.S3Uri s3Uri = new AwsS3Util.S3Uri(); s3Uri.protocol = protocol; s3Uri.endpoint = endpoint; s3Uri.accessKey = accessKey; s3Uri.secretKey = secretKey; s3Uri.rootKey = rootKey; if (sourceUri == null) sourceUri = s3Uri.toUri(); if (disableVHosts) { log.info( "The use of virtual hosted buckets on the s3 source has been DISABLED. Path style buckets will be used."); S3ClientOptions opts = new S3ClientOptions(); opts.setPathStyleAccess(true); s3.setS3ClientOptions(opts); } if (!s3.doesBucketExist(bucketName)) { throw new ConfigurationException("The bucket " + bucketName + " does not exist."); } if (rootKey == null) rootKey = ""; // make sure rootKey isn't null // for version support. TODO: genericize version support if (target instanceof S3Target) { s3Target = (S3Target) target; if (s3Target.isIncludeVersions()) { BucketVersioningConfiguration versioningConfig = s3.getBucketVersioningConfiguration(bucketName); List<String> versionedStates = Arrays.asList(BucketVersioningConfiguration.ENABLED, BucketVersioningConfiguration.SUSPENDED); versioningEnabled = versionedStates.contains(versioningConfig.getStatus()); } } }
From source file:com.emc.ecs.sync.target.S3Target.java
License:Open Source License
@Override public void configure(SyncSource source, Iterator<SyncFilter> filters, SyncTarget target) { Assert.hasText(accessKey, "accessKey is required"); Assert.hasText(secretKey, "secretKey is required"); Assert.hasText(bucketName, "bucketName is required"); Assert.isTrue(bucketName.matches("[A-Za-z0-9._-]+"), bucketName + " is not a valid bucket name"); AWSCredentials creds = new BasicAWSCredentials(accessKey, secretKey); ClientConfiguration config = new ClientConfiguration(); if (protocol != null) config.setProtocol(Protocol.valueOf(protocol.toUpperCase())); if (legacySignatures) config.setSignerOverride("S3SignerType"); if (socketTimeoutMs >= 0) config.setSocketTimeout(socketTimeoutMs); s3 = new AmazonS3Client(creds, config); if (endpoint != null) s3.setEndpoint(endpoint);/*from w w w .java 2 s . c om*/ // TODO: generalize uri translation AwsS3Util.S3Uri s3Uri = new AwsS3Util.S3Uri(); s3Uri.protocol = protocol; s3Uri.endpoint = endpoint; s3Uri.accessKey = accessKey; s3Uri.secretKey = secretKey; s3Uri.rootKey = rootKey; if (targetUri == null) targetUri = s3Uri.toUri(); if (disableVHosts) { log.info( "The use of virtual hosted buckets on the s3 source has been DISABLED. Path style buckets will be used."); S3ClientOptions opts = new S3ClientOptions(); opts.setPathStyleAccess(true); s3.setS3ClientOptions(opts); } // for version support. TODO: genericize version support if (source instanceof S3Source) { s3Source = (S3Source) source; if (!s3Source.isVersioningEnabled()) includeVersions = false; // don't include versions if source versioning is off } else if (includeVersions) { throw new ConfigurationException( "Object versions are currently only supported with the S3 source & target plugins."); } if (!s3.doesBucketExist(bucketName)) { if (createBucket) { s3.createBucket(bucketName); if (includeVersions) s3.setBucketVersioningConfiguration(new SetBucketVersioningConfigurationRequest(bucketName, new BucketVersioningConfiguration(BucketVersioningConfiguration.ENABLED))); } else { throw new ConfigurationException("The bucket " + bucketName + " does not exist."); } } if (rootKey == null) rootKey = ""; // make sure rootKey isn't null if (includeVersions) { String status = s3.getBucketVersioningConfiguration(bucketName).getStatus(); if (BucketVersioningConfiguration.OFF.equals(status)) throw new ConfigurationException("The specified bucket does not have versioning enabled."); } if (mpuThresholdMB > AwsS3Util.MAX_PUT_SIZE_MB) { log.warn("{}MB is above the maximum PUT size of {}MB. the maximum will be used instead", mpuThresholdMB, AwsS3Util.MAX_PUT_SIZE_MB); mpuThresholdMB = AwsS3Util.MAX_PUT_SIZE_MB; } if (mpuPartSizeMB < AwsS3Util.MIN_PART_SIZE_MB) { log.warn("{}MB is below the minimum MPU part size of {}MB. the minimum will be used instead", mpuPartSizeMB, AwsS3Util.MIN_PART_SIZE_MB); mpuPartSizeMB = AwsS3Util.MIN_PART_SIZE_MB; } }
From source file:com.emc.vipr.s3.s3api.java
License:Open Source License
public static ViPRS3Client getS3Client(String S3_ACCESS_KEY_ID, String S3_SECRET_KEY, String S3_ENDPOINT, String S3_ViPR_NAMESPACE) { BasicAWSCredentials creds = new BasicAWSCredentials(S3_ACCESS_KEY_ID, S3_SECRET_KEY); S3ClientOptions opt = new S3ClientOptions(); opt.setPathStyleAccess(true);/*from w w w. j ava2 s.c om*/ ViPRS3Client client = new ViPRS3Client(S3_ENDPOINT, creds); client.setS3ClientOptions(opt); if (S3_ViPR_NAMESPACE != null) { client.setNamespace(S3_ViPR_NAMESPACE); } return client; }
From source file:com.emc.vipr.services.s3.ViPRS3Client.java
License:Open Source License
/** * Constructs a client with all options specified in a ViPRS3Config instance. Use this constructor to enable the * smart client. Older constructors cannot differentiate between load balancing and virtual hosting (which is not * supported by the smart client), so this constructor is required for the smart client. * * Note that when the smart client is enabled, you *cannot* use DNS (virtual host) style buckets or namespaces. * Because of the nature of client-side load balancing, you must use path/header style requests. *//*from w w w. j a v a2 s.co m*/ public ViPRS3Client(ViPRS3Config viprConfig) { super(viprConfig.getCredentialsProvider(), viprConfig.getClientConfiguration()); this.client = new ViPRS3HttpClient(viprConfig); setEndpoint(viprConfig.getProtocol() + "://" + viprConfig.getVipHost()); // enable path-style requests (cannot use DNS with client-side load balancing) S3ClientOptions options = new S3ClientOptions(); options.setPathStyleAccess(true); setS3ClientOptions(options); }
From source file:com.emc.vipr.sync.source.S3Source.java
License:Open Source License
@Override public void configure(SyncSource source, Iterator<SyncFilter> filters, SyncTarget target) { Assert.hasText(accessKey, "accessKey is required"); Assert.hasText(secretKey, "secretKey is required"); Assert.hasText(bucketName, "bucketName is required"); AWSCredentials creds = new BasicAWSCredentials(accessKey, secretKey); ClientConfiguration config = new ClientConfiguration(); if (protocol != null) config.setProtocol(Protocol.valueOf(protocol.toUpperCase())); s3 = new AmazonS3Client(creds, config); if (endpoint != null) s3.setEndpoint(endpoint);/*from ww w .j a v a 2 s . c o m*/ if (disableVHosts) { l4j.info( "The use of virtual hosted buckets on the s3 source has been DISABLED. Path style buckets will be used."); S3ClientOptions opts = new S3ClientOptions(); opts.setPathStyleAccess(true); s3.setS3ClientOptions(opts); } if (!s3.doesBucketExist(bucketName)) { throw new ConfigurationException("The bucket " + bucketName + " does not exist."); } if (rootKey == null) rootKey = ""; // make sure rootKey isn't null if (rootKey.startsWith("/")) rootKey = rootKey.substring(1); // " " does not start with slash }
From source file:com.eucalyptus.objectstorage.client.GenericS3ClientFactory.java
License:Open Source License
public static S3ClientOptions getDefaultClientOptions() { S3ClientOptions ops = new S3ClientOptions(); ops.setPathStyleAccess(true); return ops; }
From source file:com.eucalyptus.objectstorage.client.OsgInternalS3Client.java
License:Open Source License
private synchronized void initializeNewClient(@Nonnull AWSCredentials credentials, @Nonnull String endpoint, @Nonnull Boolean https, @Nonnull Boolean useDns) { ClientConfiguration config = new ClientConfiguration(); config.setConnectionTimeout(CONNECTION_TIMEOUT_MS); //very short timeout config.setSocketTimeout(OSG_SOCKET_TIMEOUT_MS); config.setUseReaper(true);/*from w ww.j a va2s .c o m*/ config.setMaxConnections(OSG_MAX_CONNECTIONS); Protocol protocol = https ? Protocol.HTTPS : Protocol.HTTP; config.setProtocol(protocol); this.clientConfig = config; this.s3Client = new AmazonS3Client(credentials, config); this.ops = new S3ClientOptions().withPathStyleAccess(!useDns); this.s3Client.setS3ClientOptions(ops); this.instantiated = new Date(); this.currentCredentials = credentials; this.setS3Endpoint(endpoint); }