List of usage examples for com.amazonaws.services.s3 AmazonS3 setEndpoint
public void setEndpoint(String endpoint);
Overrides the default endpoint for this client.
From source file:cloudExplorer.Versioning.java
License:Open Source License
void getVersions(String key, String access_key, String secret_key, String bucket, String endpoint) { String results = null;// ww w .jav a 2 s. com Boolean check_finished = false; try { mainFrame.jTextArea1.append("\nPlease wait, loading versions."); mainFrame.calibrateTextArea(); AWSCredentials credentials = new BasicAWSCredentials(access_key, secret_key); AmazonS3 s3Client = new AmazonS3Client(credentials, new ClientConfiguration().withSignerOverride("S3SignerType")); s3Client.setEndpoint(endpoint); VersionListing vListing; if (key == null) { vListing = s3Client.listVersions(bucket, null); } else { vListing = s3Client.listVersions(bucket, key); } List<S3VersionSummary> summary = vListing.getVersionSummaries(); if (summary.size() == 0) { check_finished = true; } else { check_finished = false; } for (S3VersionSummary object : summary) { if (!Versioning.delete) { mainFrame.versioning_date.add(object.getLastModified().toString()); } mainFrame.versioning_id.add(object.getVersionId()); mainFrame.versioning_name.add(object.getKey()); System.gc(); } if (Versioning.delete) { int i = 0; for (String delVer : mainFrame.versioning_name) { del = new Delete(delVer, mainFrame.cred.getAccess_key(), mainFrame.cred.getSecret_key(), mainFrame.cred.getBucket(), mainFrame.cred.getEndpoint(), mainFrame.versioning_id.get(i)); del.startc(delVer, mainFrame.cred.getAccess_key(), mainFrame.cred.getSecret_key(), mainFrame.cred.getBucket(), mainFrame.cred.getEndpoint(), mainFrame.versioning_id.get(i)); i++; } if (!check_finished) { getVersions(key, access_key, secret_key, bucket, endpoint); } } if (Versioning.delete) { mainFrame.jTextArea1.append( "\nCompleted deleting every object. Please observe this window for any tasks that are still running."); } else { mainFrame.jTextArea1 .append("\nDone gathering Versions. If files are found, the first 1000 will be displayed."); } mainFrame.calibrateTextArea(); } catch (Exception getVersions) { } if (Versioning.delete) { Versioning.delete = false; mainFrame.reloadObjects(false); } }
From source file:com.atlassian.localstack.sample.S3Sample.java
License:Open Source License
public static void runTest(AWSCredentials credentials) throws IOException { AmazonS3 s3 = new AmazonS3Client(credentials); Region usWest2 = Region.getRegion(Regions.US_WEST_2); s3.setRegion(usWest2);/*from w w w . j a v a 2s . com*/ s3.setEndpoint(LocalstackTestRunner.getEndpointS3()); String bucketName = "my-first-s3-bucket-" + UUID.randomUUID(); String key = "MyObjectKey"; System.out.println("==========================================="); System.out.println("Getting Started with Amazon S3"); System.out.println("===========================================\n"); /* * Create a new S3 bucket - Amazon S3 bucket names are globally unique, * so once a bucket name has been taken by any user, you can't create * another bucket with that same name. * * You can optionally specify a location for your bucket if you want to * keep your data closer to your applications or users. */ System.out.println("Creating bucket " + bucketName + "\n"); s3.createBucket(bucketName); /* * List the buckets in your account */ System.out.println("Listing buckets"); for (Bucket bucket : s3.listBuckets()) { System.out.println(" - " + bucket.getName()); } System.out.println(); /* * Upload an object to your bucket - You can easily upload a file to * S3, or upload directly an InputStream if you know the length of * the data in the stream. You can also specify your own metadata * when uploading to S3, which allows you set a variety of options * like content-type and content-encoding, plus additional metadata * specific to your applications. */ System.out.println("Uploading a new object to S3 from a file\n"); s3.putObject(new PutObjectRequest(bucketName, key, createSampleFile())); /* * Download an object - When you download an object, you get all of * the object's metadata and a stream from which to read the contents. * It's important to read the contents of the stream as quickly as * possibly since the data is streamed directly from Amazon S3 and your * network connection will remain open until you read all the data or * close the input stream. * * GetObjectRequest also supports several other options, including * conditional downloading of objects based on modification times, * ETags, and selectively downloading a range of an object. */ System.out.println("Downloading an object"); S3Object object = s3.getObject(new GetObjectRequest(bucketName, key)); System.out.println("Content-Type: " + object.getObjectMetadata().getContentType()); displayTextInputStream(object.getObjectContent()); /* * List objects in your bucket by prefix - There are many options for * listing the objects in your bucket. Keep in mind that buckets with * many objects might truncate their results when listing their objects, * so be sure to check if the returned object listing is truncated, and * use the AmazonS3.listNextBatchOfObjects(...) operation to retrieve * additional results. */ System.out.println("Listing objects"); ObjectListing objectListing = s3 .listObjects(new ListObjectsRequest().withBucketName(bucketName).withPrefix("My")); for (S3ObjectSummary objectSummary : objectListing.getObjectSummaries()) { System.out.println(" - " + objectSummary.getKey() + " " + "(size = " + objectSummary.getSize() + ")"); } System.out.println(); /* * Delete an object - Unless versioning has been turned on for your bucket, * there is no way to undelete an object, so use caution when deleting objects. */ System.out.println("Deleting an object\n"); s3.deleteObject(bucketName, key); /* * Delete a bucket - A bucket must be completely empty before it can be * deleted, so remember to delete any objects from your buckets before * you try to delete them. */ System.out.println("Deleting bucket " + bucketName + "\n"); s3.deleteBucket(bucketName); }
From source file:com.bigstep.S3Sampler.java
License:Apache License
@Override public SampleResult runTest(JavaSamplerContext context) { // pull parameters String bucket = context.getParameter("bucket"); String object = context.getParameter("object"); String method = context.getParameter("method"); String local_file_path = context.getParameter("local_file_path"); String key_id = context.getParameter("key_id"); String secret_key = context.getParameter("secret_key"); String proxy_host = context.getParameter("proxy_host"); String proxy_port = context.getParameter("proxy_port"); String endpoint = context.getParameter("endpoint"); log.debug("runTest:method=" + method + " local_file_path=" + local_file_path + " bucket=" + bucket + " object=" + object); SampleResult result = new SampleResult(); result.sampleStart(); // start stopwatch try {//from ww w .j a v a2 s.c om ClientConfiguration config = new ClientConfiguration(); if (proxy_host != null && !proxy_host.isEmpty()) { config.setProxyHost(proxy_host); } if (proxy_port != null && !proxy_port.isEmpty()) { config.setProxyPort(Integer.parseInt(proxy_port)); } //config.setProtocol(Protocol.HTTP); AWSCredentials credentials = new BasicAWSCredentials(key_id, secret_key); AmazonS3 s3Client = new AmazonS3Client(credentials, config); if (endpoint != null && !endpoint.isEmpty()) { s3Client.setEndpoint(endpoint); } ObjectMetadata meta = null; if (method.equals("GET")) { File file = new File(local_file_path); //meta= s3Client.getObject(new GetObjectRequest(bucket, object), file); S3Object s3object = s3Client.getObject(bucket, object); S3ObjectInputStream stream = s3object.getObjectContent(); //while(stream.skip(1024*1024)>0); stream.close(); } else if (method.equals("PUT")) { File file = new File(local_file_path); s3Client.putObject(bucket, object, file); } result.sampleEnd(); // stop stopwatch result.setSuccessful(true); if (meta != null) { result.setResponseMessage( "OK on url:" + bucket + "/" + object + ". Length=" + meta.getContentLength()); } else { result.setResponseMessage("OK on url:" + bucket + "/" + object + ".No metadata"); } result.setResponseCodeOK(); // 200 code } catch (Exception e) { result.sampleEnd(); // stop stopwatch result.setSuccessful(false); result.setResponseMessage("Exception: " + e); // get stack trace as a String to return as document data java.io.StringWriter stringWriter = new java.io.StringWriter(); e.printStackTrace(new java.io.PrintWriter(stringWriter)); result.setResponseData(stringWriter.toString()); result.setDataType(org.apache.jmeter.samplers.SampleResult.TEXT); result.setResponseCode("500"); } return result; }
From source file:com.clicktravel.infrastructure.runtime.config.aws.AwsConfiguration.java
License:Apache License
@Bean @Autowired/* w w w.j ava 2 s. c om*/ public AmazonS3 amazonS3Client(final AWSCredentials awsCredentials, @Value("${aws.s3.client.endpoint}") final String endpoint) { final AmazonS3 amazonS3Client = new AmazonS3Client(awsCredentials); logger.info("Setting AWS S3 endpoint to: " + endpoint); amazonS3Client.setEndpoint(endpoint); return amazonS3Client; }
From source file:com.jktsoftware.amazondownloader.download.S3TypeBucket.java
License:Open Source License
public List<IObject> getObjectsInRepo() { String repoid = getRepoId();/* w ww . j a v a 2s . c o m*/ AWSCredentials awscredentials = new BasicAWSCredentials(this.credentials.getAccessKey(), this.credentials.getSecretAccessKey()); AmazonS3 s3 = new AmazonS3Client(awscredentials); s3.setEndpoint(endpoint); System.out.println("Getting objects"); ObjectListing objectListing = s3.listObjects(repoid); List<IObject> objects = new ArrayList<IObject>(); for (S3ObjectSummary objectSummary : objectListing.getObjectSummaries()) { S3TypeObject obj = new S3TypeObject(objectSummary.getKey(), objectSummary.getSize(), objectSummary.getBucketName(), objectSummary.getStorageClass(), s3); objects.add(obj); } return objects; }
From source file:com.pinterest.secor.uploader.S3UploadManager.java
License:Apache License
public S3UploadManager(SecorConfig config) { super(config); final String accessKey = mConfig.getAwsAccessKey(); final String secretKey = mConfig.getAwsSecretKey(); final String endpoint = mConfig.getAwsEndpoint(); final String region = mConfig.getAwsRegion(); final String awsRole = mConfig.getAwsRole(); s3Path = mConfig.getS3Path(); AmazonS3 client; AWSCredentialsProvider provider;//from w w w . j a v a2 s.com ClientConfiguration clientConfiguration = new ClientConfiguration(); boolean isHttpProxyEnabled = mConfig.getAwsProxyEnabled(); //proxy settings if (isHttpProxyEnabled) { LOG.info("Http Proxy Enabled for S3UploadManager"); String httpProxyHost = mConfig.getAwsProxyHttpHost(); int httpProxyPort = mConfig.getAwsProxyHttpPort(); clientConfiguration.setProxyHost(httpProxyHost); clientConfiguration.setProxyPort(httpProxyPort); } if (accessKey.isEmpty() || secretKey.isEmpty()) { provider = new DefaultAWSCredentialsProviderChain(); } else { provider = new AWSCredentialsProvider() { public AWSCredentials getCredentials() { return new BasicAWSCredentials(accessKey, secretKey); } public void refresh() { } }; } if (!awsRole.isEmpty()) { provider = new STSAssumeRoleSessionCredentialsProvider(provider, awsRole, "secor"); } client = new AmazonS3Client(provider, clientConfiguration); if (!endpoint.isEmpty()) { client.setEndpoint(endpoint); } else if (!region.isEmpty()) { client.setRegion(Region.getRegion(Regions.fromName(region))); } mManager = new TransferManager(client); }
From source file:com.shelfmap.simplequery.TokyoContext.java
License:Apache License
@Override public AmazonS3 createS3(AWSCredentials securityCredential) { AmazonS3 s3 = super.createS3(securityCredential); s3.setEndpoint("s3-ap-northeast-1.amazonaws.com"); return s3;//from w ww . j av a 2 s .c o m }
From source file:com.wowza.wms.plugin.s3upload.ModuleS3Upload.java
License:Open Source License
public void onAppStart(IApplicationInstance appInstance) { logger = WMSLoggerFactory.getLoggerObj(appInstance); this.appInstance = appInstance; try {/*from w w w.ja v a 2s.c om*/ WMSProperties props = appInstance.getProperties(); accessKey = props.getPropertyStr("s3UploadAccessKey", accessKey); secretKey = props.getPropertyStr("s3UploadSecretKey", secretKey); bucketName = props.getPropertyStr("s3UploadBucketName", bucketName); endpoint = props.getPropertyStr("s3UploadEndpoint", endpoint); resumeUploads = props.getPropertyBoolean("s3UploadResumeUploads", resumeUploads); deleteOriginalFiles = props.getPropertyBoolean("s3UploadDeletOriginalFiles", deleteOriginalFiles); // fix typo in property name deleteOriginalFiles = props.getPropertyBoolean("s3UploadDeleteOriginalFiles", deleteOriginalFiles); // This value should be the URI representation of the "Group Grantee" found here http://docs.aws.amazon.com/AmazonS3/latest/dev/acl-overview.html under "Amazon S3 Predefined Groups" aclGroupGranteeUri = props.getPropertyStr("s3UploadACLGroupGranteeUri", aclGroupGranteeUri); // This should be a string that represents the level of permissions we want to grant to the "Group Grantee" access to the file to be uploaded aclPermissionRule = props.getPropertyStr("s3UploadACLPermissionRule", aclPermissionRule); // With the passed property, check if it maps to a specified GroupGrantee GroupGrantee grantee = GroupGrantee.parseGroupGrantee(aclGroupGranteeUri); // In order for the parsing to work correctly, we will go ahead and force uppercase on the string passed Permission permission = Permission.parsePermission(aclPermissionRule.toUpperCase()); // If we have properties for specifying permisions on the file upload, create the AccessControlList object and set the Grantee and Permissions if (grantee != null && permission != null) { acl = new AccessControlList(); acl.grantPermission(grantee, permission); } if (StringUtils.isEmpty(accessKey) || StringUtils.isEmpty(secretKey)) { logger.warn( MODULE_NAME + ".onAppStart: [" + appInstance.getContextStr() + "] missing S3 credentials", WMSLoggerIDs.CAT_application, WMSLoggerIDs.EVT_comment); return; } AmazonS3 s3Client = new AmazonS3Client(new BasicAWSCredentials(accessKey, secretKey)); if (!StringUtils.isEmpty(endpoint)) s3Client.setEndpoint(endpoint); if (!StringUtils.isEmpty(bucketName)) { boolean hasBucket = false; List<Bucket> buckets = s3Client.listBuckets(); for (Bucket bucket : buckets) { if (bucket.getName().equals(bucketName)) { hasBucket = true; break; } } if (!hasBucket) { logger.warn(MODULE_NAME + ".onAppStart: [" + appInstance.getContextStr() + "] missing S3 bucket: " + bucketName, WMSLoggerIDs.CAT_application, WMSLoggerIDs.EVT_comment); return; } } logger.info(MODULE_NAME + ".onAppStart [" + appInstance.getContextStr() + "] S3 Bucket Name: " + bucketName + ", Resume Uploads: " + resumeUploads + ", Delete Original Files: " + deleteOriginalFiles, WMSLoggerIDs.CAT_application, WMSLoggerIDs.EVT_comment); transferManager = new TransferManager(s3Client); resumeUploads(); appInstance.addMediaWriterListener(new WriteListener()); } catch (AmazonS3Exception ase) { logger.error(MODULE_NAME + ".onAppStart [" + appInstance.getContextStr() + "] AmazonS3Exception: " + ase.getMessage()); } catch (Exception e) { logger.error( MODULE_NAME + ".onAppStart [" + appInstance.getContextStr() + "] exception: " + e.getMessage(), e); } catch (Throwable t) { logger.error(MODULE_NAME + ".onAppStart [" + appInstance.getContextStr() + "] throwable exception: " + t.getMessage(), t); } }
From source file:edu.sjsu.cmpe.dropbox.api.resources.S3TransferProgress.java
License:Open Source License
public S3TransferProgress(String Name, AmazonS3 s3Client, MongoTest mongo) { frame = new JFrame("Amazon S3 File Upload"); button = new JButton("Choose File..."); button.addActionListener(new ButtonListener()); this.mongo = mongo; System.out.println("Mongo is" + mongo); System.out.println("this.Mongo is" + this.mongo); pb = new JProgressBar(0, 100); pb.setStringPainted(true);// ww w. j a va 2s. c o m frame.setContentPane(createContentPane()); frame.pack(); frame.setVisible(true); s3Client.setEndpoint("http://s3-us-west-1.amazonaws.com"); tx = new TransferManager(s3Client); bucketName = Name; System.out.print("Bucket is" + bucketName); System.out.print("Bucket1 is" + Name); }
From source file:io.dockstore.common.FileProvisioning.java
License:Apache License
private static AmazonS3 getAmazonS3Client(HierarchicalINIConfiguration config) { AmazonS3 s3Client = new AmazonS3Client(new ClientConfiguration().withSignerOverride("S3Signer")); if (config.containsKey(S3_ENDPOINT)) { final String endpoint = config.getString(S3_ENDPOINT); LOG.info("found custom S3 endpoint, setting to {}", endpoint); s3Client.setEndpoint(endpoint); s3Client.setS3ClientOptions(new S3ClientOptions().withPathStyleAccess(true)); }/*from w ww . j av a 2s .c om*/ return s3Client; }