use of com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration in project georocket by georocket.
the class S3Store method getS3Client.
/**
* Get or initialize the S3 client.
* Note: this method must be synchronized because we're accessing the
* {@link #s3Client} field and we're calling this method from a worker thread.
* @return the S3 client
*/
private synchronized AmazonS3 getS3Client() {
if (s3Client == null) {
BasicAWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);
AmazonS3ClientBuilder builder = AmazonS3ClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(credentials));
if (forceSignatureV2) {
ClientConfigurationFactory configFactory = new ClientConfigurationFactory();
ClientConfiguration config = configFactory.getConfig();
config.setSignerOverride("S3SignerType");
builder = builder.withClientConfiguration(config);
}
String endpoint = "http://" + host + ":" + port;
String clientRegion = null;
if (!ServiceUtils.isS3USStandardEndpoint(endpoint)) {
clientRegion = AwsHostNameUtils.parseRegion(host, AmazonS3Client.S3_SERVICE_NAME);
}
builder = builder.withEndpointConfiguration(new EndpointConfiguration(endpoint, clientRegion));
builder = builder.withPathStyleAccessEnabled(pathStyleAccess);
s3Client = builder.build();
}
return s3Client;
}
use of com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration in project aws-doc-sdk-examples by awsdocs.
the class DocumentText method main.
public static void main(String[] arg) throws Exception {
// The S3 bucket and document
String document = "";
String bucket = "";
AmazonS3 s3client = AmazonS3ClientBuilder.standard().withEndpointConfiguration(new EndpointConfiguration("https://s3.amazonaws.com", "us-east-1")).build();
// Get the document from S3
com.amazonaws.services.s3.model.S3Object s3object = s3client.getObject(bucket, document);
S3ObjectInputStream inputStream = s3object.getObjectContent();
BufferedImage image = ImageIO.read(inputStream);
// Call DetectDocumentText
EndpointConfiguration endpoint = new EndpointConfiguration("https://textract.us-east-1.amazonaws.com", "us-east-1");
AmazonTextract client = AmazonTextractClientBuilder.standard().withEndpointConfiguration(endpoint).build();
DetectDocumentTextRequest request = new DetectDocumentTextRequest().withDocument(new Document().withS3Object(new S3Object().withName(document).withBucket(bucket)));
DetectDocumentTextResult result = client.detectDocumentText(request);
// Create frame and panel.
JFrame frame = new JFrame("RotateImage");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
DocumentText panel = new DocumentText(result, image);
panel.setPreferredSize(new Dimension(image.getWidth(), image.getHeight()));
frame.setContentPane(panel);
frame.pack();
frame.setVisible(true);
}
use of com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration in project aws-doc-sdk-examples by awsdocs.
the class AnalyzeDocument method main.
public static void main(String[] arg) throws Exception {
// The S3 bucket and document
String document = "";
String bucket = "";
AmazonS3 s3client = AmazonS3ClientBuilder.standard().withEndpointConfiguration(new EndpointConfiguration("https://s3.amazonaws.com", "us-east-1")).build();
// Get the document from S3
com.amazonaws.services.s3.model.S3Object s3object = s3client.getObject(bucket, document);
S3ObjectInputStream inputStream = s3object.getObjectContent();
BufferedImage image = ImageIO.read(inputStream);
// Call AnalyzeDocument
EndpointConfiguration endpoint = new EndpointConfiguration("https://textract.us-east-1.amazonaws.com", "us-east-1");
AmazonTextract client = AmazonTextractClientBuilder.standard().withEndpointConfiguration(endpoint).build();
AnalyzeDocumentRequest request = new AnalyzeDocumentRequest().withFeatureTypes("TABLES", "FORMS").withDocument(new Document().withS3Object(new S3Object().withName(document).withBucket(bucket)));
AnalyzeDocumentResult result = client.analyzeDocument(request);
// Create frame and panel.
JFrame frame = new JFrame("RotateImage");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
AnalyzeDocument panel = new AnalyzeDocument(result, image);
panel.setPreferredSize(new Dimension(image.getWidth(), image.getHeight()));
frame.setContentPane(panel);
frame.pack();
frame.setVisible(true);
}
use of com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration in project beam by apache.
the class S3FileSystemTest method beforeClass.
@BeforeClass
public static void beforeClass() {
api = new S3Mock.Builder().withInMemoryBackend().build();
Http.ServerBinding binding = api.start();
EndpointConfiguration endpoint = new EndpointConfiguration("http://localhost:" + binding.localAddress().getPort(), "us-west-2");
client = AmazonS3ClientBuilder.standard().withPathStyleAccessEnabled(true).withEndpointConfiguration(endpoint).withCredentials(new AWSStaticCredentialsProvider(new AnonymousAWSCredentials())).build();
}
use of com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration in project ats-framework by Axway.
the class S3Operations method getClient.
/**
* Gets configured AmazonS3 client instance. Does not perform actual request until first remote data is needed
*/
private AmazonS3 getClient() {
if (s3Client != null) {
// already cached
return s3Client;
}
ClientConfiguration config = new ClientConfiguration();
if (endpoint != null && endpoint.startsWith("https://")) {
config.setProtocol(Protocol.HTTPS);
} else {
config.setProtocol(Protocol.HTTP);
}
BasicAWSCredentials creds = new BasicAWSCredentials(accessKey, secretKey);
if (LOG.isDebugEnabled()) {
LOG.debug("Creating S3 client to " + ((endpoint == null) ? "default Amazon" : endpoint) + " endpoint with access key " + accessKey);
}
if (this.endpoint != null) {
if (region == null || region.trim().length() == 0) {
region = Regions.DEFAULT_REGION.name();
}
s3Client = AmazonS3ClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(creds)).withEndpointConfiguration(new EndpointConfiguration(endpoint, region)).withClientConfiguration(config).withPathStyleAccessEnabled(true).build();
} else {
s3Client = AmazonS3ClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(creds)).withClientConfiguration(config).withPathStyleAccessEnabled(true).build();
}
return s3Client;
}
Aggregations