Search in sources :

Example 6 with EndpointConfiguration

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;
}
Also used : AWSStaticCredentialsProvider(com.amazonaws.auth.AWSStaticCredentialsProvider) AmazonS3ClientBuilder(com.amazonaws.services.s3.AmazonS3ClientBuilder) ClientConfigurationFactory(com.amazonaws.ClientConfigurationFactory) EndpointConfiguration(com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) ClientConfiguration(com.amazonaws.ClientConfiguration)

Example 7 with EndpointConfiguration

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);
}
Also used : AmazonS3(com.amazonaws.services.s3.AmazonS3) S3ObjectInputStream(com.amazonaws.services.s3.model.S3ObjectInputStream) DetectDocumentTextRequest(com.amazonaws.services.textract.model.DetectDocumentTextRequest) Document(com.amazonaws.services.textract.model.Document) AmazonTextract(com.amazonaws.services.textract.AmazonTextract) BufferedImage(java.awt.image.BufferedImage) DetectDocumentTextResult(com.amazonaws.services.textract.model.DetectDocumentTextResult) EndpointConfiguration(com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration) S3Object(com.amazonaws.services.textract.model.S3Object)

Example 8 with EndpointConfiguration

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);
}
Also used : AmazonS3(com.amazonaws.services.s3.AmazonS3) S3ObjectInputStream(com.amazonaws.services.s3.model.S3ObjectInputStream) Document(com.amazonaws.services.textract.model.Document) AmazonTextract(com.amazonaws.services.textract.AmazonTextract) BufferedImage(java.awt.image.BufferedImage) AnalyzeDocumentResult(com.amazonaws.services.textract.model.AnalyzeDocumentResult) EndpointConfiguration(com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration) S3Object(com.amazonaws.services.textract.model.S3Object) AnalyzeDocumentRequest(com.amazonaws.services.textract.model.AnalyzeDocumentRequest)

Example 9 with EndpointConfiguration

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();
}
Also used : AWSStaticCredentialsProvider(com.amazonaws.auth.AWSStaticCredentialsProvider) AnonymousAWSCredentials(com.amazonaws.auth.AnonymousAWSCredentials) Http(akka.http.scaladsl.Http) EndpointConfiguration(com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration) S3Mock(io.findify.s3mock.S3Mock) BeforeClass(org.junit.BeforeClass)

Example 10 with EndpointConfiguration

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;
}
Also used : AWSStaticCredentialsProvider(com.amazonaws.auth.AWSStaticCredentialsProvider) EndpointConfiguration(com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration) ClientConfiguration(com.amazonaws.ClientConfiguration) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials)

Aggregations

EndpointConfiguration (com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration)13 AWSStaticCredentialsProvider (com.amazonaws.auth.AWSStaticCredentialsProvider)6 ClientConfiguration (com.amazonaws.ClientConfiguration)5 BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)5 AmazonS3ClientBuilder (com.amazonaws.services.s3.AmazonS3ClientBuilder)4 Region (com.amazonaws.regions.Region)3 AmazonS3 (com.amazonaws.services.s3.AmazonS3)3 ClientConfigurationFactory (com.amazonaws.ClientConfigurationFactory)2 AWSCredentialsProvider (com.amazonaws.auth.AWSCredentialsProvider)2 DefaultAwsRegionProviderChain (com.amazonaws.regions.DefaultAwsRegionProviderChain)2 AWSMediaStoreData (com.amazonaws.services.mediastoredata.AWSMediaStoreData)2 S3ObjectInputStream (com.amazonaws.services.s3.model.S3ObjectInputStream)2 AmazonTextract (com.amazonaws.services.textract.AmazonTextract)2 Document (com.amazonaws.services.textract.model.Document)2 S3Object (com.amazonaws.services.textract.model.S3Object)2 BufferedImage (java.awt.image.BufferedImage)2 Http (akka.http.scaladsl.Http)1 Protocol (com.amazonaws.Protocol)1 AnonymousAWSCredentials (com.amazonaws.auth.AnonymousAWSCredentials)1 AWSGlueAsyncClientBuilder (com.amazonaws.services.glue.AWSGlueAsyncClientBuilder)1