List of usage examples for com.amazonaws.services.s3 S3ClientOptions setPathStyleAccess
@Deprecated public void setPathStyleAccess(boolean pathStyleAccess)
From source file:org.apache.streams.s3.S3PersistReader.java
License:Apache License
public void prepare(Object configurationObject) { // Connect to S3 synchronized (this) { // Create the credentials Object AWSCredentials credentials = new BasicAWSCredentials(s3ReaderConfiguration.getKey(), s3ReaderConfiguration.getSecretKey()); ClientConfiguration clientConfig = new ClientConfiguration(); clientConfig.setProtocol(Protocol.valueOf(s3ReaderConfiguration.getProtocol().toString())); // We do not want path style access S3ClientOptions clientOptions = new S3ClientOptions(); clientOptions.setPathStyleAccess(false); this.amazonS3Client = new AmazonS3Client(credentials, clientConfig); if (!Strings.isNullOrEmpty(s3ReaderConfiguration.getRegion())) this.amazonS3Client .setRegion(Region.getRegion(Regions.fromName(s3ReaderConfiguration.getRegion()))); this.amazonS3Client.setS3ClientOptions(clientOptions); }/* www . j a v a2s. c o m*/ final ListObjectsRequest request = new ListObjectsRequest() .withBucketName(this.s3ReaderConfiguration.getBucket()) .withPrefix(s3ReaderConfiguration.getReaderPath()).withMaxKeys(500); ObjectListing listing = this.amazonS3Client.listObjects(request); this.files = new ArrayList<String>(); /** * If you can list files that are in this path, then you must be dealing with a directory * if you cannot list files that are in this path, then you are most likely dealing with * a simple file. */ boolean hasCommonPrefixes = listing.getCommonPrefixes().size() > 0 ? true : false; boolean hasObjectSummaries = listing.getObjectSummaries().size() > 0 ? true : false; if (hasCommonPrefixes || hasObjectSummaries) { // Handle the 'directory' use case do { if (hasCommonPrefixes) { for (String file : listing.getCommonPrefixes()) { this.files.add(file); } } else { for (final S3ObjectSummary objectSummary : listing.getObjectSummaries()) { this.files.add(objectSummary.getKey()); } } // get the next batch. listing = this.amazonS3Client.listNextBatchOfObjects(listing); } while (listing.isTruncated()); } else { // handle the single file use-case this.files.add(s3ReaderConfiguration.getReaderPath()); } if (this.files.size() <= 0) LOGGER.error("There are no files to read"); this.persistQueue = Queues.synchronizedQueue(new LinkedBlockingQueue<StreamsDatum>(10000)); this.executor = Executors.newSingleThreadExecutor(); }
From source file:org.apache.streams.s3.S3PersistWriter.java
License:Apache License
public void prepare(Object configurationObject) { // Connect to S3 synchronized (this) { try {//w ww . java 2 s.com // if the user has chosen to not set the object mapper, then set a default object mapper for them. if (this.objectMapper == null) this.objectMapper = new StreamsJacksonMapper(); // Create the credentials Object if (this.amazonS3Client == null) { AWSCredentials credentials = new BasicAWSCredentials(s3WriterConfiguration.getKey(), s3WriterConfiguration.getSecretKey()); ClientConfiguration clientConfig = new ClientConfiguration(); clientConfig.setProtocol(Protocol.valueOf(s3WriterConfiguration.getProtocol().toString())); // We do not want path style access S3ClientOptions clientOptions = new S3ClientOptions(); clientOptions.setPathStyleAccess(false); this.amazonS3Client = new AmazonS3Client(credentials, clientConfig); if (!Strings.isNullOrEmpty(s3WriterConfiguration.getRegion())) this.amazonS3Client .setRegion(Region.getRegion(Regions.fromName(s3WriterConfiguration.getRegion()))); this.amazonS3Client.setS3ClientOptions(clientOptions); } } catch (Exception e) { LOGGER.error("Exception while preparing the S3 client: {}", e); } Preconditions.checkArgument(this.amazonS3Client != null); } }
From source file:org.caboclo.clients.AmazonClient.java
License:Open Source License
private AmazonS3 getS3_() throws AmazonClientException { AmazonS3 s3_;//w w w. j a va 2s . c o m S3ClientOptions s3ClientOptions; // AWSCredentials credentials = new BasicAWSCredentials(Constants.EC2_ACCESS_KEY, Constants.EC2_SECRET_KEY); AWSCredentials credentials = new BasicAWSCredentials(getAuthenticationParameter(ACCESS_KEY), getAuthenticationParameter(SECRET_KEY)); s3_ = new AmazonS3Client(credentials); s3ClientOptions = new S3ClientOptions(); //s3_.setEndpoint(Constants.EC2_END_POINT); s3ClientOptions.setPathStyleAccess(true); s3_.setS3ClientOptions(s3ClientOptions); System.out.println(s3_.listBuckets()); return s3_; }
From source file:org.geowebcache.s3.S3BlobStoreInfo.java
License:Open Source License
/** @return {@link AmazonS3Client} constructed from this {@link S3BlobStoreInfo}. */ public AmazonS3Client buildClient() { ClientConfiguration clientConfig = new ClientConfiguration(); if (null != useHTTPS) { clientConfig.setProtocol(useHTTPS ? Protocol.HTTPS : Protocol.HTTP); }//from www. java 2 s .c o m if (null != maxConnections && maxConnections > 0) { clientConfig.setMaxConnections(maxConnections); } clientConfig.setProxyDomain(proxyDomain); clientConfig.setProxyWorkstation(proxyWorkstation); clientConfig.setProxyHost(proxyHost); if (null != proxyPort) { clientConfig.setProxyPort(proxyPort); } clientConfig.setProxyUsername(proxyUsername); clientConfig.setProxyPassword(proxyPassword); if (null != useGzip) { clientConfig.setUseGzip(useGzip); } log.debug("Initializing AWS S3 connection"); AmazonS3Client client = new AmazonS3Client(getCredentialsProvider(), clientConfig); if (endpoint != null && !"".equals(endpoint)) { S3ClientOptions s3ClientOptions = new S3ClientOptions(); s3ClientOptions.setPathStyleAccess(true); client.setS3ClientOptions(s3ClientOptions); client.setEndpoint(endpoint); } if (!client.doesBucketExist(bucket)) { client.createBucket(bucket); } return client; }