List of usage examples for com.amazonaws.services.s3 AmazonS3Client AmazonS3Client
@Deprecated
public AmazonS3Client(AWSCredentialsProvider credentialsProvider, ClientConfiguration clientConfiguration)
From source file:com.yahoo.ycsb.utils.connection.S3Connection.java
License:Open Source License
public S3Connection(String bucket, String region, String endPoint) throws ClientException { super(bucket, region, endPoint); logger.debug("S3Client.establishConnection(" + region + "," + endPoint + ") bucket: " + bucket); org.apache.log4j.Logger.getLogger("com.amazonaws").setLevel(Level.OFF); /*if (S3Connection.init == true) { init();/* w ww .j a v a 2 s .com*/ S3Connection.init = false; }*/ this.bucket = bucket; this.region = region; try { BasicAWSCredentials s3Credentials = new BasicAWSCredentials(accessKeyId, secretKey); ClientConfiguration clientConfig = new ClientConfiguration(); clientConfig.setMaxErrorRetry(Integer.parseInt(maxErrorRetry)); if (protocol.equals("HTTP")) { clientConfig.setProtocol(Protocol.HTTP); } else { clientConfig.setProtocol(Protocol.HTTPS); } if (maxConnections != null) { clientConfig.setMaxConnections(Integer.parseInt(maxConnections)); } logger.debug("Inizializing the S3 connection..."); awsClient = new AmazonS3Client(s3Credentials, clientConfig); awsClient.setRegion(Region.getRegion(Regions.fromName(region))); awsClient.setEndpoint(endPoint); logger.debug("Connection successfully initialized"); } catch (Exception e) { logger.error("Could not connect to S3 storage: " + e.toString()); e.printStackTrace(); throw new ClientException(e); } }
From source file:edu.upenn.library.fcrepo.connector.annex.S3AnnexResolverFactory.java
License:Apache License
@Override public void initialize(Properties props) { this.accessKey = props.getProperty(ACCESS_KEY_PROPNAME); this.secretKey = props.getProperty(SECRET_KEY_PROPNAME); this.bucket = props.getProperty(BUCKET_PROPNAME); AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey); ClientConfiguration clientConfig = new ClientConfiguration(); clientConfig.setProtocol(Protocol.HTTP); S3ClientOptions clientOptions = new S3ClientOptions(); clientOptions.setPathStyleAccess(true); conn = new AmazonS3Client(credentials, clientConfig); conn.setS3ClientOptions(clientOptions); conn.setEndpoint(props.getProperty(ENDPOINT_PROPNAME)); }
From source file:fi.yle.tools.aws.maven.SimpleStorageServiceWagon.java
License:Apache License
@Override protected void connectToRepository(Repository repository, AuthenticationInfo authenticationInfo, ProxyInfoProvider proxyInfoProvider) throws AuthenticationException { if (this.amazonS3 == null) { AuthenticationInfoAWSCredentialsProviderChain credentialsProvider = new AuthenticationInfoAWSCredentialsProviderChain( authenticationInfo);/*from w ww . j a v a 2s . com*/ ClientConfiguration clientConfiguration = S3Utils.getClientConfiguration(proxyInfoProvider); this.bucketName = S3Utils.getBucketName(repository); this.baseDirectory = S3Utils.getBaseDirectory(repository); if (isAssumedRoleRequested()) { this.amazonS3 = new AmazonS3Client(getAssumedCredentialsIfRequested(credentialsProvider), clientConfiguration); } else { this.amazonS3 = new AmazonS3Client(credentialsProvider, clientConfiguration); } fi.yle.tools.aws.maven.Region region = fi.yle.tools.aws.maven.Region .fromLocationConstraint(this.amazonS3.getBucketLocation(this.bucketName)); this.amazonS3.setEndpoint(region.getEndpoint()); } }
From source file:hu.mta.sztaki.lpds.cloud.entice.imageoptimizer.iaashandler.amazontarget.Storage.java
License:Apache License
/** * @param endpoint S3 endpoint URL/*from w ww . j a v a 2 s . co m*/ * @param accessKey Access key * @param secretKey Secret key * @param bucket Bucket name * @param path Key name of the object to download (path + file name) * @param file Local file to download to * @throws Exception On any error */ public static void download(String endpoint, String accessKey, String secretKey, String bucket, String path, File file) throws Exception { AmazonS3Client amazonS3Client = null; InputStream in = null; OutputStream out = null; try { AWSCredentials awsCredentials = new BasicAWSCredentials(accessKey, secretKey); ClientConfiguration clientConfiguration = new ClientConfiguration(); clientConfiguration.setMaxConnections(MAX_CONNECTIONS); clientConfiguration.setMaxErrorRetry(PredefinedRetryPolicies.DEFAULT_MAX_ERROR_RETRY); clientConfiguration.setConnectionTimeout(ClientConfiguration.DEFAULT_CONNECTION_TIMEOUT); amazonS3Client = new AmazonS3Client(awsCredentials, clientConfiguration); S3ClientOptions clientOptions = new S3ClientOptions().withPathStyleAccess(true); amazonS3Client.setS3ClientOptions(clientOptions); amazonS3Client.setEndpoint(endpoint); S3Object object = amazonS3Client.getObject(new GetObjectRequest(bucket, path)); in = object.getObjectContent(); byte[] buf = new byte[BUFFER_SIZE]; out = new FileOutputStream(file); int count; while ((count = in.read(buf)) != -1) out.write(buf, 0, count); out.close(); in.close(); } catch (AmazonServiceException x) { Shrinker.myLogger.info("download error: " + x.getMessage()); throw new Exception("download exception", x); } catch (AmazonClientException x) { Shrinker.myLogger.info("download error: " + x.getMessage()); throw new Exception("download exception", x); } catch (IOException x) { Shrinker.myLogger.info("download error: " + x.getMessage()); throw new Exception("download exception", x); } finally { if (in != null) { try { in.close(); } catch (Exception e) { } } if (out != null) { try { out.close(); } catch (Exception e) { } } if (amazonS3Client != null) { try { amazonS3Client.shutdown(); } catch (Exception e) { } } } }
From source file:hu.mta.sztaki.lpds.cloud.entice.imageoptimizer.iaashandler.amazontarget.Storage.java
License:Apache License
/** * @param file Local file to upload// w w w . j a va 2s . co m * @param endpoint S3 endpoint URL * @param accessKey Access key * @param secretKey Secret key * @param bucket Bucket name * @param path Key name (path + file name) * @throws Exception On any error */ public static void upload(File file, String endpoint, String accessKey, String secretKey, String bucket, String path) throws Exception { AmazonS3Client amazonS3Client = null; try { AWSCredentials awsCredentials = new BasicAWSCredentials(accessKey, secretKey); ClientConfiguration clientConfiguration = new ClientConfiguration(); clientConfiguration.setMaxConnections(MAX_CONNECTIONS); clientConfiguration.setMaxErrorRetry(PredefinedRetryPolicies.DEFAULT_MAX_ERROR_RETRY); clientConfiguration.setConnectionTimeout(ClientConfiguration.DEFAULT_CONNECTION_TIMEOUT); amazonS3Client = new AmazonS3Client(awsCredentials, clientConfiguration); S3ClientOptions clientOptions = new S3ClientOptions().withPathStyleAccess(true); amazonS3Client.setS3ClientOptions(clientOptions); amazonS3Client.setEndpoint(endpoint); // amazonS3Client.putObject(new PutObjectRequest(bucket, path, file)); // up to 5GB TransferManager tm = new TransferManager(amazonS3Client); // up to 5TB Upload upload = tm.upload(bucket, path, file); // while (!upload.isDone()) { upload.getProgress().getBytesTransferred(); Thread.sleep(1000); } // to get progress upload.waitForCompletion(); tm.shutdownNow(); } catch (AmazonServiceException x) { Shrinker.myLogger.info("upload error: " + x.getMessage()); throw new Exception("upload exception", x); } catch (AmazonClientException x) { Shrinker.myLogger.info("upload error: " + x.getMessage()); throw new Exception("upload exception", x); } finally { if (amazonS3Client != null) { try { amazonS3Client.shutdown(); } catch (Exception e) { } } } }
From source file:io.crate.external.S3ClientHelper.java
License:Apache License
protected AmazonS3 initClient(@Nullable String accessKey, @Nullable String secretKey) throws IOException { if (accessKey == null || secretKey == null) { return new AmazonS3Client(DEFAULT_CREDENTIALS_PROVIDER_CHAIN, CLIENT_CONFIGURATION); }/*from w ww .java 2 s . c o m*/ return new AmazonS3Client(new BasicAWSCredentials(accessKey, secretKey), CLIENT_CONFIGURATION); }
From source file:jp.aws.test.AmazonClientManager.java
License:Apache License
/** * ?/*from ww w . ja va2 s .co m*/ */ public void validateCredentials() { if (s3Client == null || ec2Client == null) { Log.i(LOG_TAG, "Creating New Clients."); // ??? SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this.context); String access_key = prefs.getString("prefs_account_access_key", ""); String secret_key = prefs.getString("prefs_account_secret_key", ""); // ? ClientConfiguration clientconfiguration = new ClientConfiguration(); clientconfiguration.setConnectionTimeout(this.connectionTimeout); // (ms) AWSCredentials credentials = new BasicAWSCredentials(access_key, secret_key); s3Client = new AmazonS3Client(credentials, clientconfiguration); ec2Client = new AmazonEC2Client(credentials, clientconfiguration); // this.changeRegion(); } }
From source file:lumbermill.internal.aws.S3ClientImpl.java
License:Apache License
public void init() { ClientConfiguration awsConfig = new ClientConfiguration(); if (System.getenv("https_proxy") != null) { URI proxy = URI.create(System.getenv("https_proxy")); awsConfig.setProxyHost(proxy.getHost()); awsConfig.setProxyPort(proxy.getPort()); }//from ww w.j av a 2s .co m //awsConfig.setConnectionTimeout(2000); //awsConfig.setRequestTimeout(2000); //awsConfig.setSocketTimeout(2000); //awsConfig.setClientExecutionTimeout(2000); AWSCredentialsProvider credentials = new DefaultAWSCredentialsProviderChain(); if (roleArn.isPresent()) { credentials = new STSAssumeRoleSessionCredentialsProvider(credentials, roleArn.get(), "lumbermills3", awsConfig); } s3Client = new AmazonS3Client(credentials, awsConfig); }
From source file:net.smartcosmos.plugin.service.aws.storage.AwsS3StorageService.java
License:Apache License
@Override public InputStream retrieve(IFile file) throws IOException { Preconditions.checkArgument((file != null), "file must not be null"); AmazonS3 s3 = new AmazonS3Client(credentials, new ClientConfiguration().withProtocol(Protocol.HTTPS)); GetObjectRequest getObjectRequest = new GetObjectRequest(getBucketName(), file.getFileName()); S3Object storedObject = s3.getObject(getObjectRequest); return storedObject.getObjectContent(); }
From source file:net.smartcosmos.plugin.service.aws.storage.AwsS3StorageService.java
License:Apache License
@Override public void delete(IFile file) throws IOException { AmazonS3 s3 = new AmazonS3Client(credentials, new ClientConfiguration().withProtocol(Protocol.HTTPS)); DeleteObjectRequest deleteObjectRequest = new DeleteObjectRequest(getBucketName(), file.getFileName()); s3.deleteObject(deleteObjectRequest); }